[Bf-blender-cvs] [33d7b36cecd] master: Outliner: Set collection color tag operator

Nathan Craddock noreply at git.blender.org
Tue Sep 15 20:47:59 CEST 2020


Commit: 33d7b36cecd4a6dab2bd5798071f58545ae0cabe
Author: Nathan Craddock
Date:   Tue Sep 15 12:29:26 2020 -0600
Branches: master
https://developer.blender.org/rB33d7b36cecd4a6dab2bd5798071f58545ae0cabe

Outliner: Set collection color tag operator

This adds a new operator to the outliner context menu. The collections
context menu now shows inline icons to set the color tag for all
selected collections.

Manifest Task: https://developer.blender.org/T77777

Differential Revision: https://developer.blender.org/D8622

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

M	release/scripts/startup/bl_ui/space_outliner.py
M	source/blender/editors/space_outliner/outliner_collections.c
M	source/blender/editors/space_outliner/outliner_intern.h
M	source/blender/editors/space_outliner/outliner_ops.c

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

diff --git a/release/scripts/startup/bl_ui/space_outliner.py b/release/scripts/startup/bl_ui/space_outliner.py
index 4497f37cfd2..c61b6218dda 100644
--- a/release/scripts/startup/bl_ui/space_outliner.py
+++ b/release/scripts/startup/bl_ui/space_outliner.py
@@ -239,6 +239,10 @@ class OUTLINER_MT_collection(Menu):
         if space.display_mode == 'VIEW_LAYER':
             layout.separator()
             layout.menu("OUTLINER_MT_collection_view_layer", icon='RENDERLAYERS')
+            layout.separator()
+
+            row = layout.row(align=True)
+            row.operator_enum("outliner.collection_color_tag_set", "color", icon_only=True)
 
         layout.separator()
 
diff --git a/source/blender/editors/space_outliner/outliner_collections.c b/source/blender/editors/space_outliner/outliner_collections.c
index efb91528e14..13086655998 100644
--- a/source/blender/editors/space_outliner/outliner_collections.c
+++ b/source/blender/editors/space_outliner/outliner_collections.c
@@ -1529,3 +1529,66 @@ void OUTLINER_OT_unhide_all(wmOperatorType *ot)
 }
 
 /** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Collection Color Tags
+ * \{ */
+
+static int outliner_color_tag_set_exec(bContext *C, wmOperator *op)
+{
+  Scene *scene = CTX_data_scene(C);
+  SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
+  const short color_tag = RNA_enum_get(op->ptr, "color");
+
+  struct IDsSelectedData selected = {
+      .selected_array = {NULL, NULL},
+  };
+
+  outliner_tree_traverse(space_outliner,
+                         &space_outliner->tree,
+                         0,
+                         TSE_SELECTED,
+                         outliner_find_selected_collections,
+                         &selected);
+
+  LISTBASE_FOREACH (LinkData *, link, &selected.selected_array) {
+    TreeElement *te_selected = (TreeElement *)link->data;
+
+    Collection *collection = outliner_collection_from_tree_element(te_selected);
+    if (collection == scene->master_collection) {
+      continue;
+    }
+    if (ID_IS_LINKED(collection)) {
+      BKE_report(op->reports, RPT_WARNING, "Can't add a color tag to a linked collection");
+      continue;
+    }
+
+    collection->color_tag = color_tag;
+  };
+
+  BLI_freelistN(&selected.selected_array);
+
+  WM_event_add_notifier(C, NC_SCENE | ND_LAYER_CONTENT, NULL);
+
+  return OPERATOR_FINISHED;
+}
+
+void OUTLINER_OT_collection_color_tag_set(wmOperatorType *ot)
+{
+  /* identifiers */
+  ot->name = "Set Color Tag";
+  ot->idname = "OUTLINER_OT_collection_color_tag_set";
+  ot->description = "Set a color tag for the selected collections";
+
+  /* api callbacks */
+  ot->exec = outliner_color_tag_set_exec;
+  ot->poll = ED_outliner_collections_editor_poll;
+
+  /* flags */
+  ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+  RNA_def_enum(
+      ot->srna, "color", rna_enum_collection_color_items, COLLECTION_COLOR_NONE, "Color Tag", "");
+}
+
+/** \} */
diff --git a/source/blender/editors/space_outliner/outliner_intern.h b/source/blender/editors/space_outliner/outliner_intern.h
index 88080218e7f..485f72781e3 100644
--- a/source/blender/editors/space_outliner/outliner_intern.h
+++ b/source/blender/editors/space_outliner/outliner_intern.h
@@ -485,6 +485,8 @@ void OUTLINER_OT_collection_disable_render(struct wmOperatorType *ot);
 void OUTLINER_OT_hide(struct wmOperatorType *ot);
 void OUTLINER_OT_unhide_all(struct wmOperatorType *ot);
 
+void OUTLINER_OT_collection_color_tag_set(struct wmOperatorType *ot);
+
 /* outliner_utils.c ---------------------------------------------- */
 
 void outliner_viewcontext_init(const struct bContext *C, TreeViewContext *tvc);
diff --git a/source/blender/editors/space_outliner/outliner_ops.c b/source/blender/editors/space_outliner/outliner_ops.c
index af7d97b6950..22541a0ab1f 100644
--- a/source/blender/editors/space_outliner/outliner_ops.c
+++ b/source/blender/editors/space_outliner/outliner_ops.c
@@ -117,6 +117,8 @@ void outliner_operatortypes(void)
   WM_operatortype_append(OUTLINER_OT_collection_show_inside);
   WM_operatortype_append(OUTLINER_OT_hide);
   WM_operatortype_append(OUTLINER_OT_unhide_all);
+
+  WM_operatortype_append(OUTLINER_OT_collection_color_tag_set);
 }
 
 void outliner_keymap(wmKeyConfig *keyconf)



More information about the Bf-blender-cvs mailing list