2.5 file browser
authorAndrea Weikert <elubie@gmx.net>
Tue, 28 Jul 2009 18:07:00 +0000 (18:07 +0000)
committerAndrea Weikert <elubie@gmx.net>
Tue, 28 Jul 2009 18:07:00 +0000 (18:07 +0000)
Bugfix: revert to previous behaviour of BLI_rename, is used for safe blendfile saving.
Added guard in file browser though to prevent user from invoking this.

source/blender/blenlib/intern/fileops.c
source/blender/editors/space_file/file_draw.c

index b9c0dd65edea3a958bfa9d6d7c1e0adc4b19c4b5..0228032df01544d42d0572eceaaa67ca3ab1eeeb 100644 (file)
@@ -311,9 +311,9 @@ void BLI_recurdir_fileops(char *dirname) {
 int BLI_rename(char *from, char *to) {
        if (!BLI_exists(from)) return 0;
 
-       /* refuse to rename if file already exists */
-       if (BLI_exists(to))
-               return 1; 
+       /* make sure the filenames are different (case insensitive) before removing */
+       if (BLI_exists(to) && BLI_strcasecmp(from, to))
+               if(BLI_delete(to, 0, 0)) return 1;
 
        return rename(from, to);
 }
@@ -391,8 +391,7 @@ void BLI_recurdir_fileops(char *dirname) {
 int BLI_rename(char *from, char *to) {
        if (!BLI_exists(from)) return 0;
        
-       /* refuse to rename if file already exists */
-       if (BLI_exists(to)) return 1;
+       if (BLI_exists(to))     if(BLI_delete(to, 0, 0)) return 1;
 
        return rename(from, to);
 }
index 1074a24f9aed15278186662194ff3a222ac7b5b8..e807bad28bf32dd573b05c2493ac44e1e3ea4866 100644 (file)
@@ -501,6 +501,8 @@ static void renamebutton_cb(bContext *C, void *arg1, char *oldname)
        char orgname[FILE_MAX+12];
        char filename[FILE_MAX+12];
        SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
+       ARegion* ar = CTX_wm_region(C);
+
        struct direntry *file = (struct direntry *)arg1;
 
        BLI_make_file_string(G.sce, orgname, sfile->params->dir, oldname);
@@ -508,10 +510,15 @@ static void renamebutton_cb(bContext *C, void *arg1, char *oldname)
        BLI_make_file_string(G.sce, newname, sfile->params->dir, filename);
 
        if( strcmp(orgname, newname) != 0 ) {
-               BLI_rename(orgname, newname);
-
-               /* to refresh the file list, does sorting again */
-               filelist_free(sfile->files);
+               if (!BLI_exists(newname)) {
+                       BLI_rename(orgname, newname);
+                       /* to make sure we show what is on disk */
+                       filelist_free(sfile->files);
+               } else {
+                       BLI_strncpy(file->relname, oldname, strlen(oldname)+1);
+               }
+               
+               ED_region_tag_redraw(ar);
        }
 }