WorkSpace: move edit mode w/ sync into own func
authorCampbell Barton <ideasman42@gmail.com>
Fri, 2 Mar 2018 12:04:19 +0000 (23:04 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 2 Mar 2018 12:04:19 +0000 (23:04 +1100)
source/blender/editors/include/ED_object.h
source/blender/editors/object/object_modes.c
source/blender/editors/scene/scene_edit.c
source/blender/editors/screen/workspace_edit.c

index 33a8ee133eabe1b8f4fb28dcc645be1bf6aa4d3c..80f230fd868ff0b638901be3369e5c583e564f7c 100644 (file)
@@ -219,6 +219,9 @@ bool ED_object_mode_generic_has_data(
         const struct EvaluationContext *eval_ctx,
         struct Object *ob);
 
+bool ED_object_mode_generic_enter_or_other_window(
+        struct bContext *C, eObjectMode object_mode);
+
 /* object_modifier.c */
 enum {
        MODIFIER_APPLY_DATA = 1,
index 8cdec2968b3c5b77e2b471d6f33822ec800510e0..47cbf782e074c6ed3e77a4898fbf00766ca9928e 100644 (file)
@@ -45,6 +45,8 @@
 
 #include "DEG_depsgraph.h"
 
+#include "ED_screen.h"
+
 #include "ED_object.h"  /* own include */
 
 /* -------------------------------------------------------------------- */
@@ -242,3 +244,41 @@ bool ED_object_mode_generic_has_data(
 }
 
 /** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Mode Syncing Utils
+ *
+ * \{ */
+
+/**
+ * A version of #ED_object_mode_generic_enter that checks if the object
+ * has an active mode mode in another window we need to use another window first.
+ */
+bool ED_object_mode_generic_enter_or_other_window(
+        struct bContext *C, eObjectMode object_mode)
+{
+       WorkSpace *workspace = CTX_wm_workspace(C);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
+       Base *basact = view_layer->basact;
+       if (basact == NULL) {
+               workspace->object_mode = OB_MODE_OBJECT;
+               return (workspace->object_mode == object_mode);
+       }
+
+       wmWindowManager *wm = CTX_wm_manager(C);
+       eObjectMode object_mode_set = OB_MODE_OBJECT;
+       view_layer->basact = NULL;
+       bool use_object_mode = ED_workspace_object_mode_in_other_window(wm, NULL, basact->object, &object_mode_set);
+       view_layer->basact = basact;
+
+       if (use_object_mode) {
+               workspace->object_mode = object_mode_set;
+               return (workspace->object_mode == object_mode);
+       }
+       else {
+               workspace->object_mode = OB_MODE_OBJECT;
+               return ED_object_mode_generic_enter(C, object_mode);
+       }
+}
+
+/** \} */
index cee73c2876729d175501782fd5d2772dd63d0c82..462820c93c0eac06ed8fbc02c8069258b6189a47 100644 (file)
@@ -156,20 +156,8 @@ void ED_scene_change_update(
        if (obact_new == obact_old) {
                /* pass */
        }
-       else if (obact_new == NULL) {
-               workspace->object_mode = OB_MODE_OBJECT;
-       }
        else {
-               eObjectMode object_mode_set = OB_MODE_OBJECT;
-               if (ED_workspace_object_mode_in_other_window(
-                           bmain->wm.first, win, obact_new, &object_mode_set))
-               {
-                       workspace->object_mode = object_mode_set;
-               }
-               else {
-                       workspace->object_mode = OB_MODE_OBJECT;
-                       ED_object_mode_generic_enter(C, object_mode_old);
-               }
+               ED_object_mode_generic_enter_or_other_window(C, object_mode_old);
        }
 
 
index 7635a2644f59dfff07a353d37b9af610550725b8..23715f667fe48e82ddc64b561434d90aaa885c38 100644 (file)
@@ -221,19 +221,12 @@ bool ED_workspace_change(
                WM_toolsystem_unlink(C, workspace_old);
                WM_toolsystem_link(C, workspace_new);
 
-               if (obact_new == NULL) {
-                       workspace_new->object_mode = OB_MODE_OBJECT;
+               if (use_object_mode) {
+                       ED_object_mode_generic_enter_or_other_window(C, workspace_new->object_mode);
                }
-               else if (use_object_mode) {
-                       eObjectMode object_mode_set = workspace_new->object_mode;
-                       if (ED_workspace_object_mode_in_other_window(
-                                   bmain->wm.first, win, obact_new, &object_mode_set))
-                       {
-                               workspace_new->object_mode = object_mode_set;
-                       }
-                       else {
+               else {
+                       if (obact_new == NULL) {
                                workspace_new->object_mode = OB_MODE_OBJECT;
-                               ED_object_mode_generic_enter(C, object_mode_set);
                        }
                }