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:
@@ -304,7 +304,7 @@ typedef struct uiSearchItems uiSearchItems;
|
||||
typedef void (*uiButHandleFunc)(struct bContext *C, void *arg1, void *arg2);
|
||||
typedef void (*uiButHandleRenameFunc)(struct bContext *C, void *arg, char *origstr);
|
||||
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 (*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);
|
||||
void autocomplete_do_name(AutoComplete *autocpl, const char *name);
|
||||
void autocomplete_end(AutoComplete *autocpl, char *autoname);
|
||||
bool autocomplete_end(AutoComplete *autocpl, char *autoname);
|
||||
|
||||
/* Panels
|
||||
*
|
||||
|
||||
@@ -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);
|
||||
change = true;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
MEM_freeN(autocpl->truncate);
|
||||
MEM_freeN(autocpl);
|
||||
return change;
|
||||
}
|
||||
|
||||
static void ui_check_but_and_iconize(uiBut *but, int icon)
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
char *str;
|
||||
/* TODO, should return false if it cant autocomp. */
|
||||
bool changed = true;
|
||||
bool change = true;
|
||||
|
||||
str = data->str;
|
||||
|
||||
if (data->searchbox)
|
||||
ui_searchbox_autocomplete(C, data->searchbox, but, data->str);
|
||||
change = ui_searchbox_autocomplete(C, data->searchbox, but, data->str);
|
||||
else
|
||||
but->autocomplete_func(C, str, but->autofunc_arg);
|
||||
change = but->autocomplete_func(C, str, but->autofunc_arg);
|
||||
|
||||
but->pos = strlen(str);
|
||||
but->selsta = but->selend = but->pos;
|
||||
|
||||
return changed;
|
||||
return change;
|
||||
}
|
||||
|
||||
/* mode for ui_textedit_copypaste() */
|
||||
|
||||
@@ -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);
|
||||
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_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);
|
||||
bool ui_searchbox_apply(uiBut *but, struct ARegion *ar);
|
||||
void ui_searchbox_free(struct bContext *C, struct ARegion *ar);
|
||||
|
||||
@@ -1039,18 +1039,20 @@ void ui_searchbox_update(bContext *C, ARegion *ar, uiBut *but, const bool reset)
|
||||
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;
|
||||
bool changed = false;
|
||||
|
||||
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);
|
||||
|
||||
autocomplete_end(data->items.autocpl, str);
|
||||
changed = autocomplete_end(data->items.autocpl, str);
|
||||
data->items.autocpl = NULL;
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
static void ui_searchbox_region_draw_cb(const bContext *UNUSED(C), ARegion *ar)
|
||||
|
||||
@@ -105,8 +105,8 @@ float file_string_width(const char *str);
|
||||
float file_font_pointsize(void);
|
||||
void file_change_dir(bContext *C, int checkdir);
|
||||
int file_select_match(struct SpaceFile *sfile, const char *pattern, char *matched_file);
|
||||
void autocomplete_directory(struct bContext *C, char *str, void *arg_v);
|
||||
void autocomplete_file(struct bContext *C, char *str, void *arg_v);
|
||||
bool autocomplete_directory(struct bContext *C, char *str, void *arg_v);
|
||||
bool autocomplete_file(struct bContext *C, char *str, void *arg_v);
|
||||
|
||||
/* file_panels.c */
|
||||
void file_panels_register(struct ARegionType *art);
|
||||
|
||||
@@ -638,9 +638,10 @@ int file_select_match(struct SpaceFile *sfile, const char *pattern, char *matche
|
||||
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);
|
||||
bool change = false;
|
||||
|
||||
/* search if str matches the beginning of name */
|
||||
if (str[0] && sfile->files) {
|
||||
@@ -675,7 +676,8 @@ void autocomplete_directory(struct bContext *C, char *str, void *UNUSED(arg_v))
|
||||
}
|
||||
closedir(dir);
|
||||
|
||||
autocomplete_end(autocpl, str);
|
||||
change = autocomplete_end(autocpl, str);
|
||||
if (change) {
|
||||
if (BLI_exists(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);
|
||||
bool change = false;
|
||||
|
||||
/* search if str matches the beginning of name */
|
||||
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_end(autocpl, str);
|
||||
change = autocomplete_end(autocpl, str);
|
||||
}
|
||||
return change;
|
||||
}
|
||||
|
||||
void ED_fileselect_clear(struct wmWindowManager *wm, struct SpaceFile *sfile)
|
||||
|
||||
Reference in New Issue
Block a user