diff options
author | Matt Ebb <matt@mke3.net> | 2010-01-27 05:20:24 +0300 |
---|---|---|
committer | Matt Ebb <matt@mke3.net> | 2010-01-27 05:20:24 +0300 |
commit | 904665f15b9a0bc165c6ee60f05f00d66c2ffc07 (patch) | |
tree | 97861f19c9fc3b4d9d904daccfe80e9c87ad9d81 /source/blender/windowmanager | |
parent | 0bb36e9ced06b04b961300b21211f456c7035bcf (diff) |
[#20728] "Export UV Layout" overwrites existing files (without feedback)
The 'save over' popup was only appearing based on a string comparison of the operator name ("Save"). Changed this to use a hidden operator property: "check_existing". Python operators must
have this property for the file selector confirmation too.
This property can also be set to false, to prevent checking for existing files, useful in the File->Save menu item to prevent the dangerously missable confirmation popup.
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r-- | source/blender/windowmanager/WM_api.h | 2 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_event_system.c | 3 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_operators.c | 35 |
3 files changed, 28 insertions, 12 deletions
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index e4ae6ad4f5b..3e454cfa923 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -218,7 +218,7 @@ void WM_operator_properties_alloc(struct PointerRNA **ptr, struct IDProperty ** void WM_operator_properties_create(struct PointerRNA *ptr, const char *opstring); void WM_operator_properties_create_ptr(struct PointerRNA *ptr, struct wmOperatorType *ot); void WM_operator_properties_free(struct PointerRNA *ptr); -void WM_operator_properties_filesel(struct wmOperatorType *ot, int filter, short type); +void WM_operator_properties_filesel(struct wmOperatorType *ot, int filter, short type, short action); void WM_operator_properties_gesture_border(struct wmOperatorType *ot, int extend); void WM_operator_properties_select_all(struct wmOperatorType *ot); diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 8ba8ed1824d..309840cf935 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -1109,7 +1109,8 @@ static int wm_handler_fileselect_call(bContext *C, ListBase *handlers, wmEventHa if(event->val==EVT_FILESELECT_EXEC) { /* a bit weak, might become arg for WM_event_fileselect? */ /* XXX also extension code in image-save doesnt work for this yet */ - if(strncmp(handler->op->type->name, "Save", 4)==0) { + if (RNA_struct_find_property(handler->op->ptr, "check_existing") && + RNA_boolean_get(handler->op->ptr, "check_existing")) { /* this gives ownership to pupmenu */ uiPupMenuSaveOver(C, handler->op, (path)? path: ""); } diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 8f088efe8a8..a3d32cf41fe 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -756,7 +756,7 @@ int WM_operator_filesel(bContext *C, wmOperator *op, wmEvent *event) } /* default properties for fileselect */ -void WM_operator_properties_filesel(wmOperatorType *ot, int filter, short type) +void WM_operator_properties_filesel(wmOperatorType *ot, int filter, short type, short action) { PropertyRNA *prop; @@ -764,6 +764,11 @@ void WM_operator_properties_filesel(wmOperatorType *ot, int filter, short type) RNA_def_string_file_name(ot->srna, "filename", "", FILE_MAX, "File Name", "Name of the file."); RNA_def_string_dir_path(ot->srna, "directory", "", FILE_MAX, "Directory", "Directory of the file."); + if (action == FILE_SAVE) { + prop= RNA_def_boolean(ot->srna, "check_existing", 1, "Check Existing", "Check and warn on overwriting existing files"); + RNA_def_property_flag(prop, PROP_HIDDEN); + } + prop= RNA_def_boolean(ot->srna, "filter_blender", (filter & BLENDERFILE), "Filter .blend files", ""); RNA_def_property_flag(prop, PROP_HIDDEN); prop= RNA_def_boolean(ot->srna, "filter_image", (filter & IMAGEFILE), "Filter image files", ""); @@ -1319,7 +1324,7 @@ static void WM_OT_open_mainfile(wmOperatorType *ot) ot->exec= wm_open_mainfile_exec; ot->poll= WM_operator_winactive; - WM_operator_properties_filesel(ot, FOLDERFILE|BLENDERFILE, FILE_BLENDER); + WM_operator_properties_filesel(ot, FOLDERFILE|BLENDERFILE, FILE_BLENDER, FILE_OPEN); RNA_def_boolean(ot->srna, "load_ui", 1, "Load UI", "Load user interface setup in the .blend file."); } @@ -1477,7 +1482,7 @@ static void WM_OT_link_append(wmOperatorType *ot) ot->flag |= OPTYPE_UNDO; - WM_operator_properties_filesel(ot, FOLDERFILE|BLENDERFILE, FILE_LOADLIB); + WM_operator_properties_filesel(ot, FOLDERFILE|BLENDERFILE, FILE_LOADLIB, FILE_OPEN); RNA_def_boolean(ot->srna, "link", 1, "Link", "Link the objects or datablocks rather than appending."); RNA_def_boolean(ot->srna, "autoselect", 1, "Select", "Select the linked objects."); @@ -1562,7 +1567,7 @@ static void WM_OT_recover_auto_save(wmOperatorType *ot) ot->invoke= wm_recover_auto_save_invoke; ot->poll= WM_operator_winactive; - WM_operator_properties_filesel(ot, BLENDERFILE, FILE_BLENDER); + WM_operator_properties_filesel(ot, BLENDERFILE, FILE_BLENDER, FILE_OPEN); } /* *************** save file as **************** */ @@ -1644,7 +1649,7 @@ static void WM_OT_save_as_mainfile(wmOperatorType *ot) ot->exec= wm_save_as_mainfile_exec; ot->poll= WM_operator_winactive; - WM_operator_properties_filesel(ot, FOLDERFILE|BLENDERFILE, FILE_BLENDER); + WM_operator_properties_filesel(ot, FOLDERFILE|BLENDERFILE, FILE_BLENDER, FILE_SAVE); RNA_def_boolean(ot->srna, "compress", 0, "Compress", "Write compressed .blend file."); RNA_def_boolean(ot->srna, "relative_remap", 0, "Remap Relative", "Remap relative paths when saving in a different directory."); } @@ -1654,7 +1659,8 @@ static void WM_OT_save_as_mainfile(wmOperatorType *ot) static int wm_save_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event) { char name[FILE_MAX]; - + int check_existing=1; + /* cancel if no active window */ if (CTX_wm_window(C) == NULL) return OPERATOR_CANCELLED; @@ -1665,10 +1671,19 @@ static int wm_save_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event) untitled(name); RNA_string_set(op->ptr, "path", name); - if (G.save_over) - uiPupMenuSaveOver(C, op, name); - else + if (RNA_struct_find_property(op->ptr, "check_existing")) + if (RNA_boolean_get(op->ptr, "check_existing")==0) + check_existing = 0; + + if (G.save_over) { + if (check_existing) + uiPupMenuSaveOver(C, op, name); + else { + WM_operator_call(C, op); + } + } else { WM_event_add_fileselect(C, op); + } return OPERATOR_RUNNING_MODAL; } @@ -1683,7 +1698,7 @@ static void WM_OT_save_mainfile(wmOperatorType *ot) ot->exec= wm_save_as_mainfile_exec; ot->poll= NULL; - WM_operator_properties_filesel(ot, FOLDERFILE|BLENDERFILE, FILE_BLENDER); + WM_operator_properties_filesel(ot, FOLDERFILE|BLENDERFILE, FILE_BLENDER, FILE_SAVE); RNA_def_boolean(ot->srna, "compress", 0, "Compress", "Write compressed .blend file."); RNA_def_boolean(ot->srna, "relative_remap", 0, "Remap Relative", "Remap relative paths when saving in a different directory."); } |