From f04bd961fd1eea4a61716b7d8d2e15d2b0af65ab Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Tue, 27 Feb 2024 23:47:40 +0100 Subject: [PATCH] UI: Manage Unused Data Operator An operator that brings up a window with Outliner in "Unused Data" mode to allow users fine-grained control over protecting and purging. Pull Request: https://projects.blender.org/blender/blender/pulls/118435 --- scripts/startup/bl_ui/space_topbar.py | 3 +- .../editors/space_outliner/outliner_edit.cc | 51 +++++++++++++++++++ .../editors/space_outliner/outliner_intern.hh | 1 + .../editors/space_outliner/outliner_ops.cc | 1 + 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/scripts/startup/bl_ui/space_topbar.py b/scripts/startup/bl_ui/space_topbar.py index 9b9ad81f9a9..89c8faa607a 100644 --- a/scripts/startup/bl_ui/space_topbar.py +++ b/scripts/startup/bl_ui/space_topbar.py @@ -239,7 +239,8 @@ class TOPBAR_MT_file_cleanup(Menu): layout = self.layout layout.separator() - props = layout.operator("outliner.orphans_purge", text="Unused Data-Blocks") + layout.operator("outliner.orphans_purge", text="Purge Unused Data") + layout.operator("outliner.orphans_manage", text="Manage Unused Data") class TOPBAR_MT_file(Menu): diff --git a/source/blender/editors/space_outliner/outliner_edit.cc b/source/blender/editors/space_outliner/outliner_edit.cc index c649b0d1be3..5a30258c079 100644 --- a/source/blender/editors/space_outliner/outliner_edit.cc +++ b/source/blender/editors/space_outliner/outliner_edit.cc @@ -71,6 +71,8 @@ #include "tree/tree_element_rna.hh" #include "tree/tree_iterator.hh" +#include "wm_window.hh" + using namespace blender::ed::outliner; namespace blender::ed::outliner { @@ -2344,4 +2346,53 @@ void OUTLINER_OT_orphans_purge(wmOperatorType *ot) /** \} */ +/* -------------------------------------------------------------------- */ +/** \name Manage Orphan Data-Blocks Operator + * \{ */ + +static int outliner_orphans_manage_invoke(bContext *C, wmOperator * /*op*/, const wmEvent *event) +{ + const int sizex = int(450.0f * UI_SCALE_FAC); + const int sizey = int(450.0f * UI_SCALE_FAC); + const rcti window_rect = { + /*xmin*/ event->xy[0], + /*xmax*/ event->xy[0] + sizex, + /*ymin*/ event->xy[1], + /*ymax*/ event->xy[1] + sizey, + }; + + if (WM_window_open(C, + IFACE_("Manage Unused Data"), + &window_rect, + SPACE_OUTLINER, + false, + false, + true, + WIN_ALIGN_LOCATION_CENTER, + nullptr, + nullptr) != nullptr) + { + SpaceOutliner *soutline = CTX_wm_space_outliner(C); + soutline->outlinevis = SO_ID_ORPHANS; + return OPERATOR_FINISHED; + } + return OPERATOR_CANCELLED; +} + +void OUTLINER_OT_orphans_manage(wmOperatorType *ot) +{ + /* identifiers */ + ot->idname = "OUTLINER_OT_orphans_manage"; + ot->name = "Manage Unused Data"; + ot->description = "Open a window to manage unused data"; + + /* callbacks */ + ot->invoke = outliner_orphans_manage_invoke; + + /* flags */ + ot->flag = OPTYPE_REGISTER; +} + +/** \} */ + } // namespace blender::ed::outliner diff --git a/source/blender/editors/space_outliner/outliner_intern.hh b/source/blender/editors/space_outliner/outliner_intern.hh index 94abc75e088..c3ec8080b78 100644 --- a/source/blender/editors/space_outliner/outliner_intern.hh +++ b/source/blender/editors/space_outliner/outliner_intern.hh @@ -507,6 +507,7 @@ void OUTLINER_OT_drivers_add_selected(wmOperatorType *ot); void OUTLINER_OT_drivers_delete_selected(wmOperatorType *ot); void OUTLINER_OT_orphans_purge(wmOperatorType *ot); +void OUTLINER_OT_orphans_manage(wmOperatorType *ot); /* `outliner_query.cc` */ diff --git a/source/blender/editors/space_outliner/outliner_ops.cc b/source/blender/editors/space_outliner/outliner_ops.cc index b94df433274..8be6ddd0949 100644 --- a/source/blender/editors/space_outliner/outliner_ops.cc +++ b/source/blender/editors/space_outliner/outliner_ops.cc @@ -60,6 +60,7 @@ void outliner_operatortypes() WM_operatortype_append(OUTLINER_OT_drivers_delete_selected); WM_operatortype_append(OUTLINER_OT_orphans_purge); + WM_operatortype_append(OUTLINER_OT_orphans_manage); WM_operatortype_append(OUTLINER_OT_parent_drop); WM_operatortype_append(OUTLINER_OT_parent_clear);