WorkSpace: use existing objects mode on select
authorCampbell Barton <ideasman42@gmail.com>
Wed, 28 Feb 2018 12:09:33 +0000 (23:09 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 28 Feb 2018 12:09:33 +0000 (23:09 +1100)
When selecting an object which is already visible in another window
use the mode from that workspace without performing any mode switching.

source/blender/editors/include/ED_screen.h
source/blender/editors/object/object_select.c
source/blender/editors/screen/workspace_edit.c

index a98f8287162660c713c77d807c5404ccccdb3e59..86b9b82e4f7149e9f51acf1018dd8b2a222902e3 100644 (file)
@@ -37,6 +37,8 @@
 #include "DNA_view3d_types.h"
 #include "DNA_workspace_types.h"
 
+#include "DNA_object_enums.h"
+
 #include "BLI_compiler_attrs.h"
 
 struct Depsgraph;
@@ -192,6 +194,10 @@ void ED_workspace_object_mode_sync_from_object(
 void ED_workspace_object_mode_sync_from_scene(
         struct wmWindowManager *wm, WorkSpace *workspace, struct Scene *scene);
 
+bool ED_workspace_object_mode_in_other_window(
+        struct wmWindowManager *wm, WorkSpace *workspace, struct Object *obact,
+        eObjectMode *r_object_mode);
+
 /* anim */
 void    ED_update_for_newframe(struct Main *bmain, struct Scene *scene, struct ViewLayer *view_layer, struct Depsgraph *depsgraph);
 
index 620ee0157248b5527b06dd97e0c4b573f0915e84..5eab16cd7276abe40dbfb75b2d80c388400c336a 100644 (file)
@@ -126,20 +126,29 @@ void ED_object_base_activate(bContext *C, Base *base)
 
        WorkSpace *workspace = CTX_wm_workspace(C);
 
-       bool reset = true;
-       if (base) {
-               Object *ob_prev = OBACT(view_layer);
-               Object *ob_curr = base->object;
-               if (ob_prev != NULL) {
-                       if (ob_prev->type == ob_curr->type) {
-                               reset = false;
-                       }
-               }
-       }
-
        eObjectMode object_mode = workspace->object_mode;
+       eObjectMode object_mode_set = OB_MODE_OBJECT;
 
+       if (base && ED_workspace_object_mode_in_other_window(
+                   CTX_wm_manager(C), workspace, base->object,
+                   &object_mode_set))
        {
+               /* Sync existing object mode with workspace. */
+               workspace->object_mode = object_mode_set;
+       }
+       else {
+               /* Apply the workspaces more to the object (when possible). */
+               bool reset = true;
+               if (base) {
+                       Object *ob_prev = OBACT(view_layer);
+                       Object *ob_curr = base->object;
+                       if (ob_prev != NULL) {
+                               if (ob_prev->type == ob_curr->type) {
+                                       reset = false;
+                               }
+                       }
+               }
+
                Scene *scene = CTX_data_scene(C);
                Object *obact = base ? base->object : NULL;
                /* We don't know the previous active object in update.
@@ -156,14 +165,14 @@ void ED_object_base_activate(bContext *C, Base *base)
                        }
                        FOREACH_OBJECT_END;
                }
-       }
 
-       workspace->object_mode = OB_MODE_OBJECT;
+               workspace->object_mode = OB_MODE_OBJECT;
 
-       view_layer->basact = base;
+               view_layer->basact = base;
 
-       if (reset == false) {
-               ED_object_mode_generic_enter(C, object_mode);
+               if (reset == false) {
+                       ED_object_mode_generic_enter(C, object_mode);
+               }
        }
 
        if (base) {
index 94527b82ce83b33d9231d2d453b0b8fdb532cab5..839b7468d4b16a436dd8a4ed6adbc537c84f75e2 100644 (file)
@@ -336,11 +336,31 @@ void ED_workspace_object_mode_sync_from_scene(wmWindowManager *wm, WorkSpace *wo
 {
        ViewLayer *view_layer = BKE_workspace_view_layer_get(workspace, scene);
        if (view_layer) {
-               Object *obact = obact = OBACT(view_layer);
+               Object *obact = OBACT(view_layer);
                ED_workspace_object_mode_sync_from_object(wm, workspace, obact);
        }
 }
 
+bool ED_workspace_object_mode_in_other_window(
+        struct wmWindowManager *wm, WorkSpace *workspace, Object *obact,
+        eObjectMode *r_object_mode)
+{
+       for (wmWindow *win = wm->windows.first; win; win = win->next) {
+               WorkSpace *workspace_iter = BKE_workspace_active_get(win->workspace_hook);
+               if (workspace != workspace_iter) {
+                       Scene *scene_iter = WM_window_get_active_scene(win);
+                       ViewLayer *view_layer_iter = BKE_view_layer_from_workspace_get(scene_iter, workspace_iter);
+                       Object *obact_iter = OBACT(view_layer_iter);
+                       if (obact == obact_iter) {
+                               *r_object_mode = workspace_iter->object_mode;
+                               return true;
+                       }
+               }
+       }
+
+       return false;
+}
+
 /** \} Workspace API */