diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenlib/BLI_util.h | 3 | ||||
-rw-r--r-- | source/blender/blenlib/intern/util.c | 16 | ||||
-rw-r--r-- | source/blender/editors/space_file/file_draw.c | 3 | ||||
-rw-r--r-- | source/blender/editors/space_file/file_intern.h | 1 | ||||
-rw-r--r-- | source/blender/editors/space_file/file_ops.c | 19 | ||||
-rw-r--r-- | source/blender/editors/space_file/filesel.c | 26 |
6 files changed, 58 insertions, 10 deletions
diff --git a/source/blender/blenlib/BLI_util.h b/source/blender/blenlib/BLI_util.h index a138ea780ea..d323f701ba5 100644 --- a/source/blender/blenlib/BLI_util.h +++ b/source/blender/blenlib/BLI_util.h @@ -72,6 +72,9 @@ void BLI_cleanup_dir(const char *relabase, char *dir); /* same as above but adds /* go back one directory */ int BLI_parent_dir(char *path); +/* return whether directory is root and thus has no parent dir */ +int BLI_has_parent(char *path); + /** * Blender's path code replacement function. * Bases @a path strings leading with "//" by the diff --git a/source/blender/blenlib/intern/util.c b/source/blender/blenlib/intern/util.c index 838648ebfd7..a236defc515 100644 --- a/source/blender/blenlib/intern/util.c +++ b/source/blender/blenlib/intern/util.c @@ -494,6 +494,22 @@ void BLI_makestringcode(const char *relfile, char *file) } } +int BLI_has_parent(char *path) +{ + int len; + int slashes = 0; + BLI_clean(path); + BLI_add_slash(path); + + len = strlen(path)-1; + while (len) { + if ((path[len] == '\\') || (path[len] == '/')) + slashes++; + len--; + } + return slashes > 1; +} + int BLI_parent_dir(char *path) { #ifdef WIN32 diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c index f8705fe63a4..f1f20a36b59 100644 --- a/source/blender/editors/space_file/file_draw.c +++ b/source/blender/editors/space_file/file_draw.c @@ -186,10 +186,11 @@ void file_draw_buttons(const bContext *C, ARegion *ar) /* Text input fields for directory and file. */ if (available_w > 0) { - uiDefBut(block, TEX, B_FS_DIRNAME, "", + but = uiDefBut(block, TEX, B_FS_DIRNAME, "", min_x, line1_y, line1_w, btn_h, params->dir, 0.0, (float)FILE_MAXFILE-1, 0, 0, "File path."); + uiButSetCompleteFunc(but, autocomplete_directory, NULL); uiDefBut(block, TEX, B_FS_FILENAME, "", min_x, line2_y, line2_w, btn_h, params->file, 0.0, (float)FILE_MAXFILE-1, 0, 0, diff --git a/source/blender/editors/space_file/file_intern.h b/source/blender/editors/space_file/file_intern.h index 732313c5a3a..dce56e05d6b 100644 --- a/source/blender/editors/space_file/file_intern.h +++ b/source/blender/editors/space_file/file_intern.h @@ -89,6 +89,7 @@ float file_string_width(const char* str); float file_font_pointsize(); void file_change_dir(struct SpaceFile *sfile); int file_select_match(struct SpaceFile *sfile, const char *pattern); +void autocomplete_directory(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 ef15586bba9..585e042ae8a 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -142,10 +142,10 @@ static void file_select(SpaceFile* sfile, ARegion* ar, const rcti* rect, short v { // XXX error("Path too long, cannot enter this directory"); } else { + BLI_cleanup_dir(G.sce, params->dir); strcat(params->dir, file->relname); - strcat(params->dir,"/"); + BLI_add_slash(params->dir); params->file[0] = '\0'; - BLI_cleanup_dir(G.sce, params->dir); file_change_dir(sfile); } } @@ -557,11 +557,13 @@ int file_parent_exec(bContext *C, wmOperator *unused) SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C); if(sfile->params) { - BLI_parent_dir(sfile->params->dir); - file_change_dir(sfile); + if (BLI_has_parent(sfile->params->dir)) { + BLI_parent_dir(sfile->params->dir); + file_change_dir(sfile); + WM_event_add_notifier(C, NC_FILE|ND_FILELIST, NULL); + } } - WM_event_add_notifier(C, NC_FILE|ND_FILELIST, NULL); - + return OPERATOR_FINISHED; } @@ -718,10 +720,11 @@ int file_directory_exec(bContext *C, wmOperator *unused) BLI_strncpy(sfile->params->dir, tmpstr, sizeof(sfile->params->dir)); } } - + BLI_add_slash(sfile->params->dir); file_change_dir(sfile); + WM_event_add_notifier(C, NC_FILE|ND_FILELIST, NULL); } - WM_event_add_notifier(C, NC_FILE|ND_FILELIST, NULL); + return OPERATOR_FINISHED; } diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c index be5feb45b4e..6c8e84f0db8 100644 --- a/source/blender/editors/space_file/filesel.c +++ b/source/blender/editors/space_file/filesel.c @@ -298,7 +298,7 @@ FileLayout* ED_fileselect_get_layout(struct SpaceFile *sfile, struct ARegion *ar void file_change_dir(struct SpaceFile *sfile) { - if (sfile->params) { + if (sfile->params && BLI_exists(sfile->params->dir)) { filelist_setdir(sfile->files, sfile->params->dir); if(folderlist_clear_next(sfile)) @@ -329,3 +329,27 @@ 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= (SpaceFile*)CTX_wm_space_data(C); + + /* search if str matches the beginning of name */ + if(str[0] && sfile->files) { + AutoComplete *autocpl= autocomplete_begin(str, FILE_MAX); + int nentries = filelist_numfiles(sfile->files); + int i; + + for(i= 0; i<nentries; ++i) { + struct direntry* file = filelist_file(sfile->files, i); + char* dir = filelist_dir(sfile->files); + if (file && S_ISDIR(file->type)) { + BLI_make_file_string(G.sce, tmp, dir, file->relname); + autocomplete_do_name(autocpl,tmp); + } + } + autocomplete_end(autocpl, str); + } +}
\ No newline at end of file |