diff options
author | Henrik Aarnio <hjaarnio@gmail.com> | 2013-11-19 19:31:48 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2013-11-19 19:42:50 +0400 |
commit | 035d86402bbb8dab2bfb086a3027e5ec93e52748 (patch) | |
tree | b41a8522214d72b40d1ff7e69d215a11880907d2 /source | |
parent | 0c0bed3b161ae005821cc68e56ea78223d5fe16c (diff) |
Fix: tab completing a filepath name in file browsers asks to create a new
directory if name was not fully matched
When hitting tab to complete a directory name in the filepath field in the
filebrowser Blender shows a "create new directory?" popup, if the beginning
of directory name typed in the field matches many entries. For example if you
have directories in the open directory called "test123" and "test456", typing
"te", tab would complete up to "test", but ask to create a new folder with the
name "test".
This patch unsets the boolean storing the info about changing filepath if the
folder with the completed name does not exist.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D10
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/include/UI_interface.h | 6 | ||||
-rw-r--r-- | source/blender/editors/interface/interface.c | 16 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_regions.c | 6 | ||||
-rw-r--r-- | source/blender/editors/space_file/filesel.c | 16 |
4 files changed, 28 insertions, 16 deletions
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 38aad640ee1..50e2e53dbf0 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -641,9 +641,13 @@ void uiButSetFocusOnEnter(struct wmWindow *win, uiBut *but); typedef struct AutoComplete AutoComplete; +#define AUTOCOMPLETE_NO_MATCH 0 +#define AUTOCOMPLETE_FULL_MATCH 1 +#define AUTOCOMPLETE_PARTIAL_MATCH 2 + AutoComplete *autocomplete_begin(const char *startname, size_t maxlen); void autocomplete_do_name(AutoComplete *autocpl, const char *name); -bool autocomplete_end(AutoComplete *autocpl, char *autoname); +int autocomplete_end(AutoComplete *autocpl, char *autoname); /* Panels * diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 96638f77b10..6ee097b066f 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -3188,6 +3188,7 @@ static int findBitIndex(unsigned int x) /* autocomplete helper functions */ struct AutoComplete { size_t maxlen; + int matches; char *truncate; const char *startname; }; @@ -3198,6 +3199,7 @@ AutoComplete *autocomplete_begin(const char *startname, size_t maxlen) autocpl = MEM_callocN(sizeof(AutoComplete), "AutoComplete"); autocpl->maxlen = maxlen; + autocpl->matches = 0; autocpl->truncate = MEM_callocN(sizeof(char) * maxlen, "AutoCompleteTruncate"); autocpl->startname = startname; @@ -3216,6 +3218,7 @@ void autocomplete_do_name(AutoComplete *autocpl, const char *name) } /* found a match */ if (startname[a] == 0) { + autocpl->matches++; /* first match */ if (truncate[0] == 0) BLI_strncpy(truncate, name, autocpl->maxlen); @@ -3233,21 +3236,26 @@ void autocomplete_do_name(AutoComplete *autocpl, const char *name) } } -bool autocomplete_end(AutoComplete *autocpl, char *autoname) +int autocomplete_end(AutoComplete *autocpl, char *autoname) { - bool change = false; + int match = AUTOCOMPLETE_NO_MATCH; if (autocpl->truncate[0]) { + if (autocpl->matches == 1) { + match = AUTOCOMPLETE_FULL_MATCH; + } else { + match = AUTOCOMPLETE_PARTIAL_MATCH; + } BLI_strncpy(autoname, autocpl->truncate, autocpl->maxlen); - change = true; } else { if (autoname != autocpl->startname) { /* don't copy a string over its self */ BLI_strncpy(autoname, autocpl->startname, autocpl->maxlen); } } + MEM_freeN(autocpl->truncate); MEM_freeN(autocpl); - return change; + return match; } static void ui_check_but_and_iconize(uiBut *but, int icon) diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index 3ef613f5867..1de0a278b56 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -1054,17 +1054,17 @@ void ui_searchbox_update(bContext *C, ARegion *ar, uiBut *but, const bool reset) bool ui_searchbox_autocomplete(bContext *C, ARegion *ar, uiBut *but, char *str) { uiSearchboxData *data = ar->regiondata; - bool changed = false; + int match = AUTOCOMPLETE_NO_MATCH; if (str[0]) { data->items.autocpl = autocomplete_begin(str, ui_get_but_string_max_length(but)); but->search_func(C, but->search_arg, but->editstr, &data->items); - changed = autocomplete_end(data->items.autocpl, str); + match = autocomplete_end(data->items.autocpl, str); data->items.autocpl = NULL; } - return changed; + return match != AUTOCOMPLETE_NO_MATCH; } static void ui_searchbox_region_draw_cb(const bContext *UNUSED(C), ARegion *ar) diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c index 9d762c80405..c6e1541352d 100644 --- a/source/blender/editors/space_file/filesel.c +++ b/source/blender/editors/space_file/filesel.c @@ -637,7 +637,7 @@ int file_select_match(struct SpaceFile *sfile, const char *pattern, char *matche bool autocomplete_directory(struct bContext *C, char *str, void *UNUSED(arg_v)) { SpaceFile *sfile = CTX_wm_space_file(C); - bool change = false; + int match = AUTOCOMPLETE_NO_MATCH; /* search if str matches the beginning of name */ if (str[0] && sfile->files) { @@ -672,9 +672,9 @@ bool autocomplete_directory(struct bContext *C, char *str, void *UNUSED(arg_v)) } closedir(dir); - change = autocomplete_end(autocpl, str); - if (change) { - if (BLI_exists(str)) { + match = autocomplete_end(autocpl, str); + if (match) { + if (match == AUTOCOMPLETE_FULL_MATCH) { BLI_add_slash(str); } else { @@ -684,13 +684,13 @@ bool autocomplete_directory(struct bContext *C, char *str, void *UNUSED(arg_v)) } } - return change; + return match == AUTOCOMPLETE_FULL_MATCH; } bool autocomplete_file(struct bContext *C, char *str, void *UNUSED(arg_v)) { SpaceFile *sfile = CTX_wm_space_file(C); - bool change = false; + int match = AUTOCOMPLETE_NO_MATCH; /* search if str matches the beginning of name */ if (str[0] && sfile->files) { @@ -704,9 +704,9 @@ bool autocomplete_file(struct bContext *C, char *str, void *UNUSED(arg_v)) autocomplete_do_name(autocpl, file->relname); } } - change = autocomplete_end(autocpl, str); + match = autocomplete_end(autocpl, str); } - return change; + return match != AUTOCOMPLETE_NO_MATCH; } void ED_fileselect_clear(struct wmWindowManager *wm, struct SpaceFile *sfile) |