[Bf-blender-cvs] [82b1cd464eb] soc-2020-outliner: Outliner: Allow setting active data from column

Nathan Craddock noreply at git.blender.org
Sat Jun 6 18:51:53 CEST 2020


Commit: 82b1cd464ebe9432be327ca019c14bf62f29ff1b
Author: Nathan Craddock
Date:   Sat Jun 6 10:48:12 2020 -0600
Branches: soc-2020-outliner
https://developer.blender.org/rB82b1cd464ebe9432be327ca019c14bf62f29ff1b

Outliner: Allow setting active data from column

Add a function to set active data from the outliner column on click. The
supported types are collections, cameras, and scenes as these types are
more "disruptive" and change the state of the scene.

For now this is set from the (cluttered) outliner selection function. I
think it would be best to attach to the drawn UI buttons, but currently
they don't want to work with attached functions.

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

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 242d033add0..ce820692486 100644
--- a/source/blender/editors/space_outliner/outliner_draw.c
+++ b/source/blender/editors/space_outliner/outliner_draw.c
@@ -1926,7 +1926,7 @@ static void outliner_draw_left_column(
         if (tvc->scene->camera == ob) {
           /* Draw check for active camera */
           but = uiDefIconBut(block,
-                             UI_BTYPE_ICON_TOGGLE,
+                             UI_BTYPE_LABEL,
                              0,
                              ICON_CHECKMARK,
                              0,
@@ -1944,7 +1944,7 @@ static void outliner_draw_left_column(
         else {
           /* Draw dot icon to set active camera */
           but = uiDefIconBut(block,
-                             UI_BTYPE_ICON_TOGGLE,
+                             UI_BTYPE_LABEL,
                              0,
                              ICON_DOT,
                              0,
@@ -1969,7 +1969,7 @@ static void outliner_draw_left_column(
       if (tvc->scene == scene) {
         /* Draw check for active scene */
         but = uiDefIconBut(block,
-                           UI_BTYPE_ICON_TOGGLE,
+                           UI_BTYPE_LABEL,
                            0,
                            ICON_CHECKMARK,
                            0,
@@ -1986,7 +1986,7 @@ static void outliner_draw_left_column(
       else {
         /* Draw dot icon to set active scene */
         but = uiDefIconBut(block,
-                           UI_BTYPE_ICON_TOGGLE,
+                           UI_BTYPE_LABEL,
                            0,
                            ICON_DOT,
                            0,
@@ -2010,7 +2010,7 @@ static void outliner_draw_left_column(
           (tselem->type == TSE_LAYER_COLLECTION && active == te->directdata)) {
         /* Draw check for active collection */
         but = uiDefIconBut(block,
-                           UI_BTYPE_ICON_TOGGLE,
+                           UI_BTYPE_LABEL,
                            0,
                            ICON_CHECKMARK,
                            0,
@@ -2027,7 +2027,7 @@ static void outliner_draw_left_column(
       else {
         /* Draw dot icon to set active collection */
         but = uiDefIconBut(block,
-                           UI_BTYPE_ICON_TOGGLE,
+                           UI_BTYPE_LABEL,
                            0,
                            ICON_DOT,
                            0,
@@ -2040,7 +2040,6 @@ static void outliner_draw_left_column(
                            0.0,
                            0.0,
                            TIP_("Set active collection"));
-        UI_but_flag_enable(but, UI_BUT_DRAG_LOCK);
         /* UI_but_func_set(but, outliner_set_active_data_fn, te, NULL); */
       }
     }
diff --git a/source/blender/editors/space_outliner/outliner_select.c b/source/blender/editors/space_outliner/outliner_select.c
index 619195ddeff..8ef6ff52382 100644
--- a/source/blender/editors/space_outliner/outliner_select.c
+++ b/source/blender/editors/space_outliner/outliner_select.c
@@ -494,22 +494,6 @@ static eOLDrawState tree_element_active_camera(bContext *C,
   }
 }
 
-/* TODO: Temporary while testing */
-void outliner_set_active_camera(bContext *C, Scene *scene, TreeElement *te)
-{
-  TreeStoreElem *tselem = TREESTORE(te);
-  Object *ob = (Object *)tselem->id;
-
-  scene->camera = ob;
-  Main *bmain = CTX_data_main(C);
-  wmWindowManager *wm = bmain->wm.first;
-
-  WM_windows_scene_data_sync(&wm->windows, scene);
-  DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE);
-  DEG_relations_tag_update(bmain);
-  WM_event_add_notifier(C, NC_SCENE | NA_EDITED, NULL);
-}
-
 static eOLDrawState tree_element_active_world(bContext *C,
                                               Scene *scene,
                                               ViewLayer *UNUSED(sl),
@@ -1127,6 +1111,46 @@ eOLDrawState tree_element_type_active(bContext *C,
   return OL_DRAWSEL_NONE;
 }
 
+/* TODO: Temporary while testing */
+void outliner_set_active_camera(bContext *C, Scene *scene, TreeElement *te)
+{
+  TreeStoreElem *tselem = TREESTORE(te);
+  Object *ob = (Object *)tselem->id;
+
+  scene->camera = ob;
+  Main *bmain = CTX_data_main(C);
+  wmWindowManager *wm = bmain->wm.first;
+
+  WM_windows_scene_data_sync(&wm->windows, scene);
+  DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE);
+  DEG_relations_tag_update(bmain);
+  WM_event_add_notifier(C, NC_SCENE | NA_EDITED, NULL);
+}
+
+static void outliner_set_active_data(bContext *C, SpaceOutliner *soops, TreeElement *te)
+{
+  TreeViewContext tvc;
+  TreeStoreElem *tselem = TREESTORE(te);
+
+  outliner_viewcontext_init(C, &tvc);
+
+  if (tselem->type == 0 && te->idcode == ID_OB) {
+    Object *ob = (Object *)tselem->id;
+    if (ob->type == OB_CAMERA) {
+      outliner_set_active_camera(C, tvc.scene, te);
+    }
+  }
+  else if (tselem->type == 0 && te->idcode == ID_SCE) {
+    Scene *scene = (Scene *)tselem->id;
+    if (scene != tvc.scene) {
+      WM_window_set_active_scene(CTX_data_main(C), C, CTX_wm_window(C), scene);
+    }
+  }
+  else if (ELEM(tselem->type, TSE_VIEW_COLLECTION_BASE, TSE_LAYER_COLLECTION)) {
+    tree_element_type_active(C, &tvc, soops, te, tselem, OL_SETSEL_NORMAL, false);
+  }
+}
+
 /* ================================================ */
 
 /* Activate a tree store element and set the walk navigation start element */
@@ -1187,11 +1211,6 @@ static void do_outliner_item_activate_tree_element(bContext *C,
     if (do_activate_data == false) {
       /* Only select in outliner. */
     }
-    else if (te->idcode == ID_SCE) {
-      if (tvc->scene != (Scene *)tselem->id) {
-        WM_window_set_active_scene(CTX_data_main(C), C, CTX_wm_window(C), (Scene *)tselem->id);
-      }
-    }
     else if ((te->idcode == ID_GR) && (soops->outlinevis != SO_VIEW_LAYER)) {
       Collection *gr = (Collection *)tselem->id;
 
@@ -1388,9 +1407,6 @@ static int outliner_item_do_activate_from_cursor(bContext *C,
   if (outliner_is_co_within_restrict_columns(soops, region, view_mval[0])) {
     return OPERATOR_CANCELLED;
   }
-  if (soops->flag & SO_LEFT_COLUMN && mval[0] < UI_UNIT_X) {
-    return OPERATOR_CANCELLED;
-  }
 
   if (!(te = outliner_find_item_at_y(soops, &soops->tree, view_mval[1]))) {
     if (deselect_all) {
@@ -1403,6 +1419,11 @@ static int outliner_item_do_activate_from_cursor(bContext *C,
            outliner_item_is_co_within_close_toggle(te, view_mval[0])) {
     return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH;
   }
+  /* Set active data on left column click */
+  /* TODO: Decide if this is best as button callbacks or here in outliner_select */
+  else if (soops->flag & SO_LEFT_COLUMN && view_mval[0] < UI_UNIT_X) {
+    outliner_set_active_data(C, soops, te);
+  }
   else {
     /* The row may also contain children, if one is hovered we want this instead of current te */
     bool merged_elements = false;



More information about the Bf-blender-cvs mailing list