forked from bartvdbraak/blender
Outliner: "Purge All" function for Outliner in "Orphaned Datablocks" mode
Many users have been requesting a way to remove unused datablocks from the file/session "without closing and reopening" Blender (or at least that's the impression I'm getting). This commit adds a new operator (exposed as the "Purge All" button in the header of the "Orphaned Datablocks" mode in the Outliner, which seems to be the logical place for this) for doing so. It does so by wrapping up the save and "revert" (i.e. reload the saved file from disk, without needing to quit Blender) operators along with a confirmation prompt for good measure. Caveats: * Ultimately, we still cannot really cleanly delete any datablocks from the current session outright without reloading the file/data at some point. Thus, we do need to reload the file again before it can be used. * This does mean that this operation is irreversible. Notably, Undo history is lost is doing this operation. Hence the warnings... (Then again, undo/redo actually reloads the entire scene DB from memory, so it's not anything uncommon ;) Other Notes: * The addition of this operator brings this mode more into line with being a kind of "Trashcan" place, with this new operator being the manual "Empty Trash" button. If the "Orphaned Datablocks" name is too obscure, maybe we could rename this mode to "Trash" or something similar?
This commit is contained in:
parent
0688f6e012
commit
263518ec49
@ -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):
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user