diff options
-rw-r--r-- | release/scripts/startup/bl_ui/space_outliner.py | 1 | ||||
-rw-r--r-- | source/blender/editors/space_outliner/outliner_collections.c | 71 | ||||
-rw-r--r-- | source/blender/editors/space_outliner/outliner_ops.c | 2 |
3 files changed, 59 insertions, 15 deletions
diff --git a/release/scripts/startup/bl_ui/space_outliner.py b/release/scripts/startup/bl_ui/space_outliner.py index f948c1a3e6a..b1ab55b7ed1 100644 --- a/release/scripts/startup/bl_ui/space_outliner.py +++ b/release/scripts/startup/bl_ui/space_outliner.py @@ -139,6 +139,7 @@ class OUTLINER_MT_edit_collections(Menu): layout.operator("outliner.collection_delete_selected", text="Delete Collections", icon='X') layout.separator() layout.operator("outliner.collection_objects_add", text="Add Selected", icon='ZOOMIN') + layout.operator("outliner.collection_objects_remove", text="Remove Selected", icon='ZOOMOUT') 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 aef12971518..239e6a9b0fc 100644 --- a/source/blender/editors/space_outliner/outliner_collections.c +++ b/source/blender/editors/space_outliner/outliner_collections.c @@ -511,6 +511,63 @@ void OUTLINER_OT_collection_objects_add(wmOperatorType *ot) } /**********************************************************************************/ +/* Remove selected objects. */ + + +static int collection_objects_remove_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_remove( + bmain, + &scene->id, + scene_collection, + ob, + true); + } + } + 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_remove(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Remove Objects"; + ot->idname = "OUTLINER_OT_collection_objects_remove"; + ot->description = "Remove selected objects from collection"; + + /* api callbacks */ + ot->exec = collection_objects_remove_exec; + ot->poll = collections_editor_poll; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} + +/**********************************************************************************/ /** * Returns true is selected element is a collection @@ -744,20 +801,6 @@ static int stubs_invoke(bContext *UNUSED(C), wmOperator *op, const wmEvent *UNUS return OPERATOR_CANCELLED; } -void OUTLINER_OT_collection_objects_remove(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Remove Object"; - ot->idname = "OUTLINER_OT_collection_objects_remove"; - ot->description = "Remove objects from collection"; - - /* api callbacks */ - ot->invoke = stubs_invoke; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; -} - void OUTLINER_OT_collection_objects_select(wmOperatorType *ot) { /* identifiers */ diff --git a/source/blender/editors/space_outliner/outliner_ops.c b/source/blender/editors/space_outliner/outliner_ops.c index cd739e5fa55..a40abb5fd3b 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_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); + WM_operatortype_append(OUTLINER_OT_collection_objects_remove); } static wmKeyMap *outliner_item_drag_drop_modal_keymap(wmKeyConfig *keyconf) |