diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2008-12-17 19:53:56 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2008-12-17 19:53:56 +0300 |
commit | 065155a17d468fd0655069f3c75af3c5fea69fa9 (patch) | |
tree | 74fafc9a5af91a7862ba26e1399c99bd96afaebc | |
parent | 3051647c98704c9cb79c2673611ba801903341f5 (diff) |
UI:
* Changed pupmenu function name and added back some standard popups.
-rw-r--r-- | source/blender/editors/include/UI_interface.h | 10 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 2 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_regions.c | 102 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_operators.c | 2 |
4 files changed, 77 insertions, 39 deletions
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 0540c0b2a25..29d1d653b39 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -205,11 +205,13 @@ typedef struct uiMenuBlockHandle { typedef uiBlock* (*uiBlockFuncFP)(struct bContext *C, struct uiMenuBlockHandle *handle, void *arg1); typedef void (*uiPupmenuFunc)(struct bContext *C, void *arg, int event); -extern void pupmenu_set_active(int val); -extern void pupmenu_col(struct bContext *C, char *instr, int mx, int my, int maxrow, uiPupmenuFunc func, void *arg); -extern void pupmenu(struct bContext *C, char *instr, int mx, int my, uiPupmenuFunc func, void *arg); +void uiPupmenuSetActive(int val); +void uiPupmenu(struct bContext *C, int maxrow, uiPupmenuFunc func, void *arg, char *str, ...); -void okee_operator(struct bContext *C, char *opname, char *str, ...); +void uiPupmenuOkee(struct bContext *C, char *opname, char *str, ...); +void uiPupmenuSaveOver(struct bContext *C, char *opname, char *filename, ...); +void uiPupmenuNotice(struct bContext *C, char *str, ...); +void uiPupmenuError(struct bContext *C, char *str, ...); /* Block */ diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 057f9863278..1d1f8cb44b9 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -165,7 +165,7 @@ static void ui_apply_but_func(bContext *C, uiBut *but) * handling is done, i.e. menus are closed, in order to avoid conflicts * with these functions removing the buttons we are working with */ - if(but->func || block->handle_func || (but->type == BUTM && block->butm_func)) { + if(but->func || block->handle_func || (but->type == BUTM && block->butm_func) || but->opname) { after= MEM_callocN(sizeof(uiAfterFunc), "uiAfterFunc"); after->func= but->func; diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index e4b3157c6a1..a6f41195142 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -1278,7 +1278,7 @@ uiBlock *ui_block_func_COL(bContext *C, uiMenuBlockHandle *handle, void *arg_but static int pupmenu_set= 0; -void pupmenu_set_active(int val) +void uiPupmenuSetActive(int val) { pupmenu_set= val; } @@ -1632,18 +1632,18 @@ uiBlock *ui_block_func_PUPMENUCOL(bContext *C, uiMenuBlockHandle *handle, void * return block; } -void pupmenu_col(bContext *C, char *instr, int mx, int my, int maxrow, uiPupmenuFunc func, void *arg) +void uiPupmenu(bContext *C, int maxrow, uiPupmenuFunc func, void *arg, char *str, ...) { uiPupMenuInfo info; uiMenuBlockHandle *menu; memset(&info, 0, sizeof(info)); - info.instr= instr; - info.mx= mx; - info.my= my; + info.mx= C->window->eventstate->x; + info.my= C->window->eventstate->y; info.maxrow= maxrow; + info.instr= str; - menu= ui_menu_block_create(C, NULL, NULL, ui_block_func_PUPMENUCOL, &info); + menu= ui_menu_block_create(C, NULL, NULL, ui_block_func_PUPMENU, &info); menu->popup= 1; UI_add_popup_handlers(&C->window->handlers, menu); @@ -1653,51 +1653,87 @@ void pupmenu_col(bContext *C, char *instr, int mx, int my, int maxrow, uiPupmenu menu->popup_arg= arg; } -void pupmenu(bContext *C, char *instr, int mx, int my, uiPupmenuFunc func, void *arg) +/* standard pupmenus */ + +static void operator_cb(bContext *C, void *arg, int retval) { - uiPupMenuInfo info; - uiMenuBlockHandle *menu; + const char *opname= arg; - memset(&info, 0, sizeof(info)); - info.instr= instr; - info.mx= mx; - info.my= my; + if(opname && retval > 0) + WM_operator_call(C, opname, WM_OP_DEFAULT, NULL); +} - menu= ui_menu_block_create(C, NULL, NULL, ui_block_func_PUPMENU, &info); - menu->popup= 1; +static void vconfirm(bContext *C, char *opname, char *title, char *itemfmt, va_list ap) +{ + char *s, buf[512]; - UI_add_popup_handlers(&C->window->handlers, menu); - WM_event_add_mousemove(C); + s= buf; + if (title) s+= sprintf(s, "%s%%t|", title); + vsprintf(s, itemfmt, ap); - menu->popup_func= func; - menu->popup_arg= arg; + uiPupmenu(C, 0, operator_cb, opname, buf); } -/* XXX test */ -static void operator_callback(bContext *C, void *arg, int retval) +static void confirm(bContext *C, char *opname, char *title, char *itemfmt, ...) { - const char *opname= arg; + va_list ap; - if(retval > 0) - WM_operator_call(C, opname, WM_OP_DEFAULT, NULL); + va_start(ap, itemfmt); + vconfirm(C, opname, title, itemfmt, ap); + va_end(ap); } -void okee_operator(bContext *C, char *opname, char *str, ...) +void uiPupmenuOkee(bContext *C, char *opname, char *str, ...) { va_list ap; - char *s, buf[512]; - int mx, my; + char titlestr[256]; - mx= C->window->eventstate->x; - my= C->window->eventstate->y; + sprintf(titlestr, "OK? %%i%d", ICON_HELP); va_start(ap, str); + vconfirm(C, opname, titlestr, str, ap); + va_end(ap); +} - s= buf; - s += sprintf(s, "OK? %%i%d%%t|", ICON_HELP); - vsprintf(s, str, ap); +void uiPupmenuSaveOver(bContext *C, char *opname, char *filename, ...) +{ + size_t len= strlen(filename); + + if(len==0) + return; + + if(BLI_exists(filename)==0) + operator_cb(C, opname, 1); + + if(filename[len-1]=='/' || filename[len-1]=='\\') { + uiPupmenuError(C, "Cannot overwrite a directory"); + return; + } + + confirm(C, opname, "Save over", filename); +} + +void uiPupmenuNotice(bContext *C, char *str, ...) +{ + va_list ap; + + va_start(ap, str); + vconfirm(C, NULL, NULL, str, ap); va_end(ap); +} - pupmenu(C, buf, mx, my, operator_callback, opname); +void uiPupmenuError(bContext *C, char *str, ...) +{ + va_list ap; + char nfmt[256]; + char titlestr[256]; + + sprintf(titlestr, "Error %%i%d", ICON_ERROR); + + sprintf(nfmt, "%s", str); + + va_start(ap, str); + vconfirm(C, NULL, titlestr, nfmt, ap); + va_end(ap); } diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 897b7b23a0e..262052c442a 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -102,7 +102,7 @@ int WM_operator_confirm(bContext *C, wmOperator *op, wmEvent *event) char buf[512]; sprintf(buf, "OK? %%i%d%%t|%s", ICON_HELP, op->type->name); - pupmenu(C, buf, event->x, event->y, operator_callback, op); + uiPupmenu(C, 0, operator_callback, op, buf); return 1; } |