[Bf-blender-cvs] [e9d621e16e2] soc-2020-outliner: Outliner: Use outliner_item_select for activation

Nathan Craddock noreply at git.blender.org
Sat Jun 6 19:03:18 CEST 2020


Commit: e9d621e16e2c8f4096a893b3a38cbdbb04e1f8b1
Author: Nathan Craddock
Date:   Tue Jun 2 20:30:03 2020 -0600
Branches: soc-2020-outliner
https://developer.blender.org/rBe9d621e16e2c8f4096a893b3a38cbdbb04e1f8b1

Outliner: Use outliner_item_select for activation

Use outliner_item_select for outliner activation. This is used in a few
places so far and could easily be extended to other operators.

outliner_item_select takes 3 booleans, select, activate, and extend and
properly sets the TSE_SELECTED and TSE_ACTIVE flags based on the bools.

Future commits will move other selection and activation logic to be in
this function.

No functional changes. Separate the mode toggling logic from the
item activation code because these are distinct behaviors. This will
make later changes easier to make, and also makes it possible to
activate on walk select without toggling modes.

Also rename functions to make purpose more clear.

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

M	source/blender/editors/space_outliner/outliner_intern.h
M	source/blender/editors/space_outliner/outliner_select.c
M	source/blender/editors/space_outliner/outliner_sync.c
M	source/blender/editors/space_outliner/outliner_tools.c

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

diff --git a/source/blender/editors/space_outliner/outliner_intern.h b/source/blender/editors/space_outliner/outliner_intern.h
index 612d9cfcbfe..551212a4aee 100644
--- a/source/blender/editors/space_outliner/outliner_intern.h
+++ b/source/blender/editors/space_outliner/outliner_intern.h
@@ -216,6 +216,16 @@ typedef struct TreeViewContext {
   Object *ob_pose;
 } TreeViewContext;
 
+typedef enum TreeItemSelect {
+  OL_ITEM_DESELECT = 0,           /* Deselect the item */
+  OL_ITEM_SELECT = (1 << 0),      /* Select the item */
+  OL_ITEM_SELECT_DATA = (1 << 1), /* Select object data */
+  OL_ITEM_ACTIVATE = (1 << 2),    /* Activate the item */
+  OL_ITEM_EXTEND = (1 << 3),      /* Extend the current selection */
+  OL_ITEM_RECURSIVE = (1 << 4),   /* Select recursively */
+  OL_ITEM_TOGGLE_MODE = (1 << 5)  /* Temporary */
+} TreeItemSelect;
+
 /* outliner_tree.c ----------------------------------------------- */
 
 void outliner_free_tree(ListBase *tree);
@@ -266,20 +276,17 @@ eOLDrawState tree_element_active(struct bContext *C,
                                  const eOLSetState set,
                                  const bool handle_all_types);
 
-void outliner_item_do_activate_from_tree_element(
-    struct bContext *C, TreeElement *te, TreeStoreElem *tselem, bool extend, bool recursive);
-
-void outliner_item_select(struct SpaceOutliner *soops,
-                          const struct TreeElement *te,
-                          const bool extend,
-                          const bool toggle);
+void outliner_item_select(struct bContext *C,
+                          struct SpaceOutliner *soops,
+                          struct TreeElement *te,
+                          const short select_flag);
 
 void outliner_object_mode_toggle(struct bContext *C,
                                  Scene *scene,
                                  ViewLayer *view_layer,
                                  Base *base);
 
-void outliner_element_activate(struct SpaceOutliner *soops, struct TreeStoreElem *tselem);
+void outliner_set_walk_element(struct SpaceOutliner *soops, struct TreeStoreElem *tselem);
 
 bool outliner_item_is_co_over_name_icons(const TreeElement *te, float view_co_x);
 bool outliner_item_is_co_within_close_toggle(const TreeElement *te, float view_co_x);
