diff --git a/source/blender/blenlib/intern/bpath.c b/source/blender/blenlib/intern/bpath.c index 2367af470fe..afe73a53e5b 100644 --- a/source/blender/blenlib/intern/bpath.c +++ b/source/blender/blenlib/intern/bpath.c @@ -622,7 +622,7 @@ static int findFileRecursive(char *filename_new, const char *dirname, const char while ((de = readdir(dir)) != NULL) { - if (strncmp(".", de->d_name, 2)==0 || strncmp("..", de->d_name, 3)==0) + if (strcmp(".", de->d_name)==0 || strcmp("..", de->d_name)==0) continue; BLI_join_dirfile(path, dirname, de->d_name); diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c index 0773ad96a7c..ac09ce6861a 100644 --- a/source/blender/editors/space_file/file_draw.c +++ b/source/blender/editors/space_file/file_draw.c @@ -180,10 +180,11 @@ void file_draw_buttons(const bContext *C, ARegion *ar) params->dir, 0.0, (float)FILE_MAX-1, 0, 0, "File path."); uiButSetCompleteFunc(but, autocomplete_directory, NULL); - uiDefBut(block, TEX, B_FS_FILENAME, "", + but = uiDefBut(block, TEX, B_FS_FILENAME, "", min_x, line2_y, line2_w-chan_offs, btn_h, params->file, 0.0, (float)FILE_MAXFILE-1, 0, 0, "File name."); + uiButSetCompleteFunc(but, autocomplete_file, NULL); } /* Filename number increment / decrement buttons. */ diff --git a/source/blender/editors/space_file/file_intern.h b/source/blender/editors/space_file/file_intern.h index a7aeaa1d365..ef05e6cac76 100644 --- a/source/blender/editors/space_file/file_intern.h +++ b/source/blender/editors/space_file/file_intern.h @@ -90,6 +90,7 @@ float file_font_pointsize(); void file_change_dir(bContext *C, int checkdir); int file_select_match(struct SpaceFile *sfile, const char *pattern); void autocomplete_directory(struct bContext *C, char *str, void *arg_v); +void autocomplete_file(struct bContext *C, char *str, void *arg_v); /* file_panels.c */ void file_panels_register(struct ARegionType *art); diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 85b3cee354b..ed098d2d44e 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -816,26 +816,15 @@ void FILE_OT_directory_new(struct wmOperatorType *ot) int file_directory_exec(bContext *C, wmOperator *unused) { - char tmpstr[FILE_MAX]; - SpaceFile *sfile= CTX_wm_space_file(C); if(sfile->params) { if ( sfile->params->dir[0] == '~' ) { - if (sfile->params->dir[1] == '\0') { - BLI_strncpy(sfile->params->dir, BLI_gethome(), sizeof(sfile->params->dir) ); - } else { - /* replace ~ with home */ - char homestr[FILE_MAX]; - char *d = &sfile->params->dir[1]; - - while ( (*d == '\\') || (*d == '/') ) - d++; - BLI_strncpy(homestr, BLI_gethome(), FILE_MAX); - BLI_join_dirfile(tmpstr, homestr, d); - BLI_strncpy(sfile->params->dir, tmpstr, sizeof(sfile->params->dir)); - } + char tmpstr[sizeof(sfile->params->dir)-1]; + strncpy(tmpstr, sfile->params->dir+1, sizeof(tmpstr)); + BLI_join_dirfile(sfile->params->dir, BLI_gethome(), tmpstr); } + #ifdef WIN32 if (sfile->params->dir[0] == '\0') get_default_root(sfile->params->dir); 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 #endif +/* path/file handeling stuff */ +#ifndef WIN32 + #include + #include +#else + #include + #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; ifiles, 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); - } } }