[#20728] "Export UV Layout" overwrites existing files (without feedback)
authorMatt Ebb <matt@mke3.net>
Wed, 27 Jan 2010 02:20:24 +0000 (02:20 +0000)
committerMatt Ebb <matt@mke3.net>
Wed, 27 Jan 2010 02:20:24 +0000 (02:20 +0000)
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.

16 files changed:
release/scripts/op/uv.py
release/scripts/ui/space_info.py
source/blender/editors/curve/editfont.c
source/blender/editors/object/object_modifier.c
source/blender/editors/screen/screendump.c
source/blender/editors/sound/sound_ops.c
source/blender/editors/space_buttons/buttons_ops.c
source/blender/editors/space_graph/graph_edit.c
source/blender/editors/space_image/image_ops.c
source/blender/editors/space_info/info_ops.c
source/blender/editors/space_sequencer/sequencer_add.c
source/blender/editors/space_text/text_ops.c
source/blender/makesdna/DNA_space_types.h
source/blender/windowmanager/WM_api.h
source/blender/windowmanager/intern/wm_event_system.c
source/blender/windowmanager/intern/wm_operators.c

index 619c1e6f5028683e9e4cfb1212fa83d43ac0100e..76675cb96a914628e573f92a7ebcd2e774c4c098 100644 (file)
@@ -30,6 +30,7 @@ class ExportUVLayout(bpy.types.Operator):
     bl_undo = True
     
     path = StringProperty(name="File Path", description="File path used for exporting the SVG file", maxlen=1024, default="")
+    check_existing = BoolProperty(name="Check Existing", description="Check and warn on overwriting existing files", default=True, hidden=True)
     only_selected = BoolProperty(name="Only Selected", description="Export Only the selected UVs", default=False)
     
     def poll(self, context):
index fb9f0f278b376f26dd98eb96ae8956b0510e1c08..d027700ccd4ca42d112a754a8279bb8aa264d159 100644 (file)
@@ -83,7 +83,7 @@ class INFO_MT_file(bpy.types.Menu):
         layout.separator()
 
         layout.operator_context = 'INVOKE_AREA'
-        layout.operator("wm.save_mainfile", text="Save", icon='FILE_TICK')
+        layout.operator("wm.save_mainfile", text="Save", icon='FILE_TICK').check_existing = False
         layout.operator_context = 'INVOKE_AREA'
         layout.operator("wm.save_as_mainfile", text="Save As...")
 
index 101f0e2074cf29e52d1e389bedaa7e60ce4f0bd9..2ebee2ad2744dbccef7f5e62055d5116422d661c 100644 (file)
@@ -420,7 +420,7 @@ void FONT_OT_file_paste(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
        /* properties */
-       WM_operator_properties_filesel(ot, FOLDERFILE|TEXTFILE, FILE_SPECIAL);
+       WM_operator_properties_filesel(ot, FOLDERFILE|TEXTFILE, FILE_SPECIAL, FILE_OPEN);
 }
 
 /******************* paste buffer operator ********************/
@@ -1642,7 +1642,7 @@ void FONT_OT_open(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* properties */
-       WM_operator_properties_filesel(ot, FOLDERFILE|FTFONTFILE, FILE_SPECIAL);
+       WM_operator_properties_filesel(ot, FOLDERFILE|FTFONTFILE, FILE_SPECIAL, FILE_OPEN);
 }
 
 /******************* delete operator *********************/
index 155e0043132d6ca36984707fe91830dafe6eadf8..30ccca6fc25f6e767f368e9e7fdc1819b17cc019 100644 (file)
@@ -914,7 +914,7 @@ void OBJECT_OT_multires_save_external(wmOperatorType *ot)
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
-       WM_operator_properties_filesel(ot, FOLDERFILE|BTXFILE, FILE_SPECIAL);
+       WM_operator_properties_filesel(ot, FOLDERFILE|BTXFILE, FILE_SPECIAL, FILE_SAVE);
 }
 
 /****************** multires pack operator *********************/
index 6f2052958ce443af7d2530c48f94b6fab3776ef4..aea23d3e404fdaf1e11e77cb901ede8fb2a07b8f 100644 (file)
@@ -175,7 +175,7 @@ void SCREEN_OT_screenshot(wmOperatorType *ot)
        
        ot->flag= 0;
        
-       WM_operator_properties_filesel(ot, FOLDERFILE|IMAGEFILE, FILE_SPECIAL);
+       WM_operator_properties_filesel(ot, FOLDERFILE|IMAGEFILE, FILE_SPECIAL, FILE_SAVE);
        RNA_def_boolean(ot->srna, "full", 1, "Full Screen", "");
 }
 
