[Bf-blender-cvs] [2a515fe6124] temp-ui-button-type-refactor: Store search item in search-button data, don't reuse general void pointer
Julian Eisel
noreply at git.blender.org
Sun Jun 7 23:29:50 CEST 2020
Commit: 2a515fe61244b3837fc77e5dfe9870ee6d934dfb
Author: Julian Eisel
Date: Sun Jun 7 21:38:12 2020 +0200
Branches: temp-ui-button-type-refactor
https://developer.blender.org/rB2a515fe61244b3837fc77e5dfe9870ee6d934dfb
Store search item in search-button data, don't reuse general void pointer
Rather than re-using the `uiBut.func_arg2` pointer to reference the active
search item, have an own pointer for that in `uiButSearch`.
Unfortunately, we still need to pass the reference as `arg2` to the
`uiBut.func` callback. But we don't need to keep `uiBut.func_arg2` set the
entire time for that.
===================================================================
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
===================================================================
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 8bc78535964..e640824a1b7 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -2962,10 +2962,10 @@ bool ui_but_string_set(bContext *C, uiBut *but, const char *str)
&search_but->rnasearchpoin, search_but->rnasearchprop, str, &rptr)) {
RNA_property_pointer_set(&but->rnapoin, but->rnaprop, rptr, NULL);
}
- else if (but->func_arg2 != NULL) {
+ else if (search_but->item_active != NULL) {
RNA_pointer_create(NULL,
RNA_property_pointer_type(&but->rnapoin, but->rnaprop),
- but->func_arg2,
+ search_but->item_active,
&rptr);
RNA_property_pointer_set(&but->rnapoin, but->rnaprop, rptr, NULL);
}
@@ -6496,6 +6496,7 @@ void UI_but_func_search_set(uiBut *but,
search_but->popup_create_fn = search_create_fn;
search_but->items_update_fn = search_update_fn;
+ search_but->item_active = active;
search_but->arg = arg;
search_but->arg_free_fn = search_arg_free_fn;
@@ -6508,7 +6509,8 @@ void UI_but_func_search_set(uiBut *but,
__func__);
}
#endif
- UI_but_func_set(but, search_exec_fn, search_but->arg, active);
+ /* Handling will pass the active item as arg2 later, so keep it NULL here. */
+ UI_but_func_set(but, search_exec_fn, search_but->arg, NULL);
}
/* search buttons show red-alert if item doesn't exist, not for menus */
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 981a4bbeb94..f9497e01bab 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -1037,8 +1037,19 @@ static void ui_apply_but_TEX(bContext *C, uiBut *but, uiHandleButtonData *data)
but->rename_orig = data->origstr;
data->origstr = NULL;
}
+
+ void *orig_arg2 = but->func_arg2;
+
+ /* If arg2 isn't in use already, pass the active search item through it. */
+ if ((but->func_arg2 == NULL) && (but->type == UI_BTYPE_SEARCH_MENU)) {
+ uiButSearch *search_but = (uiButSearch *)but;
+ but->func_arg2 = search_but->item_active;
+ }
+
ui_apply_but_func(C, but);
+ but->func_arg2 = orig_arg2;
+
data->retval = but->retval;
data->applied = true;
}
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index 45f68464eaf..667f6a2fb04 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -293,6 +293,7 @@ typedef struct uiButSearch {
uiButSearchCreateFn popup_create_fn;
uiButSearchUpdateFn items_update_fn;
+ void *item_active;
void *arg;
uiButSearchArgFreeFn arg_free_fn;
diff --git a/source/blender/editors/interface/interface_region_search.c b/source/blender/editors/interface/interface_region_search.c
index bcef932a216..b447aef78f3 100644
--- a/source/blender/editors/interface/interface_region_search.c
+++ b/source/blender/editors/interface/interface_region_search.c
@@ -272,8 +272,11 @@ bool ui_searchbox_inside(ARegion *region, int x, int y)
bool ui_searchbox_apply(uiBut *but, ARegion *region)
{
uiSearchboxData *data = region->regiondata;
+ uiButSearch *search_but = (uiButSearch *)but;
+
+ BLI_assert(but->type == UI_BTYPE_SEARCH_MENU);
- but->func_arg2 = NULL;
+ search_but->item_active = NULL;
if (data->active != -1) {
const char *name = data->items.names[data->active];
@@ -281,7 +284,7 @@ bool ui_searchbox_apply(uiBut *but, ARegion *region)
BLI_strncpy(but->editstr, name, name_sep ? (name_sep - name) : data->items.maxstrlen);
- but->func_arg2 = data->items.pointers[data->active];
+ search_but->item_active = data->items.pointers[data->active];
return true;
}
@@ -313,7 +316,7 @@ static struct ARegion *wm_searchbox_tooltip_init(struct bContext *C,
uiButSearch *search_but = (uiButSearch *)but;
if (search_but->item_tooltip_fn) {
- return search_but->item_tooltip_fn(C, region, search_but->arg, but->func_arg2);
+ return search_but->item_tooltip_fn(C, region, search_but->arg, search_but->item_active);
}
}
}
@@ -392,7 +395,7 @@ bool ui_searchbox_event(
if (is_inside) {
if (data->active != -1) {
ScrArea *area = CTX_wm_area(C);
- but->func_arg2 = data->items.pointers[data->active];
+ search_but->item_active = data->items.pointers[data->active];
WM_tooltip_timer_init(C, CTX_wm_window(C), area, butregion, wm_searchbox_tooltip_init);
tooltip_timer_started = true;
}
@@ -441,8 +444,8 @@ void ui_searchbox_update(bContext *C, ARegion *region, uiBut *but, const bool re
data->active = -1;
/* handle active */
- if (search_but->items_update_fn && but->func_arg2) {
- data->items.active = but->func_arg2;
+ if (search_but->items_update_fn && search_but->item_active) {
+ data->items.active = search_but->item_active;
ui_searchbox_update_fn(C, search_but, but->editstr, &data->items);
data->items.active = NULL;
More information about the Bf-blender-cvs
mailing list