File Browser: Keep file name after changing directory
authorJulian Eisel <eiseljulian@gmail.com>
Sat, 11 Jul 2015 03:20:35 +0000 (05:20 +0200)
committerJulian Eisel <eiseljulian@gmail.com>
Sat, 11 Jul 2015 03:48:02 +0000 (05:48 +0200)
Actually this was an intentional change in rBaeeb23efa28dc to prevent Blender from trying to open the old file from the new directory. Issue is that this is really bad for saving and basically breaks "Save As".

Some more tweaks were needed to make it work like before, so now it keeps the name of the last selected file, but clears it when selecting a folder.

source/blender/editors/space_file/file_ops.c
source/blender/editors/space_file/filesel.c

index 1b19a8d4d62e4842121bef94ccc5d2005d41d20b..c54731cc66ce3a5c0ed8f59e69adf489fc8e0024 100644 (file)
@@ -1265,16 +1265,21 @@ int file_exec(bContext *C, wmOperator *exec_op)
        const struct direntry *file = filelist_file(sfile->files, sfile->params->active_file);
        char filepath[FILE_MAX];
 
-       BLI_assert(!file || STREQ(file->relname, "..") || STREQ(file->relname, sfile->params->file));
+       /* if file is a directory it should be in sync with params->dir, otherwise
+        * with params->file; file->path might be NULL on link/append */
+       BLI_assert((file == NULL) ||
+                  (file->path == NULL) ||
+                  (STREQ(file->relname, sfile->params->file)) ||
+                  (BLI_is_dir(file->path) && STRPREFIX(file->path, sfile->params->dir)));
 
        /* directory change */
        if (file && S_ISDIR(file->type)) {
                if (FILENAME_IS_PARENT(file->relname)) {
                        BLI_parent_dir(sfile->params->dir);
                }
-               else if (sfile->params->file[0]) {
+               else if (file->relname) {
                        BLI_cleanup_dir(G.main->name, sfile->params->dir);
-                       strcat(sfile->params->dir, sfile->params->file);
+                       strcat(sfile->params->dir, file->relname);
                        BLI_add_slash(sfile->params->dir);
                }
 
index ef29b720eed9d7d738271c77112d31303e8746a2..21db41b27a54b2880b85422d47658248f6e6b95f 100644 (file)
@@ -293,7 +293,7 @@ void ED_fileselect_reset_params(SpaceFile *sfile)
 void fileselect_file_set(SpaceFile *sfile, const int index)
 {
        const struct direntry *file = filelist_file(sfile->files, index);
-       if (file && file->relname[0] && !FILENAME_IS_PARENT(file->relname)) {
+       if (file && file->relname[0] && file->path && !BLI_is_dir(file->path)) {
                BLI_strncpy(sfile->params->file, file->relname, FILE_MAXFILE);
        }
 }
@@ -588,16 +588,14 @@ void ED_file_change_dir(bContext *C, const bool checkdir)
                /* Clear search string, it is very rare to want to keep that filter while changing dir,
                 * and usually very annoying to keep it actually! */
                sfile->params->filter_search[0] = '\0';
+               sfile->params->active_file = -1;
 
                if (checkdir && !BLI_is_dir(sfile->params->dir)) {
                        BLI_strncpy(sfile->params->dir, filelist_dir(sfile->files), sizeof(sfile->params->dir));
                        /* could return but just refresh the current dir */
                }
                filelist_setdir(sfile->files, sfile->params->dir);
-               /* clear selected file to avoid trying to open it from the new dir with changed path */
-               sfile->params->file[0] = '\0';
-               sfile->params->active_file = -1;
-               
+
                if (folderlist_clear_next(sfile))
                        folderlist_free(sfile->folders_next);