[Bf-blender-cvs] [d99682c6ba0] soc-2020-outliner: Collections: Add ability to set color tag from the outliner

Nathan Craddock noreply at git.blender.org
Fri Jun 26 04:47:18 CEST 2020


Commit: d99682c6ba0270c822ea4653e7488efa4064caf0
Author: Nathan Craddock
Date:   Thu Jun 25 11:16:25 2020 -0600
Branches: soc-2020-outliner
https://developer.blender.org/rBd99682c6ba0270c822ea4653e7488efa4064caf0

Collections: Add ability to set color tag from the outliner

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

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
M	source/blender/makesrna/RNA_enum_types.h
M	source/blender/makesrna/intern/rna_collection.c

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

diff --git a/release/scripts/startup/bl_ui/space_outliner.py b/release/scripts/startup/bl_ui/space_outliner.py
index 0ecea329e71..6815c584d95 100644
--- a/release/scripts/startup/bl_ui/space_outliner.py
+++ b/release/scripts/startup/bl_ui/space_outliner.py
@@ -153,6 +153,21 @@ class OUTLINER_MT_edit_datablocks(Menu):
         layout.operator("outliner.drivers_delete_selected")
 
 
+class OUTLINER_MT_collection_color_tag(Menu):
+    bl_label = "Color Tag"
+
+    def draw(self, context):
+        layout = self.layout
+
+        layout.operator("outliner.collection_color_tag_set", text="None").color = 'NONE'
+        layout.operator("outliner.collection_color_tag_set", text="Red").color = 'RED'
+        layout.operator("outliner.collection_color_tag_set", text="Orange").color = 'ORANGE'
+        layout.operator("outliner.collection_color_tag_set", text="Yellow").color = 'YELLOW'
+        layout.operator("outliner.collection_color_tag_set", text="Green").color = 'GREEN'
+        layout.operator("outliner.collection_color_tag_set", text="Blue").color = 'BLUE'
+        layout.operator("outliner.collection_color_tag_set", text="Purple").color = 'PURPLE'
+
+
 class OUTLINER_MT_collection_view_layer(Menu):
     bl_label = "View Layer"
 
@@ -235,6 +250,8 @@ class OUTLINER_MT_collection(Menu):
         if space.display_mode == 'VIEW_LAYER':
             layout.separator()
             layout.menu("OUTLINER_MT_collection_view_layer", icon='RENDERLAYERS')
+            layout.separator()
+            layout.menu("OUTLINER_MT_collection_color_tag")
 
         layout.separator()
 
@@ -430,6 +447,7 @@ classes = (
     OUTLINER_MT_collection_new,
     OUTLINER_MT_collection_visibility,
     OUTLINER_MT_collection_view_layer,
+    OUTLINER_MT_collection_color_tag,
     OUTLINER_MT_object,
     OUTLINER_MT_context_menu,
     OUTLINER_MT_context_menu_view,
diff --git a/source/blender/editors/space_outliner/outliner_collections.c b/source/blender/editors/space_outliner/outliner_collections.c
index 131491fcc40..03064be1290 100644
--- a/source/blender/editors/space_outliner/outliner_collections.c
+++ b/source/blender/editors/space_outliner/outliner_collections.c
@@ -1484,3 +1484,51 @@ void OUTLINER_OT_unhide_all(wmOperatorType *ot)
 }
 
 /** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Collection Color Tags
+ * \{ */
+
+static int outliner_color_tag_set_exec(bContext *C, wmOperator *op)
+{
+  SpaceOutliner *soops = 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(
+      soops, &soops->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);
+    collection->color = color_tag;
+  };
+
+  BLI_freelistN(&selected.selected_array);
+
+  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 a73762df06b..394637d2f5a 100644
--- a/source/blender/editors/space_outliner/outliner_intern.h
+++ b/source/blender/editors/space_outliner/outliner_intern.h
@@ -491,6 +491,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)
diff --git a/source/blender/makesrna/RNA_enum_types.h b/source/blender/makesrna/RNA_enum_types.h
index 0c462ba6766..6dfd874fd8c 100644
--- a/source/blender/makesrna/RNA_enum_types.h
+++ b/source/blender/makesrna/RNA_enum_types.h
@@ -230,6 +230,8 @@ extern const EnumPropertyItem rna_enum_context_mode_items[];
 extern const EnumPropertyItem rna_enum_curveprofile_preset_items[];
 extern const EnumPropertyItem rna_enum_preference_section_items[];
 
