[Bf-blender-cvs] [a36495e72d2] soc-2020-outliner: Cleanup: Add new callback for mode toggle

Nathan Craddock noreply at git.blender.org
Sat Jun 13 23:21:48 CEST 2020


Commit: a36495e72d230f21b3ea63a19573deaa3991302c
Author: Nathan Craddock
Date:   Sat Jun 13 15:20:26 2020 -0600
Branches: soc-2020-outliner
https://developer.blender.org/rBa36495e72d230f21b3ea63a19573deaa3991302c

Cleanup: Add new callback for mode toggle

Instead of sharing the same callback fn for data activation and mode
toggle in the buttons, split into two similar functions to better
differentiate which action should be done.

This also fixes the issue where clicking a data activation radio button
would enter the mode toggle function instead.

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

M	source/blender/editors/space_outliner/outliner_draw.c
M	source/blender/editors/space_outliner/outliner_intern.h
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 43eefd83974..de7cac82295 100644
--- a/source/blender/editors/space_outliner/outliner_draw.c
+++ b/source/blender/editors/space_outliner/outliner_draw.c
@@ -1902,18 +1902,34 @@ static void outliner_buttons(const bContext *C,
   }
 }
 
-static void outliner_left_column_fn(bContext *C, void *tselem_poin, void *UNUSED(arg2))
+static void outliner_data_activate_fn(bContext *C, void *tselem_poin, void *UNUSED(arg2))
 {
   SpaceOutliner *soops = CTX_wm_space_outliner(C);
   TreeStoreElem *tselem = (TreeStoreElem *)tselem_poin;
+  TreeViewContext tvc;
+  outliner_viewcontext_init(C, &tvc);
+
+  TreeElement *te = outliner_find_tree_element(&soops->tree, tselem);
+  if (!te) {
+    return;
+  }
+
+  outliner_set_active_data(C, &tvc, soops, te, tselem);
+}
+
+static void outliner_mode_toggle_fn(bContext *C, void *tselem_poin, void *UNUSED(arg2))
+{
+  SpaceOutliner *soops = CTX_wm_space_outliner(C);
+  TreeStoreElem *tselem = (TreeStoreElem *)tselem_poin;
+  TreeViewContext tvc;
+  outliner_viewcontext_init(C, &tvc);
 
-  /* TODO (Nathan): Try to pass necessary data instead of searching for tree elem */
   TreeElement *te = outliner_find_tree_element(&soops->tree, tselem);
   if (!te) {
     return;
   }
 
-  outliner_left_column_click(C, soops, te);
+  outliner_item_mode_toggle(C, &tvc, te, true);
 }
 
 /* Draw icons for setting activation when in object mode */
@@ -1947,7 +1963,7 @@ static void outliner_draw_left_column_activation(const bContext *C,
                          (is_active_camera ? "" : TIP_("Set active camera")));
 
       if (!is_active_camera) {
-        UI_but_func_set(but, outliner_left_column_fn, tselem, NULL);
+        UI_but_func_set(but, outliner_data_activate_fn, tselem, NULL);
       }
     }
   }
@@ -1971,7 +1987,7 @@ static void outliner_draw_left_column_activation(const bContext *C,
                        (is_active_scene ? "" : TIP_("Set active scene")));
 
     if (!is_active_scene) {
-      UI_but_func_set(but, outliner_left_column_fn, tselem, NULL);
+      UI_but_func_set(but, outliner_data_activate_fn, tselem, NULL);
     }
   }
   else if (outliner_is_collection_tree_element(te)) {
@@ -1996,7 +2012,7 @@ static void outliner_draw_left_column_activation(const bContext *C,
                        (is_active_collection ? "" : TIP_("Set active collection")));
 
     if (!is_active_collection) {
-      UI_but_func_set(but, outliner_left_column_fn, tselem, NULL);
+      UI_but_func_set(but, outliner_data_activate_fn, tselem, NULL);
     }
   }
 }
@@ -2062,7 +2078,7 @@ static void outliner_draw_left_column_mode_toggle(uiBlock *block,
             0.0,
             0.0,
             TIP_("Remove from the current mode"));
