From 3bb7e14618cb928d43fecf0a8930a1edd85dde3e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 24 Mar 2015 15:05:27 +1100 Subject: UI: remove UI_BTYPE_SEARCH_MENU_UNLINK Internal change only, use UI_BTYPE_SEARCH_MENU with an unlink flag instead. They are really the same button type, one just happens to have the option to unlink. --- source/blender/editors/include/UI_interface.h | 2 +- source/blender/editors/interface/interface.c | 13 ++++--- .../blender/editors/interface/interface_handlers.c | 41 +++++++++++++--------- .../blender/editors/interface/interface_layout.c | 5 ++- .../blender/editors/interface/interface_regions.c | 6 ++-- .../blender/editors/interface/interface_widgets.c | 7 ++-- 6 files changed, 41 insertions(+), 33 deletions(-) (limited to 'source') diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 4542627277a..02ae098dc2e 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -185,6 +185,7 @@ enum { UI_BUT_HAS_SEP_CHAR = (1 << 27), /* but->str contains UI_SEP_CHAR, used for key shortcuts */ UI_BUT_TIP_FORCE = (1 << 28), /* force show tooltips when holding option/alt if U's USER_TOOLTIPS is off */ UI_BUT_TEXTEDIT_UPDATE = (1 << 29), /* when widget is in textedit mode, update value on each char stroke */ + UI_BUT_SEARCH_UNLINK = (1 << 30), /* show unlink for search button */ }; #define UI_PANEL_WIDTH 340 @@ -279,7 +280,6 @@ typedef enum { UI_BTYPE_WAVEFORM = (49 << 9), UI_BTYPE_VECTORSCOPE = (50 << 9), UI_BTYPE_PROGRESS_BAR = (51 << 9), - UI_BTYPE_SEARCH_MENU_UNLINK = (52 << 9), UI_BTYPE_NODE_SOCKET = (53 << 9), UI_BTYPE_SEPR = (54 << 9), UI_BTYPE_SEPR_LINE = (55 << 9), diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 48a7cf4ecf3..5714a40d508 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -1930,7 +1930,7 @@ void ui_but_value_set(uiBut *but, double value) int ui_but_string_get_max_length(uiBut *but) { - if (ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU, UI_BTYPE_SEARCH_MENU_UNLINK)) + if (ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU)) return but->hardmax; else return UI_MAX_DRAW_STR; @@ -2031,7 +2031,7 @@ static float ui_get_but_step_unit(uiBut *but, float step_default) */ void ui_but_string_get_ex(uiBut *but, char *str, const size_t maxlen, const int float_precision) { - if (but->rnaprop && ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU, UI_BTYPE_SEARCH_MENU_UNLINK)) { + if (but->rnaprop && ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU)) { PropertyType type; const char *buf = NULL; int buf_len; @@ -2073,7 +2073,7 @@ void ui_but_string_get_ex(uiBut *but, char *str, const size_t maxlen, const int BLI_strncpy(str, but->poin, maxlen); return; } - else if (ELEM(but->type, UI_BTYPE_SEARCH_MENU, UI_BTYPE_SEARCH_MENU_UNLINK)) { + else if (but->type == UI_BTYPE_SEARCH_MENU) { /* string */ BLI_strncpy(str, but->poin, maxlen); return; @@ -2194,7 +2194,7 @@ static void ui_but_string_free_internal(uiBut *but) bool ui_but_string_set(bContext *C, uiBut *but, const char *str) { - if (but->rnaprop && ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU, UI_BTYPE_SEARCH_MENU_UNLINK)) { + if (but->rnaprop && ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU)) { if (RNA_property_editable(&but->rnapoin, but->rnaprop)) { PropertyType type; @@ -2246,7 +2246,7 @@ bool ui_but_string_set(bContext *C, uiBut *but, const char *str) return true; } - else if (ELEM(but->type, UI_BTYPE_SEARCH_MENU, UI_BTYPE_SEARCH_MENU_UNLINK)) { + else if (but->type == UI_BTYPE_SEARCH_MENU) { /* string */ BLI_strncpy(but->poin, str, but->hardmax); return true; @@ -2754,7 +2754,6 @@ void ui_but_update(uiBut *but) case UI_BTYPE_TEXT: case UI_BTYPE_SEARCH_MENU: - case UI_BTYPE_SEARCH_MENU_UNLINK: if (!but->editstr) { char str[UI_MAX_DRAW_STR]; @@ -3139,7 +3138,7 @@ static uiBut *ui_def_but(uiBlock *block, int type, int retval, const char *str, ELEM(but->type, UI_BTYPE_MENU, UI_BTYPE_TEXT, UI_BTYPE_LABEL, UI_BTYPE_BLOCK, UI_BTYPE_BUT_MENU, UI_BTYPE_SEARCH_MENU, - UI_BTYPE_PROGRESS_BAR, UI_BTYPE_SEARCH_MENU_UNLINK)) + UI_BTYPE_PROGRESS_BAR)) { but->drawflag |= (UI_BUT_TEXT_LEFT | UI_BUT_ICON_LEFT); } diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 68a69c4cd4e..dc8018cd11e 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -413,7 +413,7 @@ bool ui_but_is_editable_as_text(const uiBut *but) { return ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_NUM, UI_BTYPE_NUM_SLIDER, - UI_BTYPE_SEARCH_MENU, UI_BTYPE_SEARCH_MENU_UNLINK); + UI_BTYPE_SEARCH_MENU); } @@ -1629,7 +1629,6 @@ static void ui_apply_but(bContext *C, uiBlock *block, uiBut *but, uiHandleButton ui_apply_but_BUT(C, but, data); break; case UI_BTYPE_TEXT: - case UI_BTYPE_SEARCH_MENU_UNLINK: case UI_BTYPE_SEARCH_MENU: ui_apply_but_TEX(C, but, data); break; @@ -1732,13 +1731,13 @@ static void ui_but_drop(bContext *C, const wmEvent *event, uiBut *but, uiHandleB for (wmd = drags->first; wmd; wmd = wmd->next) { if (wmd->type == WM_DRAG_ID) { /* align these types with UI_but_active_drop_name */ - if (ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU, UI_BTYPE_SEARCH_MENU_UNLINK)) { + if (ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU)) { ID *id = (ID *)wmd->poin; button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING); BLI_strncpy(data->str, id->name + 2, data->maxlen); - if (ELEM(but->type, UI_BTYPE_SEARCH_MENU, UI_BTYPE_SEARCH_MENU_UNLINK)) { + if (ELEM(but->type, UI_BTYPE_SEARCH_MENU)) { but->changed = true; ui_searchbox_update(C, data->searchbox, but, true); } @@ -1879,7 +1878,7 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data, } /* text/string and ID data */ - else if (ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU, UI_BTYPE_SEARCH_MENU_UNLINK)) { + else if (ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU)) { uiHandleButtonData *active_data = but->active; if (but->poin == NULL && but->rnapoin.data == NULL) { @@ -1899,7 +1898,7 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data, else BLI_strncpy(active_data->str, buf_paste, active_data->maxlen); - if (ELEM(but->type, UI_BTYPE_SEARCH_MENU, UI_BTYPE_SEARCH_MENU_UNLINK)) { + if (but->type == UI_BTYPE_SEARCH_MENU) { /* else uiSearchboxData.active member is not updated [#26856] */ but->changed = true; ui_searchbox_update(C, data->searchbox, but, true); @@ -2092,7 +2091,7 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, con BLI_strncpy(origstr, but->editstr, data->maxlen); - if (ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU, UI_BTYPE_SEARCH_MENU_UNLINK)) { + if (ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU)) { if (but->flag & UI_HAS_ICON) { startx += UI_DPI_ICON_SIZE / aspect; } @@ -2539,7 +2538,7 @@ static void ui_textedit_begin(bContext *C, uiBut *but, uiHandleButtonData *data) but->selend = len; /* optional searchbox */ - if (ELEM(but->type, UI_BTYPE_SEARCH_MENU, UI_BTYPE_SEARCH_MENU_UNLINK)) { + if (but->type == UI_BTYPE_SEARCH_MENU) { data->searchbox = ui_searchbox_create(C, data->region, but); ui_searchbox_update(C, data->searchbox, but, true); /* true = reset */ } @@ -6331,7 +6330,9 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent * WM_operator_name_call(C, "UI_OT_eyedropper_color", WM_OP_INVOKE_DEFAULT, NULL); return WM_UI_HANDLER_BREAK; } - else if (but->type == UI_BTYPE_SEARCH_MENU_UNLINK) { + else if ((but->type == UI_BTYPE_SEARCH_MENU) && + (but->flag & UI_BUT_SEARCH_UNLINK)) + { if (but->rnaprop && RNA_property_type(but->rnaprop) == PROP_POINTER) { StructRNA *type = RNA_property_pointer_type(&but->rnapoin, but->rnaprop); const short idcode = RNA_type_to_ID_code(type); @@ -6488,11 +6489,16 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent * break; case UI_BTYPE_TEXT: case UI_BTYPE_SEARCH_MENU: + if ((but->type == UI_BTYPE_SEARCH_MENU) && + (but->flag & UI_BUT_SEARCH_UNLINK)) + { + retval = ui_do_but_SEARCH_UNLINK(C, block, but, data, event); + if (retval & WM_UI_HANDLER_BREAK) { + break; + } + } retval = ui_do_but_TEX(C, block, but, data, event); break; - case UI_BTYPE_SEARCH_MENU_UNLINK: - retval = ui_do_but_SEARCH_UNLINK(C, block, but, data, event); - break; case UI_BTYPE_MENU: case UI_BTYPE_BLOCK: case UI_BTYPE_PULLDOWN: @@ -6731,7 +6737,7 @@ bool UI_but_active_drop_name(bContext *C) uiBut *but = ui_but_find_active_in_region(ar); if (but) { - if (ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU, UI_BTYPE_SEARCH_MENU_UNLINK)) + if (ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU)) return 1; } @@ -6848,9 +6854,10 @@ static bool ui_but_is_interactive(const uiBut *but, const bool labeledit) bool ui_but_is_search_unlink_visible(const uiBut *but) { - BLI_assert(but->type == UI_BTYPE_SEARCH_MENU_UNLINK); + BLI_assert(but->type == UI_BTYPE_SEARCH_MENU); return ((but->editstr == NULL) && - (but->drawstr[0] != '\0')); + (but->drawstr[0] != '\0') && + (but->flag & UI_BUT_SEARCH_UNLINK)); } /* x and y are only used in case event is NULL... */ @@ -7131,7 +7138,7 @@ static void button_activate_init(bContext *C, ARegion *ar, uiBut *but, uiButtonA copy_v2_fl(data->ungrab_mval, FLT_MAX); #endif - if (ELEM(but->type, UI_BTYPE_CURVE, UI_BTYPE_SEARCH_MENU, UI_BTYPE_SEARCH_MENU_UNLINK)) { + if (ELEM(but->type, UI_BTYPE_CURVE, UI_BTYPE_SEARCH_MENU)) { /* XXX curve is temp */ } else { @@ -9106,7 +9113,7 @@ static int ui_handle_menus_recursive( /* now handle events for our own menu */ if (retval == WM_UI_HANDLER_CONTINUE || event->type == TIMER) { - const bool do_but_search = (but && ELEM(but->type, UI_BTYPE_SEARCH_MENU, UI_BTYPE_SEARCH_MENU_UNLINK)); + const bool do_but_search = (but && (but->type == UI_BTYPE_SEARCH_MENU)); if (submenu && submenu->menuretval) { const bool do_ret_out_parent = (submenu->menuretval & UI_RETURN_OUT_PARENT) != 0; retval = ui_handle_menu_return_submenu(C, event, menu); diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index 44c1ed474d5..eeda7a2c390 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -1573,11 +1573,14 @@ void ui_but_add_search(uiBut *but, PointerRNA *ptr, PropertyRNA *prop, PointerRN /* turn button into search button */ if (searchprop) { - but->type = RNA_property_is_unlink(prop) ? UI_BTYPE_SEARCH_MENU_UNLINK : UI_BTYPE_SEARCH_MENU; + but->type = UI_BTYPE_SEARCH_MENU; but->hardmax = MAX2(but->hardmax, 256.0f); but->rnasearchpoin = *searchptr; but->rnasearchprop = searchprop; but->drawflag |= UI_BUT_ICON_LEFT | UI_BUT_TEXT_LEFT; + if (RNA_property_is_unlink(prop)) { + but->flag |= UI_BUT_SEARCH_UNLINK; + } if (RNA_property_type(prop) == PROP_ENUM) { /* XXX, this will have a menu string, diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index 8d7330c4dd7..7cb9dca78bf 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -394,7 +394,7 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but) data->totline++; } - if (ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU, UI_BTYPE_SEARCH_MENU_UNLINK)) { + if (ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU)) { /* better not show the value of a password */ if ((but->rnaprop && (RNA_property_subtype(but->rnaprop) == PROP_PASSWORD)) == 0) { /* full string */ @@ -815,7 +815,7 @@ static void ui_searchbox_select(bContext *C, ARegion *ar, uiBut *but, int step) } else { /* only let users step into an 'unset' state for unlink buttons */ - data->active = (but->type == UI_BTYPE_SEARCH_MENU_UNLINK) ? -1 : 0; + data->active = (but->flag & UI_BUT_SEARCH_UNLINK) ? -1 : 0; } } @@ -886,7 +886,7 @@ bool ui_searchbox_apply(uiBut *but, ARegion *ar) return true; } - else if (but->type == UI_BTYPE_SEARCH_MENU_UNLINK) { + else if (but->flag & UI_BUT_SEARCH_UNLINK) { /* It is valid for _UNLINK flavor to have no active element (it's a valid way to unlink). */ but->editstr[0] = '\0'; diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index 0b3684ff755..d95e9035207 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -873,7 +873,7 @@ static void widget_draw_icon(const uiBut *but, BIFIconID icon, float alpha, cons if (but->drawflag & UI_BUT_ICON_LEFT) { if (but->block->flag & UI_BLOCK_LOOP) { - if (ELEM(but->type, UI_BTYPE_SEARCH_MENU, UI_BTYPE_SEARCH_MENU_UNLINK)) + if (but->type == UI_BTYPE_SEARCH_MENU) xs = rect->xmin + 4.0f * ofs; else xs = rect->xmin + ofs; @@ -1542,7 +1542,7 @@ static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiB } /* unlink icon for this button type */ - if ((but->type == UI_BTYPE_SEARCH_MENU_UNLINK) && ui_but_is_search_unlink_visible(but)) { + if ((but->type == UI_BTYPE_SEARCH_MENU) && ui_but_is_search_unlink_visible(but)) { rcti temp = *rect; temp.xmin = temp.xmax - (BLI_rcti_size_y(rect) * 1.08f); @@ -3651,8 +3651,7 @@ void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rct case UI_BTYPE_TEXT: wt = widget_type(UI_WTYPE_NAME); break; - - case UI_BTYPE_SEARCH_MENU_UNLINK: + case UI_BTYPE_SEARCH_MENU: wt = widget_type(UI_WTYPE_NAME); if (but->block->flag & UI_BLOCK_LOOP) -- cgit v1.2.3