2.5
authorTon Roosendaal <ton@blender.org>
Mon, 29 Jun 2009 11:29:52 +0000 (11:29 +0000)
committerTon Roosendaal <ton@blender.org>
Mon, 29 Jun 2009 11:29:52 +0000 (11:29 +0000)
Search Menu: added feature that on opening, it shows the
current ID block, and selects it. Same can be used for other
searches, just pass on pointer to active item for the search
callback.

Also fixed arrow triangle draw for search.

source/blender/editors/include/UI_interface.h
source/blender/editors/interface/interface.c
source/blender/editors/interface/interface_layout.c
source/blender/editors/interface/interface_regions.c
source/blender/editors/interface/interface_templates.c
source/blender/editors/interface/interface_utils.c
source/blender/editors/space_info/info_header.c
source/blender/editors/space_view3d/view3d_toolbar.c

index b6d7175937380a27a74abe8b4b356b21a8d4d1ba..333536137cc8a50093e70d8ace8c03401efed8d2 100644 (file)
@@ -456,7 +456,7 @@ typedef void (*uiBlockHandleFunc)(struct bContext *C, void *arg, int event);
                /* use inside searchfunc to add items */
 int            uiSearchItemAdd(uiSearchItems *items, const char *name, void *poin, int iconid);
                /* bfunc gets search item *poin as arg2, or if NULL the old string */
-void   uiButSetSearchFunc      (uiBut *but,            uiButSearchFunc sfunc, void *arg1, uiButHandleFunc bfunc);
+void   uiButSetSearchFunc      (uiBut *but,            uiButSearchFunc sfunc, void *arg1, uiButHandleFunc bfunc, void *active);
                /* height in pixels, it's using hardcoded values still */
 int            uiSearchBoxhHeight(void);
 
index a9866d8898e4021ec34c9fee85081440ca0005e5..fcea74cc22bbb22622dbfa7cd8d8f1a126bdcbba 100644 (file)
@@ -2919,15 +2919,15 @@ uiBut *uiDefSearchBut(uiBlock *block, void *arg, int retval, int icon, int maxle
 }
 
 /* arg is user value, searchfunc and handlefunc both get it as arg */
-void uiButSetSearchFunc(uiBut *but, uiButSearchFunc sfunc, void *arg, uiButHandleFunc bfunc)
+/* if active set, button opens with this item visible and selected */
+void uiButSetSearchFunc(uiBut *but, uiButSearchFunc sfunc, void *arg, uiButHandleFunc bfunc, void *active)
 {
        but->search_func= sfunc;
        but->search_arg= arg;
        
-       uiButSetFunc(but, bfunc, arg, NULL);
+       uiButSetFunc(but, bfunc, arg, active);
 }
 
-
 /* Program Init/Exit */
 
 void UI_init(void)
index 94280ec37d36d11aa51f5af12a44360364ae4b14..f9816235b88e993cd866ba0086dc018c37f64d61 100644 (file)
@@ -936,7 +936,7 @@ void ui_but_add_search(uiBut *but, PointerRNA *ptr, PropertyRNA *prop, PointerRN
                but->rnasearchprop= searchprop;
                but->flag |= UI_ICON_LEFT|UI_TEXT_LEFT;
 
-               uiButSetSearchFunc(but, rna_search_cb, but, NULL);
+               uiButSetSearchFunc(but, rna_search_cb, but, NULL, NULL);
        }
 }
 
