From 88a12eec1757b682f19fbef15ea50ca69b7e92a0 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Wed, 28 Jun 2023 13:38:02 -0700 Subject: [PATCH 01/11] Updated to resolve merge conflicts. --- .../editors/object/object_bake_simulation.cc | 10 +- .../blender/editors/object/object_modifier.cc | 14 +- .../editors/object/object_transform.cc | 14 +- source/blender/editors/space_info/info_ops.cc | 25 ++- .../editors/space_outliner/outliner_edit.cc | 64 ++++--- source/blender/windowmanager/WM_api.h | 11 -- source/blender/windowmanager/WM_types.h | 29 +++ .../blender/windowmanager/intern/wm_files.cc | 38 +++- .../windowmanager/intern/wm_operators.c | 167 ++++++++++++++++++ 9 files changed, 321 insertions(+), 51 deletions(-) diff --git a/source/blender/editors/object/object_bake_simulation.cc b/source/blender/editors/object/object_bake_simulation.cc index 5ff75ee08f3..7dbd889f506 100644 --- a/source/blender/editors/object/object_bake_simulation.cc +++ b/source/blender/editors/object/object_bake_simulation.cc @@ -511,6 +511,13 @@ static PathUsersMap bake_simulation_get_path_users(bContext *C, const Spanmessage, "Overwrite existing bake data"); +} + static int bake_simulation_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/) { Vector objects; @@ -554,7 +561,7 @@ static int bake_simulation_invoke(bContext *C, wmOperator *op, const wmEvent * / return OPERATOR_CANCELLED; } if (has_existing_bake_data) { - return WM_operator_confirm_message(C, op, "Overwrite existing bake data"); + return WM_operator_confirm(C, op, nullptr); } return bake_simulation_exec(C, op); } @@ -651,6 +658,7 @@ void OBJECT_OT_simulation_nodes_cache_bake(wmOperatorType *ot) ot->invoke = bake_simulation_invoke; ot->modal = bake_simulation_modal; ot->poll = bake_simulation_poll; + ot->warning = bake_simulation_warning; RNA_def_boolean(ot->srna, "selected", false, "Selected", "Bake cache on all selected objects"); } diff --git a/source/blender/editors/object/object_modifier.cc b/source/blender/editors/object/object_modifier.cc index c58589f8011..cd96d489d74 100644 --- a/source/blender/editors/object/object_modifier.cc +++ b/source/blender/editors/object/object_modifier.cc @@ -36,6 +36,8 @@ #include "BLI_string_utf8.h" #include "BLI_utildefines.h" +#include "BLT_translation.h" + #include "BKE_DerivedMesh.h" #include "BKE_animsys.h" #include "BKE_armature.h" @@ -1804,6 +1806,14 @@ static int modifier_apply_exec(bContext *C, wmOperator *op) return modifier_apply_exec_ex(C, op, MODIFIER_APPLY_DATA, false); } +static void modifier_apply_warning(bContext * /*C*/, + wmOperator * /*op*/, + wmWarningDetails *warning) +{ + STRNCPY(warning->message, IFACE_("Make object data single-user and apply modifier")); + STRNCPY(warning->confirm_button, IFACE_("Apply")); +} + static int modifier_apply_invoke(bContext *C, wmOperator *op, const wmEvent *event) { int retval; @@ -1817,8 +1827,7 @@ static int modifier_apply_invoke(bContext *C, wmOperator *op, const wmEvent *eve RNA_property_boolean_set(op->ptr, prop, true); } if (RNA_property_boolean_get(op->ptr, prop)) { - return WM_operator_confirm_message( - C, op, "Make object data single-user and apply modifier"); + return WM_operator_confirm(C, op, nullptr); } } return modifier_apply_exec(C, op); @@ -1835,6 +1844,7 @@ void OBJECT_OT_modifier_apply(wmOperatorType *ot) ot->invoke = modifier_apply_invoke; ot->exec = modifier_apply_exec; ot->poll = modifier_apply_poll; + ot->warning = modifier_apply_warning; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL; diff --git a/source/blender/editors/object/object_transform.cc b/source/blender/editors/object/object_transform.cc index ac2824aae52..8f0986a54ac 100644 --- a/source/blender/editors/object/object_transform.cc +++ b/source/blender/editors/object/object_transform.cc @@ -31,6 +31,8 @@ #include "BLI_utildefines.h" #include "BLI_vector.hh" +#include "BLT_translation.h" + #include "BKE_armature.h" #include "BKE_context.h" #include "BKE_curve.h" @@ -1153,6 +1155,14 @@ static int object_transform_apply_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } +static void object_transform_apply_warning(bContext * /*C*/, + wmOperator * /*op*/, + wmWarningDetails *warning) +{ + STRNCPY(warning->message, IFACE_("Create new object-data users and apply transformation")); + STRNCPY(warning->confirm_button, IFACE_("Apply")); +} + static int object_transform_apply_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/) { Object *ob = ED_object_active_context(C); @@ -1166,8 +1176,7 @@ static int object_transform_apply_invoke(bContext *C, wmOperator *op, const wmEv RNA_property_boolean_set(op->ptr, prop, true); } if (RNA_property_boolean_get(op->ptr, prop)) { - return WM_operator_confirm_message( - C, op, "Create new object-data users and apply transformation"); + return WM_operator_confirm(C, op, nullptr); } } return object_transform_apply_exec(C, op); @@ -1184,6 +1193,7 @@ void OBJECT_OT_transform_apply(wmOperatorType *ot) ot->exec = object_transform_apply_exec; ot->invoke = object_transform_apply_invoke; ot->poll = ED_operator_objectmode; + ot->warning = object_transform_apply_warning; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; diff --git a/source/blender/editors/space_info/info_ops.cc b/source/blender/editors/space_info/info_ops.cc index 5d6f93d4477..9ce0a0a804b 100644 --- a/source/blender/editors/space_info/info_ops.cc +++ b/source/blender/editors/space_info/info_ops.cc @@ -87,10 +87,13 @@ static int unpack_libraries_exec(bContext *C, wmOperator *op) /** \name Unpack Blend File Libraries Operator * \{ */ -static int unpack_libraries_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/) +static void unpack_libraries_warning(bContext * /* C */, + wmOperator * /* op */, + wmWarningDetails *warning) { - return WM_operator_confirm_message( - C, op, "Unpack Linked Libraries - creates directories, all new paths should work"); + STRNCPY(warning->message, IFACE_("Creates directories, all new paths should work")); + STRNCPY(warning->confirm_button, IFACE_("Unpack")); + warning->icon = ALERT_ICON_INFO; } void FILE_OT_unpack_libraries(wmOperatorType *ot) @@ -101,8 +104,9 @@ void FILE_OT_unpack_libraries(wmOperatorType *ot) ot->description = "Restore all packed linked data-blocks to their original locations"; /* api callbacks */ - ot->invoke = unpack_libraries_invoke; + ot->invoke = WM_operator_confirm; ot->exec = unpack_libraries_exec; + ot->warning = unpack_libraries_warning; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -158,7 +162,14 @@ static int pack_all_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -static int pack_all_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/) +static void pack_all_warning(bContext * /* C */, wmOperator * /* op */, wmWarningDetails *warning) +{ + STRNCPY(warning->message, + IFACE_("Some images are mofified. These changes will be lost. Continue?")); + STRNCPY(warning->confirm_button, IFACE_("Pack")); +} + +static int pack_all_invoke(bContext *C, wmOperator *op, const wmEvent * /* event */) { Main *bmain = CTX_data_main(C); Image *ima; @@ -173,8 +184,7 @@ static int pack_all_invoke(bContext *C, wmOperator *op, const wmEvent * /*event* } if (ima) { - return WM_operator_confirm_message( - C, op, "Some images are painted on. These changes will be lost. Continue?"); + return WM_operator_confirm(C, op, nullptr); } return pack_all_exec(C, op); @@ -190,6 +200,7 @@ void FILE_OT_pack_all(wmOperatorType *ot) /* api callbacks */ ot->exec = pack_all_exec; ot->invoke = pack_all_invoke; + ot->warning = pack_all_warning; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; diff --git a/source/blender/editors/space_outliner/outliner_edit.cc b/source/blender/editors/space_outliner/outliner_edit.cc index 70572136677..5c9c085c2cf 100644 --- a/source/blender/editors/space_outliner/outliner_edit.cc +++ b/source/blender/editors/space_outliner/outliner_edit.cc @@ -2131,6 +2131,43 @@ static bool ed_operator_outliner_id_orphans_active(bContext *C) return true; } +static void orphans_purge_warning(bContext *C, wmOperator *op, wmWarningDetails *warning) +{ + Main *bmain = CTX_data_main(C); + int num_tagged[INDEX_ID_MAX] = {0}; + + const bool do_local_ids = RNA_boolean_get(op->ptr, "do_local_ids"); + const bool do_linked_ids = RNA_boolean_get(op->ptr, "do_linked_ids"); + const bool do_recursive_cleanup = RNA_boolean_get(op->ptr, "do_recursive"); + + /* Tag all IDs to delete. */ + BKE_lib_query_unused_ids_tag( + bmain, LIB_TAG_DOIT, do_local_ids, do_linked_ids, do_recursive_cleanup, num_tagged); + + DynStr *dyn_str = BLI_dynstr_new(); + bool is_first = true; + for (int i = 0; i < INDEX_ID_MAX - 2; i++) { + if (num_tagged[i] != 0) { + if (!is_first) { + BLI_dynstr_append(dyn_str, ", "); + } + else { + is_first = false; + } + BLI_dynstr_appendf(dyn_str, + "%d %s", + num_tagged[i], + TIP_(BKE_idtype_idcode_to_name_plural(BKE_idtype_idcode_from_index(i)))); + } + } + + STRNCPY(warning->title, IFACE_("Remove Unused Data")); + STRNCPY(warning->message, BLI_dynstr_get_cstring(dyn_str)); + STRNCPY(warning->confirm_button, IFACE_("Purge")); + + BLI_dynstr_free(dyn_str); +} + static int outliner_orphans_purge_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/) { Main *bmain = CTX_data_main(C); @@ -2151,31 +2188,7 @@ static int outliner_orphans_purge_invoke(bContext *C, wmOperator *op, const wmEv return OPERATOR_CANCELLED; } - DynStr *dyn_str = BLI_dynstr_new(); - BLI_dynstr_appendf(dyn_str, TIP_("Purging %d unused data-blocks ("), num_tagged[INDEX_ID_NULL]); - bool is_first = true; - for (int i = 0; i < INDEX_ID_MAX - 2; i++) { - if (num_tagged[i] != 0) { - if (!is_first) { - BLI_dynstr_append(dyn_str, ", "); - } - else { - is_first = false; - } - BLI_dynstr_appendf(dyn_str, - "%d %s", - num_tagged[i], - TIP_(BKE_idtype_idcode_to_name_plural(BKE_idtype_idcode_from_index(i)))); - } - } - BLI_dynstr_append(dyn_str, TIP_("). Click here to proceed...")); - - char *message = BLI_dynstr_get_cstring(dyn_str); - int ret = WM_operator_confirm_message(C, op, message); - - MEM_freeN(message); - BLI_dynstr_free(dyn_str); - return ret; + return WM_operator_confirm(C, op, nullptr); } static int outliner_orphans_purge_exec(bContext *C, wmOperator *op) @@ -2232,6 +2245,7 @@ void OUTLINER_OT_orphans_purge(wmOperatorType *ot) ot->invoke = outliner_orphans_purge_invoke; ot->exec = outliner_orphans_purge_exec; ot->poll = ed_operator_outliner_id_orphans_active; + ot->warning = orphans_purge_warning; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 1c87a9ef8f4..29aebe0e1f8 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -716,17 +716,6 @@ int WM_operator_props_dialog_popup(struct bContext *C, struct wmOperator *op, in int WM_operator_redo_popup(struct bContext *C, struct wmOperator *op); int WM_operator_ui_popup(struct bContext *C, struct wmOperator *op, int width); -/** - * Can't be used as an invoke directly, needs message arg (can be NULL). - */ -int WM_operator_confirm_message_ex(struct bContext *C, - struct wmOperator *op, - const char *title, - int icon, - const char *message, - wmOperatorCallContext opcontext); -int WM_operator_confirm_message(struct bContext *C, struct wmOperator *op, const char *message); - /* Operator API. */ void WM_operator_free(struct wmOperator *op); diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index 469735445c6..ba3dc28f987 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -907,6 +907,30 @@ typedef struct wmTimer { bool sleep; } wmTimer; +typedef enum wmWarningSize { + WM_WARNING_SIZE_SMALL = 0, + WM_WARNING_SIZE_LARGE, +} wmWarningSize; + +typedef enum wmWarningPosition { + WM_WARNING_POSITION_MOUSE = 0, + WM_WARNING_POSITION_CENTER, +} wmWarningPosition; + +typedef struct wmWarningDetails { + char title[1024]; + char message[1024]; + char confirm_button[256]; + char cancel_button[256]; + int icon; + wmWarningSize size; + wmWarningPosition position; + bool confirm_default; + bool cancel_default; + bool mouse_move_quit; + bool red_alert; +} wmWarningDetails; + typedef struct wmOperatorType { /** Text for UI, undo (should not exceed #OP_MAX_TYPENAME). */ const char *name; @@ -990,6 +1014,11 @@ typedef struct wmOperatorType { */ char *(*get_description)(struct bContext *C, struct wmOperatorType *, struct PointerRNA *); + /** + * If using WM_operator_confirm the following can override all parts of the dialog. + */ + void (*warning)(struct bContext *C, struct wmOperator *, wmWarningDetails *warning); + /** rna for properties */ struct StructRNA *srna; diff --git a/source/blender/windowmanager/intern/wm_files.cc b/source/blender/windowmanager/intern/wm_files.cc index 74c02bb740e..0ddf9d4f39a 100644 --- a/source/blender/windowmanager/intern/wm_files.cc +++ b/source/blender/windowmanager/intern/wm_files.cc @@ -2275,6 +2275,13 @@ static int wm_homefile_write_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } +static void save_homefile_warning(bContext * /*C*/, wmOperator * /*op*/, wmWarningDetails *warning) +{ + STRNCPY(warning->confirm_button, IFACE_("Save")); + warning->size = WM_WARNING_SIZE_LARGE; + warning->position = WM_WARNING_POSITION_CENTER; +} + void WM_OT_save_homefile(wmOperatorType *ot) { ot->name = "Save Startup File"; @@ -2283,6 +2290,7 @@ void WM_OT_save_homefile(wmOperatorType *ot) ot->invoke = WM_operator_confirm; ot->exec = wm_homefile_write_exec; + ot->warning = save_homefile_warning; } /** \} */ @@ -2439,6 +2447,19 @@ void WM_OT_read_userpref(wmOperatorType *ot) ot->exec = wm_userpref_read_exec; } +static void wm_userpref_read_factory_warning(bContext * /*C*/, + wmOperator * /*op*/, + wmWarningDetails *warning) +{ + STRNCPY(warning->title, IFACE_("Load factory default preferences")); + STRNCPY(warning->message, + IFACE_("To make changes to preferences permanent, use \"Save Preferences\"")); + STRNCPY(warning->confirm_button, IFACE_("Load")); + warning->icon = ALERT_ICON_BLENDER; + warning->size = WM_WARNING_SIZE_LARGE; + warning->position = WM_WARNING_POSITION_CENTER; +} + void WM_OT_read_factory_userpref(wmOperatorType *ot) { ot->name = "Load Factory Preferences"; @@ -2449,6 +2470,7 @@ void WM_OT_read_factory_userpref(wmOperatorType *ot) ot->invoke = WM_operator_confirm; ot->exec = wm_userpref_read_exec; + ot->warning = wm_userpref_read_factory_warning; read_factory_reset_props(ot); } @@ -2648,16 +2670,26 @@ void WM_OT_read_homefile(wmOperatorType *ot) /* omit poll to run in background mode */ } +static void read_factory_warning(bContext * /*C*/, wmOperator * /*op*/, wmWarningDetails *warning) +{ + STRNCPY(warning->title, IFACE_("Load factory default startup file and preferences.")); + STRNCPY(warning->message, + IFACE_("To make changes permanent, use \"Save Startup File\" and \"Save Preferences\"")); + STRNCPY(warning->confirm_button, IFACE_("Load")); + warning->icon = ALERT_ICON_BLENDER; + warning->size = WM_WARNING_SIZE_LARGE; + warning->position = WM_WARNING_POSITION_CENTER; +} + void WM_OT_read_factory_settings(wmOperatorType *ot) { ot->name = "Load Factory Settings"; ot->idname = "WM_OT_read_factory_settings"; - ot->description = - "Load factory default startup file and preferences. " - "To make changes permanent, use \"Save Startup File\" and \"Save Preferences\""; + ot->description = "Load factory default startup file and preferences"; ot->invoke = WM_operator_confirm; ot->exec = wm_homefile_read_exec; + ot->warning = read_factory_warning; /* Omit poll to run in background mode. */ read_factory_reset_props(ot); diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index b99c0388f0e..e94ccb96572 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -1170,6 +1170,168 @@ int WM_enum_search_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(eve return OPERATOR_INTERFACE; } +static void wm_operator_block_cancel(bContext *C, void *arg_op, void *arg_block) +{ + wmOperator *op = arg_op; + uiBlock *block = arg_block; + UI_popup_block_close(C, CTX_wm_window(C), block); + WM_redraw_windows(C); + if (op) { + if (op->type->cancel) { + op->type->cancel(C, op); + } + WM_operator_free(op); + } +} + +static void wm_operator_block_confirm(bContext *C, void *arg_op, void *arg_block) +{ + wmOperator *op = arg_op; + uiBlock *block = arg_block; + UI_popup_block_close(C, CTX_wm_window(C), block); + WM_redraw_windows(C); + if (op) { + WM_operator_call_ex(C, op, true); + } +} + +static uiBlock *wm_block_confirm_create(bContext *C, ARegion *region, void *arg_op) +{ + wmOperator *op = arg_op; + + wmWarningDetails warning = {0}; + + /* Operator description must be freed. */ + char *desc = WM_operatortype_description(C, op->type, op->ptr); + STRNCPY_RLEN(warning.title, desc); + MEM_freeN(desc); + + STRNCPY_RLEN(warning.confirm_button, WM_operatortype_name(op->type, op->ptr)); + STRNCPY_RLEN(warning.cancel_button, IFACE_("Cancel")); + warning.icon = ALERT_ICON_WARNING; + warning.size = WM_WARNING_SIZE_SMALL; + warning.position = WM_WARNING_POSITION_MOUSE; + warning.confirm_default = true; + warning.cancel_default = false; + warning.mouse_move_quit = false; + warning.red_alert = false; + + /* uiBlock.flag */ + int block_flags = UI_BLOCK_KEEP_OPEN | UI_BLOCK_NO_WIN_CLIP | UI_BLOCK_NUMSELECT; + + if (op->type->warning) { + op->type->warning(C, op, &warning); + } + if (warning.mouse_move_quit) { + block_flags |= UI_BLOCK_MOVEMOUSE_QUIT; + } + if (warning.icon < ALERT_ICON_WARNING || warning.icon >= ALERT_ICON_MAX) { + warning.icon = ALERT_ICON_QUESTION; + } + + uiBlock *block = UI_block_begin(C, region, __func__, UI_EMBOSS); + UI_block_theme_style_set(block, UI_BLOCK_THEME_STYLE_POPUP); + UI_block_flag_enable(block, block_flags); + + const uiStyle *style = UI_style_get_dpi(); + int text_width = MAX3( + 120 * UI_SCALE_FAC, + BLF_width(style->widget.uifont_id, warning.title, ARRAY_SIZE(warning.title)), + BLF_width(style->widget.uifont_id, warning.message, ARRAY_SIZE(warning.message))); + + const bool small = warning.size == WM_WARNING_SIZE_SMALL; + const int padding = (small ? 7 : 14) * UI_SCALE_FAC; + const short icon_size = (small ? (warning.message[0] ? 48 : 32) : 64) * UI_SCALE_FAC; + const int dialog_width = icon_size + text_width + (style->columnspace * 2.5); + const float split_factor = (float)icon_size / (float)(dialog_width - style->columnspace); + + uiLayout *block_layout = UI_block_layout( + block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, dialog_width, UI_UNIT_Y, 0, style); + + /* Split layout to put alert icon on left side. */ + uiLayout *split_block = uiLayoutSplit(block_layout, split_factor, false); + + /* Alert icon on the left. */ + uiLayout *layout = uiLayoutRow(split_block, true); + /* Using 'align_left' with 'row' avoids stretching the icon along the width of column. */ + uiLayoutSetAlignment(layout, UI_LAYOUT_ALIGN_LEFT); + uiDefButAlert(block, warning.icon, 0, 0, icon_size, icon_size); + + /* The rest of the content on the right. */ + layout = uiLayoutColumn(split_block, true); + + if (warning.title[0]) { + if (!warning.message[0]) { + uiItemS(layout); + } + uiItemL_ex(layout, warning.title, ICON_NONE, true, false); + } + if (warning.message[0]) { + uiItemL(layout, warning.message, ICON_NONE); + } + + uiItemS_ex(layout, small ? 0.5f : 4.0f); + + /* Buttons. */ + +#ifdef _WIN32 + const bool windows_layout = true; +#else + const bool windows_layout = false; +#endif + + uiBut *confirm = NULL; + uiBut *cancel = NULL; + int height = UI_UNIT_Y; + uiLayout *split = uiLayoutSplit(small ? block_layout : layout, 0.0f, true); + uiLayoutSetScaleY(split, small ? 1.1f : 1.2f); + uiLayoutColumn(split, false); + + if (windows_layout) { + confirm = uiDefIconTextBut( + block, UI_BTYPE_BUT, 0, 0, warning.confirm_button, 0, 0, 0, height, 0, 0, 0, 0, 0, NULL); + uiLayoutColumn(split, false); + } + + cancel = uiDefIconTextBut( + block, UI_BTYPE_BUT, 0, 0, warning.cancel_button, 0, 0, 0, height, 0, 0, 0, 0, 0, NULL); + + if (!windows_layout) { + uiLayoutColumn(split, false); + confirm = uiDefIconTextBut( + block, UI_BTYPE_BUT, 0, 0, warning.confirm_button, 0, 0, 0, height, 0, 0, 0, 0, 0, NULL); + } + + UI_block_func_set(block, NULL, NULL, NULL); + UI_but_func_set(confirm, wm_operator_block_confirm, op, block); + UI_but_func_set(cancel, wm_operator_block_cancel, op, block); + UI_but_drawflag_disable(confirm, UI_BUT_TEXT_LEFT); + UI_but_drawflag_disable(cancel, UI_BUT_TEXT_LEFT); + + if (warning.red_alert) { + UI_but_flag_enable(confirm, UI_BUT_REDALERT); + } + else { + if (warning.cancel_default) { + UI_but_flag_enable(cancel, UI_BUT_ACTIVE_DEFAULT); + } + else if (warning.confirm_default) { + UI_but_flag_enable(confirm, UI_BUT_ACTIVE_DEFAULT); + } + } + + if (warning.position == WM_WARNING_POSITION_MOUSE) { + int x = uiLayoutGetWidth(layout) * (windows_layout ? -0.33f : -0.66f); + int y = UI_UNIT_Y * (warning.message[0] ? 3.1 : 2.5); + UI_block_bounds_set_popup(block, padding, (const int[2]){x, y}); + } + else if (warning.position == WM_WARNING_POSITION_CENTER) { + UI_block_bounds_set_centered(block, padding); + } + + return block; +} + int WM_operator_confirm_message_ex(bContext *C, wmOperator *op, const char *title, @@ -1196,6 +1358,11 @@ int WM_operator_confirm_message_ex(bContext *C, int WM_operator_confirm_message(bContext *C, wmOperator *op, const char *message) { + if (op->type->warning) { + UI_popup_block_invoke(C, wm_block_confirm_create, op, NULL); + return OPERATOR_RUNNING_MODAL; + } + return WM_operator_confirm_message_ex( C, op, IFACE_("OK?"), ICON_QUESTION, message, WM_OP_EXEC_REGION_WIN); } -- 2.30.2 From 18158dcbdbf9679cd2489f0df76874ebb3fee6d0 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Tue, 18 Jul 2023 17:33:32 -0700 Subject: [PATCH 02/11] Updating to main. "Load Factory Settings" made aware of file dirty status. --- .../blender/windowmanager/intern/wm_files.cc | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/source/blender/windowmanager/intern/wm_files.cc b/source/blender/windowmanager/intern/wm_files.cc index 78198ce5d4c..b0c45bb63b9 100644 --- a/source/blender/windowmanager/intern/wm_files.cc +++ b/source/blender/windowmanager/intern/wm_files.cc @@ -2674,11 +2674,23 @@ void WM_OT_read_homefile(wmOperatorType *ot) /* omit poll to run in background mode */ } -static void read_factory_warning(bContext * /*C*/, wmOperator * /*op*/, wmWarningDetails *warning) +static void read_factory_warning(bContext *C, wmOperator * /*op*/, wmWarningDetails *warning) { STRNCPY(warning->title, IFACE_("Load factory default startup file and preferences.")); - STRNCPY(warning->message, - IFACE_("To make changes permanent, use \"Save Startup File\" and \"Save Preferences\"")); + + if (wm_file_or_session_data_has_unsaved_changes(CTX_data_main(C), CTX_wm_manager(C))) { + STRNCPY(warning->message, + IFACE_("WARNING: Your file is unsaved. Proceeding will abandon your changes")); + warning->confirm_default = false; + warning->cancel_default = true; + } + else { + STRNCPY(warning->message, + IFACE_("To make changes to preferences permanent, use \"Save Preferences\"")); + warning->confirm_default = true; + warning->cancel_default = false; + } + STRNCPY(warning->confirm_button, IFACE_("Load")); warning->icon = ALERT_ICON_BLENDER; warning->size = WM_WARNING_SIZE_LARGE; -- 2.30.2 From 5794e66ba406261703fbed0adfd4a3f083b893b8 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Tue, 18 Jul 2023 19:02:15 -0700 Subject: [PATCH 03/11] just change of icon when file is unsaved --- source/blender/windowmanager/intern/wm_files.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/blender/windowmanager/intern/wm_files.cc b/source/blender/windowmanager/intern/wm_files.cc index b0c45bb63b9..8c539d3762d 100644 --- a/source/blender/windowmanager/intern/wm_files.cc +++ b/source/blender/windowmanager/intern/wm_files.cc @@ -2282,6 +2282,7 @@ static int wm_homefile_write_exec(bContext *C, wmOperator *op) static void save_homefile_warning(bContext * /*C*/, wmOperator * /*op*/, wmWarningDetails *warning) { STRNCPY(warning->confirm_button, IFACE_("Save")); + warning->icon = ALERT_ICON_BLENDER; warning->size = WM_WARNING_SIZE_LARGE; warning->position = WM_WARNING_POSITION_CENTER; } @@ -2681,18 +2682,19 @@ static void read_factory_warning(bContext *C, wmOperator * /*op*/, wmWarningDeta if (wm_file_or_session_data_has_unsaved_changes(CTX_data_main(C), CTX_wm_manager(C))) { STRNCPY(warning->message, IFACE_("WARNING: Your file is unsaved. Proceeding will abandon your changes")); + warning->icon = ALERT_ICON_WARNING; warning->confirm_default = false; warning->cancel_default = true; } else { STRNCPY(warning->message, IFACE_("To make changes to preferences permanent, use \"Save Preferences\"")); + warning->icon = ALERT_ICON_BLENDER; warning->confirm_default = true; warning->cancel_default = false; } STRNCPY(warning->confirm_button, IFACE_("Load")); - warning->icon = ALERT_ICON_BLENDER; warning->size = WM_WARNING_SIZE_LARGE; warning->position = WM_WARNING_POSITION_CENTER; } -- 2.30.2 From 5dc7cc686d080ee1246da609511716b54116cbfd Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Wed, 26 Jul 2023 14:18:29 -0700 Subject: [PATCH 04/11] Adding new bits. not done. --- source/blender/windowmanager/WM_types.h | 3 ++ .../windowmanager/intern/wm_operators.cc | 44 ++++++++++++++----- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index cbb41da9529..db68fafa9a8 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -930,6 +930,9 @@ typedef enum wmWarningPosition { typedef struct wmWarningDetails { char title[1024]; char message[1024]; + char message2[1024]; + char link_target[1024]; + char link_text[1024]; char confirm_button[256]; char cancel_button[256]; int icon; diff --git a/source/blender/windowmanager/intern/wm_operators.cc b/source/blender/windowmanager/intern/wm_operators.cc index afa2b4f2448..ec4b003cc1e 100644 --- a/source/blender/windowmanager/intern/wm_operators.cc +++ b/source/blender/windowmanager/intern/wm_operators.cc @@ -1177,8 +1177,8 @@ int WM_enum_search_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/ static void wm_operator_block_cancel(bContext *C, void *arg_op, void *arg_block) { - wmOperator *op = arg_op; - uiBlock *block = arg_block; + wmOperator *op = static_cast(arg_op); + uiBlock *block = static_cast(arg_block); UI_popup_block_close(C, CTX_wm_window(C), block); WM_redraw_windows(C); if (op) { @@ -1191,8 +1191,8 @@ static void wm_operator_block_cancel(bContext *C, void *arg_op, void *arg_block) static void wm_operator_block_confirm(bContext *C, void *arg_op, void *arg_block) { - wmOperator *op = arg_op; - uiBlock *block = arg_block; + wmOperator *op = static_cast(arg_op); + uiBlock *block = static_cast(arg_block); UI_popup_block_close(C, CTX_wm_window(C), block); WM_redraw_windows(C); if (op) { @@ -1202,7 +1202,7 @@ static void wm_operator_block_confirm(bContext *C, void *arg_op, void *arg_block static uiBlock *wm_block_confirm_create(bContext *C, ARegion *region, void *arg_op) { - wmOperator *op = arg_op; + wmOperator *op = static_cast(arg_op); wmWarningDetails warning = {0}; @@ -1239,10 +1239,24 @@ static uiBlock *wm_block_confirm_create(bContext *C, ARegion *region, void *arg_ UI_block_flag_enable(block, block_flags); const uiStyle *style = UI_style_get_dpi(); - int text_width = MAX3( + int text_width = MAX2( 120 * UI_SCALE_FAC, - BLF_width(style->widget.uifont_id, warning.title, ARRAY_SIZE(warning.title)), - BLF_width(style->widget.uifont_id, warning.message, ARRAY_SIZE(warning.message))); + BLF_width(style->widget.uifont_id, warning.title, ARRAY_SIZE(warning.title))); + if (warning.message[0]) { + text_width = MAX2( + text_width, + BLF_width(style->widget.uifont_id, warning.message, ARRAY_SIZE(warning.message))); + } + if (warning.message2[0]) { + text_width = MAX2( + text_width, + BLF_width(style->widget.uifont_id, warning.message2, ARRAY_SIZE(warning.message2))); + } + if (warning.link_text[0]) { + text_width = MAX2( + text_width, + BLF_width(style->widget.uifont_id, warning.link_text, ARRAY_SIZE(warning.link_text))); + } const bool small = warning.size == WM_WARNING_SIZE_SMALL; const int padding = (small ? 7 : 14) * UI_SCALE_FAC; @@ -1274,6 +1288,13 @@ static uiBlock *wm_block_confirm_create(bContext *C, ARegion *region, void *arg_ if (warning.message[0]) { uiItemL(layout, warning.message, ICON_NONE); } + if (warning.message2[0]) { + uiItemL(layout, warning.message2, ICON_NONE); + } + + if (warning.link_target[0] && warning.link_text[0]) { + uiItemL(layout, warning.link_text, ICON_NONE); + } uiItemS_ex(layout, small ? 0.5f : 4.0f); @@ -1326,9 +1347,10 @@ static uiBlock *wm_block_confirm_create(bContext *C, ARegion *region, void *arg_ } if (warning.position == WM_WARNING_POSITION_MOUSE) { - int x = uiLayoutGetWidth(layout) * (windows_layout ? -0.33f : -0.66f); - int y = UI_UNIT_Y * (warning.message[0] ? 3.1 : 2.5); - UI_block_bounds_set_popup(block, padding, (const int[2]){x, y}); + int bounds_offset[2]; + bounds_offset[0] = uiLayoutGetWidth(layout) * (windows_layout ? -0.33f : -0.66f); + bounds_offset[1] = UI_UNIT_Y * (warning.message[0] ? 3.1 : 2.5); + UI_block_bounds_set_popup(block, padding, bounds_offset); } else if (warning.position == WM_WARNING_POSITION_CENTER) { UI_block_bounds_set_centered(block, padding); -- 2.30.2 From cc7d9d32c505fc1beed238a75aa2b92fdf91ac48 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Wed, 26 Jul 2023 21:52:55 -0700 Subject: [PATCH 05/11] Changes to Load Factory Startup --- source/blender/windowmanager/intern/wm_files.cc | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/source/blender/windowmanager/intern/wm_files.cc b/source/blender/windowmanager/intern/wm_files.cc index 14e18bf64d2..ed6436bdb01 100644 --- a/source/blender/windowmanager/intern/wm_files.cc +++ b/source/blender/windowmanager/intern/wm_files.cc @@ -2691,21 +2691,19 @@ void WM_OT_read_homefile(wmOperatorType *ot) static void read_factory_warning(bContext *C, wmOperator * /*op*/, wmWarningDetails *warning) { STRNCPY(warning->title, IFACE_("Load factory default startup file and preferences.")); + STRNCPY(warning->message, + IFACE_("To make changes to preferences permanent, use \"Save Preferences\"")); + warning->icon = ALERT_ICON_BLENDER; + warning->confirm_default = true; + warning->cancel_default = false; if (wm_file_or_session_data_has_unsaved_changes(CTX_data_main(C), CTX_wm_manager(C))) { - STRNCPY(warning->message, + STRNCPY(warning->message2, IFACE_("WARNING: Your file is unsaved. Proceeding will abandon your changes")); warning->icon = ALERT_ICON_WARNING; warning->confirm_default = false; warning->cancel_default = true; } - else { - STRNCPY(warning->message, - IFACE_("To make changes to preferences permanent, use \"Save Preferences\"")); - warning->icon = ALERT_ICON_BLENDER; - warning->confirm_default = true; - warning->cancel_default = false; - } STRNCPY(warning->confirm_button, IFACE_("Load")); warning->size = WM_WARNING_SIZE_LARGE; -- 2.30.2 From 2b18e9d4ef80f6ac15f0164c68d9855d32241cfe Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Fri, 8 Sep 2023 13:26:16 -0700 Subject: [PATCH 06/11] NULL -> nullptr --- .../windowmanager/intern/wm_operators.cc | 44 +++++++++++++++---- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/source/blender/windowmanager/intern/wm_operators.cc b/source/blender/windowmanager/intern/wm_operators.cc index 5a4d67dee13..555c70ee084 100644 --- a/source/blender/windowmanager/intern/wm_operators.cc +++ b/source/blender/windowmanager/intern/wm_operators.cc @@ -1295,29 +1295,55 @@ static uiBlock *wm_block_confirm_create(bContext *C, ARegion *region, void *arg_ const bool windows_layout = false; #endif - uiBut *confirm = NULL; - uiBut *cancel = NULL; + uiBut *confirm = nullptr; + uiBut *cancel = nullptr; int height = UI_UNIT_Y; uiLayout *split = uiLayoutSplit(small ? block_layout : layout, 0.0f, true); uiLayoutSetScaleY(split, small ? 1.1f : 1.2f); uiLayoutColumn(split, false); if (windows_layout) { - confirm = uiDefIconTextBut( - block, UI_BTYPE_BUT, 0, 0, warning.confirm_button, 0, 0, 0, height, 0, 0, 0, 0, 0, NULL); + confirm = uiDefIconTextBut(block, + UI_BTYPE_BUT, + 0, + 0, + warning.confirm_button, + 0, + 0, + 0, + height, + 0, + 0, + 0, + 0, + 0, + nullptr); uiLayoutColumn(split, false); } cancel = uiDefIconTextBut( - block, UI_BTYPE_BUT, 0, 0, warning.cancel_button, 0, 0, 0, height, 0, 0, 0, 0, 0, NULL); + block, UI_BTYPE_BUT, 0, 0, warning.cancel_button, 0, 0, 0, height, 0, 0, 0, 0, 0, nullptr); if (!windows_layout) { uiLayoutColumn(split, false); - confirm = uiDefIconTextBut( - block, UI_BTYPE_BUT, 0, 0, warning.confirm_button, 0, 0, 0, height, 0, 0, 0, 0, 0, NULL); + confirm = uiDefIconTextBut(block, + UI_BTYPE_BUT, + 0, + 0, + warning.confirm_button, + 0, + 0, + 0, + height, + 0, + 0, + 0, + 0, + 0, + nullptr); } - UI_block_func_set(block, NULL, NULL, NULL); + UI_block_func_set(block, nullptr, nullptr, nullptr); UI_but_func_set(confirm, wm_operator_block_confirm, op, block); UI_but_func_set(cancel, wm_operator_block_cancel, op, block); UI_but_drawflag_disable(confirm, UI_BUT_TEXT_LEFT); @@ -1376,7 +1402,7 @@ int WM_operator_confirm_message_ex(bContext *C, int WM_operator_confirm_message(bContext *C, wmOperator *op, const char *message) { if (op->type->warning) { - UI_popup_block_invoke(C, wm_block_confirm_create, op, NULL); + UI_popup_block_invoke(C, wm_block_confirm_create, op, nullptr); return OPERATOR_RUNNING_MODAL; } -- 2.30.2 From 20ed79e38679a07897ed7f256e0f47d81b1ef82c Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Fri, 8 Sep 2023 13:45:48 -0700 Subject: [PATCH 07/11] Missing include --- source/blender/editors/object/object_transform.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/source/blender/editors/object/object_transform.cc b/source/blender/editors/object/object_transform.cc index c57075045d6..06519d9e70b 100644 --- a/source/blender/editors/object/object_transform.cc +++ b/source/blender/editors/object/object_transform.cc @@ -29,6 +29,7 @@ #include "BLI_math_matrix.h" #include "BLI_math_matrix.hh" #include "BLI_math_rotation.h" +#include "BLI_string.h" #include "BLI_task.hh" #include "BLI_utildefines.h" #include "BLI_vector.hh" -- 2.30.2 From 9ebb54835dfeedcab98abc501a3e1bc9f91621fc Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Wed, 3 Jan 2024 15:49:48 -0800 Subject: [PATCH 08/11] Removal of all the actual dialog changes. --- .../editors/object/object_bake_simulation.cc | 10 +-- .../blender/editors/object/object_modifier.cc | 14 +--- .../editors/object/object_transform.cc | 15 +---- source/blender/editors/space_info/info_ops.cc | 23 ++----- .../editors/space_outliner/outliner_edit.cc | 64 ++++++++----------- source/blender/windowmanager/WM_api.hh | 5 ++ .../blender/windowmanager/intern/wm_files.cc | 50 +-------------- 7 files changed, 44 insertions(+), 137 deletions(-) diff --git a/source/blender/editors/object/object_bake_simulation.cc b/source/blender/editors/object/object_bake_simulation.cc index 9b9fb21bed6..480a315cf3b 100644 --- a/source/blender/editors/object/object_bake_simulation.cc +++ b/source/blender/editors/object/object_bake_simulation.cc @@ -607,13 +607,6 @@ static PathUsersMap bake_simulation_get_path_users(bContext *C, const Spanmessage, "Overwrite existing bake data"); -} - static int bake_simulation_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/) { Vector objects; @@ -657,7 +650,7 @@ static int bake_simulation_invoke(bContext *C, wmOperator *op, const wmEvent * / return OPERATOR_CANCELLED; } if (has_existing_bake_data) { - return WM_operator_confirm(C, op, nullptr); + return WM_operator_confirm_message(C, op, "Overwrite existing bake data"); } return bake_simulation_exec(C, op); } @@ -931,7 +924,6 @@ void OBJECT_OT_simulation_nodes_cache_bake(wmOperatorType *ot) ot->invoke = bake_simulation_invoke; ot->modal = bake_simulation_modal; ot->poll = bake_simulation_poll; - ot->warning = bake_simulation_warning; RNA_def_boolean(ot->srna, "selected", false, "Selected", "Bake cache on all selected objects"); } diff --git a/source/blender/editors/object/object_modifier.cc b/source/blender/editors/object/object_modifier.cc index 9b1d8087021..c1aad69163b 100644 --- a/source/blender/editors/object/object_modifier.cc +++ b/source/blender/editors/object/object_modifier.cc @@ -35,8 +35,6 @@ #include "BLI_string_utf8.h" #include "BLI_utildefines.h" -#include "BLT_translation.h" - #include "BKE_DerivedMesh.hh" #include "BKE_animsys.h" #include "BKE_armature.hh" @@ -1796,14 +1794,6 @@ static int modifier_apply_exec(bContext *C, wmOperator *op) return modifier_apply_exec_ex(C, op, MODIFIER_APPLY_DATA, false); } -static void modifier_apply_warning(bContext * /*C*/, - wmOperator * /*op*/, - wmWarningDetails *warning) -{ - STRNCPY(warning->message, IFACE_("Make object data single-user and apply modifier")); - STRNCPY(warning->confirm_button, IFACE_("Apply")); -} - static int modifier_apply_invoke(bContext *C, wmOperator *op, const wmEvent *event) { int retval; @@ -1817,7 +1807,8 @@ static int modifier_apply_invoke(bContext *C, wmOperator *op, const wmEvent *eve RNA_property_boolean_set(op->ptr, prop, true); } if (RNA_property_boolean_get(op->ptr, prop)) { - return WM_operator_confirm(C, op, nullptr); + return WM_operator_confirm_message( + C, op, "Make object data single-user and apply modifier"); } } return modifier_apply_exec(C, op); @@ -1834,7 +1825,6 @@ void OBJECT_OT_modifier_apply(wmOperatorType *ot) ot->invoke = modifier_apply_invoke; ot->exec = modifier_apply_exec; ot->poll = modifier_apply_poll; - ot->warning = modifier_apply_warning; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL; diff --git a/source/blender/editors/object/object_transform.cc b/source/blender/editors/object/object_transform.cc index 4353b3e77ce..0e3cd5f3c0d 100644 --- a/source/blender/editors/object/object_transform.cc +++ b/source/blender/editors/object/object_transform.cc @@ -29,13 +29,10 @@ #include "BLI_math_matrix.h" #include "BLI_math_matrix.hh" #include "BLI_math_rotation.h" -#include "BLI_string.h" #include "BLI_task.hh" #include "BLI_utildefines.h" #include "BLI_vector.hh" -#include "BLT_translation.h" - #include "BKE_armature.hh" #include "BKE_context.hh" #include "BKE_curve.hh" @@ -1158,14 +1155,6 @@ static int object_transform_apply_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -static void object_transform_apply_warning(bContext * /*C*/, - wmOperator * /*op*/, - wmWarningDetails *warning) -{ - STRNCPY(warning->message, IFACE_("Create new object-data users and apply transformation")); - STRNCPY(warning->confirm_button, IFACE_("Apply")); -} - static int object_transform_apply_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/) { Object *ob = ED_object_active_context(C); @@ -1179,7 +1168,8 @@ static int object_transform_apply_invoke(bContext *C, wmOperator *op, const wmEv RNA_property_boolean_set(op->ptr, prop, true); } if (RNA_property_boolean_get(op->ptr, prop)) { - return WM_operator_confirm(C, op, nullptr); + return WM_operator_confirm_message( + C, op, "Create new object-data users and apply transformation"); } } return object_transform_apply_exec(C, op); @@ -1196,7 +1186,6 @@ void OBJECT_OT_transform_apply(wmOperatorType *ot) ot->exec = object_transform_apply_exec; ot->invoke = object_transform_apply_invoke; ot->poll = ED_operator_objectmode; - ot->warning = object_transform_apply_warning; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; diff --git a/source/blender/editors/space_info/info_ops.cc b/source/blender/editors/space_info/info_ops.cc index dcd6f4e3bd8..80d5bc96023 100644 --- a/source/blender/editors/space_info/info_ops.cc +++ b/source/blender/editors/space_info/info_ops.cc @@ -86,13 +86,10 @@ static int unpack_libraries_exec(bContext *C, wmOperator *op) /** \name Unpack Blend File Libraries Operator * \{ */ -static void unpack_libraries_warning(bContext * /* C */, - wmOperator * /* op */, - wmWarningDetails *warning) +static int unpack_libraries_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/) { - STRNCPY(warning->message, IFACE_("Creates directories, all new paths should work")); - STRNCPY(warning->confirm_button, IFACE_("Unpack")); - warning->icon = ALERT_ICON_INFO; + return WM_operator_confirm_message( + C, op, "Unpack Linked Libraries - creates directories, all new paths should work"); } void FILE_OT_unpack_libraries(wmOperatorType *ot) @@ -103,9 +100,8 @@ void FILE_OT_unpack_libraries(wmOperatorType *ot) ot->description = "Restore all packed linked data-blocks to their original locations"; /* api callbacks */ - ot->invoke = WM_operator_confirm; + ot->invoke = unpack_libraries_invoke; ot->exec = unpack_libraries_exec; - ot->warning = unpack_libraries_warning; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -161,13 +157,6 @@ static int pack_all_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -static void pack_all_warning(bContext * /* C */, wmOperator * /* op */, wmWarningDetails *warning) -{ - STRNCPY(warning->message, - IFACE_("Some images are mofified. These changes will be lost. Continue?")); - STRNCPY(warning->confirm_button, IFACE_("Pack")); -} - static int pack_all_invoke(bContext *C, wmOperator *op, const wmEvent * /* event */) { Main *bmain = CTX_data_main(C); @@ -183,7 +172,8 @@ static int pack_all_invoke(bContext *C, wmOperator *op, const wmEvent * /* event } if (ima) { - return WM_operator_confirm(C, op, nullptr); + return WM_operator_confirm_message( + C, op, "Some images are painted on. These changes will be lost. Continue?"); } return pack_all_exec(C, op); @@ -199,7 +189,6 @@ void FILE_OT_pack_all(wmOperatorType *ot) /* api callbacks */ ot->exec = pack_all_exec; ot->invoke = pack_all_invoke; - ot->warning = pack_all_warning; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; diff --git a/source/blender/editors/space_outliner/outliner_edit.cc b/source/blender/editors/space_outliner/outliner_edit.cc index 2b8ff0b003a..dced5b95f6b 100644 --- a/source/blender/editors/space_outliner/outliner_edit.cc +++ b/source/blender/editors/space_outliner/outliner_edit.cc @@ -2124,43 +2124,6 @@ static bool ed_operator_outliner_id_orphans_active(bContext *C) return true; } -static void orphans_purge_warning(bContext *C, wmOperator *op, wmWarningDetails *warning) -{ - Main *bmain = CTX_data_main(C); - int num_tagged[INDEX_ID_MAX] = {0}; - - const bool do_local_ids = RNA_boolean_get(op->ptr, "do_local_ids"); - const bool do_linked_ids = RNA_boolean_get(op->ptr, "do_linked_ids"); - const bool do_recursive_cleanup = RNA_boolean_get(op->ptr, "do_recursive"); - - /* Tag all IDs to delete. */ - BKE_lib_query_unused_ids_tag( - bmain, LIB_TAG_DOIT, do_local_ids, do_linked_ids, do_recursive_cleanup, num_tagged); - - DynStr *dyn_str = BLI_dynstr_new(); - bool is_first = true; - for (int i = 0; i < INDEX_ID_MAX - 2; i++) { - if (num_tagged[i] != 0) { - if (!is_first) { - BLI_dynstr_append(dyn_str, ", "); - } - else { - is_first = false; - } - BLI_dynstr_appendf(dyn_str, - "%d %s", - num_tagged[i], - TIP_(BKE_idtype_idcode_to_name_plural(BKE_idtype_idcode_from_index(i)))); - } - } - - STRNCPY(warning->title, IFACE_("Remove Unused Data")); - STRNCPY(warning->message, BLI_dynstr_get_cstring(dyn_str)); - STRNCPY(warning->confirm_button, IFACE_("Purge")); - - BLI_dynstr_free(dyn_str); -} - static int outliner_orphans_purge_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/) { Main *bmain = CTX_data_main(C); @@ -2181,7 +2144,31 @@ static int outliner_orphans_purge_invoke(bContext *C, wmOperator *op, const wmEv return OPERATOR_CANCELLED; } - return WM_operator_confirm(C, op, nullptr); + DynStr *dyn_str = BLI_dynstr_new(); + BLI_dynstr_appendf(dyn_str, TIP_("Purging %d unused data-blocks ("), num_tagged[INDEX_ID_NULL]); + bool is_first = true; + for (int i = 0; i < INDEX_ID_MAX - 2; i++) { + if (num_tagged[i] != 0) { + if (!is_first) { + BLI_dynstr_append(dyn_str, ", "); + } + else { + is_first = false; + } + BLI_dynstr_appendf(dyn_str, + "%d %s", + num_tagged[i], + TIP_(BKE_idtype_idcode_to_name_plural(BKE_idtype_idcode_from_index(i)))); + } + } + BLI_dynstr_append(dyn_str, TIP_("). Click here to proceed...")); + + char *message = BLI_dynstr_get_cstring(dyn_str); + int ret = WM_operator_confirm_message(C, op, message); + + MEM_freeN(message); + BLI_dynstr_free(dyn_str); + return ret; } static int outliner_orphans_purge_exec(bContext *C, wmOperator *op) @@ -2238,7 +2225,6 @@ void OUTLINER_OT_orphans_purge(wmOperatorType *ot) ot->invoke = outliner_orphans_purge_invoke; ot->exec = outliner_orphans_purge_exec; ot->poll = ed_operator_outliner_id_orphans_active; - ot->warning = orphans_purge_warning; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; diff --git a/source/blender/windowmanager/WM_api.hh b/source/blender/windowmanager/WM_api.hh index da7144e9684..85cdc93ee90 100644 --- a/source/blender/windowmanager/WM_api.hh +++ b/source/blender/windowmanager/WM_api.hh @@ -712,6 +712,11 @@ int WM_operator_props_dialog_popup(bContext *C, wmOperator *op, int width); int WM_operator_redo_popup(bContext *C, wmOperator *op); int WM_operator_ui_popup(bContext *C, wmOperator *op, int width); +/** + * Can't be used as an invoke directly, needs message arg (can be NULL). + */ +int WM_operator_confirm_message(bContext *C, wmOperator *op, const char *message); + /* Operator API. */ void WM_operator_free(wmOperator *op); diff --git a/source/blender/windowmanager/intern/wm_files.cc b/source/blender/windowmanager/intern/wm_files.cc index 1c50eb82710..161b797a419 100644 --- a/source/blender/windowmanager/intern/wm_files.cc +++ b/source/blender/windowmanager/intern/wm_files.cc @@ -2327,14 +2327,6 @@ static int wm_homefile_write_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } -static void save_homefile_warning(bContext * /*C*/, wmOperator * /*op*/, wmWarningDetails *warning) -{ - STRNCPY(warning->confirm_button, IFACE_("Save")); - warning->icon = ALERT_ICON_BLENDER; - warning->size = WM_WARNING_SIZE_LARGE; - warning->position = WM_WARNING_POSITION_CENTER; -} - void WM_OT_save_homefile(wmOperatorType *ot) { ot->name = "Save Startup File"; @@ -2343,7 +2335,6 @@ void WM_OT_save_homefile(wmOperatorType *ot) ot->invoke = WM_operator_confirm; ot->exec = wm_homefile_write_exec; - ot->warning = save_homefile_warning; } /** \} */ @@ -2507,19 +2498,6 @@ void WM_OT_read_userpref(wmOperatorType *ot) ot->exec = wm_userpref_read_exec; } -static void wm_userpref_read_factory_warning(bContext * /*C*/, - wmOperator * /*op*/, - wmWarningDetails *warning) -{ - STRNCPY(warning->title, IFACE_("Load factory default preferences")); - STRNCPY(warning->message, - IFACE_("To make changes to preferences permanent, use \"Save Preferences\"")); - STRNCPY(warning->confirm_button, IFACE_("Load")); - warning->icon = ALERT_ICON_BLENDER; - warning->size = WM_WARNING_SIZE_LARGE; - warning->position = WM_WARNING_POSITION_CENTER; -} - void WM_OT_read_factory_userpref(wmOperatorType *ot) { ot->name = "Load Factory Preferences"; @@ -2530,7 +2508,6 @@ void WM_OT_read_factory_userpref(wmOperatorType *ot) ot->invoke = WM_operator_confirm; ot->exec = wm_userpref_read_exec; - ot->warning = wm_userpref_read_factory_warning; read_factory_reset_props(ot); } @@ -2753,37 +2730,16 @@ void WM_OT_read_homefile(wmOperatorType *ot) /* omit poll to run in background mode */ } -static void read_factory_warning(bContext *C, wmOperator * /*op*/, wmWarningDetails *warning) -{ - STRNCPY(warning->title, IFACE_("Load factory default startup file and preferences.")); - STRNCPY(warning->message, - IFACE_("To make changes to preferences permanent, use \"Save Preferences\"")); - warning->icon = ALERT_ICON_BLENDER; - warning->confirm_default = true; - warning->cancel_default = false; - - if (wm_file_or_session_data_has_unsaved_changes(CTX_data_main(C), CTX_wm_manager(C))) { - STRNCPY(warning->message2, - IFACE_("WARNING: Your file is unsaved. Proceeding will abandon your changes")); - warning->icon = ALERT_ICON_WARNING; - warning->confirm_default = false; - warning->cancel_default = true; - } - - STRNCPY(warning->confirm_button, IFACE_("Load")); - warning->size = WM_WARNING_SIZE_LARGE; - warning->position = WM_WARNING_POSITION_CENTER; -} - void WM_OT_read_factory_settings(wmOperatorType *ot) { ot->name = "Load Factory Settings"; ot->idname = "WM_OT_read_factory_settings"; - ot->description = "Load factory default startup file and preferences"; + ot->description = + "Load factory default startup file and preferences. " + "To make changes permanent, use \"Save Startup File\" and \"Save Preferences\""; ot->invoke = WM_operator_confirm; ot->exec = wm_homefile_read_exec; - ot->warning = read_factory_warning; /* Omit poll to run in background mode. */ read_factory_reset_props(ot); -- 2.30.2 From 4aa860d514c118a8cd4df88038ffc0799d74c796 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Wed, 3 Jan 2024 15:52:35 -0800 Subject: [PATCH 09/11] Unintentional formatting change --- source/blender/editors/space_info/info_ops.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/editors/space_info/info_ops.cc b/source/blender/editors/space_info/info_ops.cc index 80d5bc96023..d1ff69381f9 100644 --- a/source/blender/editors/space_info/info_ops.cc +++ b/source/blender/editors/space_info/info_ops.cc @@ -157,7 +157,7 @@ static int pack_all_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -static int pack_all_invoke(bContext *C, wmOperator *op, const wmEvent * /* event */) +static int pack_all_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/) { Main *bmain = CTX_data_main(C); Image *ima; -- 2.30.2 From 39b7bba98359787d48d7113f1e36a7dbc39e1531 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Wed, 3 Jan 2024 17:10:13 -0800 Subject: [PATCH 10/11] Calm warnings --- source/blender/windowmanager/intern/wm_operators.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/blender/windowmanager/intern/wm_operators.cc b/source/blender/windowmanager/intern/wm_operators.cc index 7469b1b3d61..0dc01dcf9b3 100644 --- a/source/blender/windowmanager/intern/wm_operators.cc +++ b/source/blender/windowmanager/intern/wm_operators.cc @@ -1210,11 +1210,11 @@ static uiBlock *wm_block_confirm_create(bContext *C, ARegion *region, void *arg_ { wmOperator *op = static_cast(arg_op); - wmWarningDetails warning = {0}; + wmWarningDetails warning = {{0}}; - STRNCPY_RLEN(warning.title, WM_operatortype_description(C, op->type, op->ptr).c_str()); - STRNCPY_RLEN(warning.confirm_button, WM_operatortype_name(op->type, op->ptr).c_str()); - STRNCPY_RLEN(warning.cancel_button, IFACE_("Cancel")); + STRNCPY(warning.title, WM_operatortype_description(C, op->type, op->ptr).c_str()); + STRNCPY(warning.confirm_button, WM_operatortype_name(op->type, op->ptr).c_str()); + STRNCPY(warning.cancel_button, IFACE_("Cancel")); warning.icon = ALERT_ICON_WARNING; warning.size = WM_WARNING_SIZE_SMALL; warning.position = WM_WARNING_POSITION_MOUSE; -- 2.30.2 From 25fc92fedbf8a82c3b14a38ab4eea98a1ea81323 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Wed, 3 Jan 2024 17:14:17 -0800 Subject: [PATCH 11/11] Removing one extra change from main. --- source/blender/windowmanager/WM_api.hh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/blender/windowmanager/WM_api.hh b/source/blender/windowmanager/WM_api.hh index 85cdc93ee90..95063dffba1 100644 --- a/source/blender/windowmanager/WM_api.hh +++ b/source/blender/windowmanager/WM_api.hh @@ -715,6 +715,12 @@ int WM_operator_ui_popup(bContext *C, wmOperator *op, int width); /** * Can't be used as an invoke directly, needs message arg (can be NULL). */ +int WM_operator_confirm_message_ex(bContext *C, + wmOperator *op, + const char *title, + int icon, + const char *message, + wmOperatorCallContext opcontext); int WM_operator_confirm_message(bContext *C, wmOperator *op, const char *message); /* Operator API. */ -- 2.30.2