diff options
author | Campbell Barton <ideasman42@gmail.com> | 2016-03-02 06:05:49 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2016-03-02 06:09:16 +0300 |
commit | d49985ce488f7d734ae727379e5bb4569a9dc700 (patch) | |
tree | 37cc50f9e1be0e69e9b08d58fe08f17aada7ba2b /source/blender | |
parent | 69b66d549bcc82b5667916e647d43578bada5dd2 (diff) |
UI: Show categories in operator search popup
Gives better context especially when operators have generic names.
Diffstat (limited to 'source/blender')
5 files changed, 108 insertions, 3 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 32c9177fafe..ddd78308a44 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -4411,7 +4411,7 @@ uiBut *uiDefSearchButO_ptr( but = uiDefSearchBut(block, arg, retval, icon, maxlen, x, y, width, height, a1, a2, tip); UI_but_func_search_set( - but, ui_searchbox_create_generic, operator_enum_search_cb, + but, ui_searchbox_create_operator, operator_enum_search_cb, but, operator_enum_call_cb, NULL); but->optype = ot; diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index 99656b89ee2..90aeee7aa50 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -593,6 +593,7 @@ void ui_color_picker_to_rgb(float r_cp0, float r_cp1, float r_cp2, float *r, flo /* searchbox for string button */ ARegion *ui_searchbox_create_generic(struct bContext *C, struct ARegion *butregion, uiBut *but); +ARegion *ui_searchbox_create_operator(struct bContext *C, struct ARegion *butregion, uiBut *but); bool ui_searchbox_inside(struct ARegion *ar, int x, int y); int ui_searchbox_find_index(struct ARegion *ar, const char *name); void ui_searchbox_update(struct bContext *C, struct ARegion *ar, uiBut *but, const bool reset); diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index 2a309fc126c..4a3500e72de 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -1328,6 +1328,110 @@ ARegion *ui_searchbox_create_generic(bContext *C, ARegion *butregion, uiBut *but return ar; } +/** + * Similar to Python's `str.title` except... + * + * - we know words are upper case and ascii only. + * - '_' are replaces by spaces. + */ +static void str_tolower_titlecaps_ascii(char *str, const size_t len) +{ + size_t i; + bool prev_delim = true; + + for (i = 0; (i < len) && str[i]; i++) { + if (str[i] >= 'A' && str[i] <= 'Z') { + if (prev_delim == false) { + str[i] += 'a' - 'A'; + } + } + else if (str[i] == '_') { + str[i] = ' '; + } + + prev_delim = ELEM(str[i], ' ') || (str[i] >= '0' && str[i] <= '9'); + } + +} + +static void ui_searchbox_region_draw_cb__operator(const bContext *UNUSED(C), ARegion *ar) +{ + uiSearchboxData *data = ar->regiondata; + + /* pixel space */ + wmOrtho2_region_pixelspace(ar); + + if (data->noback == false) + ui_draw_search_back(NULL, NULL, &data->bbox); /* style not used yet */ + + /* draw text */ + if (data->items.totitem) { + rcti rect; + int a; + + /* draw items */ + for (a = 0; a < data->items.totitem; a++) { + rcti rect_pre, rect_post; + ui_searchbox_butrect(&rect, data, a); + + rect_pre = rect; + rect_post = rect; + + rect_pre.xmax = rect_post.xmin = rect.xmin + ((rect.xmax - rect.xmin) / 4); + + /* widget itself */ + { + wmOperatorType *ot = data->items.pointers[a]; + + int state = (a == data->active) ? UI_ACTIVE : 0; + char text_pre[128]; + char *text_pre_p = strstr(ot->idname, "_OT_"); + if (text_pre_p == NULL) { + text_pre[0] = '\0'; + } + else { + int text_pre_len; + text_pre_p += 1; + text_pre_len = BLI_strncpy_rlen( + text_pre, ot->idname, min_ii(sizeof(text_pre), text_pre_p - ot->idname)); + text_pre[text_pre_len] = ':'; + text_pre[text_pre_len + 1] = '\0'; + str_tolower_titlecaps_ascii(text_pre, sizeof(text_pre)); + } + + rect_pre.xmax += 4; /* sneaky, avoid showing ugly margin */ + ui_draw_menu_item(&data->fstyle, &rect_pre, text_pre, data->items.icons[a], state, false); + ui_draw_menu_item(&data->fstyle, &rect_post, data->items.names[a], 0, state, data->use_sep); + } + + } + /* indicate more */ + if (data->items.more) { + ui_searchbox_butrect(&rect, data, data->items.maxitem - 1); + glEnable(GL_BLEND); + UI_icon_draw((BLI_rcti_size_x(&rect)) / 2, rect.ymin - 9, ICON_TRIA_DOWN); + glDisable(GL_BLEND); + } + if (data->items.offset) { + ui_searchbox_butrect(&rect, data, 0); + glEnable(GL_BLEND); + UI_icon_draw((BLI_rcti_size_x(&rect)) / 2, rect.ymax - 7, ICON_TRIA_UP); + glDisable(GL_BLEND); + } + } +} + +ARegion *ui_searchbox_create_operator(bContext *C, ARegion *butregion, uiBut *but) +{ + ARegion *ar; + + ar = ui_searchbox_create_generic(C, butregion, but); + + ar->type->draw = ui_searchbox_region_draw_cb__operator; + + return ar; +} + void ui_searchbox_free(bContext *C, ARegion *ar) { ui_region_temp_remove(C, CTX_wm_screen(C), ar); diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 079205b4f0d..af3080d39c4 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -3308,7 +3308,7 @@ static void operator_search_cb(const bContext *C, void *UNUSED(arg), const char void UI_but_func_operator_search(uiBut *but) { UI_but_func_search_set( - but, ui_searchbox_create_generic, operator_search_cb, + but, ui_searchbox_create_operator, operator_search_cb, NULL, operator_call_cb, NULL); } diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 16f12d41b06..179677a0cb1 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -1945,7 +1945,7 @@ static int wm_search_menu_invoke(bContext *C, wmOperator *UNUSED(op), const wmEv { struct SearchPopupInit_Data data = { .size = { - UI_searchbox_size_x(), + UI_searchbox_size_x() * 2, UI_searchbox_size_y(), }, }; |