[Bf-blender-cvs] [73eb89c] workspaces: Make object mode part of the workspace

Julian Eisel noreply at git.blender.org
Wed Jan 4 23:36:58 CET 2017


Commit: 73eb89c64343f329199347457da13be26ae580ea
Author: Julian Eisel
Date:   Wed Jan 4 23:12:51 2017 +0100
Branches: workspaces
https://developer.blender.org/rB73eb89c64343f329199347457da13be26ae580ea

Make object mode part of the workspace

Each workspace now stores the last set object mode type, activating a workspace also activates this mode. This commit also removes the object mode menu from the 3D view header, it's displayed in the info editor header now (and later will be in the top-bar).

We have one issue with Grease Pencil here though: The active grease pencil data-block depends on the active editor, and an editor can only enter GPencil edit mode if it has an active GPencil data-block. The new object mode menu is independent of 3D Views (or any other editor supporting GPencil) though. For now the menu simply won't show the GPencil edit mode item, it will be back once GPencil gets its own object type (as planned). GPencil still provides other ways to enter this mode.

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

M	release/scripts/startup/bl_ui/space_info.py
M	source/blender/blenkernel/BKE_workspace.h
M	source/blender/blenkernel/intern/workspace.c
M	source/blender/editors/include/ED_screen.h
M	source/blender/editors/object/object_edit.c
M	source/blender/editors/screen/workspace_edit.c
M	source/blender/editors/space_view3d/view3d_header.c
M	source/blender/makesdna/dna_workspace_types.h
M	source/blender/makesrna/intern/rna_workspace.c
M	source/blender/windowmanager/intern/wm_event_system.c
M	source/blenderplayer/bad_level_call_stubs/stubs.c

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

diff --git a/release/scripts/startup/bl_ui/space_info.py b/release/scripts/startup/bl_ui/space_info.py
index 8c8f33c..01b3fe1 100644
--- a/release/scripts/startup/bl_ui/space_info.py
+++ b/release/scripts/startup/bl_ui/space_info.py
@@ -51,6 +51,9 @@ class INFO_HT_header(Header):
         if rd.has_multiple_engines:
             layout.prop(rd, "engine", text="")
 
+        act_mode_item = bpy.types.Object.bl_rna.properties['mode'].enum_items[context.workspace.object_mode]
+        layout.operator_menu_enum("object.mode_set", "mode", text=act_mode_item.name, icon=act_mode_item.icon)
+
         layout.separator()
 
         layout.template_running_jobs()
diff --git a/source/blender/blenkernel/BKE_workspace.h b/source/blender/blenkernel/BKE_workspace.h
index 9b7eb6c..8c33edd 100644
--- a/source/blender/blenkernel/BKE_workspace.h
+++ b/source/blender/blenkernel/BKE_workspace.h
@@ -76,8 +76,10 @@ struct ID *BKE_workspace_id_get(WorkSpace *workspace);
 const char *BKE_workspace_name_get(const WorkSpace *workspace);
 WorkSpaceLayout *BKE_workspace_active_layout_get(const struct WorkSpace *ws) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
 void             BKE_workspace_active_layout_set(WorkSpace *ws, WorkSpaceLayout *layout) ATTR_NONNULL(1);
-struct bScreen *BKE_workspace_active_screen_get(const struct WorkSpace *ws) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
+struct bScreen *BKE_workspace_active_screen_get(const WorkSpace *ws) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
 void            BKE_workspace_active_screen_set(WorkSpace *ws, struct bScreen *screen) ATTR_NONNULL(1);
+enum ObjectMode BKE_workspace_object_mode_get(const WorkSpace *workspace) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
+void            BKE_workspace_object_mode_set(WorkSpace *workspace, const enum ObjectMode mode) ATTR_NONNULL();
 ListBase *BKE_workspace_layouts_get(WorkSpace *workspace) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
 WorkSpaceLayout *BKE_workspace_new_layout_get(const WorkSpace *workspace) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
 void             BKE_workspace_new_layout_set(WorkSpace *workspace, WorkSpaceLayout *layout) ATTR_NONNULL(1);
diff --git a/source/blender/blenkernel/intern/workspace.c b/source/blender/blenkernel/intern/workspace.c
index bcbc06f..1e77bd5 100644
--- a/source/blender/blenkernel/intern/workspace.c
+++ b/source/blender/blenkernel/intern/workspace.c
@@ -32,6 +32,7 @@
 #include "BKE_main.h"
 #include "BKE_workspace.h"
 
+#include "DNA_object_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
 #include "dna_workspace_types.h"
