For all buttons with search-menu option, the button will show a
red-alert drawing when input doesn't exist. Will help debugging when messing with uv-layer names, vertex groups, etc. Also closes bugreport #24905
This commit is contained in:
@@ -3394,6 +3394,7 @@ uiBut *uiDefSearchBut(uiBlock *block, void *arg, int retval, int icon, int maxle
|
||||
return but;
|
||||
}
|
||||
|
||||
|
||||
/* arg is user value, searchfunc and handlefunc both get it as arg */
|
||||
/* if active set, button opens with this item visible and selected */
|
||||
void uiButSetSearchFunc(uiBut *but, uiButSearchFunc sfunc, void *arg, uiButHandleFunc bfunc, void *active)
|
||||
@@ -3402,6 +3403,13 @@ void uiButSetSearchFunc(uiBut *but, uiButSearchFunc sfunc, void *arg, uiButHandl
|
||||
but->search_arg= arg;
|
||||
|
||||
uiButSetFunc(but, bfunc, arg, active);
|
||||
|
||||
/* search buttons show red-alert if item doesn't exist, not for menus */
|
||||
if(0==(but->block->flag & UI_BLOCK_LOOP)) {
|
||||
/* skip empty buttons, not all buttons need input, we only show invalid */
|
||||
if(but->drawstr[0])
|
||||
ui_but_search_test(but);
|
||||
}
|
||||
}
|
||||
|
||||
/* Program Init/Exit */
|
||||
|
@@ -421,6 +421,7 @@ void ui_searchbox_autocomplete(struct bContext *C, struct ARegion *ar, uiBut *bu
|
||||
void ui_searchbox_event(struct bContext *C, struct ARegion *ar, uiBut *but, struct wmEvent *event);
|
||||
void ui_searchbox_apply(uiBut *but, struct ARegion *ar);
|
||||
void ui_searchbox_free(struct bContext *C, struct ARegion *ar);
|
||||
void ui_but_search_test(uiBut *but);
|
||||
|
||||
typedef uiBlock* (*uiBlockHandleCreateFunc)(struct bContext *C, struct uiPopupBlockHandle *handle, void *arg1);
|
||||
|
||||
|
@@ -611,9 +611,12 @@ int uiSearchItemAdd(uiSearchItems *items, const char *name, void *poin, int icon
|
||||
return 1;
|
||||
}
|
||||
|
||||
BLI_strncpy(items->names[items->totitem], name, items->maxstrlen);
|
||||
items->pointers[items->totitem]= poin;
|
||||
items->icons[items->totitem]= iconid;
|
||||
if(items->names)
|
||||
BLI_strncpy(items->names[items->totitem], name, items->maxstrlen);
|
||||
if(items->pointers)
|
||||
items->pointers[items->totitem]= poin;
|
||||
if(items->icons)
|
||||
items->icons[items->totitem]= iconid;
|
||||
|
||||
items->totitem++;
|
||||
|
||||
@@ -1077,6 +1080,32 @@ void ui_searchbox_free(bContext *C, ARegion *ar)
|
||||
ui_remove_temporary_region(C, CTX_wm_screen(C), ar);
|
||||
}
|
||||
|
||||
/* sets red alert if button holds a string it can't find */
|
||||
void ui_but_search_test(uiBut *but)
|
||||
{
|
||||
uiSearchItems *items= MEM_callocN(sizeof(uiSearchItems), "search items");
|
||||
char *strp[2], str[256];
|
||||
|
||||
items->maxitem= 1;
|
||||
items->maxstrlen= 256;
|
||||
strp[0]= str;
|
||||
items->names= strp;
|
||||
|
||||
/* changed flag makes search only find name */
|
||||
but->changed= TRUE;
|
||||
but->search_func(but->block->evil_C, but->search_arg, but->drawstr, items);
|
||||
but->changed= 0;
|
||||
|
||||
if(items->totitem==0)
|
||||
uiButSetFlag(but, UI_BUT_REDALERT);
|
||||
else if(items->totitem==1) {
|
||||
if(strcmp(but->drawstr, str)!=0)
|
||||
uiButSetFlag(but, UI_BUT_REDALERT);
|
||||
}
|
||||
|
||||
MEM_freeN(items);
|
||||
}
|
||||
|
||||
|
||||
/************************* Creating Menu Blocks **********************/
|
||||
|
||||
|
Reference in New Issue
Block a user