diff options
4 files changed, 38 insertions, 9 deletions
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index b591b99b31b..77bdd85d9fb 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -629,6 +629,8 @@ void uiButSetSearchFunc(uiBut *but, uiButSearchFunc sfunc, void *arg1, /* height in pixels, it's using hardcoded values still */ int uiSearchBoxHeight(void); int uiSearchBoxWidth(void); +/* check if a string is in an existing search box */ +int uiSearchItemFindIndex(uiSearchItems *items, const char *name); void uiBlockSetHandleFunc(uiBlock *block, uiBlockHandleFunc func, void *arg); void uiBlockSetButmFunc(uiBlock *block, uiMenuHandleFunc func, void *arg); diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index bd3ded01780..e8fcd7a0f40 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -2056,8 +2056,13 @@ static void ui_textedit_end(bContext *C, uiBut *but, uiHandleButtonData *data) } if (data->searchbox) { - if (data->cancel == false) - ui_searchbox_apply(but, data->searchbox); + if (data->cancel == false) { + if ((ui_searchbox_apply(but, data->searchbox) == false) || + (ui_searchbox_find_index(data->searchbox, but->editstr) == -1)) + { + data->cancel = true; + } + } ui_searchbox_free(C, data->searchbox); data->searchbox = NULL; diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index 68426f5ead2..4b2fb102305 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -475,10 +475,11 @@ void ui_popup_block_scrolltest(struct uiBlock *block); /* searchbox for string button */ ARegion *ui_searchbox_create(struct bContext *C, struct ARegion *butregion, uiBut *but); 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); void ui_searchbox_event(struct bContext *C, struct ARegion *ar, uiBut *but, const struct wmEvent *event); -void 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_but_search_test(uiBut *but); diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index 03d831035b2..f9523c28048 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -801,6 +801,17 @@ int uiSearchBoxWidth(void) return 9 * UI_UNIT_X; } +int uiSearchItemFindIndex(uiSearchItems *items, const char *name) +{ + int i; + for (i = 0; i < items->totitem; i++) { + if (STREQ(name, items->names[i])) { + return i; + } + } + return -1; +} + /* ar is the search box itself */ static void ui_searchbox_select(bContext *C, ARegion *ar, uiBut *but, int step) { @@ -866,6 +877,12 @@ static void ui_searchbox_butrect(rcti *rect, uiSearchboxData *data, int itemnr) } +int ui_searchbox_find_index(ARegion *ar, const char *name) +{ + uiSearchboxData *data = ar->regiondata; + return uiSearchItemFindIndex(&data->items, name); +} + /* x and y in screencoords */ bool ui_searchbox_inside(ARegion *ar, int x, int y) { @@ -875,7 +892,7 @@ bool ui_searchbox_inside(ARegion *ar, int x, int y) } /* string validated to be of correct length (but->hardmax) */ -void ui_searchbox_apply(uiBut *but, ARegion *ar) +bool ui_searchbox_apply(uiBut *but, ARegion *ar) { uiSearchboxData *data = ar->regiondata; @@ -890,6 +907,11 @@ void ui_searchbox_apply(uiBut *but, ARegion *ar) if (cpoin) cpoin[0] = '|'; but->func_arg2 = data->items.pointers[data->active - 1]; + + return true; + } + else { + return false; } } @@ -1287,14 +1309,13 @@ void ui_but_search_test(uiBut *but) but->search_func(but->block->evil_C, but->search_arg, but->drawstr, items); /* only redalert when we are sure of it, this can miss cases when >10 matches */ - if (items->totitem == 0) + if (items->totitem == 0) { uiButSetFlag(but, UI_BUT_REDALERT); + } else if (items->more == 0) { - for (x1 = 0; x1 < items->totitem; x1++) - if (strcmp(but->drawstr, items->names[x1]) == 0) - break; - if (x1 == items->totitem) + if (uiSearchItemFindIndex(items, but->drawstr) == -1) { uiButSetFlag(but, UI_BUT_REDALERT); + } } for (x1 = 0; x1 < items->maxitem; x1++) { |