From 529b8786f8eeec42f865a3ed73bdab33dbb015e2 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Wed, 1 May 2024 16:29:19 +0200 Subject: [PATCH] UI: Custom Text and Confirmation Button Text for Props Confirm For operators that use WM_operator_props_popup_confirm allow custom title and confirmation button text. Pull Request: https://projects.blender.org/blender/blender/pulls/121287 --- .../blender/editors/animation/anim_markers.cc | 3 ++- .../editors/geometry/geometry_attributes.cc | 5 +++-- .../grease_pencil/intern/grease_pencil_edit.cc | 11 +++++++++-- .../intern/grease_pencil_layers.cc | 10 +++++++++- .../editors/mesh/editmesh_mask_extract.cc | 5 ++++- .../blender/editors/object/object_relations.cc | 8 +++++++- source/blender/editors/object/object_remesh.cc | 8 +++++++- .../editors/space_sequencer/sequencer_edit.cc | 8 +++++++- .../editors/space_userpref/userpref_ops.cc | 3 ++- .../blender/editors/uvedit/uvedit_unwrap_ops.cc | 15 +++++++++++++-- source/blender/windowmanager/WM_api.hh | 7 +++++++ .../windowmanager/intern/wm_operators.cc | 17 ++++++++++++++--- 12 files changed, 84 insertions(+), 16 deletions(-) diff --git a/source/blender/editors/animation/anim_markers.cc b/source/blender/editors/animation/anim_markers.cc index f72827ffe75..f3ac44a63d7 100644 --- a/source/blender/editors/animation/anim_markers.cc +++ b/source/blender/editors/animation/anim_markers.cc @@ -1744,7 +1744,8 @@ static int ed_marker_rename_invoke(bContext *C, wmOperator *op, const wmEvent *e RNA_string_set(op->ptr, "name", marker->name); } - return WM_operator_props_popup_confirm(C, op, event); + return WM_operator_props_popup_confirm_ex( + C, op, event, IFACE_("Rename Selected Time Marker"), IFACE_("Rename")); } static void MARKER_OT_rename(wmOperatorType *ot) diff --git a/source/blender/editors/geometry/geometry_attributes.cc b/source/blender/editors/geometry/geometry_attributes.cc index 81d2603f3af..5cc73d8e82d 100644 --- a/source/blender/editors/geometry/geometry_attributes.cc +++ b/source/blender/editors/geometry/geometry_attributes.cc @@ -278,7 +278,7 @@ static int geometry_attribute_add_invoke(bContext *C, wmOperator *op, const wmEv if (!RNA_property_is_set(op->ptr, prop)) { RNA_property_string_set(op->ptr, prop, DATA_("Attribute")); } - return WM_operator_props_popup_confirm(C, op, event); + return WM_operator_props_popup_confirm_ex(C, op, event, IFACE_("Add Attribute"), IFACE_("Add")); } void GEOMETRY_OT_attribute_add(wmOperatorType *ot) @@ -398,7 +398,8 @@ static int geometry_color_attribute_add_invoke(bContext *C, wmOperator *op, cons if (!RNA_property_is_set(op->ptr, prop)) { RNA_property_string_set(op->ptr, prop, DATA_("Color")); } - return WM_operator_props_popup_confirm(C, op, event); + return WM_operator_props_popup_confirm_ex( + C, op, event, IFACE_("Add Color Attribute"), IFACE_("Add")); } enum class ConvertAttributeMode { diff --git a/source/blender/editors/grease_pencil/intern/grease_pencil_edit.cc b/source/blender/editors/grease_pencil/intern/grease_pencil_edit.cc index 7f7404573cd..141d06b432a 100644 --- a/source/blender/editors/grease_pencil/intern/grease_pencil_edit.cc +++ b/source/blender/editors/grease_pencil/intern/grease_pencil_edit.cc @@ -1394,13 +1394,19 @@ static int grease_pencil_clean_loose_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } +static int grease_pencil_clean_loose_invoke(bContext *C, wmOperator *op, const wmEvent *event) +{ + return WM_operator_props_popup_confirm_ex( + C, op, event, IFACE_("Remove Loose Points"), IFACE_("Delete")); +} + static void GREASE_PENCIL_OT_clean_loose(wmOperatorType *ot) { ot->name = "Clean Loose Points"; ot->idname = "GREASE_PENCIL_OT_clean_loose"; ot->description = "Remove loose points"; - ot->invoke = WM_operator_props_popup_confirm; + ot->invoke = grease_pencil_clean_loose_invoke; ot->exec = grease_pencil_clean_loose_exec; ot->poll = active_grease_pencil_layer_poll; @@ -1783,7 +1789,8 @@ static int grease_pencil_move_to_layer_invoke(bContext *C, wmOperator *op, const { const bool add_new_layer = RNA_boolean_get(op->ptr, "add_new_layer"); if (add_new_layer) { - return WM_operator_props_popup_confirm(C, op, event); + return WM_operator_props_popup_confirm_ex( + C, op, event, IFACE_("Move to New Layer"), IFACE_("Create")); } return grease_pencil_move_to_layer_exec(C, op); } diff --git a/source/blender/editors/grease_pencil/intern/grease_pencil_layers.cc b/source/blender/editors/grease_pencil/intern/grease_pencil_layers.cc index e7033fb75b4..8d69e9e0ed8 100644 --- a/source/blender/editors/grease_pencil/intern/grease_pencil_layers.cc +++ b/source/blender/editors/grease_pencil/intern/grease_pencil_layers.cc @@ -10,6 +10,8 @@ #include "BKE_grease_pencil.hh" #include "BKE_report.hh" +#include "BLT_translation.hh" + #include "DEG_depsgraph.hh" #include "ED_grease_pencil.hh" @@ -64,6 +66,12 @@ static int grease_pencil_layer_add_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } +static int grease_pencil_layer_add_invoke(bContext *C, wmOperator *op, const wmEvent *event) +{ + return WM_operator_props_popup_confirm_ex( + C, op, event, IFACE_("Add New Grease Pencil Layer"), IFACE_("Add")); +} + static void GREASE_PENCIL_OT_layer_add(wmOperatorType *ot) { /* identifiers */ @@ -72,7 +80,7 @@ static void GREASE_PENCIL_OT_layer_add(wmOperatorType *ot) ot->description = "Add a new Grease Pencil layer in the active object"; /* callbacks */ - ot->invoke = WM_operator_props_popup_confirm; + ot->invoke = grease_pencil_layer_add_invoke; ot->exec = grease_pencil_layer_add_exec; ot->poll = active_grease_pencil_poll; diff --git a/source/blender/editors/mesh/editmesh_mask_extract.cc b/source/blender/editors/mesh/editmesh_mask_extract.cc index eef3125fb80..427d1697f43 100644 --- a/source/blender/editors/mesh/editmesh_mask_extract.cc +++ b/source/blender/editors/mesh/editmesh_mask_extract.cc @@ -22,6 +22,8 @@ #include "BLI_math_vector.h" +#include "BLT_translation.hh" + #include "DEG_depsgraph.hh" #include "DEG_depsgraph_build.hh" @@ -294,7 +296,8 @@ static int paint_mask_extract_exec(bContext *C, wmOperator *op) static int paint_mask_extract_invoke(bContext *C, wmOperator *op, const wmEvent *e) { - return WM_operator_props_popup_confirm(C, op, e); + return WM_operator_props_popup_confirm_ex( + C, op, e, IFACE_("Create Mesh From Paint Mask"), IFACE_("Extract")); } static void geometry_extract_props(StructRNA *srna) diff --git a/source/blender/editors/object/object_relations.cc b/source/blender/editors/object/object_relations.cc index d4ac5f1aeff..f519c62d72b 100644 --- a/source/blender/editors/object/object_relations.cc +++ b/source/blender/editors/object/object_relations.cc @@ -2857,6 +2857,12 @@ static int make_single_user_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } +static int make_single_user_invoke(bContext *C, wmOperator *op, const wmEvent *event) +{ + return WM_operator_props_popup_confirm_ex( + C, op, event, IFACE_("Make Selected Objects Single-User"), IFACE_("Make Single")); +} + void OBJECT_OT_make_single_user(wmOperatorType *ot) { static const EnumPropertyItem type_items[] = { @@ -2874,7 +2880,7 @@ void OBJECT_OT_make_single_user(wmOperatorType *ot) * nothing by default. */ /* api callbacks */ - ot->invoke = WM_operator_props_popup_confirm; + ot->invoke = make_single_user_invoke; ot->exec = make_single_user_exec; ot->poll = ED_operator_objectmode; diff --git a/source/blender/editors/object/object_remesh.cc b/source/blender/editors/object/object_remesh.cc index 86dbdcbffdf..0ad9aff2ccf 100644 --- a/source/blender/editors/object/object_remesh.cc +++ b/source/blender/editors/object/object_remesh.cc @@ -1079,6 +1079,12 @@ static const EnumPropertyItem mode_type_items[] = { {0, nullptr, 0, nullptr, nullptr}, }; +static int quadriflow_remesh_invoke(bContext *C, wmOperator *op, const wmEvent *event) +{ + return WM_operator_props_popup_confirm_ex( + C, op, event, IFACE_("QuadriFlow Remesh the Selected Mesh"), IFACE_("Remesh")); +} + void OBJECT_OT_quadriflow_remesh(wmOperatorType *ot) { /* identifiers */ @@ -1092,7 +1098,7 @@ void OBJECT_OT_quadriflow_remesh(wmOperatorType *ot) ot->poll = object_remesh_poll; ot->poll_property = quadriflow_poll_property; ot->check = quadriflow_check; - ot->invoke = WM_operator_props_popup_confirm; + ot->invoke = quadriflow_remesh_invoke; ot->exec = quadriflow_remesh_exec; ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; diff --git a/source/blender/editors/space_sequencer/sequencer_edit.cc b/source/blender/editors/space_sequencer/sequencer_edit.cc index da63a433bf3..6850029b1de 100644 --- a/source/blender/editors/space_sequencer/sequencer_edit.cc +++ b/source/blender/editors/space_sequencer/sequencer_edit.cc @@ -1899,6 +1899,12 @@ static int sequencer_separate_images_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } +static int sequencer_separate_images_invoke(bContext *C, wmOperator *op, const wmEvent *event) +{ + return WM_operator_props_popup_confirm_ex( + C, op, event, IFACE_("Separate Sequence Images"), IFACE_("Separate")); +} + void SEQUENCER_OT_images_separate(wmOperatorType *ot) { /* Identifiers. */ @@ -1908,7 +1914,7 @@ void SEQUENCER_OT_images_separate(wmOperatorType *ot) /* Api callbacks. */ ot->exec = sequencer_separate_images_exec; - ot->invoke = WM_operator_props_popup_confirm; + ot->invoke = sequencer_separate_images_invoke; ot->poll = sequencer_edit_poll; /* Flags. */ diff --git a/source/blender/editors/space_userpref/userpref_ops.cc b/source/blender/editors/space_userpref/userpref_ops.cc index adcfc8c8bc7..676aad358f3 100644 --- a/source/blender/editors/space_userpref/userpref_ops.cc +++ b/source/blender/editors/space_userpref/userpref_ops.cc @@ -379,7 +379,8 @@ static int preferences_extension_repo_add_invoke(bContext *C, wmOperator *op, co RNA_property_string_set(op->ptr, prop_name, name_default); } - return WM_operator_props_popup_confirm(C, op, event); + return WM_operator_props_popup_confirm_ex( + C, op, event, IFACE_("Add New Extension Repository"), IFACE_("Create")); } static void preferences_extension_repo_add_ui(bContext * /*C*/, wmOperator *op) diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.cc b/source/blender/editors/uvedit/uvedit_unwrap_ops.cc index 4b72e8d368a..38703959040 100644 --- a/source/blender/editors/uvedit/uvedit_unwrap_ops.cc +++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.cc @@ -1628,6 +1628,11 @@ static void uv_pack_islands_ui(bContext * /*C*/, wmOperator *op) uiItemS(layout); } +static int uv_pack_islands_invoke(bContext *C, wmOperator *op, const wmEvent *event) +{ + return WM_operator_props_popup_confirm_ex(C, op, event, IFACE_("Pack Islands"), IFACE_("Pack")); +} + void UV_OT_pack_islands(wmOperatorType *ot) { static const EnumPropertyItem pack_target[] = { @@ -1663,7 +1668,7 @@ void UV_OT_pack_islands(wmOperatorType *ot) #ifdef USE_INTERACTIVE_PACK ot->invoke = WM_operator_props_popup_call; #else - ot->invoke = WM_operator_props_popup_confirm; + ot->invoke = uv_pack_islands_invoke; #endif ot->ui = uv_pack_islands_ui; ot->poll = ED_operator_uvedit; @@ -2935,6 +2940,12 @@ static int smart_project_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } +static int smart_project_invoke(bContext *C, wmOperator *op, const wmEvent *event) +{ + return WM_operator_props_popup_confirm_ex( + C, op, event, IFACE_("Smart UV Project"), IFACE_("Unwrap")); +} + void UV_OT_smart_project(wmOperatorType *ot) { PropertyRNA *prop; @@ -2949,7 +2960,7 @@ void UV_OT_smart_project(wmOperatorType *ot) /* api callbacks */ ot->exec = smart_project_exec; ot->poll = ED_operator_uvmap; - ot->invoke = WM_operator_props_popup_confirm; + ot->invoke = smart_project_invoke; /* properties */ prop = RNA_def_float_rotation(ot->srna, diff --git a/source/blender/windowmanager/WM_api.hh b/source/blender/windowmanager/WM_api.hh index 2deaa4b4f3c..5f5b82a4f9a 100644 --- a/source/blender/windowmanager/WM_api.hh +++ b/source/blender/windowmanager/WM_api.hh @@ -733,6 +733,13 @@ bool WM_operator_winactive(bContext *C); * just wraps #WM_operator_props_dialog_popup. */ int WM_operator_props_popup_confirm(bContext *C, wmOperator *op, const wmEvent *event); + +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); + /** * Same as #WM_operator_props_popup but call the operator first, * This way - the button values correspond to the result of the operator. diff --git a/source/blender/windowmanager/intern/wm_operators.cc b/source/blender/windowmanager/intern/wm_operators.cc index f86d8bc8c3c..0b2da6c2ce1 100644 --- a/source/blender/windowmanager/intern/wm_operators.cc +++ b/source/blender/windowmanager/intern/wm_operators.cc @@ -1725,7 +1725,9 @@ int WM_operator_ui_popup(bContext *C, wmOperator *op, int width) static int wm_operator_props_popup_ex(bContext *C, wmOperator *op, const bool do_call, - const bool do_redo) + const bool do_redo, + std::optional title = std::nullopt, + std::optional confirm_text = std::nullopt) { if ((op->type->flag & OPTYPE_REGISTER) == 0) { BKE_reportf(op->reports, @@ -1748,7 +1750,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); + return WM_operator_props_dialog_popup(C, op, 300, title, confirm_text); } UI_popup_block_ex(C, wm_block_create_redo, nullptr, wm_block_redo_cancel_cb, op, op); @@ -1760,9 +1762,18 @@ static int wm_operator_props_popup_ex(bContext *C, return OPERATOR_RUNNING_MODAL; } +int WM_operator_props_popup_confirm_ex(bContext *C, + wmOperator *op, + const wmEvent * /*event*/, + std::optional title, + std::optional confirm_text) +{ + return wm_operator_props_popup_ex(C, op, false, false, title, confirm_text); +} + int WM_operator_props_popup_confirm(bContext *C, wmOperator *op, const wmEvent * /*event*/) { - return wm_operator_props_popup_ex(C, op, false, false); + return wm_operator_props_popup_ex(C, op, false, false, {}, {}); } int WM_operator_props_popup_call(bContext *C, wmOperator *op, const wmEvent * /*event*/)