UI: Show categories in operator search popup
authorCampbell Barton <ideasman42@gmail.com>
Wed, 2 Mar 2016 03:05:49 +0000 (14:05 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 2 Mar 2016 03:09:16 +0000 (14:09 +1100)
Gives better context especially when operators have generic names.

source/blender/editors/interface/interface.c
source/blender/editors/interface/interface_intern.h
source/blender/editors/interface/interface_regions.c
source/blender/editors/interface/interface_templates.c
source/blender/windowmanager/intern/wm_operators.c

index 32c9177fafe837cbba3a17c09034c871d29fb0fe..ddd78308a4419d4cb9ef6a061a53c786cc505135 100644 (file)
@@ -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;
index 99656b89ee219954ba83daebca12a6a8c6718cdc..90aeee7aa50131c9a4b7111050769feb9a133326 100644 (file)
@@ -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);
index 2a309fc126ccc27a7b914a3c04c086e05a9862ff..4a3500e72defcb9b1e4a834ad058243ae6ac07d2 100644 (file)
@@ -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);
index 079205b4f0d2563a1063bdb0dc8db9c904f7fe33..af3080d39c4147a270d0e0e728efc4995bba1404 100644 (file)
@@ -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);
 }
 
index 16f12d41b068eca5a7ba39fc65ce0b73cbf4275b..179677a0cb1fd24b6d4ffc139b1df2a1192d9e4b 100644 (file)
@@ -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(),
                },
        };