diff --git a/source/blender/windowmanager/intern/wm_files.cc b/source/blender/windowmanager/intern/wm_files.cc index 19ca178d5d5..1503510ed2d 100644 --- a/source/blender/windowmanager/intern/wm_files.cc +++ b/source/blender/windowmanager/intern/wm_files.cc @@ -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(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", ""); } /** \} */