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
This commit is contained in:
Henrik Aarnio 2013-11-19 16:31:48 +01:00 committed by Brecht Van Lommel
parent 0c0bed3b16
commit 035d86402b
5 changed files with 29 additions and 17 deletions

@ -1 +1 @@
Subproject commit 3adbc8f30b229e7c9ff465183d5ab0acbbdf921a
Subproject commit 2c7464fb9510bedc6a19c43064ae83ed15f3f7c7

View File

@ -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
*

View File

@ -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)

View File

@ -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)

View File

@ -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)