Added CTRL+W save Blender file.

It's the first user of the uiPupMenuSaveOver() function,
which I've recoded to accept an operator pointer.
This is required because the operator property 'filename'
has to be set to work. Other 'save over' users will
require running operators too I guess.
This commit is contained in:
2009-02-08 19:15:59 +00:00
parent 3fcc36d0b0
commit eb929804d2
5 changed files with 78 additions and 22 deletions

View File

@@ -238,9 +238,8 @@ void uiMenuSeparator(uiMenuItem *head);
uiMenuItem *uiPupMenuBegin(const char *title, int icon);
void uiPupMenuEnd(struct bContext *C, struct uiMenuItem *head);
void uiPupMenu(struct bContext *C, int maxrow, uiMenuHandleFunc func, void *arg, char *str, ...);
void uiPupMenuOkee(struct bContext *C, char *opname, char *str, ...);
void uiPupMenuSaveOver(struct bContext *C, char *opname, char *filename, ...);
void uiPupMenuSaveOver(struct bContext *C, struct wmOperator *op, char *filename);
void uiPupMenuNotice(struct bContext *C, char *str, ...);
void uiPupMenuError(struct bContext *C, char *str, ...);
void uiPupMenuReports(struct bContext *C, struct ReportList *reports);

View File

@@ -3753,6 +3753,8 @@ static int ui_handler_popup(bContext *C, wmEvent *event, void *userdata)
if(temp.opname)
WM_operator_name_call(C, temp.opname, temp.opcontext, NULL);
}
else if(temp.cancel_func)
temp.cancel_func(temp.popup_arg);
}
else {
/* re-enable tooltips */

View File

@@ -279,6 +279,7 @@ struct uiPopupBlockHandle {
int popup;
void (*popup_func)(struct bContext *C, void *arg, int event);
void (*cancel_func)(void *arg);
void *popup_arg;
/* for operator popups */

View File

@@ -2203,8 +2203,10 @@ void uiPupMenuEnd(bContext *C, uiMenuItem *head)
MEM_freeN(head);
}
/* this one only to be called with operatortype name option */
void uiPupMenu(bContext *C, int maxrow, uiMenuHandleFunc func, void *arg, char *str, ...)
/* ************** standard pupmenus *************** */
/* this one can called with operatortype name and operators */
static uiPopupBlockHandle *ui_pup_menu(bContext *C, int maxrow, uiMenuHandleFunc func, void *arg, char *str, ...)
{
wmWindow *window= CTX_wm_window(C);
uiPupMenuInfo info;
@@ -2224,11 +2226,12 @@ void uiPupMenu(bContext *C, int maxrow, uiMenuHandleFunc func, void *arg, char *
menu->popup_func= func;
menu->popup_arg= arg;
return menu;
}
/* standard pupmenus */
static void operator_cb(bContext *C, void *arg, int retval)
static void operator_name_cb(bContext *C, void *arg, int retval)
{
const char *opname= arg;
@@ -2236,7 +2239,7 @@ static void operator_cb(bContext *C, void *arg, int retval)
WM_operator_name_call(C, opname, WM_OP_EXEC_DEFAULT, NULL);
}
static void vconfirm(bContext *C, char *opname, char *title, char *itemfmt, va_list ap)
static void vconfirm_opname(bContext *C, char *opname, char *title, char *itemfmt, va_list ap)
{
char *s, buf[512];
@@ -2244,18 +2247,37 @@ static void vconfirm(bContext *C, char *opname, char *title, char *itemfmt, va_l
if (title) s+= sprintf(s, "%s%%t|", title);
vsprintf(s, itemfmt, ap);
uiPupMenu(C, 0, operator_cb, opname, buf);
ui_pup_menu(C, 0, operator_name_cb, opname, buf);
}
static void confirm(bContext *C, char *opname, char *title, char *itemfmt, ...)
static void operator_cb(bContext *C, void *arg, int retval)
{
va_list ap;
va_start(ap, itemfmt);
vconfirm(C, opname, title, itemfmt, ap);
va_end(ap);
wmOperator *op= arg;
if(op && retval > 0)
WM_operator_call(C, op);
else
WM_operator_free(op);
}
static void confirm_cancel_operator(void *opv)
{
WM_operator_free(opv);
}
static void confirm_operator(bContext *C, wmOperator *op, char *title, char *item)
{
uiPopupBlockHandle *handle;
char *s, buf[512];
s= buf;
if (title) s+= sprintf(s, "%s%%t|%s", title, item);
handle= ui_pup_menu(C, 0, operator_cb, op, buf);
handle->cancel_func= confirm_cancel_operator;
}
void uiPupMenuOkee(bContext *C, char *opname, char *str, ...)
{
va_list ap;
@@ -2264,11 +2286,12 @@ void uiPupMenuOkee(bContext *C, char *opname, char *str, ...)
sprintf(titlestr, "OK? %%i%d", ICON_HELP);
va_start(ap, str);
vconfirm(C, opname, titlestr, str, ap);
vconfirm_opname(C, opname, titlestr, str, ap);
va_end(ap);
}
void uiPupMenuSaveOver(bContext *C, char *opname, char *filename, ...)
void uiPupMenuSaveOver(bContext *C, wmOperator *op, char *filename)
{
size_t len= strlen(filename);
@@ -2276,14 +2299,15 @@ void uiPupMenuSaveOver(bContext *C, char *opname, char *filename, ...)
return;
if(BLI_exists(filename)==0)
operator_cb(C, opname, 1);
operator_cb(C, op, 1);
if(filename[len-1]=='/' || filename[len-1]=='\\') {
uiPupMenuError(C, "Cannot overwrite a directory");
WM_operator_free(op);
return;
}
confirm(C, opname, "Save over", filename);
confirm_operator(C, op, "Save over", filename);
}
void uiPupMenuNotice(bContext *C, char *str, ...)
@@ -2291,7 +2315,7 @@ void uiPupMenuNotice(bContext *C, char *str, ...)
va_list ap;
va_start(ap, str);
vconfirm(C, NULL, NULL, str, ap);
vconfirm_opname(C, NULL, NULL, str, ap);
va_end(ap);
}
@@ -2306,7 +2330,7 @@ void uiPupMenuError(bContext *C, char *str, ...)
sprintf(nfmt, "%s", str);
va_start(ap, str);
vconfirm(C, NULL, titlestr, nfmt, ap);
vconfirm_opname(C, NULL, titlestr, nfmt, ap);
va_end(ap);
}
@@ -2331,7 +2355,7 @@ void uiPupMenuReports(bContext *C, ReportList *reports)
}
str= BLI_dynstr_get_cstring(ds);
uiPupMenu(C, 0, NULL, NULL, str);
ui_pup_menu(C, 0, NULL, NULL, str);
MEM_freeN(str);
BLI_dynstr_free(ds);