+extern const EnumPropertyItem rna_enum_collection_color_items[];
+
 /* API calls */
 int rna_node_tree_type_to_enum(struct bNodeTreeType *typeinfo);
 int rna_node_tree_idname_to_enum(const char *idname);
diff --git a/source/blender/makesrna/intern/rna_collection.c b/source/blender/makesrna/intern/rna_collection.c
index 49a8cfe1058..04d94e87f32 100644
--- a/source/blender/makesrna/intern/rna_collection.c
+++ b/source/blender/makesrna/intern/rna_collection.c
@@ -30,6 +30,29 @@
 
 #include "WM_types.h"
 
+const EnumPropertyItem rna_enum_collection_color_items[] = {
+    {COLLECTION_COLOR_NONE, "NONE", 0, "None", "Assign no color tag to the collection"},
+    {COLLECTION_COLOR_RED, "RED", 0, "Red", "Assign a red color tag to the collection"},
+    {COLLECTION_COLOR_ORANGE,
+     "ORANGE",
+     0,
+     "Orange",
+     "Assign an orange color tag to the collection"},
+    {COLLECTION_COLOR_YELLOW,
+     "YELLOW",
+     0,
+     "Yellow",
+     "Assign a yellow color tag to the collection"},
+    {COLLECTION_COLOR_GREEN, "GREEN", 0, "Green", "Assign a green color tag to the collection"},
+    {COLLECTION_COLOR_BLUE, "BLUE", 0, "Blue", "Assign a blue color tag to the collection"},
+    {COLLECTION_COLOR_PURPLE,
+     "PURPLE",
+     0,
+     "Purple",
+     "Assign a purple color tag to the collection"},
+    {0, NULL, 0, NULL, NULL},
+};
+
 #ifdef RNA_RUNTIME
 
 #  include "DNA_object_types.h"
@@ -387,29 +410,6 @@ void RNA_def_collections(BlenderRNA *brna)
   StructRNA *srna;
   PropertyRNA *prop;
 
-  static const EnumPropertyItem collection_color_items[] = {
-      {COLLECTION_COLOR_NONE, "NONE", 0, "None", "Assign no color tag to the collection"},
-      {COLLECTION_COLOR_RED, "RED", 0, "Red", "Assign a red color tag to the collection"},
-      {COLLECTION_COLOR_ORANGE,
-       "ORANGE",
-       0,
-       "Orange",
-       "Assign an orange color tag to the collection"},
-      {COLLECTION_COLOR_YELLOW,
-       "YELLOW",
-       0,
-       "Yellow",
-       "Assign a yellow color tag to the collection"},
-      {COLLECTION_COLOR_GREEN, "GREEN", 0, "Green", "Assign a green color tag to the collection"},
-      {COLLECTION_COLOR_BLUE, "BLUE", 0, "Blue", "Assign a blue color tag to the collection"},
-      {COLLECTION_COLOR_PURPLE,
-       "PURPLE",
-       0,
-       "Purple",
-       "Assign a purple color tag to the collection"},
-      {0, NULL, 0, NULL, NULL},
-  };
-
   srna = RNA_def_struct(brna, "Collection", "ID");
   RNA_def_struct_ui_text(srna, "Collection", "Collection of Object data-blocks");
   RNA_def_struct_ui_icon(srna, ICON_GROUP);
@@ -499,7 +499,7 @@ void RNA_def_collections(BlenderRNA *brna)
 
   prop = RNA_def_property(srna, "color", PROP_ENUM, PROP_NONE);
   RNA_def_property_enum_sdna(prop, NULL, "color");
-  RNA_def_property_enum_items(prop, collection_color_items);
+  RNA_def_property_enum_items(prop, rna_enum_collection_color_items);
   RNA_def_property_ui_text(prop, "Collection Color", "Color tag for a collection");
   RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, NULL);



More information about the Bf-blender-cvs mailing list