diff --git a/source/blender/editors/space_outliner/outliner_select.c b/source/blender/editors/space_outliner/outliner_select.c
index 8ef6ff52382..03eb1804f12 100644
--- a/source/blender/editors/space_outliner/outliner_select.c
+++ b/source/blender/editors/space_outliner/outliner_select.c
@@ -111,7 +111,7 @@ static bool do_outliner_activate_common(bContext *C,
  * If extend is used, we try to have the other compatible selected objects in the new mode as well.
  * Otherwise only the new object will be active, selected and in the edit mode.
  */
-static void do_outliner_activate_obdata(
+static void do_outliner_item_editmode_toggle(
     bContext *C, Scene *scene, ViewLayer *view_layer, Base *base, const bool extend)
 {
   Main *bmain = CTX_data_main(C);
@@ -159,7 +159,7 @@ static void do_outliner_activate_obdata(
   }
 }
 
-static void do_outliner_activate_pose(
+static void do_outliner_item_posemode_toggle(
     bContext *C, Scene *scene, ViewLayer *view_layer, Base *base, const bool extend)
 {
   Main *bmain = CTX_data_main(C);
@@ -214,10 +214,42 @@ void outliner_object_mode_toggle(bContext *C, Scene *scene, ViewLayer *view_laye
 {
   Object *obact = OBACT(view_layer);
   if (obact->mode & OB_MODE_EDIT) {
-    do_outliner_activate_obdata(C, scene, view_layer, base, true);
+    do_outliner_item_editmode_toggle(C, scene, view_layer, base, true);
   }
   else if (obact->mode & OB_MODE_POSE) {
-    do_outliner_activate_pose(C, scene, view_layer, base, true);
+    do_outliner_item_posemode_toggle(C, scene, view_layer, base, true);
+  }
+}
+
+/* Toggle the item's interaction mode if supported */
+static void outliner_item_mode_toggle(bContext *C,
+                                      TreeViewContext *tvc,
+                                      TreeElement *te,
+                                      const bool extend)
+{
+  TreeStoreElem *tselem = TREESTORE(te);
+
+  if (tselem->type == 0) {
+    if (OB_DATA_SUPPORT_EDITMODE(te->idcode)) {
+      Object *ob = (Object *)outliner_search_back(te, ID_OB);
+      if ((ob != NULL) && (ob->data == tselem->id)) {
+        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);
+        }
+      }
+    }
+    else if (ELEM(te->idcode, ID_GD)) {
+      /* set grease pencil to object mode */
+      WM_operator_name_call(C, "GPENCIL_OT_editmode_toggle", WM_OP_INVOKE_REGION_WIN, NULL);
+    }
+  }
+  else if (tselem->type == TSE_POSE_BASE) {
+    Object *ob = (Object *)tselem->id;
+    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);
+    }
   }
 }
 
@@ -863,8 +895,8 @@ static eOLDrawState tree_element_active_text(bContext *UNUSED(C),
   return OL_DRAWSEL_NONE;
 }
 
-static eOLDrawState tree_element_active_pose(bContext *C,
-                                             Scene *scene,
+static eOLDrawState tree_element_active_pose(bContext *UNUSED(C),
+                                             Scene *UNUSED(scene),
                                              ViewLayer *view_layer,
                                              TreeElement *UNUSED(te),
                                              TreeStoreElem *tselem,
@@ -879,7 +911,6 @@ static eOLDrawState tree_element_active_pose(bContext *C,
   }
 
   if (set != OL_SETSEL_NONE) {
-    do_outliner_activate_pose(C, scene, view_layer, base, (set == OL_SETSEL_EXTEND));
   }
   else {
     if (ob->mode & OB_MODE_POSE) {
@@ -1153,11 +1184,11 @@ static void outliner_set_active_data(bContext *C, SpaceOutliner *soops, TreeElem
 
 /* ================================================ */
 
-/* Activate a tree store element and set the walk navigation start element */
-void outliner_element_activate(SpaceOutliner *soops, TreeStoreElem *tselem)
+/* Set the walk navigation start element */
+void outliner_set_walk_element(SpaceOutliner *soops, TreeStoreElem *tselem)
 {
-  outliner_flag_set(&soops->tree, TSE_ACTIVE | TSE_ACTIVE_WALK, false);
-  tselem->flag |= TSE_ACTIVE | TSE_ACTIVE_WALK;
+  outliner_flag_set(&soops->tree, TSE_ACTIVE_WALK, false);
+  tselem->flag |= TSE_ACTIVE_WALK;
 }
 
 /**
@@ -1173,9 +1204,8 @@ static void do_outliner_item_activate_tree_element(bContext *C,
                                                    TreeStoreElem *tselem,
                                                    const bool extend,
                                                    const bool recursive,
-                                                   const bool is_over_name_icons)
+                                                   const bool do_activate_data)
 {
-  bool do_activate_data = soops->flag & SO_SYNC_SELECT || is_over_name_icons;
   /* Always makes active object, except for some specific types. */
   if (ELEM(tselem->type,
            TSE_SEQUENCE,
@@ -1193,7 +1223,6 @@ static void do_outliner_item_activate_tree_element(bContext *C,
     /* Support pose mode toggle, keeping the active object as is. */
   }
   else if (do_activate_data) {
-    /* Only activate when synced selection is enabled */
     tree_element_set_active_object(C,
                                    tvc->scene,
                                    tvc->view_layer,
@@ -1204,8 +1233,7 @@ static void do_outliner_item_activate_tree_element(bContext *C,
                                    recursive && tselem->type == 0);
   }
 
-  /* Mark as active in the outliner */
-  outliner_element_activate(soops, tselem);
+  outliner_set_walk_element(soops, tselem);
 
   if (tselem->type == 0) {  // the lib blocks
     if (do_activate_data == false) {
@@ -1251,19 +1279,6 @@ static void do_outliner_item_activate_tree_element(bContext *C,
       DEG_id_tag_update(&tvc->scene->id, ID_RECALC_SELECT);
       WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, tvc->scene);
     }
-    else if (OB_DATA_SUPPORT_EDITMODE(te->idcode)) {
-      Object *ob = (Object *)outliner_search_back(te, ID_OB);
-      if ((ob != NULL) && (ob->data == tselem->id)) {
-        Base *base = BKE_view_layer_base_find(tvc->view_layer, ob);
-        if ((base != NULL) && (base->flag & BASE_VISIBLE_DEPSGRAPH)) {
-          do_outliner_activate_obdata(C, tvc->scene, tvc->view_layer, base, extend);
-        }
-      }
-    }
-    else if (ELEM(te->idcode, ID_GD)) {
-      /* set grease pencil to object mode */
-      WM_operator_name_call(C, "GPENCIL_OT_editmode_toggle", WM_OP_INVOKE_REGION_WIN, NULL);
-    }
     else {  // rest of types
       tree_element_active(C, tvc, soops, te, OL_SETSEL_NORMAL, false);
     }
@@ -1274,23 +1289,49 @@ static void do_outliner_item_activate_tree_element(bContext *C,
   }
 }
 
-/**
- * \param extend: Don't deselect other items, only modify \a te.
- * \param toggle: Select \a te when not selected, deselect when selected.
- */
-void outliner_item_select(SpaceOutliner *soops,
-                          const TreeElement *te,
-                          const bool extend,
-                          const bool toggle)
+/* Select the item using the set flags */
+void outliner_item_select(bContext *C,
+                          SpaceOutliner *soops,
+                          TreeElement *te,
+                          const short select_flag)
 {
   TreeStoreElem *tselem = TREESTORE(te);
-  const short new_flag = (toggle && (tselem->flag & TSE_ACTIVE)) ? (tselem->flag ^ TSE_SELECTED) :
-                                                                   (tselem->flag | TSE_SELECTED);
+  const bool activate = select_flag & OL_ITEM_ACTIVATE;
+  const bool extend = select_flag & OL_ITEM_EXTEND;
+  const bool activate_data = select_flag & OL_ITEM_SELECT_DATA;
 
-  if (extend == false) {
-    outliner_flag_set(&soops->tree, TSE_SELECTED, false);
+  /* Clear previous active when activating and clear s

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list