diff options
author | Nathan Craddock <nzcraddock@gmail.com> | 2020-09-15 21:29:26 +0300 |
---|---|---|
committer | Nathan Craddock <nzcraddock@gmail.com> | 2020-09-15 21:47:09 +0300 |
commit | 33d7b36cecd4a6dab2bd5798071f58545ae0cabe (patch) | |
tree | 421a7b793d86b650406fc32f1eb9e554d3bac8f3 /source/blender | |
parent | 26a40ac8facfdc4a35ac2fb2daf339787ea1f6c4 (diff) |
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
Diffstat (limited to 'source/blender')
3 files changed, 67 insertions, 0 deletions
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) |