[Bf-blender-cvs] [263518e] master: Outliner: "Purge All" function for Outliner in "Orphaned Datablocks" mode

Joshua Leung noreply at git.blender.org
Sun Feb 15 13:23:09 CET 2015


Commit: 263518ec4909a8e108a587988b6c64e66b12ac9f
Author: Joshua Leung
Date:   Mon Feb 16 01:15:58 2015 +1300
Branches: master
https://developer.blender.org/rB263518ec4909a8e108a587988b6c64e66b12ac9f

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?

===================================================================

M	release/scripts/startup/bl_ui/space_outliner.py
M	source/blender/editors/space_outliner/outliner_edit.c
M	source/blender/editors/space_outliner/outliner_intern.h
M	source/blender/editors/space_outliner/outliner_ops.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_outliner.py b/release/scripts/startup/bl_ui/space_outliner.py
index 47c8cc6..9c60189 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 d17ab33..b865f33 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 aa2a889..50feceb 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 fbfaf26..f586957 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);




More information about the Bf-blender-cvs mailing list