Cleanup: Remove unecessary storage of search filter in uiBlock

Since the search is applied all in one phase, there is no need to store
a reference to the search filter in every uiBlock. Instead just pass it
as an argument to UI_block_apply_search_filter.
This commit is contained in:
2020-09-24 11:22:30 -05:00
parent bdbe95578d
commit 7fb0cb2b93
5 changed files with 14 additions and 25 deletions

View File

@@ -676,7 +676,6 @@ char UI_block_emboss_get(uiBlock *block);
void UI_block_emboss_set(uiBlock *block, char emboss);
bool UI_block_is_search_only(const uiBlock *block);
void UI_block_set_search_only(uiBlock *block, bool search_only);
void UI_block_set_search_filter(uiBlock *block, const char *search_filter);
void UI_block_free(const struct bContext *C, uiBlock *block);
void UI_blocklist_free(const struct bContext *C, struct ListBase *lb);
@@ -1870,7 +1869,7 @@ uiLayout *UI_block_layout(uiBlock *block,
void UI_block_layout_set_current(uiBlock *block, uiLayout *layout);
void UI_block_layout_resolve(uiBlock *block, int *r_x, int *r_y);
bool UI_block_apply_search_filter(uiBlock *block);
bool UI_block_apply_search_filter(uiBlock *block, const char *search_filter);
void UI_region_message_subscribe(struct ARegion *region, struct wmMsgBus *mbus);

View File

@@ -3594,11 +3594,6 @@ void UI_block_set_search_only(uiBlock *block, bool search_only)
SET_FLAG_FROM_TEST(block->flag, search_only, UI_BLOCK_SEARCH_ONLY);
}
void UI_block_set_search_filter(uiBlock *block, const char *search_filter)
{
block->search_filter = search_filter;
}
static void ui_but_build_drawstr_float(uiBut *but, double value)
{
size_t slen = 0;

View File

@@ -524,12 +524,6 @@ struct uiBlock {
*/
char display_device[64];
/**
* Pointer to the space's property search string.
* The block doesn't allocate this or change it.
*/
const char *search_filter;
struct PieMenuData pie_data;
};

View File

@@ -5161,10 +5161,10 @@ void uiLayoutRootSetSearchOnly(uiLayout *layout, bool search_only)
/* Disabled for performance reasons, but this could be turned on in the future. */
// #define PROPERTY_SEARCH_USE_TOOLTIPS
static bool block_search_panel_label_matches(const uiBlock *block)
static bool block_search_panel_label_matches(const uiBlock *block, const char *search_string)
{
if ((block->panel != NULL) && (block->panel->type != NULL)) {
if (BLI_strcasestr(block->panel->type->label, block->search_filter)) {
if (BLI_strcasestr(block->panel->type->label, search_string)) {
return true;
}
}
@@ -5294,12 +5294,12 @@ static bool button_group_has_search_match(uiButtonGroup *button_group, const cha
*
* \return True if the block has any search results.
*/
static bool block_search_filter_tag_buttons(uiBlock *block)
static bool block_search_filter_tag_buttons(uiBlock *block, const char *search_filter)
{
bool has_result = false;
LISTBASE_FOREACH (uiLayoutRoot *, root, &block->layouts) {
LISTBASE_FOREACH (uiButtonGroup *, button_group, &root->button_groups) {
if (button_group_has_search_match(button_group, block->search_filter)) {
if (button_group_has_search_match(button_group, search_filter)) {
LISTBASE_FOREACH (LinkData *, link, &button_group->buttons) {
uiBut *but = link->data;
but->flag |= UI_SEARCH_FILTER_MATCHES;
@@ -5325,15 +5325,17 @@ static void block_search_deactivate_buttons(uiBlock *block)
*
* \note Must not be run after #UI_block_layout_resolve.
*/
bool UI_block_apply_search_filter(uiBlock *block)
bool UI_block_apply_search_filter(uiBlock *block, const char *search_filter)
{
if (!(block->search_filter && block->search_filter[0])) {
if (search_filter == NULL || search_filter[0] == '\0') {
return false;
}
const bool panel_label_matches = block_search_panel_label_matches(block);
const bool panel_label_matches = block_search_panel_label_matches(block, search_filter);
const bool has_result = panel_label_matches ? true : block_search_filter_tag_buttons(block);
const bool has_result = (panel_label_matches) ?
true :
block_search_filter_tag_buttons(block, search_filter);
block_search_remove_search_only_roots(block);

View File

@@ -2607,7 +2607,6 @@ static void ed_panel_draw(const bContext *C,
strncat(block_name, unique_panel_str, INSTANCED_PANEL_UNIQUE_STR_LEN);
}
uiBlock *block = UI_block_begin(C, region, block_name, UI_EMBOSS);
UI_block_set_search_filter(block, search_filter);
UI_block_set_search_only(block, search_only);
bool open;
@@ -2634,7 +2633,7 @@ static void ed_panel_draw(const bContext *C,
pt->draw_header_preset(C, panel);
UI_block_apply_search_filter(block);
UI_block_apply_search_filter(block, search_filter);
UI_block_layout_resolve(block, &xco, &yco);
UI_block_translate(block, headerend - xco, 0);
panel->layout = NULL;
@@ -2666,7 +2665,7 @@ static void ed_panel_draw(const bContext *C,
pt->draw_header(C, panel);
UI_block_apply_search_filter(block);
UI_block_apply_search_filter(block, search_filter);
UI_block_layout_resolve(block, &xco, &yco);
panel->labelofs = xco - labelx;
panel->layout = NULL;
@@ -2703,7 +2702,7 @@ static void ed_panel_draw(const bContext *C,
pt->draw(C, panel);
UI_block_apply_search_filter(block);
UI_block_apply_search_filter(block, search_filter);
UI_block_layout_resolve(block, &xco, &yco);
panel->layout = NULL;