UI: replace uiPupMenuOkee & uiPupMenuSaveOver with WM_operator_confirm

This commit is contained in:
2014-02-09 12:28:14 +11:00
parent 873f901e5a
commit b105d2ac7f
5 changed files with 16 additions and 90 deletions

View File

@@ -348,10 +348,8 @@ struct uiPopupMenu *uiPupMenuBegin(struct bContext *C, const char *title, int ic
void uiPupMenuEnd(struct bContext *C, struct uiPopupMenu *head);
struct uiLayout *uiPupMenuLayout(uiPopupMenu *head);
void uiPupMenuOkee(struct bContext *C, const char *opname, const char *str, ...) ATTR_PRINTF_FORMAT(3, 4);
void uiPupMenuSaveOver(struct bContext *C, struct wmOperator *op, const char *filename);
void uiPupMenuReports(struct bContext *C, struct ReportList *reports) ATTR_NONNULL();
void uiPupMenuInvoke(struct bContext *C, const char *idname); /* popup registered menu */
void uiPupMenuInvoke(struct bContext *C, const char *idname) ATTR_NONNULL();
/* Popup Blocks
*

View File

@@ -2607,86 +2607,6 @@ uiLayout *uiPupMenuLayout(uiPopupMenu *pup)
/*************************** Standard Popup Menus ****************************/
static void operator_name_cb(bContext *C, void *arg, int retval)
{
const char *opname = arg;
if (opname && retval > 0)
WM_operator_name_call(C, opname, WM_OP_EXEC_DEFAULT, NULL);
}
static void operator_cb(bContext *C, void *arg, int retval)
{
wmOperator *op = arg;
if (op && retval > 0)
WM_operator_call(C, op);
else
WM_operator_free(op);
}
static void confirm_cancel_operator(bContext *UNUSED(C), void *opv)
{
WM_operator_free(opv);
}
static void vconfirm_opname(bContext *C, const char *opname, const char *title,
const char *itemfmt, va_list ap) ATTR_PRINTF_FORMAT(4, 0);
static void vconfirm_opname(bContext *C, const char *opname, const char *title,
const char *itemfmt, va_list ap)
{
uiPopupBlockHandle *handle;
char *s, buf[512];
s = buf;
if (title) s += sprintf(s, "%s%%t|", title);
vsnprintf(s, sizeof(buf) - (s - buf), itemfmt, ap);
buf[sizeof(buf) - 1] = '\0';
handle = ui_popup_menu_create(C, NULL, NULL, NULL, NULL, buf);
handle->popup_func = operator_name_cb;
handle->popup_arg = (void *)opname;
}
static void confirm_operator(bContext *C, wmOperator *op, const char *title, const char *item)
{
uiPopupBlockHandle *handle;
char *s, buf[512];
s = buf;
if (title) s += BLI_snprintf(s, sizeof(buf), "%s%%t|%s", title, item);
(void)s;
handle = ui_popup_menu_create(C, NULL, NULL, NULL, NULL, buf);
handle->popup_func = operator_cb;
handle->popup_arg = op;
handle->cancel_func = confirm_cancel_operator;
}
void uiPupMenuOkee(bContext *C, const char *opname, const char *str, ...)
{
va_list ap;
char titlestr[256];
BLI_snprintf(titlestr, sizeof(titlestr), IFACE_("OK? %%i%d"), ICON_QUESTION);
va_start(ap, str);
vconfirm_opname(C, opname, titlestr, str, ap);
va_end(ap);
}
/* note, only call this is the file exists,
* the case where the file does not exist so can be saved without a
* popup must be checked for already, since saving from here
* will free the operator which will break invoke().
* The operator state for this is implicitly OPERATOR_RUNNING_MODAL */
void uiPupMenuSaveOver(bContext *C, wmOperator *op, const char *filename)
{
confirm_operator(C, op, IFACE_("Save Over?"), filename);
}
void uiPupMenuReports(bContext *C, ReportList *reports)
{
Report *report;

View File

@@ -188,8 +188,7 @@ static int pack_all_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(ev
}
if (ima) {
uiPupMenuOkee(C, "FILE_OT_pack_all", "Some images are painted on. These changes will be lost. Continue?");
return OPERATOR_CANCELLED;
return WM_operator_confirm_message(C, op, "Some images are painted on. These changes will be lost. Continue?");
}
return pack_all_exec(C, op);

View File

@@ -205,7 +205,11 @@ int WM_operator_props_dialog_popup(struct bContext *C, struct wmOperator *op,
int WM_operator_redo_popup (struct bContext *C, struct wmOperator *op);
int WM_operator_ui_popup (struct bContext *C, struct wmOperator *op, int width, int height);
int WM_operator_confirm_message(struct bContext *C, struct wmOperator *op, const char *message);
int WM_operator_confirm_message_ex(struct bContext *C, struct wmOperator *op,
const char *title, const int icon,
const char *message);
int WM_operator_confirm_message(struct bContext *C, struct wmOperator *op,
const char *message);
/* operator api */
void WM_operator_free (struct wmOperator *op);

View File

@@ -1107,7 +1107,9 @@ int WM_enum_search_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(eve
}
/* 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)
int WM_operator_confirm_message_ex(bContext *C, wmOperator *op,
const char *title, const int icon,
const char *message)
{
uiPopupMenu *pup;
uiLayout *layout;
@@ -1118,7 +1120,7 @@ int WM_operator_confirm_message(bContext *C, wmOperator *op, const char *message
else
properties = NULL;
pup = uiPupMenuBegin(C, IFACE_("OK?"), ICON_QUESTION);
pup = uiPupMenuBegin(C, title, icon);
layout = uiPupMenuLayout(pup);
uiItemFullO_ptr(layout, op->type, message, ICON_NONE, properties, WM_OP_EXEC_REGION_WIN, 0);
uiPupMenuEnd(C, pup);
@@ -1126,6 +1128,10 @@ int WM_operator_confirm_message(bContext *C, wmOperator *op, const char *message
return OPERATOR_CANCELLED;
}
int WM_operator_confirm_message(bContext *C, wmOperator *op, const char *message)
{
return WM_operator_confirm_message_ex(C, op, IFACE_("OK?"), ICON_QUESTION, message);
}
int WM_operator_confirm(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
@@ -2796,8 +2802,7 @@ static int wm_save_mainfile_invoke(bContext *C, wmOperator *op, const wmEvent *U
if (G.save_over) {
if (BLI_exists(name)) {
uiPupMenuSaveOver(C, op, name);
ret = OPERATOR_RUNNING_MODAL;
ret = WM_operator_confirm_message_ex(C, op, IFACE_("Save Over?"), ICON_QUESTION, name);
}
else {
ret = wm_save_as_mainfile_exec(C, op);