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
This commit is contained in:
Nathan Craddock 2020-09-15 12:29:26 -06:00
parent 26a40ac8fa
commit 33d7b36cec
Notes: blender-bot 2023-02-14 03:13:26 +01:00
Referenced by issue #77408, Continued Outliner Improvements Design
4 changed files with 71 additions and 0 deletions

View File

@ -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()

View File

@ -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", "");
}
/** \} */

View File

@ -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);

View File

@ -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)