diff --git a/release/scripts/startup/bl_ui/space_outliner.py b/release/scripts/startup/bl_ui/space_outliner.py index 47c8cc65247..9c6018965a7 100644 --- a/release/scripts/startup/bl_ui/space_outliner.py +++ b/release/scripts/startup/bl_ui/space_outliner.py @@ -57,6 +57,8 @@ class OUTLINER_HT_header(Header): else: row = layout.row() row.label(text="No Keying Set active") + elif space.display_mode == 'ORPHANED_DATABLOCKS': + layout.operator("outliner.orphans_purge") class OUTLINER_MT_editor_menus(Menu): diff --git a/source/blender/editors/space_outliner/outliner_edit.c b/source/blender/editors/space_outliner/outliner_edit.c index d17ab33d0fa..b865f33b3ad 100644 --- a/source/blender/editors/space_outliner/outliner_edit.c +++ b/source/blender/editors/space_outliner/outliner_edit.c @@ -1458,6 +1458,62 @@ void OUTLINER_OT_keyingset_remove_selected(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } + +/* ************************************************************** */ +/* ORPHANED DATABLOCKS */ + +static int ed_operator_outliner_id_orphans_active(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_ID_ORPHANS); + } + return 0; +} + +/* Purge Orphans Operator --------------------------------------- */ + +static int outliner_orphans_purge_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(evt)) +{ + /* present a prompt to informing users that this change is irreversible */ + return WM_operator_confirm_message(C, op, + "Purging unused datablocks cannot be undone. " + "Click here to proceed..."); +} + +static int outliner_orphans_purge_exec(bContext *C, wmOperator *op) +{ + /* Firstly, ensure that the file has been saved, + * so that the latest changes since the last save + * are retained... + */ + WM_operator_name_call(C, "WM_OT_save_mainfile", WM_OP_EXEC_DEFAULT, NULL); + + /* Now, reload the file to get rid of the orphans... */ + WM_operator_name_call(C, "WM_OT_revert_mainfile", WM_OP_EXEC_DEFAULT, NULL); + return OPERATOR_FINISHED; +} + +void OUTLINER_OT_orphans_purge(wmOperatorType *ot) +{ + /* identifiers */ + ot->idname = "OUTLINER_OT_orphans_purge"; + ot->name = "Purge All"; + ot->description = "Clears all orphaned datablocks without any users from the file (cannot be undone)"; + + /* callbacks */ + ot->invoke = outliner_orphans_purge_invoke; + ot->exec = outliner_orphans_purge_exec; + ot->poll = ed_operator_outliner_id_orphans_active; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} + +/* ************************************************************** */ +/* DRAG AND DROP OPERATORS */ + /* ******************** Parent Drop Operator *********************** */ static int parent_drop_exec(bContext *C, wmOperator *op) diff --git a/source/blender/editors/space_outliner/outliner_intern.h b/source/blender/editors/space_outliner/outliner_intern.h index aa2a8896b17..50fecebb742 100644 --- a/source/blender/editors/space_outliner/outliner_intern.h +++ b/source/blender/editors/space_outliner/outliner_intern.h @@ -235,6 +235,8 @@ void OUTLINER_OT_keyingset_remove_selected(struct wmOperatorType *ot); void OUTLINER_OT_drivers_add_selected(struct wmOperatorType *ot); void OUTLINER_OT_drivers_delete_selected(struct wmOperatorType *ot); +void OUTLINER_OT_orphans_purge(struct wmOperatorType *ot); + void OUTLINER_OT_parent_drop(struct wmOperatorType *ot); void OUTLINER_OT_parent_clear(struct wmOperatorType *ot); void OUTLINER_OT_scene_drop(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_outliner/outliner_ops.c b/source/blender/editors/space_outliner/outliner_ops.c index fbfaf26104e..f5869575cc6 100644 --- a/source/blender/editors/space_outliner/outliner_ops.c +++ b/source/blender/editors/space_outliner/outliner_ops.c @@ -74,6 +74,8 @@ void outliner_operatortypes(void) WM_operatortype_append(OUTLINER_OT_drivers_add_selected); WM_operatortype_append(OUTLINER_OT_drivers_delete_selected); + + WM_operatortype_append(OUTLINER_OT_orphans_purge); WM_operatortype_append(OUTLINER_OT_parent_drop); WM_operatortype_append(OUTLINER_OT_parent_clear);