fix for filesel autocomplete, it had the annoying behavior if you entered in a non-existing name, of executing it and then asking to add the dir.

This commit is contained in:
2013-06-19 11:53:48 +00:00
parent 15016873ab
commit 9d4cc7885d
7 changed files with 37 additions and 24 deletions

View File

@@ -304,7 +304,7 @@ typedef struct uiSearchItems uiSearchItems;
typedef void (*uiButHandleFunc)(struct bContext *C, void *arg1, void *arg2); typedef void (*uiButHandleFunc)(struct bContext *C, void *arg1, void *arg2);
typedef void (*uiButHandleRenameFunc)(struct bContext *C, void *arg, char *origstr); typedef void (*uiButHandleRenameFunc)(struct bContext *C, void *arg, char *origstr);
typedef void (*uiButHandleNFunc)(struct bContext *C, void *argN, void *arg2); typedef void (*uiButHandleNFunc)(struct bContext *C, void *argN, void *arg2);
typedef void (*uiButCompleteFunc)(struct bContext *C, char *str, void *arg); typedef bool (*uiButCompleteFunc)(struct bContext *C, char *str, void *arg);
typedef void (*uiButSearchFunc)(const struct bContext *C, void *arg, const char *str, uiSearchItems *items); typedef void (*uiButSearchFunc)(const struct bContext *C, void *arg, const char *str, uiSearchItems *items);
typedef void (*uiBlockHandleFunc)(struct bContext *C, void *arg, int event); typedef void (*uiBlockHandleFunc)(struct bContext *C, void *arg, int event);
@@ -644,7 +644,7 @@ typedef struct AutoComplete AutoComplete;
AutoComplete *autocomplete_begin(const char *startname, size_t maxlen); AutoComplete *autocomplete_begin(const char *startname, size_t maxlen);
void autocomplete_do_name(AutoComplete *autocpl, const char *name); void autocomplete_do_name(AutoComplete *autocpl, const char *name);
void autocomplete_end(AutoComplete *autocpl, char *autoname); bool autocomplete_end(AutoComplete *autocpl, char *autoname);
/* Panels /* Panels
* *

View File

@@ -3086,16 +3086,21 @@ void autocomplete_do_name(AutoComplete *autocpl, const char *name)
} }
} }
void autocomplete_end(AutoComplete *autocpl, char *autoname) bool autocomplete_end(AutoComplete *autocpl, char *autoname)
{ {
if (autocpl->truncate[0]) bool change = false;
if (autocpl->truncate[0]) {
BLI_strncpy(autoname, autocpl->truncate, autocpl->maxlen); BLI_strncpy(autoname, autocpl->truncate, autocpl->maxlen);
change = true;
}
else { else {
if (autoname != autocpl->startname) /* don't copy a string over its self */ if (autoname != autocpl->startname) { /* don't copy a string over its self */
BLI_strncpy(autoname, autocpl->startname, autocpl->maxlen); BLI_strncpy(autoname, autocpl->startname, autocpl->maxlen);
} }
}
MEM_freeN(autocpl->truncate); MEM_freeN(autocpl->truncate);
MEM_freeN(autocpl); MEM_freeN(autocpl);
return change;
} }
static void ui_check_but_and_iconize(uiBut *but, int icon) static void ui_check_but_and_iconize(uiBut *but, int icon)

View File

