[Bf-blender-cvs] [9f78f471d7a] blender2.8: Workspaces: switch object mode when switching workspaces.

Brecht Van Lommel noreply at git.blender.org
Thu Aug 30 16:20:47 CEST 2018


Commit: 9f78f471d7aeacd357349f0eb4b8f8bbc01db756
Author: Brecht Van Lommel
Date:   Tue Aug 21 15:27:29 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB9f78f471d7aeacd357349f0eb4b8f8bbc01db756

Workspaces: switch object mode when switching workspaces.

In the workspace properties a mode can now be configured that is
automatically enabled when switching to the workspace.

This is a test to validate how well it works. The weak point is
that if you don't have an appropriate object already select it will
not switch modes.

See T56475.

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

M	release/scripts/startup/bl_ui/__init__.py
R092	release/scripts/startup/bl_ui/properties_data_workspace.py	release/scripts/startup/bl_ui/properties_workspace.py
M	source/blender/blenloader/intern/versioning_defaults.c
M	source/blender/editors/screen/workspace_edit.c
M	source/blender/makesdna/DNA_workspace_types.h
M	source/blender/makesrna/RNA_enum_types.h
M	source/blender/makesrna/intern/rna_object.c
M	source/blender/makesrna/intern/rna_workspace.c

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

diff --git a/release/scripts/startup/bl_ui/__init__.py b/release/scripts/startup/bl_ui/__init__.py
index d88cee4424b..093739c5b08 100644
--- a/release/scripts/startup/bl_ui/__init__.py
+++ b/release/scripts/startup/bl_ui/__init__.py
@@ -92,7 +92,7 @@ _modules = [
     "space_view3d_toolbar",
 
     # XXX, keep last so panels show after all other tool options.
-    "properties_data_workspace",
+    "properties_workspace",
 ]
 
 import bpy
diff --git a/release/scripts/startup/bl_ui/properties_data_workspace.py b/release/scripts/startup/bl_ui/properties_workspace.py
similarity index 92%
rename from release/scripts/startup/bl_ui/properties_data_workspace.py
rename to release/scripts/startup/bl_ui/properties_workspace.py
index b01ed640b2c..d07e2dbbaf6 100644
--- a/release/scripts/startup/bl_ui/properties_data_workspace.py
+++ b/release/scripts/startup/bl_ui/properties_workspace.py
@@ -36,11 +36,15 @@ class WORKSPACE_PT_main(WorkSpaceButtonsPanel, Panel):
     bl_options = {'DEFAULT_CLOSED'}
 
     def draw(self, context):
-        pass
+        workspace = context.workspace
+
+        layout = self.layout
+        layout.use_property_split = True
+        layout.prop(workspace, "object_mode", text="Mode")
 
 
-class WORKSPACE_PT_owner_ids(WorkSpaceButtonsPanel, Panel):
-    bl_label = "Workspace Add-ons"
+class WORKSPACE_PT_addons(WorkSpaceButtonsPanel, Panel):
+    bl_label = "Filter Add-ons"
     bl_parent_id = "WORKSPACE_PT_main"
 
     def draw_header(self, context):
@@ -102,7 +106,7 @@ class WORKSPACE_PT_custom_props(WorkSpaceButtonsPanel, PropertyPanel, Panel):
 
 classes = (
     WORKSPACE_PT_main,
-    WORKSPACE_PT_owner_ids,
+    WORKSPACE_PT_addons,
     WORKSPACE_PT_custom_props,
 )
 