-        UI_but_func_set(but, outliner_left_column_fn, tselem, NULL);
+        UI_but_func_set(but, outliner_mode_toggle_fn, tselem, NULL);
       }
       else {
         /* Not all objects have particle systems */
@@ -2084,7 +2100,7 @@ static void outliner_draw_left_column_mode_toggle(uiBlock *block,
             1.0,
             0.6,
             TIP_("Add to the current mode"));
-        UI_but_func_set(but, outliner_left_column_fn, tselem, NULL);
+        UI_but_func_set(but, outliner_mode_toggle_fn, tselem, NULL);
       }
     }
   }
diff --git a/source/blender/editors/space_outliner/outliner_intern.h b/source/blender/editors/space_outliner/outliner_intern.h
index e551fbdd5b5..590609e1a8a 100644
--- a/source/blender/editors/space_outliner/outliner_intern.h
+++ b/source/blender/editors/space_outliner/outliner_intern.h
@@ -290,7 +290,16 @@ void outliner_set_walk_element(struct SpaceOutliner *soops, struct TreeStoreElem
 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);
 
-void outliner_left_column_click(struct bContext *C, struct SpaceOutliner *soops, TreeElement *te);
+void outliner_item_mode_toggle(struct bContext *C,
+                               TreeViewContext *tvc,
+                               TreeElement *te,
+                               const bool extend);
+
+void outliner_set_active_data(struct bContext *C,
+                              TreeViewContext *tvc,
+                              SpaceOutliner *soops,
+                              TreeElement *te,
+                              struct TreeStoreElem *tselem);
 
 /* outliner_edit.c ---------------------------------------------- */
 typedef void (*outliner_operation_cb)(struct bContext *C,
diff --git a/source/blender/editors/space_outliner/outliner_select.c b/source/blender/editors/space_outliner/outliner_select.c
index 126dda94a46..5df46b9edc0 100644
--- a/source/blender/editors/space_outliner/outliner_select.c
+++ b/source/blender/editors/space_outliner/outliner_select.c
@@ -245,10 +245,10 @@ void outliner_object_mode_toggle(bContext *C, Scene *scene, ViewLayer *view_laye
 }
 
 /* Toggle the item's interaction mode if supported */
-static void outliner_item_mode_toggle(bContext *C,
-                                      TreeViewContext *tvc,
-                                      TreeElement *te,
-                                      const bool extend)
+void outliner_item_mode_toggle(bContext *C,
+                               TreeViewContext *tvc,
+                               TreeElement *te,
+                               const bool extend)
 {
   TreeStoreElem *tselem = TREESTORE(te);
 
@@ -1176,11 +1176,11 @@ static void outliner_set_active_camera(bContext *C, Scene *scene, TreeStoreElem
   WM_event_add_notifier(C, NC_SCENE | NA_EDITED, NULL);
 }
 
-static void outliner_set_active_data(bContext *C,
-                                     TreeViewContext *tvc,
-                                     SpaceOutliner *soops,
-                                     TreeElement *te,
-                                     TreeStoreElem *tselem)
+void outliner_set_active_data(bContext *C,
+                              TreeViewContext *tvc,
+                              SpaceOutliner *soops,
+                              TreeElement *te,
+                              TreeStoreElem *tselem)
 {
   if (tselem->type == 0 && te->idcode == ID_OB) {
     Object *ob = (Object *)tselem->id;
@@ -1199,21 +1199,6 @@ static void outliner_set_active_data(bContext *C,
   }
 }
 
-void outliner_left_column_click(bContext *C, SpaceOutliner *soops, TreeElement *te)
-{
-  TreeStoreElem *tselem = TREESTORE(te);
-  TreeViewContext tvc;
-  outliner_viewcontext_init(C, &tvc);
-
-  if (tvc.obact && tvc.obact->mode != OB_MODE_OBJECT) {
-    /* TODO (Nathan): this runs when clicking activation icons in non-object modes */
-    outliner_item_mode_toggle(C, &tvc, te, true);
-  }
-  else {
-    outliner_set_active_data(C, &tvc, soops, te, tselem);
-  }
-}
-
 /* ================================================ */
 
 /* Set the walk navigation start element */



More information about the Bf-blender-cvs mailing list