Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_outliner/outliner_collections.c
| Show First 20 Lines • Show All 442 Lines • ▼ Show 20 Lines | static TreeElement *outliner_active_collection(bContext *C) | ||||
| return data.te; | return data.te; | ||||
| } | } | ||||
| static int collection_duplicate_exec(bContext *C, wmOperator *op) | static int collection_duplicate_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| SpaceOutliner *soops = CTX_wm_space_outliner(C); | SpaceOutliner *soops = CTX_wm_space_outliner(C); | ||||
| TreeElement *te = outliner_active_collection(C); | TreeElement *te = outliner_active_collection(C); | ||||
| bool hierarchy = strstr(op->idname, "hierarchy") != NULL; | |||||
| bool linked = strstr(op->idname, "linked") != NULL; | |||||
| /* Can happen when calling from a key binding. */ | /* Can happen when calling from a key binding. */ | ||||
| if (te == NULL) { | if (te == NULL) { | ||||
| BKE_report(op->reports, RPT_ERROR, "No active collection"); | BKE_report(op->reports, RPT_ERROR, "No active collection"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| Collection *collection = outliner_collection_from_tree_element(te); | Collection *collection = outliner_collection_from_tree_element(te); | ||||
| Collection *parent = (te->parent) ? outliner_collection_from_tree_element(te->parent) : NULL; | Collection *parent = (te->parent) ? outliner_collection_from_tree_element(te->parent) : NULL; | ||||
| if (collection->flag & COLLECTION_IS_MASTER) { | if (collection->flag & COLLECTION_IS_MASTER) { | ||||
| BKE_report(op->reports, RPT_ERROR, "Can't duplicate the master collection"); | BKE_report(op->reports, RPT_ERROR, "Can't duplicate the master collection"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| switch (soops->outlinevis) { | switch (soops->outlinevis) { | ||||
| case SO_SCENES: | case SO_SCENES: | ||||
| case SO_VIEW_LAYER: | case SO_VIEW_LAYER: | ||||
| case SO_LIBRARIES: | case SO_LIBRARIES: | ||||
| BKE_collection_copy(bmain, parent, collection); | BKE_collection_duplicate(bmain, parent, collection, hierarchy, !linked); | ||||
| break; | break; | ||||
| } | } | ||||
| DEG_relations_tag_update(bmain); | DEG_relations_tag_update(bmain); | ||||
| WM_main_add_notifier(NC_SCENE | ND_LAYER, CTX_data_scene(C)); | WM_main_add_notifier(NC_SCENE | ND_LAYER, CTX_data_scene(C)); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| void OUTLINER_OT_collection_duplicate(wmOperatorType *ot) | void OUTLINER_OT_collection_duplicate(wmOperatorType *ot) | ||||
| { | { | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Duplicate Collection"; | ot->name = "Duplicate Collection"; | ||||
| ot->idname = "OUTLINER_OT_collection_duplicate"; | ot->idname = "OUTLINER_OT_collection_duplicate"; | ||||
| ot->description = "Duplicate selected collections"; | ot->description = "Make a new collection with linked content (collection and objects)"; | ||||
| /* api callbacks */ | |||||
| ot->exec = collection_duplicate_exec; | |||||
| ot->poll = ED_outliner_collections_editor_poll; | |||||
| /* flags */ | |||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | |||||
| } | |||||
| void OUTLINER_OT_collection_duplicate_hierarchy(wmOperatorType *ot) | |||||
| { | |||||
| /* identifiers */ | |||||
| ot->name = "Duplicate Collection Hierarchy"; | |||||
| ot->idname = "OUTLINER_OT_collection_duplicate_hierarchy"; | |||||
| ot->description = "Duplicate entire hierarchy and make all content single user"; | |||||
| /* api callbacks */ | |||||
| ot->exec = collection_duplicate_exec; | |||||
| ot->poll = ED_outliner_collections_editor_poll; | |||||
| /* flags */ | |||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | |||||
| } | |||||
| void OUTLINER_OT_collection_duplicate_linked_hierarchy(wmOperatorType *ot) | |||||
| { | |||||
| /* identifiers */ | |||||
| ot->name = "Duplicate Linked Collection Hierarchy"; | |||||
| ot->idname = "OUTLINER_OT_collection_duplicate_linked_hierarchy"; | |||||
| ot->description = "Duplicate entire hierarchy with linked object data"; | |||||
| /* api callbacks */ | /* api callbacks */ | ||||
| ot->exec = collection_duplicate_exec; | ot->exec = collection_duplicate_exec; | ||||
| ot->poll = ED_outliner_collections_editor_poll; | ot->poll = ED_outliner_collections_editor_poll; | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 829 Lines • Show Last 20 Lines | |||||