@@ -213,6 +214,15 @@ void BKE_workspace_active_screen_set(WorkSpace *ws, bScreen *screen)
 	ws->act_layout = BKE_workspace_layout_find(ws, screen);
 }
 
+ObjectMode BKE_workspace_object_mode_get(const WorkSpace *workspace)
+{
+	return workspace->object_mode;
+}
+void BKE_workspace_object_mode_set(WorkSpace *workspace, const ObjectMode mode)
+{
+	workspace->object_mode = mode;
+}
+
 ListBase *BKE_workspace_layouts_get(WorkSpace *workspace)
 {
 	return &workspace->layouts;
diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h
index 108409c..2482c15 100644
--- a/source/blender/editors/include/ED_screen.h
+++ b/source/blender/editors/include/ED_screen.h
@@ -123,13 +123,16 @@ Scene   *ED_screen_scene_find(const struct bScreen *screen, const struct wmWindo
 void    ED_screen_preview_render(const struct bScreen *screen, int size_x, int size_y, unsigned int *r_rect) ATTR_NONNULL();
 
 /* workspaces */
-bool ED_workspace_change(struct bContext *C, struct wmWindow *win, struct WorkSpace *ws_new) ATTR_NONNULL();
+bool ED_workspace_change(struct bContext *C, struct wmWindowManager *wm, struct wmWindow *win,
+                         struct WorkSpace *ws_new) ATTR_NONNULL();
 struct WorkSpace *ED_workspace_duplicate(struct WorkSpace *workspace_old, struct Main *bmain, struct wmWindow *win);
 struct WorkSpaceLayout *ED_workspace_layout_add(struct WorkSpace *workspace, struct wmWindow *win, const char *name) ATTR_NONNULL();
 struct WorkSpaceLayout *ED_workspace_layout_duplicate(struct WorkSpace *workspace,
                                                       const struct WorkSpaceLayout *layout_old,
                                                       struct wmWindow *win) ATTR_NONNULL();
-bool ED_workspace_delete(struct Main *bmain, struct bContext *C, struct wmWindow *win, struct WorkSpace *ws);
+bool ED_workspace_delete(struct Main *bmain, struct bContext *C,
+                         struct wmWindowManager *wm, struct wmWindow *win,
+                         struct WorkSpace *ws);
 void ED_workspace_scene_data_sync(struct WorkSpace *workspace, Scene *scene);
 bool ED_workspace_layout_delete(struct bContext *C, struct WorkSpace *workspace, struct WorkSpaceLayout *layout_old) ATTR_NONNULL();
 bool ED_workspace_layout_cycle(struct bContext *C, struct WorkSpace *workspace, const short direction) ATTR_NONNULL();
diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c
index 111afcd..30d1795 100644
--- a/source/blender/editors/object/object_edit.c
+++ b/source/blender/editors/object/object_edit.c
@@ -82,6 +82,7 @@
 #include "BKE_modifier.h"
 #include "BKE_editmesh.h"
 #include "BKE_report.h"
+#include "BKE_workspace.h"
 
 #include "ED_armature.h"
 #include "ED_curve.h"
@@ -1689,8 +1690,11 @@ bool ED_object_mode_compat_set(bContext *C, Object *ob, int mode, ReportList *re
 {
 	bool ok;
 	if (!ELEM(ob->mode, mode, OB_MODE_OBJECT)) {
+		WorkSpace *workspace = CTX_wm_workspace(C);
 		const char *opstring = object_mode_op_string(ob->mode);
+
 		WM_operator_name_call(C, opstring, WM_OP_EXEC_REGION_WIN, NULL);
+		BKE_workspace_object_mode_set(workspace, ob->mode);
 		ok = ELEM(ob->mode, mode, OB_MODE_OBJECT);
 		if (!ok) {
 			wmOperatorType *ot = WM_operatortype_find(opstring, false);
@@ -1800,13 +1804,15 @@ void OBJECT_OT_mode_set(wmOperatorType *ot)
 }
 
 
-
 void ED_object_toggle_modes(bContext *C, int mode)
 {
 	if (mode != OB_MODE_OBJECT) {
+		WorkSpace *workspace = CTX_wm_workspace(C);
 		const char *opstring = object_mode_op_string(mode);
+
 		if (opstring) {
 			WM_operator_name_call(C, opstring, WM_OP_EXEC_REGION_WIN, NULL);
+			BKE_workspace_object_mode_set(workspace, mode);
 		}
 	}
 }
diff --git a/source/blender/editors/screen/workspace_edit.c b/source/blender/editors/screen/workspace_edit.c
index 5586b18..719e490 100644
--- a/source/blender/editors/screen/workspace_edit.c
+++ b/source/blender/editors/screen/workspace_edit.c
@@ -30,9 +30,11 @@
 
 #include "BLI_listbase.h"
 
+#include "DNA_object_types.h"
 #include "DNA_screen_types.h"
 #include "DNA_windowmanager_types.h"
 
+#include "ED_object.h"
 #include "ED_screen.h"
 
 #include "WM_api.h"
@@ -46,6 +48,21 @@
  * \brief API for managing workspaces and their data.
  * \{ */
 
+/**
+ * Changes the object mode (if needed) to the one set in \a workspace_new.
+ * Object mode is still stored on object level. In future it should all be workspace level instead.
+ */
+static void workspace_change_update_mode(const WorkSpace *workspace_old, const WorkSpace *workspace_new,
+                                         bContext *C, Object *ob_act, ReportList *reports)
+{
+	ObjectMode mode_old = BKE_workspace_object_mode_get(workspace_old);
+	ObjectMode mode_new = BKE_workspace_object_mode_get(workspace_new);
+
+	if (mode_old != mode_new) {
+		ED_object_mode_compat_set(C, ob_act, mode_new, reports);
+		ED_object_toggle_modes(C, mode_new);
+	}
+}
 
 /**
  * \brief Change the active workspace.
@@ -56,12 +73,12 @@
  * \warning Do NOT call in area/region queues!
  * \returns success.
  */
-bool ED_workspace_change(bContext *C, wmWindow *win, WorkSpace *ws_new)
+bool ED_workspace_change(bContext *C, wmWindowManager *wm, wmWindow *win, WorkSpace *workspace_new)
 {
 	Main *bmain = CTX_data_main(C);
 	WorkSpace *workspace_old = WM_window_get_active_workspace(win);
 	bScreen *screen_old = BKE_workspace_active_screen_get(workspace_old);
-	bScreen *screen_new = BKE_workspace_active_screen_get(ws_new);
+	bScreen *screen_new = BKE_workspace_active_screen_get(workspace_new);
 
 	if (!(screen_new = screen_set_ensure_valid(bmain, win, screen_new))) {
 		return false;
@@ -69,10 +86,13 @@ bool ED_workspace_change(bContext *C, wmWindow *win, WorkSpace *ws_new)
 
 	if (screen_old != screen_new) {
 		screen_set_prepare(C, win, screen_new, screen_old);
-		WM_window_set_active_workspace(win, ws_new);
+		WM_window_set_active_workspace(win, workspace_new);
 		screen_set_refresh(bmain, C, win);
 	}
-	BLI_assert(CTX_wm_workspace(C) == ws_new);
+
+	workspace_change_update_mode(workspace_old, workspace_new, C, CTX_data_active_object(C), &wm->reports);
+
+	BLI_assert(CTX_wm_workspace(C) == workspace_new);
 
 	return true;
 }
@@ -105,7 +125,7 @@ WorkSpace *ED_workspace_duplicate(WorkSpace *workspace_old, Main *bmain, wmWindo
 /**
  * \return if succeeded.
  */
-bool ED_workspace_delete(Main *bmain, bContext *C, wmWindow *win, WorkSpace *ws)
+bool ED_workspace_delete(Main *bmain, bContext *C, wmWindowManager *wm, wmWindow *win, WorkSpace *ws)
 {
 	if (BLI_listbase_is_single(&bmain->workspaces)) {
 		return false;
@@ -115,7 +135,7 @@ bool ED_workspace_delete(Main *bmain, bContext *C, wmWindow *win, WorkSpace *ws)
 		WorkSpace *prev = BKE_workspace_prev_get(ws);
 		WorkSpace *next = BKE_workspace_next_get(ws);
 
-		ED_workspace_change(C, win, (prev != NULL) ? prev : next);
+		ED_workspace_change(C, wm, win, (prev != NULL) ? prev : next);
 	}
 	BKE_libblock_free(bmain, BKE_workspace_id_get(ws));
 
@@ -165,9 +185,10 @@ static void WORKSPACE_OT_workspace_new(wmOperatorType *ot)
 static int workspace_delete_exec(bContext *C, wmOperator *UNUSED(op))
 {
 	Main *bmain = CTX_data_main(C);
+	wmWindowManager *wm = CTX_wm_manager(C);
 	wmWindow *win = CTX_wm_window(C);
 
-	ED_workspace_delete(bmain, C, win, WM_window_get_active_workspace(win));
+	ED_workspace_delete(bmain, C, wm, win, WM_window_get_active_workspace(win));
 
 	return OPERATOR_FINISHED;
 }
diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c
index 876d97e..ed1a565 100644
--- a/source/blender/editors/space_view3d/view3d

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list