index 61cf612e912354452e3da535057fb28d4db3ef52..49e3abf4d0c0a6ce9257e5dc88e884be64f81464 100644 (file)
@@ -437,6 +437,7 @@ struct uiSearchItems {
        int *icons;
 
        AutoComplete *autocpl;
+       void *active;
 };
 
 typedef struct uiSearchboxData {
@@ -459,6 +460,14 @@ int uiSearchItemAdd(uiSearchItems *items, const char *name, void *poin, int icon
                return 1;
        }
        
+       /* hijack for finding active item */
+       if(items->active) {
+               if(poin==items->active)
+                       items->offset_i= items->totitem;
+               items->totitem++;
+               return 1;
+       }
+       
        if(items->totitem>=items->maxitem) {
                items->more= 1;
                return 0;
@@ -597,20 +606,52 @@ void ui_searchbox_update(bContext *C, ARegion *ar, uiBut *but, int reset)
        /* reset vars */
        data->items.totitem= 0;
        data->items.more= 0;
-       if(reset==0)
+       if(reset==0) {
                data->items.offset_i= data->items.offset;
+       }
        else {
                data->items.offset_i= data->items.offset= 0;
                data->active= 0;
+               
+               /* handle active */
+               if(but->search_func && but->func_arg2) {
+                       data->items.active= but->func_arg2;
+                       but->search_func(C, but->search_arg, but->editstr, &data->items);
+                       data->items.active= NULL;
+                       
+                       /* found active item, calculate real offset by centering it */
+                       if(data->items.totitem) {
+                               /* first case, begin of list */
+                               if(data->items.offset_i < data->items.maxitem) {
+                                       data->active= data->items.offset_i+1;
+                                       data->items.offset_i= 0;
+                               }
+                               else {
+                                       /* second case, end of list */
+                                       if(data->items.totitem - data->items.offset_i <= data->items.maxitem) {
+                                               data->active= 1 + data->items.offset_i - data->items.totitem + data->items.maxitem;
+                                               data->items.offset_i= data->items.totitem - data->items.maxitem;
+                                       }
+                                       else {
+                                               /* center active item */
+                                               data->items.offset_i -= data->items.maxitem/2;
+                                               data->active= 1 + data->items.maxitem/2;
+                                       }
+                               }
+                       }
+                       data->items.offset= data->items.offset_i;
+                       data->items.totitem= 0;
+               }
        }
        
        /* callback */
        if(but->search_func)
                but->search_func(C, but->search_arg, but->editstr, &data->items);
        
-       if(reset) {
+       /* handle case where editstr is equal to one of items */
+       if(reset && data->active==0) {
                int a;
-               /* handle case where editstr is equal to one of items */
+               
                for(a=0; a<data->items.totitem; a++) {
                        char *cpoin= strchr(data->items.names[a], '|');
                        
@@ -666,13 +707,15 @@ static void ui_searchbox_region_draw(const bContext *C, ARegion *ar)
                }
                /* indicate more */
                if(data->items.more) {
+                       ui_searchbox_butrect(&rect, data, data->items.maxitem-1);
                        glEnable(GL_BLEND);
-                       UI_icon_draw((data->bbox.xmax-data->bbox.xmin)/2, 8, ICON_TRIA_DOWN);
+                       UI_icon_draw((rect.xmax-rect.xmin)/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((data->bbox.xmax-data->bbox.xmin)/2, data->bbox.ymax-13, ICON_TRIA_UP);
+                       UI_icon_draw((rect.xmax-rect.xmin)/2, rect.ymax-7, ICON_TRIA_UP);
                        glDisable(GL_BLEND);
                }
        }
index a006187c4aa78f5d92a06e8be9605b286ba459c5..b128da7b97fce75d90b4d4f57b6041850bd985eb 100644 (file)
@@ -112,6 +112,7 @@ static uiBlock *search_menu(bContext *C, ARegion *ar, void *arg_litem)
 {
        static char search[256];
        static TemplateID template;
+       PointerRNA idptr;
        wmEvent event;
        wmWindow *win= CTX_wm_window(C);
        uiBlock *block;
@@ -122,6 +123,9 @@ static uiBlock *search_menu(bContext *C, ARegion *ar, void *arg_litem)
        /* arg_litem is malloced, can be freed by parent button */
        template= *((TemplateID*)arg_litem);
        
+       /* get active id for showing first item */
+       idptr= RNA_property_pointer_get(&template.ptr, template.prop);
+
        block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
        uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_RET_1);
        
@@ -129,7 +133,7 @@ static uiBlock *search_menu(bContext *C, ARegion *ar, void *arg_litem)
        uiDefBut(block, LABEL, 0, "", 10, 15, 150, uiSearchBoxhHeight(), NULL, 0, 0, 0, 0, NULL);
        
        but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, 256, 10, 0, 150, 19, "");
-       uiButSetSearchFunc(but, id_search_cb, &template, id_search_call_cb);
+       uiButSetSearchFunc(but, id_search_cb, &template, id_search_call_cb, idptr.data);
        
        uiBoundsBlock(block, 6);
        uiBlockSetDirection(block, UI_DOWN);    
index 3ed81a3e9bcd9288d8a831fff469bb6518ddda8d..eb79848d7d21c3e6362deefecb5cea5071864b2e 100644 (file)
@@ -327,7 +327,7 @@ static uiBlock *id_search_menu(bContext *C, ARegion *ar, void *arg_params)
        uiDefBut(block, LABEL, 0, "", 10, 15, 150, uiSearchBoxhHeight(), NULL, 0, 0, 0, 0, NULL);
        
        but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, 256, 10, 0, 150, 19, "");
-       uiButSetSearchFunc(but, id_search_cb, &params, id_search_call_cb);
+       uiButSetSearchFunc(but, id_search_cb, &params, id_search_call_cb, NULL);
        
        uiBoundsBlock(block, 6);
        uiBlockSetDirection(block, UI_DOWN);    
index 7b65a70117c5281d4eeca8e48cc5821188d73266..7d6e2ca05c003d7d769c02733caccc53298e6e9a 100644 (file)
@@ -491,7 +491,7 @@ void info_header_buttons(const bContext *C, ARegion *ar)
                static char search[256]= "";
                uiBut *but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, 256, xco+5, yco, 120, 19, "");
                
-               uiButSetSearchFunc(but, operator_search_cb, NULL, operator_call_cb);
+               uiButSetSearchFunc(but, operator_search_cb, NULL, operator_call_cb, NULL);
 
                xco+= 125;
        }
index 34a935103a7c7bfd9d5f041532e21726727a0d61..ea365d59ac7f55fdc6d69eb9dbd0353663ea5ce6 100644 (file)
@@ -204,7 +204,7 @@ static uiBlock *tool_search_menu(bContext *C, ARegion *ar, void *arg_listbase)
        uiDefBut(block, LABEL, 0, "", 10, 15, 150, uiSearchBoxhHeight(), NULL, 0, 0, 0, 0, NULL);
        
        but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, OP_MAX_TYPENAME, 10, 0, 150, 19, "");
-       uiButSetSearchFunc(but, operator_search_cb, arg_listbase, operator_call_cb);
+       uiButSetSearchFunc(but, operator_search_cb, arg_listbase, operator_call_cb, NULL);
        
        uiBoundsBlock(block, 6);
        uiBlockSetDirection(block, UI_DOWN);