[Bf-blender-cvs] [b09e0f8abee] soc-2020-outliner: Outliner: Add mode switching to remaining modes in left column

Nathan Craddock noreply at git.blender.org
Sat Jun 13 22:34:19 CEST 2020


Commit: b09e0f8abee394bed14d94546d33174153e3a65e
Author: Nathan Craddock
Date:   Sat Jun 13 14:32:23 2020 -0600
Branches: soc-2020-outliner
https://developer.blender.org/rBb09e0f8abee394bed14d94546d33174153e3a65e

Outliner: Add mode switching to remaining modes in left column

When in modes other than edit or pose, icons are drawn next to each
object in the outliner that also supports the same mode. When the icon
is clicked, that object is activated and swapped into that edit mode.

When Lock Object Modes is disabled and objects are left in their modes,
the icons all draw as if they were simultaneously in that mode. This is
the only issue currently, otherwise it seems to work well.

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

M	source/blender/editors/space_outliner/outliner_draw.c
M	source/blender/editors/space_outliner/outliner_select.c

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

diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c
index ffbd0aca3eb..43eefd83974 100644
--- a/source/blender/editors/space_outliner/outliner_draw.c
+++ b/source/blender/editors/space_outliner/outliner_draw.c
@@ -2040,35 +2040,40 @@ static void outliner_draw_left_column_mode_toggle(uiBlock *block,
                                                   TreeStoreElem *tselem)
 {
   uiBut *but;
-  const int mode_icon = outliner_get_mode_icon(tvc->obact->mode);
+  const int active_mode = tvc->obact->mode;
 
   if (tselem->type == 0 && te->idcode == ID_OB) {
     Object *ob = (Object *)tselem->id;
 
     if (ob->type == tvc->obact->type) {
       if (ob->mode == tvc->obact->mode) {
-        but = uiDefIconBut(block,
-                           UI_BTYPE_ICON_TOGGLE,
-                           0,
-                           (ob->mode == tvc->obact->mode ? mode_icon : ICON_DOT),
-                           0,
-                           te->ys,
-                           UI_UNIT_X,
-                           UI_UNIT_Y,
-                           NULL,
-                           0.0,
-                           0.0,
-                           0.0,
-                           0.0,
-                           TIP_("Remove from the current mode"));
+        but = uiDefIconBut(
+            block,
+            UI_BTYPE_ICON_TOGGLE,
+            0,
+            (ob->mode == tvc->obact->mode ? outliner_get_mode_icon(active_mode) : ICON_DOT),
+            0,
+            te->ys,
+            UI_UNIT_X,
+            UI_UNIT_Y,
+            NULL,
+            0.0,
+            0.0,
+            0.0,
+            0.0,
+            TIP_("Remove from the current mode"));
         UI_but_func_set(but, outliner_left_column_fn, tselem, NULL);
       }
       else {
+        /* Not all objects have particle systems */
+        if (active_mode == OB_MODE_PARTICLE_EDIT && !ob->particlesystem.first) {
+          return;
+        }
         but = uiDefIconBut(
             block,
             (tselem->flag & TSE_HIGHLIGHTED ? UI_BTYPE_ICON_TOGGLE : UI_BTYPE_LABEL),
             0,
-            mode_icon,
+            outliner_get_mode_icon(active_mode),
             0,
             te->ys,
             UI_UNIT_X,
@@ -2078,7 +2083,7 @@ static void outliner_draw_left_column_mode_toggle(uiBlock *block,
             0.0,
             1.0,
             0.6,
-            TIP_("Add too the current mode"));
+            TIP_("Add to the current mode"));
         UI_but_func_set(but, outliner_left_column_fn, tselem, NULL);
       }
     }
diff --git a/source/blender/editors/space_outliner/outliner_select.c b/source/blender/editors/space_outliner/outliner_select.c
index 1770ce5127e..126dda94a46 100644
--- a/source/blender/editors/space_outliner/outliner_select.c
+++ b/source/blender/editors/space_outliner/outliner_select.c
@@ -210,9 +210,26 @@ static void do_outliner_item_posemode_toggle(
 }
 
 /* Toggle interaction mode for modes that do not allow multi-object editing */
-static void do_outliner_item_mode_toggle_generic(bContext *C)
+static void do_outliner_item_mode_toggle_generic(bContext *C, TreeViewContext *tvc, Base *base)
 {
-  /* TODO: switch active object and call operator */
+  Main *bmain = CTX_data_main(C);
+  Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
+  const int active_mode = tvc->obact->mode;
+
+  /* Remove the active object from the mode */
+  if (tvc->scene->toolsettings->object_flag & SCE_OBJECT_MODE_LOCK) {
+    ED_object_mode_generic_exit(bmain, depsgraph, tvc->scene, tvc->obact);
+  }
+
+  Base *base_old = BKE_view_layer_base_find(tvc->view_layer, tvc->obact);
+  if (base_old) {
+    ED_object_base_select(base_old, BA_DESELECT);
+  }
+  ED_object_base_activate(C, base);
+  ED_object_base_select(base, BA_SELECT);
+  ED_object_mode_set(C, active_mode);
+
+  ED_outliner_select_sync_from_object_tag(C);
 }
 
 /* For draw callback to run mode switching */
@@ -237,21 +254,20 @@ static void outliner_item_mode_toggle(bContext *C,
 
   if (tselem->type == 0 && te->idcode == ID_OB) {
     Object *ob = (Object *)tselem->id;
+    Base *base = BKE_view_layer_base_find(tvc->view_layer, ob);
+
+    if (!base || !(base->flag & BASE_VISIBLE_DEPSGRAPH)) {
+      return;
+    }
 
     if (tvc->ob_edit && OB_TYPE_SUPPORT_EDITMODE(ob->type)) {
-      Base *base = BKE_view_layer_base_find(tvc->view_layer, ob);
-      if ((base != NULL) && (base->flag & BASE_VISIBLE_DEPSGRAPH)) {
-        do_outliner_item_editmode_toggle(C, tvc->scene, tvc->view_layer, base, extend);
-      }
+      do_outliner_item_editmode_toggle(C, tvc->scene, tvc->view_layer, base, extend);
     }
     else if (tvc->ob_pose && ob->type == OB_ARMATURE) {
-      Base *base = BKE_view_layer_base_find(tvc->view_layer, ob);
-      if (base != NULL) {
-        do_outliner_item_posemode_toggle(C, tvc->scene, tvc->view_layer, base, extend);
-      }
+      do_outliner_item_posemode_toggle(C, tvc->scene, tvc->view_layer, base, extend);
     }
     else {
-      do_outliner_item_mode_toggle_generic(C);
+      do_outliner_item_mode_toggle_generic(C, tvc, base);
     }
   }
 }



More information about the Bf-blender-cvs mailing list