[Bf-blender-cvs] [8252a414d8c] blender2.8: Outliner/Collection: Operator to create (nested) collections

Dalai Felinto noreply at git.blender.org
Fri Dec 29 16:39:10 CET 2017


Commit: 8252a414d8cb15b42726d6f96d01cae97514d793
Author: Dalai Felinto
Date:   Fri Dec 29 11:36:54 2017 -0200
Branches: blender2.8
https://developer.blender.org/rB8252a414d8cb15b42726d6f96d01cae97514d793

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.

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

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

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

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
@@ -85,6 +85,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 */
 
@@ -333,6 +346,81 @@ void OUTLINER_OT_collection_new(wmOperatorType *ot)
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
+/**********************************************************************************/
+/* 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;
+}
+
 /**********************************************************************************/
 
 /**
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);
 }



More information about the Bf-blender-cvs mailing list