@@ -1828,20 +1828,19 @@ static bool ui_textedit_delete(uiBut *but, uiHandleButtonData *data, int directi
static bool ui_textedit_autocomplete(bContext *C, uiBut *but, uiHandleButtonData *data) static bool ui_textedit_autocomplete(bContext *C, uiBut *but, uiHandleButtonData *data)
{ {
char *str; char *str;
/* TODO, should return false if it cant autocomp. */ bool change = true;
bool changed = true;
str = data->str; str = data->str;
if (data->searchbox) if (data->searchbox)
ui_searchbox_autocomplete(C, data->searchbox, but, data->str); change = ui_searchbox_autocomplete(C, data->searchbox, but, data->str);
else else
but->autocomplete_func(C, str, but->autofunc_arg); change = but->autocomplete_func(C, str, but->autofunc_arg);
but->pos = strlen(str); but->pos = strlen(str);
but->selsta = but->selend = but->pos; but->selsta = but->selend = but->pos;
return changed; return change;
} }
/* mode for ui_textedit_copypaste() */ /* mode for ui_textedit_copypaste() */

View File

@@ -471,7 +471,7 @@ ARegion *ui_searchbox_create(struct bContext *C, struct ARegion *butregion, uiBu
bool ui_searchbox_inside(struct ARegion *ar, int x, int y); bool ui_searchbox_inside(struct ARegion *ar, int x, int y);
int ui_searchbox_find_index(struct ARegion *ar, const char *name); int ui_searchbox_find_index(struct ARegion *ar, const char *name);
void ui_searchbox_update(struct bContext *C, struct ARegion *ar, uiBut *but, const bool reset); void ui_searchbox_update(struct bContext *C, struct ARegion *ar, uiBut *but, const bool reset);
void ui_searchbox_autocomplete(struct bContext *C, struct ARegion *ar, uiBut *but, char *str); bool ui_searchbox_autocomplete(struct bContext *C, struct ARegion *ar, uiBut *but, char *str);
void ui_searchbox_event(struct bContext *C, struct ARegion *ar, uiBut *but, const struct wmEvent *event); void ui_searchbox_event(struct bContext *C, struct ARegion *ar, uiBut *but, const struct wmEvent *event);
bool ui_searchbox_apply(uiBut *but, struct ARegion *ar); bool ui_searchbox_apply(uiBut *but, struct ARegion *ar);
void ui_searchbox_free(struct bContext *C, struct ARegion *ar); void ui_searchbox_free(struct bContext *C, struct ARegion *ar);

View File

@@ -1039,18 +1039,20 @@ void ui_searchbox_update(bContext *C, ARegion *ar, uiBut *but, const bool reset)
ED_region_tag_redraw(ar); ED_region_tag_redraw(ar);
} }
void ui_searchbox_autocomplete(bContext *C, ARegion *ar, uiBut *but, char *str) bool ui_searchbox_autocomplete(bContext *C, ARegion *ar, uiBut *but, char *str)
{ {
uiSearchboxData *data = ar->regiondata; uiSearchboxData *data = ar->regiondata;
bool changed = false;
if (str[0]) { if (str[0]) {
data->items.autocpl = autocomplete_begin(str, ui_get_but_string_max_length(but)); data->items.autocpl = autocomplete_begin(str, ui_get_but_string_max_length(but));
but->search_func(C, but->search_arg, but->editstr, &data->items); but->search_func(C, but->search_arg, but->editstr, &data->items);
autocomplete_end(data->items.autocpl, str); changed = autocomplete_end(data->items.autocpl, str);
data->items.autocpl = NULL; data->items.autocpl = NULL;
} }
return changed;
} }
static void ui_searchbox_region_draw_cb(const bContext *UNUSED(C), ARegion *ar) static void ui_searchbox_region_draw_cb(const bContext *UNUSED(C), ARegion *ar)

View File

@@ -105,8 +105,8 @@ float file_string_width(const char *str);
float file_font_pointsize(void); float file_font_pointsize(void);
void file_change_dir(bContext *C, int checkdir); void file_change_dir(bContext *C, int checkdir);
int file_select_match(struct SpaceFile *sfile, const char *pattern, char *matched_file); int file_select_match(struct SpaceFile *sfile, const char *pattern, char *matched_file);
void autocomplete_directory(struct bContext *C, char *str, void *arg_v); bool autocomplete_directory(struct bContext *C, char *str, void *arg_v);
void autocomplete_file(struct bContext *C, char *str, void *arg_v); bool autocomplete_file(struct bContext *C, char *str, void *arg_v);
/* file_panels.c */ /* file_panels.c */
void file_panels_register(struct ARegionType *art); void file_panels_register(struct ARegionType *art);

View File

@@ -638,9 +638,10 @@ int file_select_match(struct SpaceFile *sfile, const char *pattern, char *matche
return match; return match;
} }
void autocomplete_directory(struct bContext *C, char *str, void *UNUSED(arg_v)) bool autocomplete_directory(struct bContext *C, char *str, void *UNUSED(arg_v))
{ {
SpaceFile *sfile = CTX_wm_space_file(C); SpaceFile *sfile = CTX_wm_space_file(C);
bool change = false;
/* search if str matches the beginning of name */ /* search if str matches the beginning of name */
if (str[0] && sfile->files) { if (str[0] && sfile->files) {
@@ -675,7 +676,8 @@ void autocomplete_directory(struct bContext *C, char *str, void *UNUSED(arg_v))
} }
closedir(dir); closedir(dir);
autocomplete_end(autocpl, str); change = autocomplete_end(autocpl, str);
if (change) {
if (BLI_exists(str)) { if (BLI_exists(str)) {
BLI_add_slash(str); BLI_add_slash(str);
} }
@@ -684,11 +686,15 @@ void autocomplete_directory(struct bContext *C, char *str, void *UNUSED(arg_v))
} }
} }
} }
}
return change;
} }
void autocomplete_file(struct bContext *C, char *str, void *UNUSED(arg_v)) bool autocomplete_file(struct bContext *C, char *str, void *UNUSED(arg_v))
{ {
SpaceFile *sfile = CTX_wm_space_file(C); SpaceFile *sfile = CTX_wm_space_file(C);
bool change = false;
/* search if str matches the beginning of name */ /* search if str matches the beginning of name */
if (str[0] && sfile->files) { if (str[0] && sfile->files) {
@@ -702,8 +708,9 @@ void autocomplete_file(struct bContext *C, char *str, void *UNUSED(arg_v))
autocomplete_do_name(autocpl, file->relname); autocomplete_do_name(autocpl, file->relname);
} }
} }
autocomplete_end(autocpl, str); change = autocomplete_end(autocpl, str);
} }
return change;
} }
void ED_fileselect_clear(struct wmWindowManager *wm, struct SpaceFile *sfile) void ED_fileselect_clear(struct wmWindowManager *wm, struct SpaceFile *sfile)