[Bf-blender-cvs] [8174f8f] workspaces: Add a workspace browsing button to Info Editor header

Julian Eisel noreply at git.blender.org
Fri Dec 2 11:42:52 CET 2016


Commit: 8174f8fcbe1ae5ee2e52de0acd49f7d649a016c7
Author: Julian Eisel
Date:   Fri Dec 2 01:25:05 2016 +0100
Branches: workspaces
https://developer.blender.org/rB8174f8fcbe1ae5ee2e52de0acd49f7d649a016c7

Add a workspace browsing button to Info Editor header

And actually make it work.

===================================================================

M	release/scripts/startup/bl_ui/space_info.py
M	source/blender/blenkernel/intern/workspace.c
M	source/blender/editors/screen/screen_ops.c
M	source/blender/makesrna/intern/rna_main_api.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_info.py b/release/scripts/startup/bl_ui/space_info.py
index d77113e..84464a6 100644
--- a/release/scripts/startup/bl_ui/space_info.py
+++ b/release/scripts/startup/bl_ui/space_info.py
@@ -40,6 +40,7 @@ class INFO_HT_header(Header):
             layout.operator("screen.back_to_previous", icon='SCREEN_BACK', text="Back to Previous")
             layout.separator()
         else:
+            layout.template_ID(context.window, "workspace", new="workspace.workspace_new", unlink="workspace.workspace_delete")
             layout.template_ID_preview(context.window, "screen", new="screen.new", unlink="screen.delete", rows=2, cols=6)
             layout.template_ID(context.screen, "scene", new="scene.new", unlink="scene.delete")
 
diff --git a/source/blender/blenkernel/intern/workspace.c b/source/blender/blenkernel/intern/workspace.c
index 5893443..0151f9a 100644
--- a/source/blender/blenkernel/intern/workspace.c
+++ b/source/blender/blenkernel/intern/workspace.c
@@ -45,5 +45,5 @@ WorkSpace *BKE_workspace_duplicate(Main *bmain, const WorkSpace *from)
 
 void BKE_workspace_free(WorkSpace *ws)
 {
-	(void)ws;
+	UNUSED_VARS(ws);
 }
diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c
index 813551a..5a8b122 100644
--- a/source/blender/editors/screen/screen_ops.c
+++ b/source/blender/editors/screen/screen_ops.c
@@ -4279,6 +4279,61 @@ static void SCREEN_OT_space_context_cycle(wmOperatorType *ot)
 	             "Direction to cycle through");
 }
 
+/* **** Workspaces **** */
+/* For now here, should later get its own module */
+
+static int workspace_new_exec(bContext *C, wmOperator *UNUSED(op))
+{
+	wmWindow *win = CTX_wm_window(C);
+	WorkSpace *old_ws = win->workspace;
+
+	/* TODO API function to activate workspace */
+	id_us_min(&old_ws->id);
+	id_us_ensure_real(&old_ws->id);
+	win->workspace = BKE_workspace_duplicate(CTX_data_main(C), old_ws);
+//	WM_event_add_notifier(C, NC_SCREEN | ND_SCREENBROWSE, sc); /* TODO own notifier */
+
+	return OPERATOR_FINISHED;
+}
+
+static void WORKSPACE_OT_workspace_new(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "New Workspace";
+	ot->description = "Add a new workspace";
+	ot->idname = "WORKSPACE_OT_workspace_new";
+
+	/* api callbacks */
+	ot->exec = workspace_new_exec;
+	ot->poll = WM_operator_winactive;
+}
+
+static int workspace_delete_exec(bContext *C, wmOperator *UNUSED(op))
+{
+	Main *bmain = CTX_data_main(C);
+	wmWindow *win = CTX_wm_window(C);
+
+	/* TODO API function to remove workspace */
+	if (!BLI_listbase_is_single(&bmain->workspaces)) {
+		WorkSpace *ws_next = win->workspace->id.next;
+		BKE_libblock_free(bmain, win->workspace);
+		win->workspace = ws_next ? ws_next : bmain->workspaces.first;
+		id_us_plus(&win->workspace->id);
+	}
+
+	return OPERATOR_FINISHED;
+}
+
+static void WORKSPACE_OT_workspace_delete(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Delete Workspace";
+	ot->description = "Delete the active workspace";
+	ot->idname = "WORKSPACE_OT_workspace_delete";
+
+	/* api callbacks */
+	ot->exec = workspace_delete_exec;
+}
 
 /* ****************  Assigning operatortypes to global list, adding handlers **************** */
 
@@ -4331,7 +4386,9 @@ void ED_operatortypes_screen(void)
 	WM_operatortype_append(SCREEN_OT_delete);
 	WM_operatortype_append(SCENE_OT_new);
 	WM_operatortype_append(SCENE_OT_delete);
-	
+	WM_operatortype_append(WORKSPACE_OT_workspace_new);
+	WM_operatortype_append(WORKSPACE_OT_workspace_delete);
+
 	/* tools shared by more space types */
 	WM_operatortype_append(ED_OT_undo);
 	WM_operatortype_append(ED_OT_undo_push);
diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c
index d2f0060..9bb603a 100644
--- a/source/blender/makesrna/intern/rna_main_api.c
+++ b/source/blender/makesrna/intern/rna_main_api.c
@@ -83,6 +83,7 @@
 #include "BKE_mask.h"
 #include "BKE_gpencil.h"
 #include "BKE_linestyle.h"
+#include "BKE_workspace.h"
 
 #include "DNA_armature_types.h"
 #include "DNA_camera_types.h"




More information about the Bf-blender-cvs mailing list