[Bf-blender-cvs] [a6a2aa2fc47] temp-geometry-nodes-attribute-search: Attribute Search: Accept all strings as valid results
Hans Goudey
noreply at git.blender.org
Tue Feb 23 23:35:05 CET 2021
Commit: a6a2aa2fc47747fcd5a8d83a714deb1d8a448889
Author: Hans Goudey
Date: Tue Feb 23 16:34:59 2021 -0600
Branches: temp-geometry-nodes-attribute-search
https://developer.blender.org/rBa6a2aa2fc47747fcd5a8d83a714deb1d8a448889
Attribute Search: Accept all strings as valid results
Since the names in the search box are only hints, any attribute name
is potentially valid. Error messages can tell when it is not.
===================================================================
M source/blender/editors/include/UI_interface.h
M source/blender/editors/interface/interface.c
M source/blender/editors/interface/interface_handlers.c
M source/blender/editors/interface/interface_intern.h
M source/blender/editors/interface/interface_region_search.c
M source/blender/editors/space_node/node_geometry_attribute_search.cc
===================================================================
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 81641239c6a..029e5998da1 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -1602,6 +1602,7 @@ void UI_but_func_search_set(uiBut *but,
void UI_but_func_search_set_context_menu(uiBut *but, uiButSearchContextMenuFn context_menu_fn);
void UI_but_func_search_set_tooltip(uiBut *but, uiButSearchTooltipFn tooltip_fn);
void UI_but_func_search_set_sep_string(uiBut *but, const char *search_sep_string);
+void UI_but_func_search_set_all_strings_valid(uiBut *but, const bool value);
/* height in pixels, it's using hardcoded values still */
int UI_searchbox_size_y(void);
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 6e25ec9d275..b1e524ca62e 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -6661,6 +6661,14 @@ void UI_but_func_search_set_tooltip(uiBut *but, uiButSearchTooltipFn tooltip_fn)
but_search->item_tooltip_fn = tooltip_fn;
}
+void UI_but_func_search_set_all_strings_valid(uiBut *but, const bool value)
+{
+ uiButSearch *but_search = (uiButSearch *)but;
+ BLI_assert(but->type == UI_BTYPE_SEARCH_MENU);
+
+ but_search->all_strings_valid = value;
+}
+
/* Callbacks for operator search button. */
static void operator_enum_search_update_fn(const struct bContext *C,
void *but,
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 0002cc8abf0..45abf548607 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -3407,9 +3407,13 @@ static void ui_textedit_end(bContext *C, uiBut *but, uiHandleButtonData *data)
}
if (data->searchbox) {
+ uiButSearch *but_search = (uiButSearch *)but;
+ BLI_assert(but->type == UI_BTYPE_SEARCH_MENU);
+
if (data->cancel == false) {
if ((ui_searchbox_apply(but, data->searchbox) == false) &&
- (ui_searchbox_find_index(data->searchbox, but->editstr) == -1)) {
+ (ui_searchbox_find_index(data->searchbox, but->editstr) == -1) &&
+ !but_search->all_strings_valid) {
data->cancel = true;
/* ensure menu (popup) too is closed! */
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index 3da66d45abd..a4e542d1377 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -316,6 +316,12 @@ typedef struct uiButSearch {
struct PointerRNA rnasearchpoin;
struct PropertyRNA *rnasearchprop;
+
+ /**
+ * The search box only provides suggestions, it does not force
+ * the string to match one of the search items when applying.
+ */
+ bool all_strings_valid;
} uiButSearch;
/** Derived struct for #UI_BTYPE_DECORATOR */
diff --git a/source/blender/editors/interface/interface_region_search.c b/source/blender/editors/interface/interface_region_search.c
index 2c07f5c3c03..f40c888197f 100644
--- a/source/blender/editors/interface/interface_region_search.c
+++ b/source/blender/editors/interface/interface_region_search.c
@@ -1052,14 +1052,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++) {
diff --git a/source/blender/editors/space_node/node_geometry_attribute_search.cc b/source/blender/editors/space_node/node_geometry_attribute_search.cc
index cff936c1bf5..1eba849c59b 100644
--- a/source/blender/editors/space_node/node_geometry_attribute_search.cc
+++ b/source/blender/editors/space_node/node_geometry_attribute_search.cc
@@ -68,7 +68,6 @@ struct AttributeSearchData {
const bNodeTree &node_tree;
const bNode &node;
bNodeSocket &socket;
- std::string current_value;
/* Needed for proper interaction with the search button. Otherwise the interface code can't keep
* track of which button is active by comparing pointers to this struct, because it is newly
@@ -107,9 +106,6 @@ static void attribute_search_update_fn(const bContext *C,
}
}
- /* Always add the current value. */
- UI_search_item_add(items, data->current_value.c_str(), &data->current_value, ICON_NONE, 0, 0);
-
MEM_freeN(filtered_items);
BLI_string_search_free(search);
}
@@ -146,7 +142,6 @@ void button_add_attribute_search(
*space_node->edittree,
*node,
*socket,
- current_value,
but,
UI_butstore_create(block),
block,
@@ -154,6 +149,8 @@ void button_add_attribute_search(
UI_butstore_register(data->button_store, &data->search_button);
+ UI_but_func_search_set_all_strings_valid(but, true);
+
UI_but_func_search_set(but,
nullptr,
attribute_search_update_fn,
More information about the Bf-blender-cvs
mailing list