diff --git a/source/blender/blenloader/intern/versioning_defaults.c b/source/blender/blenloader/intern/versioning_defaults.c
index e6f8e70f70b..1fd82d01cf5 100644
--- a/source/blender/blenloader/intern/versioning_defaults.c
+++ b/source/blender/blenloader/intern/versioning_defaults.c
@@ -76,6 +76,26 @@ void BLO_update_defaults_userpref_blend(void)
  * This function can be emptied each time the startup.blend is updated. */
 void BLO_update_defaults_startup_blend(Main *bmain)
 {
+	for (WorkSpace *workspace = bmain->workspaces.first; workspace; workspace = workspace->id.next) {
+		const char *name = workspace->id.name + 2;
+
+		if (STREQ(name, "2D Animation")) {
+			workspace->object_mode = OB_MODE_GPENCIL_PAINT;
+		}
+		if (STREQ(name, "3D Animation")) {
+			workspace->object_mode = OB_MODE_POSE;
+		}
+		else if (STREQ(name, "Texture Paint")) {
+			workspace->object_mode = OB_MODE_TEXTURE_PAINT;
+		}
+		else if (STREQ(name, "Sculpting")) {
+			workspace->object_mode = OB_MODE_SCULPT;
+		}
+		else if (STREQ(name, "UV Editing")) {
+			workspace->object_mode = OB_MODE_EDIT;
+		}
+	}
+
 	for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
 		for (ScrArea *area = screen->areabase.first; area; area = area->next) {
 			for (ARegion *ar = area->regionbase.first; ar; ar = ar->next) {
diff --git a/source/blender/editors/screen/workspace_edit.c b/source/blender/editors/screen/workspace_edit.c
index 246d2fed1a1..77fc20a98a5 100644
--- a/source/blender/editors/screen/workspace_edit.c
+++ b/source/blender/editors/screen/workspace_edit.c
@@ -172,24 +172,29 @@ bool ED_workspace_change(
 	screen_new = screen_change_prepare(screen_old, screen_new, bmain, C, win);
 	BLI_assert(BKE_workspace_layout_screen_get(layout_new) == screen_new);
 
-	if (screen_new) {
-		BKE_workspace_hook_layout_for_workspace_set(win->workspace_hook, workspace_new, layout_new);
-		BKE_workspace_active_set(win->workspace_hook, workspace_new);
+	if (screen_new == NULL) {
+		return false;
+	}
 
-		/* update screen *after* changing workspace - which also causes the
-		 * actual screen change and updates context (including CTX_wm_workspace) */
-		screen_change_update(C, win, screen_new);
-		workspace_change_update(workspace_new, workspace_old, C, wm);
+	BKE_workspace_hook_layout_for_workspace_set(win->workspace_hook, workspace_new, layout_new);
+	BKE_workspace_active_set(win->workspace_hook, workspace_new);
 
-		BLI_assert(CTX_wm_workspace(C) == workspace_new);
+	/* update screen *after* changing workspace - which also causes the
+	 * actual screen change and updates context (including CTX_wm_workspace) */
+	screen_change_update(C, win, screen_new);
+	workspace_change_update(workspace_new, workspace_old, C, wm);
 
-		WM_toolsystem_unlink_all(C, workspace_old);
-		WM_toolsystem_reinit_all(C, win);
+	BLI_assert(CTX_wm_workspace(C) == workspace_new);
 
-		return true;
+	WM_toolsystem_unlink_all(C, workspace_old);
+	WM_toolsystem_reinit_all(C, win);
+
+	/* Automatic mode switching. */
+	if (workspace_new->object_mode != workspace_old->object_mode) {
+		ED_object_mode_generic_enter(C, workspace_new->object_mode);
 	}
 
-	return false;
+	return true;
 }
 
 /**
diff --git a/source/blender/makesdna/DNA_workspace_types.h b/source/blender/makesdna/DNA_workspace_types.h
index 3eb40bfa523..fd56c246c96 100644
--- a/source/blender/makesdna/DNA_workspace_types.h
+++ b/source/blender/makesdna/DNA_workspace_types.h
@@ -144,8 +144,10 @@ typedef struct WorkSpace {
 	char tools_space_type;
 	/** Type is different for each space-type. */
 	char tools_mode;
+	char _pad[6];
+
+	int object_mode;
 
-	char _pad[2];
 	int flags DNA_PRIVATE_WORKSPACE; /* enum eWorkSpaceFlags */
 
 	/* Info text from modal operators (runtime). */
diff --git a/source/blender/makesrna/RNA_enum_types.h b/source/blender/makesrna/RNA_enum_types.h
index 8d3d7f81deb..613454e2f33 100644
--- a/source/blender/makesrna/RNA_enum_types.h
+++ b/source/blender/makesrna/RNA_enum_types.h
@@ -43,6 +43,7 @@ extern const EnumPropertyItem DummyRNA_DEFAULT_items[];
 extern const EnumPropertyItem rna_enum_id_type_items[];
 
 extern const EnumPropertyItem rna_enum_object_mode_items[];
+extern const EnumPropertyItem rna_enum_workspace_object_mode_items[];
 extern const EnumPropertyItem rna_enum_object_empty_drawtype_items[];
 extern const EnumPropertyItem rna_enum_object_gpencil_type_items[];
 extern const EnumPropertyItem rna_enum_metaelem_type_items[];
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c
index ec5daa69d6d..6fbd7abaa39 100644
--- a/source/blender/makesrna/intern/rna_object.c
+++ b/source/blender/makesrna/intern/rna_object.c
@@ -81,6 +81,23 @@ const EnumPropertyItem rna_enum_object_mode_items[] = {
 	{0, NULL, 0, NULL, NULL}
 };
 
+/* Same as above, but with names that distinguish grease pencil. */
+const EnumPropertyItem rna_enum_workspace_object_mode_items[] = {
+	{OB_MODE_OBJECT, "OBJECT", ICON_OBJECT_DATAMODE, "Object Mode", ""},
+	{OB_MODE_EDIT, "EDIT", ICON_EDITMODE_HLT, "Edit Mode", ""},
+	{OB_MODE_POSE, "POSE", ICON_POSE_HLT, "Pose Mode", ""},
+	{OB_MODE_SCULPT, "SCULPT", ICON_SCULPTMODE_HLT, "Sculpt Mode", ""},
+	{OB_MODE_VERTEX_PAINT, "VERTEX_PAINT", ICON_VPAINT_HLT, "Vertex Paint", ""},
+	{OB_MODE_WEIGHT_PAINT, "WEIGHT_PAINT", ICON_WPAINT_HLT, "Weight Paint", ""},
+	{OB_MODE_TEXTURE_PAINT, "TEXTURE_PAINT", ICON_TPAINT_HLT, "Texture Paint", ""},
+	{OB_MODE_PARTICLE_EDIT, "PARTICLE_EDIT", ICON_PARTICLEMODE, "Particle Edit", ""},
+	{OB_MODE_GPENCIL_EDIT, "GPENCIL_EDIT", ICON_EDITMODE_HLT, "Grease Pencil Edit Mode", "Edit Grease Pencil Strokes"},
+	{OB_MODE_GPENCIL_SCULPT, "GPENCIL_SCULPT", ICON_SCULPTMODE_HLT, "Grease Pencil Sculpt Mode", "Sculpt Grease Pencil Strokes"},
+	{OB_MODE_GPENCIL_PAINT, "GPENCIL_PAINT", ICON_GREASEPENCIL, "Grease Pencil Draw", "Paint Grease Pencil Strokes"},
+	{OB_MODE_GPENCIL_WEIGHT, "GPENCIL_WEIGHT", ICON_WPAINT_HLT, "Grease Pencil Weight Paint", "Grease Pencil Weight Paint Strokes" },
+	{0, NULL, 0, NULL, NULL}
+};
+
 const EnumPropertyItem rna_enum_object_empty_drawtype_items[] = {
 	{OB_PLAINAXES, "PLAIN_AXES", 0, "Plain Axes", ""},
 	{OB_ARROWS, "ARROWS", 0, "Arrows", ""},
diff --git a/source/blender/makesrna/intern/rna_workspace.c b/source/blender/makesrna/intern/rna_workspace.c
index db6a58fa85e..b9ca6412f7a 100644
--- a/source/blender/makesrna/intern/rna_workspace.c
+++ b/source/blender/makesrna/intern/rna_workspace.c
@@ -320,11 +320,9 @@ static void rna_def_workspace(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Active Tool Space", "Tool mode");
 	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
 
-#if 0
 	prop = RNA_def_property(srna, "object_mode", PROP_ENUM, PROP_NONE);
-	RNA_def_property_enum_items(prop, rna_enum_object_mode_items);
-	RNA_def_property_ui_text(prop, "Mode", "Object interaction mode used in this window");
-#endif
+	RNA_def_property_enum_items(prop, rna_enum_workspace_object_mode_items);
+	RNA_def_property_ui_text(prop, "Object Mode", "Switch to this object mode when activating the workspace");
 
 	/* Flags */
 	prop = RNA_def_property(srna, "use_filter_by_owner", PROP_BOOLEAN, PROP_NONE);



More information about the Bf-blender-cvs mailing list