diff options
author | Hans Goudey <h.goudey@me.com> | 2020-09-09 21:00:56 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2020-09-09 21:01:32 +0300 |
commit | 58488c08b869a42f81c2acec5b14504a59d5b500 (patch) | |
tree | 96b8f45f5f3f70bb11fca73c04b3a029306d344a /source/blender/editors/screen | |
parent | 6a76eeaced199de1143a9e6c54e6a7ca29a3bc7f (diff) |
Property Search: Single tab
This adds a search bar to the properties editor. The full search for every tab
isn't includede in this patch, but the interaction with panels, searching
behavior, internal UI, region level, and DNA changes are included here.
The block-level search works by iterating over the block's buttons and
checking whether they match the search. If they do, they are tagged with
a flag, and the block's panel is tagged too.
For every update (text edit), the panel's expansion is set to whether the
panel has a result or not.
There is some complications to this that you might no initially think of:
1. Closed panel's subpanels have to be searched too. This adds some
complexity and special cases to the area-level panel layout code.
2. //Maybe more if I think of things to add here//
There might be some methods of simplifying some of the logic, particularly
around choosing whether to highlight panel headers. Also note that automatic
subpanel expansion isn't working right now. I'll look into this, but I want to post
all the patches first.
**Future Improvements**
Here are some improvements possible in the future that won't be part of this patch:
1. Use the new fuzzy search in BLI
2. Reseting panels to their expansion before the search started if you `esc`
out of the text box
3. Open parent panels if their subpanels have a match but they don't. This
requires adding a reference to parent panels for subpanels.
Differential Revision: https://developer.blender.org/D8856
Diffstat (limited to 'source/blender/editors/screen')
-rw-r--r-- | source/blender/editors/screen/area.c | 55 |
1 files changed, 49 insertions, 6 deletions
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c index 8ec58b4c75e..c145dfd0278 100644 --- a/source/blender/editors/screen/area.c +++ b/source/blender/editors/screen/area.c @@ -492,6 +492,9 @@ void ED_region_do_layout(bContext *C, ARegion *region) UI_SetTheme(area ? area->spacetype : 0, at->regionid); at->layout(C, region); + + /* Clear temporary update flag. */ + region->flag &= ~RGN_FLAG_SEARCH_FILTER_UPDATE; } /* only exported for WM */ @@ -736,6 +739,28 @@ void ED_area_tag_refresh(ScrArea *area) /* *************************************************************** */ +/** + * Returns the search string if the space type supports property search. + */ +char *ED_area_search_filter_get(const bContext *C) +{ + SpaceProperties *sbuts = CTX_wm_space_properties(C); + if (sbuts != NULL) { + return sbuts->search_string; + } + return NULL; +} + +void ED_region_search_filter_update(const bContext *C, ARegion *region) +{ + region->flag |= RGN_FLAG_SEARCH_FILTER_UPDATE; + + const char *search_filter = ED_area_search_filter_get(C); + SET_FLAG_FROM_TEST(region->flag, search_filter[0] != '\0', RGN_FLAG_SEARCH_FILTER_ACTIVE); +} + +/* *************************************************************** */ + /* use NULL to disable it */ void ED_area_status_text(ScrArea *area, const char *str) { @@ -2558,7 +2583,8 @@ static void ed_panel_draw(const bContext *C, Panel *panel, int w, int em, - char *unique_panel_str) + char *unique_panel_str, + bool search_only) { const uiStyle *style = UI_style_get_dpi(); @@ -2571,6 +2597,7 @@ 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_only(block, search_only); bool open; panel = UI_panel_begin(region, lb, block, pt, panel, &open); @@ -2590,6 +2617,7 @@ static void ed_panel_draw(const bContext *C, 1, 0, style); + uiLayoutRootSetSearchOnly(panel->layout, search_only); pt->draw_header_preset(C, panel); @@ -2620,6 +2648,7 @@ static void ed_panel_draw(const bContext *C, panel->layout = UI_block_layout( block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER, labelx, labely, UI_UNIT_Y, 1, 0, style); } + uiLayoutRootSetSearchOnly(panel->layout, search_only); pt->draw_header(C, panel); @@ -2631,7 +2660,7 @@ static void ed_panel_draw(const bContext *C, panel->labelofs = 0; } - if (open) { + if (open || UI_block_has_search_filter(block) || search_only) { short panelContext; /* panel context can either be toolbar region or normal panels region */ @@ -2655,6 +2684,7 @@ static void ed_panel_draw(const bContext *C, em, 0, style); + uiLayoutRootSetSearchOnly(panel->layout, search_only || !open); pt->draw(C, panel); @@ -2669,13 +2699,14 @@ static void ed_panel_draw(const bContext *C, UI_block_end(C, block); /* Draw child panels. */ - if (open) { + if (open || UI_block_has_search_filter(block)) { LISTBASE_FOREACH (LinkData *, link, &pt->children) { PanelType *child_pt = link->data; Panel *child_panel = UI_panel_find_by_type(&panel->children, child_pt); if (child_pt->draw && (!child_pt->poll || child_pt->poll(C, child_pt))) { - ed_panel_draw(C, region, &panel->children, child_pt, child_panel, w, em, unique_panel_str); + ed_panel_draw( + C, region, &panel->children, child_pt, child_panel, w, em, unique_panel_str, !open); } } } @@ -2813,7 +2844,8 @@ void ED_region_panels_layout_ex(const bContext *C, panel, (pt->flag & PNL_DRAW_BOX) ? w_box_panel : w, em, - NULL); + NULL, + false); } /* Draw "polyinstantaited" panels that don't have a 1 to 1 correspondence with their types. */ @@ -2846,7 +2878,18 @@ void ED_region_panels_layout_ex(const bContext *C, panel, (panel->type->flag & PNL_DRAW_BOX) ? w_box_panel : w, em, - unique_panel_str); + unique_panel_str, + false); + } + } + + if (region->flag & RGN_FLAG_SEARCH_FILTER_UPDATE && + region->flag & RGN_FLAG_SEARCH_FILTER_ACTIVE) { + LISTBASE_FOREACH (Panel *, panel, ®ion->panels) { + if (panel->type == NULL || (panel->type->flag & PNL_NO_HEADER)) { + continue; /* Some panels don't have a type. */ + } + UI_panel_set_expansion_from_seach_filter(C, panel); } } |