diff options
author | Hans Goudey <h.goudey@me.com> | 2021-03-02 20:42:05 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-03-02 20:42:05 +0300 |
commit | 1a8aee0a7cec0c2718932fdeece9dc071689f928 (patch) | |
tree | 10ec791fad13cf373297c2c760bd7837638f7453 /source/blender/editors/interface/interface_region_search.c | |
parent | 5a3b7c532952d29e1ee3b26aba10a91b5bc3af31 (diff) |
UI: Expose an "is first search" boolean to search button callbacks
Currently when you open an RNA collection search button, like a
vertex group selector, the search filter isn't applied until you
start typing, in order to display every option at the start.
Otherwise they wouldn't be visible, since the search filter would
run for the current text.
Currently this check happens in one place, but it relies on the
`changed` value of `uiBut`. This is fine in the interface directory,
but anywhere else it would require exposing `uiBut.changed`, which
is probably too low-level to expose.
The solution is adding an `is_first` argument to the search callbacks,
which is nice for a few reasons:
- They work at a higher level of abstraction, meaning they don't
have to worry about how exactly to tell if this is the first
search.
- It makes it easier to do special behavior when the search menu
is first opened.
- Then, obviously, it makes that state accessible without including
`interface_intern.h`.
Needed for attribute search: T85658
Differential Revision: https://developer.blender.org/D10528
Diffstat (limited to 'source/blender/editors/interface/interface_region_search.c')
-rw-r--r-- | source/blender/editors/interface/interface_region_search.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/source/blender/editors/interface/interface_region_search.c b/source/blender/editors/interface/interface_region_search.c index 2c07f5c3c03..9297da5307a 100644 --- a/source/blender/editors/interface/interface_region_search.c +++ b/source/blender/editors/interface/interface_region_search.c @@ -468,7 +468,8 @@ static void ui_searchbox_update_fn(bContext *C, wmWindow *win = CTX_wm_window(C); WM_tooltip_clear(C, win); } - search_but->items_update_fn(C, search_but->arg, str, items); + const bool is_first_search = !search_but->but.changed; + search_but->items_update_fn(C, search_but->arg, str, items, is_first_search); } /* region is the search box itself */ @@ -1052,14 +1053,16 @@ void ui_but_search_refresh(uiButSearch *search_but) ui_searchbox_update_fn(but->block->evil_C, search_but, but->drawstr, items); - /* Only red-alert when we are sure of it, this can miss cases when >10 matches. */ - if (items->totitem == 0) { - UI_but_flag_enable(but, UI_BUT_REDALERT); - } - else if (items->more == 0) { - if (UI_search_items_find_index(items, but->drawstr) == -1) { + if (!search_but->all_strings_valid) { + /* Only red-alert when we are sure of it, this can miss cases when >10 matches. */ + if (items->totitem == 0) { UI_but_flag_enable(but, UI_BUT_REDALERT); } + else if (items->more == 0) { + if (UI_search_items_find_index(items, but->drawstr) == -1) { + UI_but_flag_enable(but, UI_BUT_REDALERT); + } + } } for (x1 = 0; x1 < items->maxitem; x1++) { |