[Bf-blender-cvs] [e257f3c75ee] soc-2019-outliner: Outliner: Refactor show active to show all instances of object

Nathan Craddock noreply at git.blender.org
Sat Jul 27 05:30:59 CEST 2019


Commit: e257f3c75ee5da313d151971dc64ebe18b849294
Author: Nathan Craddock
Date:   Fri Jul 26 21:29:10 2019 -0600
Branches: soc-2019-outliner
https://developer.blender.org/rBe257f3c75ee5da313d151971dc64ebe18b849294

Outliner: Refactor show active to show all instances of object

Previously the show active operator opened the tree to show the
first instance of the active object. With collection linking,
the active object could be in multiple collections. This expands
the show active operator to expand all hierarchies that contain
the active object. The view will be centered on the first
active object in the outliner.

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

M	source/blender/editors/space_outliner/outliner_edit.c

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

diff --git a/source/blender/editors/space_outliner/outliner_edit.c b/source/blender/editors/space_outliner/outliner_edit.c
index 53b8014eb5c..9308527eac3 100644
--- a/source/blender/editors/space_outliner/outliner_edit.c
+++ b/source/blender/editors/space_outliner/outliner_edit.c
@@ -1251,19 +1251,17 @@ static int outliner_open_back(TreeElement *te)
   return retval;
 }
 
-static int outliner_show_active_exec(bContext *C, wmOperator *UNUSED(op))
+/* Return the active base, editbone or posebone from the outliner, or NULL if none exists */
+static TreeElement *outliner_show_active_get_element(bContext *C,
+                                                     SpaceOutliner *so,
+                                                     ViewLayer *view_layer)
 {
-  SpaceOutliner *so = CTX_wm_space_outliner(C);
-  ViewLayer *view_layer = CTX_data_view_layer(C);
-  ARegion *ar = CTX_wm_region(C);
-  View2D *v2d = &ar->v2d;
-
   TreeElement *te;
 
   Object *obact = OBACT(view_layer);
 
   if (!obact) {
-    return OPERATOR_CANCELLED;
+    return NULL;
   }
 
   te = outliner_find_id(so, &so->tree, &obact->id);
@@ -1286,12 +1284,42 @@ static int outliner_show_active_exec(bContext *C, wmOperator *UNUSED(op))
     }
   }
 
-  if (te) {
-    /* open up tree to active object/bone */
+  return te;
+}
+
+static void outliner_show_active(SpaceOutliner *so, ARegion *ar, TreeElement *te, ID *id)
+{
+  /* open up tree to active object/bone */
+  if (TREESTORE(te)->id == id) {
     if (outliner_open_back(te)) {
       outliner_set_coordinates(ar, so);
     }
+    return;
+  }
+
+  for (TreeElement *ten = te->subtree.first; ten; ten = ten->next) {
+    outliner_show_active(so, ar, ten, id);
+  }
+}
+
+static int outliner_show_active_exec(bContext *C, wmOperator *UNUSED(op))
+{
+  SpaceOutliner *so = CTX_wm_space_outliner(C);
+  ViewLayer *view_layer = CTX_data_view_layer(C);
+  ARegion *ar = CTX_wm_region(C);
+  View2D *v2d = &ar->v2d;
+
+  TreeElement *te = outliner_show_active_get_element(C, so, view_layer);
+
+  if (te) {
+    ID *id = TREESTORE(te)->id;
+
+    /* Expand all elements in the outliner with matching ID */
+    for (TreeElement *ten = so->tree.first; ten; ten = ten->next) {
+      outliner_show_active(so, ar, ten, id);
+    }
 
+    /* Center view on first element found */
     int size_y = BLI_rcti_size_y(&v2d->mask) + 1;
     int y_min = MIN2(ar->v2d.tot.ymin, v2d->cur.ymin);
     int ytop = te->ys + size_y / 2;
@@ -1307,6 +1335,9 @@ static int outliner_show_active_exec(bContext *C, wmOperator *UNUSED(op))
     v2d->cur.ymax = ytop;
     v2d->cur.ymin = ytop - size_y;
   }
+  else {
+    return OPERATOR_CANCELLED;
+  }
 
   ED_region_tag_redraw_no_rebuild(ar);



More information about the Bf-blender-cvs mailing list