Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDalai Felinto <dfelinto@gmail.com>2017-12-29 16:36:54 +0300
committerDalai Felinto <dfelinto@gmail.com>2017-12-29 18:36:55 +0300
commit8252a414d8cb15b42726d6f96d01cae97514d793 (patch)
tree409b68d1afc15c1bfefc3df81e2b3c2f35a036d5 /source/blender/editors/space_outliner/outliner_collections.c
parentf2a24afe8c1aa0221b378585e3c1901cc568a6d7 (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/editors/space_outliner/outliner_collections.c')
-rw-r--r--source/blender/editors/space_outliner/outliner_collections.c88
1 files changed, 88 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