Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Leung <aligorith@gmail.com>2015-02-15 15:15:58 +0300
committerJoshua Leung <aligorith@gmail.com>2015-02-15 15:21:47 +0300
commit263518ec4909a8e108a587988b6c64e66b12ac9f (patch)
treeb6606283c50c904ef22c4398bd9cb4772e10f033 /source/blender/editors/space_outliner/outliner_edit.c
parent0688f6e01201defc36df906c2d7086eb7f44d849 (diff)
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?
Diffstat (limited to 'source/blender/editors/space_outliner/outliner_edit.c')
-rw-r--r--source/blender/editors/space_outliner/outliner_edit.c56
1 files changed, 56 insertions, 0 deletions
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)