diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-05-08 03:34:03 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-05-08 03:34:03 +0400 |
commit | 14b41f907803a1383075f497dfc7ab9bcb843ad8 (patch) | |
tree | 8f199dbce7f7dd244fbed4d2a257ed2f5d6e295c /source/blender/editors/space_file/filesel.c | |
parent | b2b780f2fe9a97ce4ed97e9fc93ec05b6c4d906d (diff) |
bugfix [#22276] filemanager autocompleate based on current path
also added autocomp to filename in fileselector
Diffstat (limited to 'source/blender/editors/space_file/filesel.c')
-rw-r--r-- | source/blender/editors/space_file/filesel.c | 70 |
1 files changed, 58 insertions, 12 deletions
diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c index ea098ffcdb4..916f8dfcd62 100644 --- a/source/blender/editors/space_file/filesel.c +++ b/source/blender/editors/space_file/filesel.c @@ -42,6 +42,15 @@ #include <sys/times.h> #endif +/* path/file handeling stuff */ +#ifndef WIN32 + #include <dirent.h> + #include <unistd.h> +#else + #include <io.h> + #include "BLI_winstuff.h" +#endif + #include "DNA_space_types.h" #include "DNA_screen_types.h" #include "DNA_userdef_types.h" @@ -432,10 +441,55 @@ int file_select_match(struct SpaceFile *sfile, const char *pattern) return match; } - void autocomplete_directory(struct bContext *C, char *str, void *arg_v) { - char tmp[FILE_MAX]; + SpaceFile *sfile= CTX_wm_space_file(C); + + /* search if str matches the beginning of name */ + if(str[0] && sfile->files) { + char dirname[FILE_MAX]; + + DIR *dir; + struct dirent *de; + + BLI_split_dirfile(str, dirname, NULL); + + dir = opendir(dirname); + + if(dir) { + AutoComplete *autocpl= autocomplete_begin(str, FILE_MAX); + + while ((de = readdir(dir)) != NULL) { + if (strcmp(".", de->d_name)==0 || strcmp("..", de->d_name)==0) { + /* pass */ + } + else { + char path[FILE_MAX]; + struct stat status; + + BLI_join_dirfile(path, dirname, de->d_name); + + if (stat(path, &status) == 0) { + if (S_ISDIR(status.st_mode)) { /* is subdir */ + autocomplete_do_name(autocpl, path); + } + } + } + } + closedir(dir); + + autocomplete_end(autocpl, str); + if (BLI_exists(str)) { + BLI_add_slash(str); + } else { + BLI_make_exist(str); + } + } + } +} + +void autocomplete_file(struct bContext *C, char *str, void *arg_v) +{ SpaceFile *sfile= CTX_wm_space_file(C); /* search if str matches the beginning of name */ @@ -446,19 +500,11 @@ void autocomplete_directory(struct bContext *C, char *str, void *arg_v) for(i= 0; i<nentries; ++i) { struct direntry* file = filelist_file(sfile->files, i); - const char* dir = filelist_dir(sfile->files); - if (file && S_ISDIR(file->type)) { - // BLI_make_file_string(G.sce, tmp, dir, file->relname); - BLI_join_dirfile(tmp, dir, file->relname); - autocomplete_do_name(autocpl,tmp); + if (file && S_ISREG(file->type)) { + autocomplete_do_name(autocpl, file->relname); } } autocomplete_end(autocpl, str); - if (BLI_exists(str)) { - BLI_add_slash(str); - } else { - BLI_make_exist(str); - } } } |