index d48a322f56291c6b5d40a606d04dc03ccf8c461f..d5de3f8101b97f79385bbd0734995c2f6f2d1283 100644 (file)
@@ -114,7 +114,7 @@ void SOUND_OT_open(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
        /* properties */
-       WM_operator_properties_filesel(ot, FOLDERFILE|SOUNDFILE|MOVIEFILE, FILE_SPECIAL);
+       WM_operator_properties_filesel(ot, FOLDERFILE|SOUNDFILE|MOVIEFILE, FILE_SPECIAL, FILE_OPEN);
        RNA_def_boolean(ot->srna, "cache", FALSE, "Cache", "Cache the sound in memory.");
 }
 
index 634b3e36ea7f2b200c5ed79580edcf1837116942..406ecd77136a61632c5e2ac240c054cf96043a45 100644 (file)
@@ -148,6 +148,6 @@ void BUTTONS_OT_file_browse(wmOperatorType *ot)
        ot->cancel= file_browse_cancel;
 
        /* properties */
-       WM_operator_properties_filesel(ot, 0, FILE_SPECIAL);
+       WM_operator_properties_filesel(ot, 0, FILE_SPECIAL, FILE_OPEN);
 }
 
index 00951db61d3ef21d7be1a63f6d9144ae5b1d9037..3c7ce2778b619f494db7ac2b1aa1e462567788b0 100644 (file)
@@ -1138,7 +1138,7 @@ void GRAPH_OT_sound_bake (wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
        /* properties */
-       WM_operator_properties_filesel(ot, FOLDERFILE|SOUNDFILE|MOVIEFILE, FILE_SPECIAL);
+       WM_operator_properties_filesel(ot, FOLDERFILE|SOUNDFILE|MOVIEFILE, FILE_SPECIAL, FILE_OPEN);
        RNA_def_float(ot->srna, "low", 0.0f, 0.0, 100000.0, "Lowest frequency", "", 0.1, 1000.00);
        RNA_def_float(ot->srna, "high", 100000.0, 0.0, 100000.0, "Highest frequency", "", 0.1, 1000.00);
        RNA_def_float(ot->srna, "attack", 0.005, 0.0, 2.0, "Attack time", "", 0.01, 0.1);
index b730f075f8f5dc9581687f0eb43a6c23944822d0..7dd26c3165821db09fe8bb0eee3c6af1a044320e 100644 (file)
@@ -741,7 +741,7 @@ void IMAGE_OT_open(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
        /* properties */
-       WM_operator_properties_filesel(ot, FOLDERFILE|IMAGEFILE|MOVIEFILE, FILE_SPECIAL);
+       WM_operator_properties_filesel(ot, FOLDERFILE|IMAGEFILE|MOVIEFILE, FILE_SPECIAL, FILE_OPEN);
 }
 
 /******************** replace image operator ********************/
@@ -794,7 +794,7 @@ void IMAGE_OT_replace(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
        /* properties */
-       WM_operator_properties_filesel(ot, FOLDERFILE|IMAGEFILE|MOVIEFILE, FILE_SPECIAL);
+       WM_operator_properties_filesel(ot, FOLDERFILE|IMAGEFILE|MOVIEFILE, FILE_SPECIAL, FILE_OPEN);
 }
 
 /******************** save image as operator ********************/
@@ -962,7 +962,7 @@ void IMAGE_OT_save_as(wmOperatorType *ot)
 
        /* properties */
        RNA_def_enum(ot->srna, "file_type", image_file_type_items, R_PNG, "File Type", "File type to save image as.");
-       WM_operator_properties_filesel(ot, FOLDERFILE|IMAGEFILE|MOVIEFILE, FILE_SPECIAL);
+       WM_operator_properties_filesel(ot, FOLDERFILE|IMAGEFILE|MOVIEFILE, FILE_SPECIAL, FILE_SAVE);
 }
 
 /******************** save image operator ********************/
index 81506d42d874be3273a138ab64b3d0bb3abafb86..5d8ff3849e6c156d85d851e10cea396c0f85b153 100644 (file)
@@ -306,5 +306,5 @@ void FILE_OT_find_missing_files(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
        /* properties */
-       WM_operator_properties_filesel(ot, 0, FILE_SPECIAL);
+       WM_operator_properties_filesel(ot, 0, FILE_SPECIAL, FILE_OPEN);
 }
