[Bf-blender-cvs] [10e885c56b0] temp-geometry-nodes-attribute-search: UI: Expose an "is first search" boolean to search button callbacks

Hans Goudey noreply at git.blender.org
Thu Feb 25 03:46:08 CET 2021


Commit: 10e885c56b0d22217e53a5ebceb295081462b8b9
Author: Hans Goudey
Date:   Wed Feb 24 17:48:46 2021 -0600
Branches: temp-geometry-nodes-attribute-search
https://developer.blender.org/rB10e885c56b0d22217e53a5ebceb295081462b8b9

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 list every option at the start. Otherwise
they wouldn't be visible, since the search filter would run.

Currently this same check happens in one place, but it checks the
`changed` value of `uiBut`. This is fine in the interface directory,
but anywhere else it doesn't work. And I think exposing `uiBut.changed`
is not a good idea, since it's too general and is only used for this
specific situation anyway.

So, 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`.

Ref T85658

Maniphest Tasks: T85658

Differential Revision: https://developer.blender.org/D10528

===================================================================

M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface.c
M	source/blender/editors/interface/interface_intern.h
M	source/blender/editors/interface/interface_region_search.c
M	source/blender/editors/interface/interface_template_search_menu.c
M	source/blender/editors/interface/interface_template_search_operator.c
M	source/blender/editors/interface/interface_templates.c
M	source/blender/editors/interface/interface_utils.c
M	source/blender/editors/space_node/node_select.c
M	source/blender/editors/space_outliner/outliner_tools.c

===================================================================

diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 029e5998da1..fa527e15093 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -502,7 +502,8 @@ typedef struct ARegion *(*uiButSearchCreateFn)(struct bContext *C,
 typedef void (*uiButSearchUpdateFn)(const struct bContext *C,
                                     void *arg,
                                     const char *str,
-                                    uiSearchItems *items);
+                                    uiSearchItems *items,
+                                    const bool is_first);
 typedef void (*uiButSearchArgFreeFn)(void *arg);
 typedef bool (*uiButSearchContextMenuFn)(struct bContext *C,
                                          void *arg,
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index b1e524ca62e..ed2984e1a86 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -6673,7 +6673,8 @@ void UI_but_func_search_set_all_strings_valid(uiBut *but, const bool value)
 static void operator_enum_search_update_fn(const struct bContext *C,
                                            void *but,
                                            const char *str,
-                                           uiSearchItems *items)
+                                           uiSearchItems *items,
+                                           const bool UNUSED(is_first))
 {
   wmOperatorType *ot = ((uiBut *)but)->optype;
   PropertyRNA *prop = ot->prop;
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index a4e542d1377..39b63d2b222 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -1199,7 +1199,8 @@ typedef struct uiRNACollectionSearch {
 void ui_rna_collection_search_update_fn(const struct bContext *C,
                                         void *arg,
                                         const char *str,
-                                        uiSearchItems *items);
+                                        uiSearchItems *items,
+                                        const bool is_first);
 
 /* interface_ops.c */
 bool ui_jump_to_target_button_poll(struct bContext *C);
diff --git a/source/blender/editors/interface/interface_region_search.c b/source/blender/editors/interface/interface_region_search.c
index f40c888197f..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 */
diff --git a/source/blender/editors/interface/interface_template_search_menu.c b/source/blender/editors/interface/interface_template_search_menu.c
index 25cf2e12377..e1f8f63dcbf 100644
--- a/source/blender/editors/interface/interface_template_search_menu.c
+++ b/source/blender/editors/interface/interface_template_search_menu.c
@@ -990,7 +990,8 @@ static void menu_search_exec_fn(bContext *C, void *UNUSED(arg1), void *arg2)
 static void menu_search_update_fn(const bContext *UNUSED(C),
                                   void *arg,
                                   const char *str,
-                                  uiSearchItems *items)
+                                  uiSearchItems *items,
+                                  const bool UNUSED(is_first))
 {
   struct MenuSearch_Data *data = arg;
 
diff --git a/source/blender/editors/interface/interface_template_search_operator.c b/source/blender/editors/interface/interface_template_search_operator.c
index ff0f9a2e5cd..2c83f184ff0 100644
--- a/source/blender/editors/interface/interface_template_search_operator.c
+++ b/source/blender/editors/interface/interface_template_search_operator.c
@@ -59,7 +59,8 @@ static void operator_search_exec_fn(bContext *C, void *UNUSED(arg1), void *arg2)
 static void operator_search_update_fn(const bContext *C,
                                       void *UNUSED(arg),
                                       const char *str,
-                                      uiSearchItems *items)
+                                      uiSearchItems *items,
+                                      const bool UNUSED(is_first))
 {
   GHashIterator iter;
 
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 67446ca681f..eadbe618899 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -393,7 +393,8 @@ static bool id_search_add(const bContext *C, TemplateID *template_ui, uiSearchIt
 static void id_search_cb(const bContext *C,
                          void *arg_template,
                          const char *str,
-                         uiSearchItems *items)
+                         uiSearchItems *items,
+                         const bool UNUSED(is_first))
 {
   TemplateID *template_ui = (TemplateID *)arg_template;
   ListBase *lb = template_ui->idlb;
@@ -464,7 +465,8 @@ static void id_search_cb_tagged(const bContext *C,
 static void id_search_cb_objects_from_scene(const bContext *C,
                                             void *arg_template,
                                             const char *str,
-                                            uiSearchItems *items)
+                                            uiSearchItems *items,
+                                            const bool UNUSED(is_first))
 {
   TemplateID *template_ui = (TemplateID *)arg_template;
   ListBase *lb = template_ui->idlb;
@@ -518,7 +520,7 @@ static uiBlock *id_search_menu(bContext *C, ARegion *region, void *arg_litem)
   static TemplateID template_ui;
   PointerRNA active_item_ptr;
   void (*id_search_update_fn)(
-      const bContext *, void *, const char *, uiSearchItems *) = id_search_cb;
+      const bContext *, void *, const char *, uiSearchItems *, const bool) = id_search_cb;
 
   /* arg_litem is malloced, can be freed by parent button */
   template_ui = *((TemplateID *)arg_litem);
diff --git a/source/blender/editors/interface/interface_utils.c b/source/blender/editors/interface/interface_utils.c
index 5311bb57da9..877800c1ba2 100644
--- a/source/blender/editors/interface/interface_utils.c
+++ b/source/blender/editors/interface/interface_utils.c
@@ -405,7 +405,8 @@ static bool add_collection_search_item(CollItemSearch *cis,
 void ui_rna_collection_search_update_fn(const struct bContext *C,
                                         void *arg,
                                         const char *str,
-                                        uiSearchItems *items)
+                                        uiSearchItems *items,
+                                        const bool is_first)
 {
   uiRNACollectionSearch *data = arg;
   const int flag = RNA_property_flag(data->target_prop);
@@ -415,7 +416,7 @@ void ui_rna_collection_search_update_fn(const struct bContext *C,
    * match the RNA name exactly. So only for pointer properties, the name can be modified to add
    * further UI hints. */
   const bool requires_exact_data_name = !is_ptr_target;
-  const bool skip_filter = data->search_but && !data->search_but->changed;
+  const bool skip_filter = is_first;
   char name_buf[UI_MAX_DRAW_STR];
   char *name;
   bool has_id_icon = false;
diff --git a/source/blender/editors/space_node/node_select.c b/source/blender/editors/space_node/node_select.c
index 58d22c2864f..704b7350bb9 100644
--- a/source/blender/editors/space_node/node_select.c
+++ b/source/blender/editors/space_node/node_select.c
@@ -1178,7 +1178,8 @@ static void node_find_create_label(const bNode *node, char *str, int maxlen)
 static void node_find_update_fn(const struct bContext *C,
                                 void *UNUSED(arg),
                                 const char *str,
-                                uiSearchItems *items)
+                                uiSearchItems *items,
+                                const bool UNUSED(is_first))
 {
   SpaceNode *snode = CTX_wm_space_node(C);
 
diff --git a/source/blender/editors/space_outliner/outliner_tools.c b/source/blender/editors/space_outliner/outliner_tools.c
index 8bc32f5f3a7..31f9f3d7721 100644
--- a/source/blender/editors/space_outliner/outliner_tools.c
+++ b/source/blender/editors/space_outliner/outliner_tools.c
@@ -554,7 +554,8 @@ static void merged_element_search_fn_recursive(
 static void merged_element_search_update_fn(const bContext *UNUSED(C),
                                             void *data,
                                             const char *str,
-                                            uiSearchItems *items)
+                                            uiSearchItems *items,
+                                            const bool UNUSED(is_first))
 {
   MergedSearchData *search_data = (MergedSearchData *)data;
   TreeElement *parent = search_data->parent_element;



More information about the Bf-blender-cvs mailing list