[Bf-blender-cvs] [39112a4f7b2] master: UI: Remove orphan datablocks directly from File->Clean Up menu

Antonio Vazquez noreply at git.blender.org
Fri Dec 20 17:35:49 CET 2019


Commit: 39112a4f7b2b5e65dd73b13215e9df67f27ab88a
Author: Antonio Vazquez
Date:   Fri Dec 20 17:35:12 2019 +0100
Branches: master
https://developer.blender.org/rB39112a4f7b2b5e65dd73b13215e9df67f27ab88a

UI: Remove orphan datablocks directly from File->Clean Up menu

Actually, to purge orphans datablock you need go to Outliner, enable Orphan mode and press Purge button (that sometimes is out of the view because the window is too narrow).

To have this option hidden make very difficult to users use and understand what means orphan data, so this patch just adds a new Clean Up menu to File menu with this option. This menu could be used in the future for more clean up options. To have a general Clean Up menu is common used in other softwares.

Reviewed By: billreynish, mont29

Differential Revision: https://developer.blender.org/D6445

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

M	release/scripts/startup/bl_ui/space_topbar.py
M	source/blender/editors/space_outliner/outliner_edit.c

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

diff --git a/release/scripts/startup/bl_ui/space_topbar.py b/release/scripts/startup/bl_ui/space_topbar.py
index 6316744eca9..7dbf49d01e3 100644
--- a/release/scripts/startup/bl_ui/space_topbar.py
+++ b/release/scripts/startup/bl_ui/space_topbar.py
@@ -243,6 +243,16 @@ class TOPBAR_MT_app(Menu):
                         text="Install Application Template...")
 
 
+class TOPBAR_MT_file_cleanup(Menu):
+    bl_label = "Clean Up"
+
+    def draw(self, context):
+        layout = self.layout
+        layout.separator()
+
+        layout.operator("outliner.orphans_purge")
+
+
 class TOPBAR_MT_file(Menu):
     bl_label = "File"
 
@@ -281,6 +291,7 @@ class TOPBAR_MT_file(Menu):
         layout.separator()
 
         layout.menu("TOPBAR_MT_file_external_data")
+        layout.menu("TOPBAR_MT_file_cleanup")
 
         layout.separator()
 
@@ -823,6 +834,7 @@ classes = (
     TOPBAR_MT_file_import,
     TOPBAR_MT_file_export,
     TOPBAR_MT_file_external_data,
+    TOPBAR_MT_file_cleanup,
     TOPBAR_MT_file_previews,
     TOPBAR_MT_edit,
     TOPBAR_MT_render,
diff --git a/source/blender/editors/space_outliner/outliner_edit.c b/source/blender/editors/space_outliner/outliner_edit.c
index c8a6c2a87e3..8c4df1d7a7b 100644
--- a/source/blender/editors/space_outliner/outliner_edit.c
+++ b/source/blender/editors/space_outliner/outliner_edit.c
@@ -1311,7 +1311,8 @@ static int outliner_show_active_exec(bContext *C, wmOperator *UNUSED(op))
       outliner_show_active(so, ar, te, id);
     }
 
-    /* Also open back from the active_element (only done for the first found occurance of ID though). */
+    /* Also open back from the active_element (only done for the first found occurance of ID
+     * though). */
     outliner_show_active(so, ar, active_element, id);
 
     /* Center view on first element found */
@@ -2176,9 +2177,15 @@ void OUTLINER_OT_keyingset_remove_selected(wmOperatorType *ot)
 static bool ed_operator_outliner_id_orphans_active(bContext *C)
 {
   ScrArea *sa = CTX_wm_area(C);
-  if ((sa) && (sa->spacetype == SPACE_OUTLINER)) {
-    SpaceOutliner *so = CTX_wm_space_outliner(C);
-    return (so->outlinevis == SO_ID_ORPHANS);
+  if (sa != NULL) {
+    if (sa->spacetype == SPACE_TOPBAR) {
+      return true;
+    }
+
+    if (sa->spacetype == SPACE_OUTLINER) {
+      SpaceOutliner *so = CTX_wm_space_outliner(C);
+      return (so->outlinevis == SO_ID_ORPHANS);
+    }
   }
   return 0;
 }
@@ -2245,6 +2252,7 @@ static int outliner_orphans_purge_invoke(bContext *C, wmOperator *op, const wmEv
 static int outliner_orphans_purge_exec(bContext *C, wmOperator *op)
 {
   Main *bmain = CTX_data_main(C);
+  ScrArea *sa = CTX_wm_area(C);
   SpaceOutliner *soops = CTX_wm_space_outliner(C);
   int num_tagged[INDEX_ID_MAX] = {0};
 
@@ -2271,7 +2279,9 @@ static int outliner_orphans_purge_exec(bContext *C, wmOperator *op)
    *      outliner several mouse events can be handled in one cycle without
    *      handling notifiers/redraw which leads to deleting the same object twice.
    *      cleanup tree here to prevent such cases. */
-  outliner_cleanup_tree(soops);
+  if ((sa != NULL) && (sa->spacetype == SPACE_OUTLINER)) {
+    outliner_cleanup_tree(soops);
+  }
 
   DEG_relations_tag_update(bmain);
   WM_event_add_notifier(C, NC_ID | NA_EDITED, NULL);



More information about the Bf-blender-cvs mailing list