From 1cfc83d5f66fa978f41041560a45fd514be0cf10 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 9 Jul 2024 18:42:01 +1000 Subject: [PATCH] UI: add cancel_default option to WindowManager.invoke_props_dialog Make it possible that the cancel option is default for operator popups. --- source/blender/makesrna/intern/rna_wm_api.cc | 5 ++++- source/blender/windowmanager/WM_api.hh | 6 ++++-- .../blender/windowmanager/intern/wm_operators.cc | 15 +++++++++------ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/source/blender/makesrna/intern/rna_wm_api.cc b/source/blender/makesrna/intern/rna_wm_api.cc index c0f818ad378..49fa2464e0c 100644 --- a/source/blender/makesrna/intern/rna_wm_api.cc +++ b/source/blender/makesrna/intern/rna_wm_api.cc @@ -236,6 +236,7 @@ static int rna_Operator_props_dialog_popup(bContext *C, const int width, const char *title, const char *confirm_text, + const bool cancel_default, const char *text_ctxt, const bool translate) { @@ -246,7 +247,8 @@ static int rna_Operator_props_dialog_popup(bContext *C, op, width, title ? std::make_optional(title) : std::nullopt, - confirm_text ? std::make_optional(confirm_text) : std::nullopt); + confirm_text ? std::make_optional(confirm_text) : std::nullopt, + cancel_default); } static int keymap_item_modifier_flag_from_args(bool any, int shift, int ctrl, int alt, int oskey) @@ -913,6 +915,7 @@ void RNA_api_wm(StructRNA *srna) parm, "Confirm Text", "Optional text to show instead to the default \"OK\" confirmation button text"); + RNA_def_property(func, "cancel_default", PROP_BOOLEAN, PROP_NONE); api_ui_item_common_translation(func); /* invoke enum */ diff --git a/source/blender/windowmanager/WM_api.hh b/source/blender/windowmanager/WM_api.hh index 7554fe80662..af8ced680bb 100644 --- a/source/blender/windowmanager/WM_api.hh +++ b/source/blender/windowmanager/WM_api.hh @@ -741,7 +741,8 @@ int WM_operator_props_popup_confirm_ex(bContext *C, wmOperator *op, const wmEvent *event, std::optional title = std::nullopt, - std::optional confirm_text = std::nullopt); + std::optional confirm_text = std::nullopt, + bool cancel_default = false); /** * Same as #WM_operator_props_popup but call the operator first, @@ -755,7 +756,8 @@ int WM_operator_props_dialog_popup(bContext *C, wmOperator *op, int width, std::optional title = std::nullopt, - std::optional confirm_text = std::nullopt); + std::optional confirm_text = std::nullopt, + bool cancel_default = false); int WM_operator_redo_popup(bContext *C, wmOperator *op); int WM_operator_ui_popup(bContext *C, wmOperator *op, int width); diff --git a/source/blender/windowmanager/intern/wm_operators.cc b/source/blender/windowmanager/intern/wm_operators.cc index fe8c2de35c2..5676badbf0a 100644 --- a/source/blender/windowmanager/intern/wm_operators.cc +++ b/source/blender/windowmanager/intern/wm_operators.cc @@ -1766,7 +1766,8 @@ static int wm_operator_props_popup_ex(bContext *C, const bool do_call, const bool do_redo, std::optional title = std::nullopt, - std::optional confirm_text = std::nullopt) + std::optional confirm_text = std::nullopt, + const bool cancel_default = false) { if ((op->type->flag & OPTYPE_REGISTER) == 0) { BKE_reportf(op->reports, @@ -1789,7 +1790,7 @@ static int wm_operator_props_popup_ex(bContext *C, /* If we don't have global undo, we can't do undo push for automatic redo, * so we require manual OK clicking in this popup. */ if (!do_redo || !(U.uiflag & USER_GLOBALUNDO)) { - return WM_operator_props_dialog_popup(C, op, 300, title, confirm_text); + return WM_operator_props_dialog_popup(C, op, 300, title, confirm_text, cancel_default); } UI_popup_block_ex(C, wm_block_create_redo, nullptr, wm_block_redo_cancel_cb, op, op); @@ -1805,9 +1806,10 @@ int WM_operator_props_popup_confirm_ex(bContext *C, wmOperator *op, const wmEvent * /*event*/, std::optional title, - std::optional confirm_text) + std::optional confirm_text, + const bool cancel_default) { - return wm_operator_props_popup_ex(C, op, false, false, title, confirm_text); + return wm_operator_props_popup_ex(C, op, false, false, title, confirm_text, cancel_default); } int WM_operator_props_popup_confirm(bContext *C, wmOperator *op, const wmEvent * /*event*/) @@ -1829,7 +1831,8 @@ int WM_operator_props_dialog_popup(bContext *C, wmOperator *op, int width, std::optional title, - std::optional confirm_text) + std::optional confirm_text, + const bool cancel_default) { wmOpPopUp *data = MEM_new(__func__); data->op = op; @@ -1841,7 +1844,7 @@ int WM_operator_props_dialog_popup(bContext *C, data->icon = ALERT_ICON_NONE; data->size = WM_POPUP_SIZE_SMALL; data->position = WM_POPUP_POSITION_MOUSE; - data->cancel_default = false; + data->cancel_default = cancel_default; data->mouse_move_quit = false; data->include_properties = true;