diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2017-12-29 16:36:54 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2017-12-29 18:36:55 +0300 |
commit | 8252a414d8cb15b42726d6f96d01cae97514d793 (patch) | |
tree | 409b68d1afc15c1bfefc3df81e2b3c2f35a036d5 /source/blender | |
parent | f2a24afe8c1aa0221b378585e3c1901cc568a6d7 (diff) |
Outliner/Collection: Operator to create (nested) collections
This is part of T53495.
This operator is intended for the outliner when viewing Collections (at the moment, Master Collection Tree).
It has a shortcut "C", and will be added to a menu shortly.
Diffstat (limited to 'source/blender')
3 files changed, 94 insertions, 0 deletions
diff --git a/source/blender/editors/space_outliner/outliner_collections.c b/source/blender/editors/space_outliner/outliner_collections.c index 05e7755209b..35d0a34b984 100644 --- a/source/blender/editors/space_outliner/outliner_collections.c +++ b/source/blender/editors/space_outliner/outliner_collections.c @@ -86,6 +86,19 @@ static CollectionOverride *outliner_override_active(bContext *UNUSED(C)) #endif /* -------------------------------------------------------------------- */ +/* Poll functions. */ + +static int collections_editor_poll(bContext *C) +{ + ScrArea *sa = CTX_wm_area(C); + if ((sa) && (sa->spacetype == SPACE_OUTLINER)) { + SpaceOops *so = CTX_wm_space_outliner(C); + return (so->outlinevis == SO_COLLECTIONS); + } + return 0; +} + +/* -------------------------------------------------------------------- */ /* collection manager operators */ /** @@ -334,6 +347,81 @@ void OUTLINER_OT_collection_new(wmOperatorType *ot) } /**********************************************************************************/ +/* Add new nested collection. */ + +struct CollectionNewData +{ + bool error; + SceneCollection *scene_collection; +}; + +static TreeTraversalAction collection_find_selected_to_add(TreeElement *te, void *customdata) +{ + struct CollectionNewData *data = customdata; + SceneCollection *scene_collection = outliner_scene_collection_from_tree_element(te); + + if (!scene_collection) { + return TRAVERSE_SKIP_CHILDS; + } + + if (data->scene_collection != NULL) { + data->error = true; + return TRAVERSE_BREAK; + } + + data->scene_collection = scene_collection; + return TRAVERSE_CONTINUE; +} + +static int collection_nested_new_exec(bContext *C, wmOperator *op) +{ + SpaceOops *soops = CTX_wm_space_outliner(C); + Main *bmain = CTX_data_main(C); + Scene *scene = CTX_data_scene(C); + ViewLayer *view_layer = CTX_data_view_layer(C); + + struct CollectionNewData data = { + .error = false, + .scene_collection = NULL, + }; + + outliner_tree_traverse(soops, &soops->tree, 0, TSE_SELECTED, collection_find_selected_to_add, &data); + + if (data.error) { + BKE_report(op->reports, RPT_ERROR, "More than one collection is selected"); + return OPERATOR_CANCELLED; + } + + SceneCollection *scene_collection; + scene_collection = BKE_collection_add( + &scene->id, + data.scene_collection, + COLLECTION_TYPE_NONE, + NULL); + BKE_collection_link(view_layer, scene_collection); + + outliner_cleanup_tree(soops); + DEG_relations_tag_update(bmain); + WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL); + return OPERATOR_FINISHED; +} + +void OUTLINER_OT_collection_nested_new(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "New Nested Collection"; + ot->idname = "OUTLINER_OT_collection_nested_new"; + ot->description = "Add a new collection inside selected collection"; + + /* api callbacks */ + ot->exec = collection_nested_new_exec; + ot->poll = collections_editor_poll; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} + +/**********************************************************************************/ /** * Returns true is selected element is a collection diff --git a/source/blender/editors/space_outliner/outliner_intern.h b/source/blender/editors/space_outliner/outliner_intern.h index abf733d0684..0025631c85f 100644 --- a/source/blender/editors/space_outliner/outliner_intern.h +++ b/source/blender/editors/space_outliner/outliner_intern.h @@ -340,6 +340,8 @@ void OUTLINER_OT_collection_objects_remove(struct wmOperatorType *ot); void OUTLINER_OT_collection_objects_select(struct wmOperatorType *ot); void OUTLINER_OT_collection_objects_deselect(struct wmOperatorType *ot); +void OUTLINER_OT_collection_nested_new(struct wmOperatorType *ot); + /* outliner_utils.c ---------------------------------------------- */ TreeElement *outliner_find_item_at_y(const SpaceOops *soops, const ListBase *tree, float view_co_y); diff --git a/source/blender/editors/space_outliner/outliner_ops.c b/source/blender/editors/space_outliner/outliner_ops.c index 856dd022c14..925d7a83b36 100644 --- a/source/blender/editors/space_outliner/outliner_ops.c +++ b/source/blender/editors/space_outliner/outliner_ops.c @@ -335,6 +335,8 @@ void outliner_operatortypes(void) WM_operatortype_append(OUTLINER_OT_collection_objects_remove); WM_operatortype_append(OUTLINER_OT_collection_objects_select); WM_operatortype_append(OUTLINER_OT_collection_objects_deselect); + + WM_operatortype_append(OUTLINER_OT_collection_nested_new); } static wmKeyMap *outliner_item_drag_drop_modal_keymap(wmKeyConfig *keyconf) @@ -432,6 +434,8 @@ void outliner_keymap(wmKeyConfig *keyconf) WM_keymap_verify_item(keymap, "OUTLINER_OT_drivers_add_selected", DKEY, KM_PRESS, 0, 0); WM_keymap_verify_item(keymap, "OUTLINER_OT_drivers_delete_selected", DKEY, KM_PRESS, KM_ALT, 0); + WM_keymap_verify_item(keymap, "OUTLINER_OT_collection_nested_new", CKEY, KM_PRESS, 0, 0); + outliner_item_drag_drop_modal_keymap(keyconf); } |