View File

@@ -417,6 +417,7 @@ static int wm_save_as_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *even
return OPERATOR_RUNNING_MODAL;
}
/* function used for WM_OT_save_mainfile too */
static int wm_save_as_mainfile_exec(bContext *C, wmOperator *op)
{
char filename[FILE_MAX];
@@ -431,7 +432,7 @@ static int wm_save_as_mainfile_exec(bContext *C, wmOperator *op)
static void WM_OT_save_as_mainfile(wmOperatorType *ot)
{
ot->name= "Open Blender File";
ot->name= "Save As Blender File";
ot->idname= "WM_OT_save_as_mainfile";
ot->invoke= wm_save_as_mainfile_invoke;
@@ -444,6 +445,33 @@ static void WM_OT_save_as_mainfile(wmOperatorType *ot)
}
/* *************** Save file directly ******** */
static int wm_save_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
RNA_string_set(op->ptr, "filename", G.sce);
uiPupMenuSaveOver(C, op, G.sce);
return OPERATOR_RUNNING_MODAL;
}
static void WM_OT_save_mainfile(wmOperatorType *ot)
{
ot->name= "Save Blender File";
ot->idname= "WM_OT_save_mainfile";
ot->invoke= wm_save_mainfile_invoke;
ot->exec= wm_save_as_mainfile_exec;
ot->poll= WM_operator_winactive;
ot->flag= 0;
RNA_def_property(ot->srna, "filename", PROP_STRING, PROP_FILEPATH);
}
/* *********************** */
static void WM_OT_window_fullscreen_toggle(wmOperatorType *ot)
@@ -1192,6 +1220,7 @@ void wm_operatortype_init(void)
WM_operatortype_append(WM_OT_open_mainfile);
WM_operatortype_append(WM_OT_jobs_timer);
WM_operatortype_append(WM_OT_save_as_mainfile);
WM_operatortype_append(WM_OT_save_mainfile);
}
/* default keymap for windows and screens, only call once per WM */
@@ -1208,6 +1237,7 @@ void wm_window_keymap(wmWindowManager *wm)
WM_keymap_verify_item(keymap, "WM_OT_save_homefile", UKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_verify_item(keymap, "WM_OT_open_recentfile", OKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_verify_item(keymap, "WM_OT_open_mainfile", F1KEY, KM_PRESS, 0, 0);
WM_keymap_verify_item(keymap, "WM_OT_save_mainfile", WKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_verify_item(keymap, "WM_OT_save_as_mainfile", F2KEY, KM_PRESS, 0, 0);
WM_keymap_verify_item(keymap, "WM_OT_window_fullscreen_toggle", F11KEY, KM_PRESS, 0, 0);
WM_keymap_verify_item(keymap, "WM_OT_exit_blender", QKEY, KM_PRESS, KM_CTRL, 0);