Page Menu
Home
Search
Configure Global Search
Log In
Paste
P2066
UI code hack for D10623 part 2
Active
Public
Actions
Authored by
Hans Goudey (HooglyBoogly)
on Apr 13 2021, 6:04 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Tags
None
Subscribers
None
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 7a189139358..2300b4429a6 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -507,6 +507,10 @@ typedef void (*uiButSearchUpdateFn)(const struct bContext *C,
const char *str,
uiSearchItems *items,
const bool is_first);
+typedef void (*uiButSearchExecFn)(struct bContext *C,
+ void *arg1,
+ void *arg2,
+ const char *current_button_str);
typedef void (*uiButSearchArgFreeFn)(void *arg);
typedef bool (*uiButSearchContextMenuFn)(struct bContext *C,
void *arg,
@@ -1602,7 +1606,7 @@ void UI_but_func_search_set(uiBut *but,
void *arg,
const bool free_arg,
uiButSearchArgFreeFn search_arg_free_fn,
- uiButHandleFunc search_exec_fn,
+ uiButSearchExecFn search_exec_fn,
void *active);
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);
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 26136f8d905..e0709538441 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -6606,9 +6606,10 @@ uiBut *uiDefSearchBut(uiBlock *block,
* should be freed when the button is destroyed.
* \param search_arg_free_fn: When non-null, use this function to free \a arg.
* \param search_exec_fn: Function that executes the action, gets \a arg as the first argument.
- * The second argument as the active item-pointer
- * \param active: When non-null, this item-pointer item will be visible and selected,
- * otherwise the first item will be selected.
+ * The second argument as the active item-pointer, and the third argument is the string currently
+ * displayed in the button, for situations where there is no corresponding item.
+ * \param active: When non-null, this item-pointer item will be visible and selected, otherwise the
+ * first item will be selected.
*/
void UI_but_func_search_set(uiBut *but,
uiButSearchCreateFn search_create_fn,
@@ -6616,7 +6617,7 @@ void UI_but_func_search_set(uiBut *but,
void *arg,
const bool free_arg,
uiButSearchArgFreeFn search_arg_free_fn,
- uiButHandleFunc search_exec_fn,
+ uiButSearchExecFn search_exec_fn,
void *active)
{
uiButSearch *search_but = (uiButSearch *)but;
@@ -6638,6 +6639,8 @@ void UI_but_func_search_set(uiBut *but,
search_but->items_update_fn = search_update_fn;
search_but->item_active = active;
+ search_but->exec_fn = search_exec_fn;
+
search_but->arg = arg;
search_but->arg_free_fn = search_arg_free_fn;
@@ -6658,8 +6661,9 @@ void UI_but_func_search_set(uiBut *but,
}
}
- /* search buttons show red-alert if item doesn't exist, not for menus */
- if (0 == (but->block->flag & UI_BLOCK_LOOP)) {
+ /* search buttons show red-alert if item doesn't exist, not for menus. Don't do this for
+ * buttons where any result is valid anyway, since any string will be valid anyway. */
+ if (0 == (but->block->flag & UI_BLOCK_LOOP) && !search_but->results_are_suggestions) {
/* skip empty buttons, not all buttons need input, we only show invalid */
if (but->drawstr[0]) {
ui_but_search_refresh(search_but);
@@ -6756,7 +6760,10 @@ static void operator_enum_search_update_fn(const struct bContext *C,
}
}
-static void operator_enum_search_exec_fn(struct bContext *UNUSED(C), void *but, void *arg2)
+static void operator_enum_search_exec_fn(struct bContext *UNUSED(C),
+ void *but,
+ void *arg2,
+ const char *UNUSED(current_button_str))
{
wmOperatorType *ot = ((uiBut *)but)->optype;
PointerRNA *opptr = UI_but_operator_ptr_get(but); /* Will create it if needed! */
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index a5a5a69728e..26b2576e4a6 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -451,7 +451,9 @@ typedef struct uiAfterFunc {
PropertyRNA *rnaprop;
void *search_arg;
+ uiButSearchExecFn search_exec_fn;
uiButSearchArgFreeFn search_arg_free_fn;
+ const char *current_button_str;
bContextStore *context;
@@ -803,9 +805,11 @@ static void ui_apply_but_func(bContext *C, uiBut *but)
if (but->type == UI_BTYPE_SEARCH_MENU) {
uiButSearch *search_but = (uiButSearch *)but;
after->search_arg_free_fn = search_but->arg_free_fn;
+ after->search_exec_fn = search_but->exec_fn;
after->search_arg = search_but->arg;
search_but->arg_free_fn = NULL;
search_but->arg = NULL;
+ after->current_button_str = but->drawstr;
}
if (but->context) {
@@ -953,9 +957,14 @@ static void ui_apply_but_funcs_after(bContext *C)
if (after.func) {
after.func(C, after.func_arg1, after.func_arg2);
}
- if (after.funcN) {
- after.funcN(C, after.func_argN, after.func_arg2);
+ // if (after.funcN) {
+ // after.funcN(C, after.func_argN, after.func_arg2);
+ // }
+
+ if (after.search_exec_fn) {
+ after.search_exec_fn(C, after.func_argN, after.func_arg2, after.current_button_str);
}
+
if (after.func_argN) {
MEM_freeN(after.func_argN);
}
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index 4c96512b4f3..ddf17696717 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -308,6 +308,7 @@ typedef struct uiButSearch {
uiButSearchCreateFn popup_create_fn;
uiButSearchUpdateFn items_update_fn;
+ uiButSearchExecFn exec_fn;
void *item_active;
void *arg;
diff --git a/source/blender/editors/interface/interface_template_search_menu.c b/source/blender/editors/interface/interface_template_search_menu.c
index 91ad6619889..ee9751f4550 100644
--- a/source/blender/editors/interface/interface_template_search_menu.c
+++ b/source/blender/editors/interface/interface_template_search_menu.c
@@ -934,7 +934,10 @@ static void menu_search_arg_free_fn(void *data_v)
MEM_freeN(data);
}
-static void menu_search_exec_fn(bContext *C, void *UNUSED(arg1), void *arg2)
+static void menu_search_exec_fn(bContext *C,
+ void *UNUSED(arg1),
+ void *arg2,
+ const char *UNUSED(current_button_str))
{
struct MenuSearch_Item *item = arg2;
if (item == NULL) {
diff --git a/source/blender/editors/interface/interface_template_search_operator.c b/source/blender/editors/interface/interface_template_search_operator.c
index 2b765a1a2f5..0b840a75a36 100644
--- a/source/blender/editors/interface/interface_template_search_operator.c
+++ b/source/blender/editors/interface/interface_template_search_operator.c
@@ -47,7 +47,10 @@
/** \name Operator Search Template Implementation
* \{ */
-static void operator_search_exec_fn(bContext *C, void *UNUSED(arg1), void *arg2)
+static void operator_search_exec_fn(bContext *C,
+ void *UNUSED(arg1),
+ void *arg2,
+ const char *UNUSED(current_button_str))
{
wmOperatorType *ot = arg2;
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 760fbe75688..6f6d8f36eee 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -233,7 +233,7 @@ static uiBlock *template_common_search_menu(const bContext *C,
ARegion *region,
uiButSearchUpdateFn search_update_fn,
void *search_arg,
- uiButHandleFunc search_exec_fn,
+ uiButSearchExecFn search_exec_fn,
void *active_item,
uiButSearchTooltipFn item_tooltip_fn,
const int preview_rows,
@@ -345,7 +345,10 @@ typedef struct TemplateID {
} TemplateID;
/* Search browse menu, assign */
-static void template_ID_set_property_exec_fn(bContext *C, void *arg_template, void *item)
+static void template_ID_set_property_exec_fn(bContext *C,
+ void *arg_template,
+ void *item,
+ const char *UNUSED(current_button_str))
{
TemplateID *template_ui = (TemplateID *)arg_template;
@@ -1654,7 +1657,10 @@ typedef struct TemplateSearch {
int preview_rows, preview_cols;
} TemplateSearch;
-static void template_search_exec_fn(bContext *C, void *arg_template, void *item)
+static void template_search_exec_fn(bContext *C,
+ void *arg_template,
+ void *item,
+ const char *UNUSED(current_button_str))
{
TemplateSearch *template_search = arg_template;
uiRNACollectionSearch *coll_search = &template_search->search_data;
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 145c1659ac0..7422333bc72 100644
--- a/source/blender/editors/space_node/node_geometry_attribute_search.cc
+++ b/source/blender/editors/space_node/node_geometry_attribute_search.cc
@@ -100,14 +100,14 @@ static void attribute_search_update_fn(
/* Note that the attribute domain and data type are dummies, since
* #AvailableAttributeInfo equality is only based on the string. */
if (!attribute_hints.contains(AvailableAttributeInfo{str, ATTR_DOMAIN_AUTO, CD_PROP_BOOL})) {
- UI_search_item_add(items, str, (void *)str, ICON_ADD, 0, 0);
+ UI_search_item_add(items, str, nullptr, ICON_ADD, 0, 0);
}
}
if (str[0] == '\0' && !is_first) {
/* Allow clearing the text field when the string is empty, but not on the first pass,
* or opening an attribute field for the first time would show this search item. */
- UI_search_item_add(items, str, (void *)str, ICON_X, 0, 0);
+ UI_search_item_add(items, str, nullptr, ICON_X, 0, 0);
}
/* Don't filter when the menu is first opened, but still run the search
@@ -133,14 +133,22 @@ static void attribute_search_update_fn(
BLI_string_search_free(search);
}
-static void attribute_search_exec_fn(bContext *UNUSED(C), void *data_v, void *item_v)
+static void attribute_search_exec_fn(bContext *UNUSED(C),
+ void *data_v,
+ void *item_v,
+ const char *current_button_str)
{
AttributeSearchData *data = static_cast<AttributeSearchData *>(data_v);
AvailableAttributeInfo *item = static_cast<AvailableAttributeInfo *>(item_v);
bNodeSocket &socket = data->socket;
bNodeSocketValueString *value = static_cast<bNodeSocketValueString *>(socket.default_value);
- BLI_strncpy(value->value, item->name.c_str(), MAX_NAME);
+ if (item) {
+ BLI_strncpy(value->value, item->name.c_str(), MAX_NAME);
+ }
+ else {
+ BLI_strncpy(value->value, current_button_str, MAX_NAME);
+ }
}
void node_geometry_add_attribute_search_button(const bNodeTree *node_tree,
diff --git a/source/blender/editors/space_node/node_select.c b/source/blender/editors/space_node/node_select.c
index de63aa07acb..0260a4af7cb 100644
--- a/source/blender/editors/space_node/node_select.c
+++ b/source/blender/editors/space_node/node_select.c
@@ -1220,7 +1220,10 @@ static void node_find_update_fn(const struct bContext *C,
BLI_string_search_free(search);
}
-static void node_find_exec_fn(struct bContext *C, void *UNUSED(arg1), void *arg2)
+static void node_find_exec_fn(struct bContext *C,
+ void *UNUSED(arg1),
+ void *arg2,
+ const char *UNUSED(current_button_str))
{
SpaceNode *snode = CTX_wm_space_node(C);
bNode *active = arg2;
diff --git a/source/blender/editors/space_outliner/outliner_tools.c b/source/blender/editors/space_outliner/outliner_tools.c
index c7b46cd640b..600f7ba2fb5 100644
--- a/source/blender/editors/space_outliner/outliner_tools.c
+++ b/source/blender/editors/space_outliner/outliner_tools.c
@@ -568,7 +568,10 @@ static void merged_element_search_update_fn(const bContext *UNUSED(C),
}
/* Activate an element from the merged element search menu */
-static void merged_element_search_exec_fn(struct bContext *C, void *UNUSED(arg1), void *element)
+static void merged_element_search_exec_fn(struct bContext *C,
+ void *UNUSED(arg1),
+ void *element,
+ const char *UNUSED(current_button_str))
{
SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
TreeElement *te = (TreeElement *)element;
Event Timeline
Hans Goudey (HooglyBoogly)
created this paste.
Apr 13 2021, 6:04 PM
Hans Goudey (HooglyBoogly)
changed the title of this paste from
Command-Line Input
to
UI code hack for D10623 part 2
.
Apr 13 2021, 6:04 PM
Hans Goudey (HooglyBoogly)
mentioned this in
D10623: Geometry Nodes: Add domain and data type to attribute search
.
Apr 13 2021, 6:40 PM
Log In to Comment