[Bf-blender-cvs] [eaf559d52aa] blender2.8: Outliner/Collections: Add selected objects operator

Dalai Felinto noreply at git.blender.org
Wed Jan 3 23:22:36 CET 2018


Commit: eaf559d52aa56faf4f1d76781ac4fc75ca31119e
Author: Dalai Felinto
Date:   Wed Jan 3 17:58:01 2018 -0200
Branches: blender2.8
https://developer.blender.org/rBeaf559d52aa56faf4f1d76781ac4fc75ca31119e

Outliner/Collections: Add selected objects operator

This is part of T53495.

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

M	release/scripts/startup/bl_ui/space_outliner.py
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/release/scripts/startup/bl_ui/space_outliner.py b/release/scripts/startup/bl_ui/space_outliner.py
index 043ca19ba11..f948c1a3e6a 100644
--- a/release/scripts/startup/bl_ui/space_outliner.py
+++ b/release/scripts/startup/bl_ui/space_outliner.py
@@ -137,6 +137,8 @@ class OUTLINER_MT_edit_collections(Menu):
 
         layout.operator("outliner.collection_nested_new", text="New Collection", icon='NEW')
         layout.operator("outliner.collection_delete_selected", text="Delete Collections", icon='X')
+        layout.separator()
+        layout.operator("outliner.collection_objects_add", text="Add Selected", icon='ZOOMIN')
 
 
 class OUTLINER_MT_edit_datablocks(Menu):
diff --git a/source/blender/editors/space_outliner/outliner_collections.c b/source/blender/editors/space_outliner/outliner_collections.c
index 7689131bad4..aef12971518 100644
--- a/source/blender/editors/space_outliner/outliner_collections.c
+++ b/source/blender/editors/space_outliner/outliner_collections.c
@@ -439,6 +439,77 @@ void OUTLINER_OT_collection_delete_selected(wmOperatorType *ot)
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
+/**********************************************************************************/
+/* Add new selected objects. */
+
+struct SceneCollectionSelectedData {
+	ListBase scene_collections_array;
+};
+
+static TreeTraversalAction collection_find_selected_scene_collections(TreeElement *te, void *customdata)
+{
+	struct SceneCollectionSelectedData *data = customdata;
+	SceneCollection *scene_collection = outliner_scene_collection_from_tree_element(te);
+
+	if (!scene_collection) {
+		return TRAVERSE_SKIP_CHILDS;
+	}
+
+	BLI_addtail(&data->scene_collections_array, BLI_genericNodeN(scene_collection));
+	return TRAVERSE_CONTINUE;
+}
+
+static int collection_objects_add_exec(bContext *C, wmOperator *op)
+{
+	SpaceOops *soops = CTX_wm_space_outliner(C);
+	Main *bmain = CTX_data_main(C);
+	Scene *scene = CTX_data_scene(C);
+
+	struct SceneCollectionSelectedData data = {
+		.scene_collections_array = {NULL, NULL},
+	};
+
+	outliner_tree_traverse(soops, &soops->tree, 0, TSE_SELECTED, collection_find_selected_scene_collections, &data);
+
+	if (BLI_listbase_is_empty(&data.scene_collections_array)) {
+		BKE_report(op->reports, RPT_ERROR, "No collection is selected");
+		return OPERATOR_CANCELLED;
+	}
+
+	CTX_DATA_BEGIN (C, struct Object *, ob, selected_objects)
+	{
+		LINKLIST_FOREACH(LinkData *, link, &data.scene_collections_array) {
+			SceneCollection *scene_collection = link->data;
+			BKE_collection_object_add(
+			            &scene->id,
+			            scene_collection,
+			            ob);
+		}
+	}
+	CTX_DATA_END;
+	BLI_freelistN(&data.scene_collections_array);
+
+	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_objects_add(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Add Objects";
+	ot->idname = "OUTLINER_OT_collection_objects_add";
+	ot->description = "Add selected objects to collection";
+
+	/* api callbacks */
+	ot->exec = collection_objects_add_exec;
+	ot->poll = collections_editor_poll;
+
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
 /**********************************************************************************/
 
 /**
@@ -673,20 +744,6 @@ static int stubs_invoke(bContext *UNUSED(C), wmOperator *op, const wmEvent *UNUS
 	return OPERATOR_CANCELLED;
 }
 
-void OUTLINER_OT_collection_objects_add(wmOperatorType *ot)
-{
-	/* identifiers */
-	ot->name = "Add Objects";
-	ot->idname = "OUTLINER_OT_collection_objects_add";
-	ot->description = "Add selected objects to collection";
-
-	/* api callbacks */
-	ot->invoke = stubs_invoke;
-
-	/* flags */
-	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-}
-
 void OUTLINER_OT_collection_objects_remove(wmOperatorType *ot)
 {
 	/* identifiers */
diff --git a/source/blender/editors/space_outliner/outliner_intern.h b/source/blender/editors/space_outliner/outliner_intern.h
index c73e4f4aadd..fc924ecdfba 100644
--- a/source/blender/editors/space_outliner/outliner_intern.h
+++ b/source/blender/editors/space_outliner/outliner_intern.h
@@ -335,11 +335,11 @@ void OUTLINER_OT_collection_link(struct wmOperatorType *ot);
 void OUTLINER_OT_collection_unlink(struct wmOperatorType *ot);
 void OUTLINER_OT_collection_new(struct wmOperatorType *ot);
 void OUTLINER_OT_collection_override_new(struct wmOperatorType *ot);
-void OUTLINER_OT_collection_objects_add(struct wmOperatorType *ot);
 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_objects_add(struct wmOperatorType *ot);
 void OUTLINER_OT_collection_nested_new(struct wmOperatorType *ot);
 void OUTLINER_OT_collection_delete_selected(struct wmOperatorType *ot);
 
diff --git a/source/blender/editors/space_outliner/outliner_ops.c b/source/blender/editors/space_outliner/outliner_ops.c
index 98e8aca0e1f..cd739e5fa55 100644
--- a/source/blender/editors/space_outliner/outliner_ops.c
+++ b/source/blender/editors/space_outliner/outliner_ops.c
@@ -331,13 +331,13 @@ void outliner_operatortypes(void)
 	WM_operatortype_append(OUTLINER_OT_collection_unlink);
 	WM_operatortype_append(OUTLINER_OT_collection_new);
 	WM_operatortype_append(OUTLINER_OT_collection_override_new);
-	WM_operatortype_append(OUTLINER_OT_collection_objects_add);
 	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);
 	WM_operatortype_append(OUTLINER_OT_collection_delete_selected);
+	WM_operatortype_append(OUTLINER_OT_collection_objects_add);
 }
 
 static wmKeyMap *outliner_item_drag_drop_modal_keymap(wmKeyConfig *keyconf)



More information about the Bf-blender-cvs mailing list