UI: Clear Recent Cleanup Option
Adds an option to the "Clear Recent Files List" operator to allow it to remove only items that are not found. By default it clears "All Items" but this can be changed to "Items Not Found". Pull Request: https://projects.blender.org/blender/blender/pulls/127024
This commit is contained in:
committed by
Harley Acheson
parent
89095826fd
commit
4317f50f5f
@@ -3771,25 +3771,51 @@ void WM_OT_save_mainfile(wmOperatorType *ot)
|
||||
/** \name Clear Recent Files List Operator
|
||||
* \{ */
|
||||
|
||||
static int wm_clear_recent_files_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/)
|
||||
enum ClearRecentInclude { CLEAR_RECENT_ALL, CLEAR_RECENT_MISSING };
|
||||
|
||||
static const EnumPropertyItem prop_clear_recent_types[] = {
|
||||
{CLEAR_RECENT_ALL, "ALL", 0, "All Items", ""},
|
||||
{CLEAR_RECENT_MISSING, "MISSING", 0, "Items Not Found", ""},
|
||||
{0, nullptr, 0, nullptr, nullptr},
|
||||
};
|
||||
|
||||
static int wm_clear_recent_files_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
{
|
||||
return WM_operator_confirm_ex(C,
|
||||
op,
|
||||
nullptr,
|
||||
IFACE_("Remove all items from the recent files list"),
|
||||
IFACE_("Remove All"),
|
||||
ALERT_ICON_WARNING,
|
||||
false);
|
||||
return WM_operator_props_popup_confirm_ex(
|
||||
C, op, event, IFACE_("Clear Recent Files List"), IFACE_("Remove"));
|
||||
}
|
||||
|
||||
static int wm_clear_recent_files_exec(bContext * /*C*/, wmOperator * /*op*/)
|
||||
static int wm_clear_recent_files_exec(bContext * /*C*/, wmOperator *op)
|
||||
{
|
||||
wm_history_files_free();
|
||||
ClearRecentInclude include = static_cast<ClearRecentInclude>(RNA_enum_get(op->ptr, "remove"));
|
||||
|
||||
if (include == CLEAR_RECENT_ALL) {
|
||||
wm_history_files_free();
|
||||
}
|
||||
else if (include == CLEAR_RECENT_MISSING) {
|
||||
LISTBASE_FOREACH_MUTABLE (RecentFile *, recent, &G.recent_files) {
|
||||
if (!BLI_exists(recent->filepath)) {
|
||||
BLI_freelinkN(&G.recent_files, recent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wm_history_file_write();
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
static void wm_clear_recent_files_ui(bContext * /*C*/, wmOperator *op)
|
||||
{
|
||||
uiLayout *layout = op->layout;
|
||||
uiLayoutSetPropSep(layout, true);
|
||||
uiLayoutSetPropDecorate(layout, false);
|
||||
|
||||
uiItemS(layout);
|
||||
uiItemR(layout, op->ptr, "remove", UI_ITEM_R_TOGGLE, nullptr, ICON_NONE);
|
||||
uiItemS(layout);
|
||||
}
|
||||
|
||||
void WM_OT_clear_recent_files(wmOperatorType *ot)
|
||||
{
|
||||
ot->name = "Clear Recent Files List";
|
||||
@@ -3798,6 +3824,14 @@ void WM_OT_clear_recent_files(wmOperatorType *ot)
|
||||
|
||||
ot->invoke = wm_clear_recent_files_invoke;
|
||||
ot->exec = wm_clear_recent_files_exec;
|
||||
ot->ui = wm_clear_recent_files_ui;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER;
|
||||
|
||||
/* props */
|
||||
ot->prop = RNA_def_enum(
|
||||
ot->srna, "remove", prop_clear_recent_types, CLEAR_RECENT_ALL, "Remove", "");
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
Reference in New Issue
Block a user