Workspaces: switch object mode when switching workspaces.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Tue, 21 Aug 2018 13:27:29 +0000 (15:27 +0200)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Thu, 30 Aug 2018 14:10:03 +0000 (16:10 +0200)
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.

release/scripts/startup/bl_ui/__init__.py
release/scripts/startup/bl_ui/properties_workspace.py [moved from release/scripts/startup/bl_ui/properties_data_workspace.py with 92% similarity]
source/blender/blenloader/intern/versioning_defaults.c
source/blender/editors/screen/workspace_edit.c
source/blender/makesdna/DNA_workspace_types.h
source/blender/makesrna/RNA_enum_types.h
source/blender/makesrna/intern/rna_object.c
source/blender/makesrna/intern/rna_workspace.c

index d88cee4..093739c 100644 (file)
@@ -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
@@ -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,
 )
 
index e6f8e70..1fd82d0 100644 (file)
@@ -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) {
index 246d2fe..77fc20a 100644 (file)
@@ -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;
 }
 
 /**
index 3eb40bf..fd56c24 100644 (file)
@@ -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). */
index 8d3d7f8..613454e 100644 (file)
@@ -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[];
index ec5daa6..6fbd7ab 100644 (file)
@@ -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", ""},
index db6a58f..b9ca641 100644 (file)
@@ -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);