UI: Improved Operator Confirmations #104670

Merged
Harley Acheson merged 23 commits from Harley/blender:ConfirmDialogs into main 2024-01-04 18:42:34 +01:00
7 changed files with 44 additions and 137 deletions
Showing only changes of commit 9ebb54835d - Show all commits

View File

@ -607,13 +607,6 @@ static PathUsersMap bake_simulation_get_path_users(bContext *C, const Span<Objec
return path_users;
}
static void bake_simulation_warning(bContext * /*C*/,
wmOperator * /*op*/,
wmWarningDetails *warning)
{
STRNCPY(warning->message, "Overwrite existing bake data");
}
static int bake_simulation_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/)
{
Vector<Object *> 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");
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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);