index 29995c89662eb6a054439c32e1bb218017d3146b..6938b238e7980394ac92647358dab120c10198d7 100644 (file)
@@ -336,7 +336,7 @@ void SEQUENCER_OT_movie_strip_add(struct wmOperatorType *ot)
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
-       WM_operator_properties_filesel(ot, FOLDERFILE|MOVIEFILE, FILE_SPECIAL);
+       WM_operator_properties_filesel(ot, FOLDERFILE|MOVIEFILE, FILE_SPECIAL, FILE_OPEN);
        sequencer_generic_props__internal(ot, SEQPROP_STARTFRAME|SEQPROP_FILES);
        RNA_def_boolean(ot->srna, "sound", TRUE, "Sound", "Load sound with the movie");
 }
@@ -373,7 +373,7 @@ void SEQUENCER_OT_sound_strip_add(struct wmOperatorType *ot)
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
-       WM_operator_properties_filesel(ot, FOLDERFILE|SOUNDFILE, FILE_SPECIAL);
+       WM_operator_properties_filesel(ot, FOLDERFILE|SOUNDFILE, FILE_SPECIAL, FILE_OPEN);
        sequencer_generic_props__internal(ot, SEQPROP_STARTFRAME|SEQPROP_FILES);
        RNA_def_boolean(ot->srna, "cache", FALSE, "Cache", "Cache the sound in memory.");
 }
@@ -456,7 +456,7 @@ void SEQUENCER_OT_image_strip_add(struct wmOperatorType *ot)
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
-       WM_operator_properties_filesel(ot, FOLDERFILE|IMAGEFILE, FILE_SPECIAL);
+       WM_operator_properties_filesel(ot, FOLDERFILE|IMAGEFILE, FILE_SPECIAL, FILE_OPEN);
        sequencer_generic_props__internal(ot, SEQPROP_STARTFRAME|SEQPROP_ENDFRAME|SEQPROP_FILES);
 }
 
@@ -599,7 +599,7 @@ void SEQUENCER_OT_effect_strip_add(struct wmOperatorType *ot)
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
-       WM_operator_properties_filesel(ot, 0, FILE_SPECIAL);
+       WM_operator_properties_filesel(ot, 0, FILE_SPECIAL, FILE_OPEN);
        sequencer_generic_props__internal(ot, SEQPROP_STARTFRAME|SEQPROP_ENDFRAME);
        RNA_def_enum(ot->srna, "type", sequencer_prop_effect_types, SEQ_CROSS, "Type", "Sequencer effect type");
        RNA_def_float_vector(ot->srna, "color", 3, NULL, 0.0f, 1.0f, "Color", "Initialize the strip with this color (only used when type='COLOR')", 0.0f, 1.0f);
index e385b2f5f2a34f8bb85e948244932c117a0c0853..bc103466c495f75059028577e10ed4be7152d707 100644 (file)
@@ -287,7 +287,7 @@ void TEXT_OT_open(wmOperatorType *ot)
        ot->poll= text_new_poll;
 
        /* properties */
-       WM_operator_properties_filesel(ot, FOLDERFILE|TEXTFILE|PYSCRIPTFILE, FILE_SPECIAL);
+       WM_operator_properties_filesel(ot, FOLDERFILE|TEXTFILE|PYSCRIPTFILE, FILE_SPECIAL, FILE_OPEN);
 }
 
 /******************* reload operator *********************/
@@ -527,7 +527,7 @@ void TEXT_OT_save_as(wmOperatorType *ot)
        ot->poll= text_edit_poll;
 
        /* properties */
-       WM_operator_properties_filesel(ot, FOLDERFILE|TEXTFILE|PYSCRIPTFILE, FILE_SPECIAL);
+       WM_operator_properties_filesel(ot, FOLDERFILE|TEXTFILE|PYSCRIPTFILE, FILE_SPECIAL, FILE_SAVE);
 }
 
 /******************* run script operator *********************/
index 4a7866d7058da0f8337ed46dee5850ad077abdad..01b03477dbf24584fd0d69a2fb041ad5a6330c14 100644 (file)
@@ -649,6 +649,9 @@ enum FileSortTypeE {
 #define FILE_LOADLIB           1
 #define FILE_MAIN                      2
 #define FILE_LOADFONT          3
+/* filesel op property -> action */
+#define FILE_OPEN                      0
+#define FILE_SAVE                      1
 
 /* sfile->flag and simasel->flag */
 #define FILE_SHOWSHORT         1
index e4ae6ad4f5ba1ae19f79b9315ed833a9aed9d296..3e454cfa92399b537e47a47c8100651b89688c3d 100644 (file)
@@ -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);
 
index 8ba8ed1824dd72de1721cd0a794461ec1ca99075..309840cf935ccd0e613dc825ffbc72771ae701eb 100644 (file)
@@ -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: "");
                                        }
index 8f088efe8a8cb6fb85d4df17978da44b41c9c941..a3d32cf41fed492d1e43032c24d9670d0be6ec24 100644 (file)
@@ -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.");
 }