Add red alert in UI controls for datablock pointer properties
This commit is contained in:
@@ -695,7 +695,7 @@ void UI_but_func_search_set(
|
|||||||
int UI_searchbox_size_y(void);
|
int UI_searchbox_size_y(void);
|
||||||
int UI_searchbox_size_x(void);
|
int UI_searchbox_size_x(void);
|
||||||
/* check if a string is in an existing search box */
|
/* check if a string is in an existing search box */
|
||||||
int UI_search_items_find_index(uiSearchItems *items, const char *name);
|
int UI_search_items_find_index(uiSearchItems *items, const char *name, const size_t offset);
|
||||||
|
|
||||||
void UI_block_func_handle_set(uiBlock *block, uiBlockHandleFunc func, void *arg);
|
void UI_block_func_handle_set(uiBlock *block, uiBlockHandleFunc func, void *arg);
|
||||||
void UI_block_func_butmenu_set(uiBlock *block, uiMenuHandleFunc func, void *arg);
|
void UI_block_func_butmenu_set(uiBlock *block, uiMenuHandleFunc func, void *arg);
|
||||||
|
@@ -4372,7 +4372,7 @@ void UI_but_func_search_set(
|
|||||||
if (0 == (but->block->flag & UI_BLOCK_LOOP)) {
|
if (0 == (but->block->flag & UI_BLOCK_LOOP)) {
|
||||||
/* skip empty buttons, not all buttons need input, we only show invalid */
|
/* skip empty buttons, not all buttons need input, we only show invalid */
|
||||||
if (but->drawstr[0])
|
if (but->drawstr[0])
|
||||||
ui_but_search_refresh(but);
|
ui_but_search_refresh(but, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -605,7 +605,7 @@ int ui_searchbox_autocomplete(struct bContext *C, struct ARegion *ar, uiBut *but
|
|||||||
void ui_searchbox_event(struct bContext *C, struct ARegion *ar, uiBut *but, const struct wmEvent *event);
|
void ui_searchbox_event(struct bContext *C, struct ARegion *ar, uiBut *but, const struct wmEvent *event);
|
||||||
bool ui_searchbox_apply(uiBut *but, struct ARegion *ar);
|
bool ui_searchbox_apply(uiBut *but, struct ARegion *ar);
|
||||||
void ui_searchbox_free(struct bContext *C, struct ARegion *ar);
|
void ui_searchbox_free(struct bContext *C, struct ARegion *ar);
|
||||||
void ui_but_search_refresh(uiBut *but);
|
void ui_but_search_refresh(uiBut *but, const bool is_template_ID);
|
||||||
|
|
||||||
uiBlock *ui_popup_block_refresh(
|
uiBlock *ui_popup_block_refresh(
|
||||||
struct bContext *C, uiPopupBlockHandle *handle,
|
struct bContext *C, uiPopupBlockHandle *handle,
|
||||||
|
@@ -811,11 +811,11 @@ int UI_searchbox_size_x(void)
|
|||||||
return 12 * UI_UNIT_X;
|
return 12 * UI_UNIT_X;
|
||||||
}
|
}
|
||||||
|
|
||||||
int UI_search_items_find_index(uiSearchItems *items, const char *name)
|
int UI_search_items_find_index(uiSearchItems *items, const char *name, const size_t offset)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < items->totitem; i++) {
|
for (i = 0; i < items->totitem; i++) {
|
||||||
if (STREQ(name, items->names[i])) {
|
if (STREQ(name, items->names[i] + offset)) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -894,7 +894,7 @@ static void ui_searchbox_butrect(rcti *r_rect, uiSearchboxData *data, int itemnr
|
|||||||
int ui_searchbox_find_index(ARegion *ar, const char *name)
|
int ui_searchbox_find_index(ARegion *ar, const char *name)
|
||||||
{
|
{
|
||||||
uiSearchboxData *data = ar->regiondata;
|
uiSearchboxData *data = ar->regiondata;
|
||||||
return UI_search_items_find_index(&data->items, name);
|
return UI_search_items_find_index(&data->items, name, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* x and y in screencoords */
|
/* x and y in screencoords */
|
||||||
@@ -1420,14 +1420,14 @@ void ui_searchbox_free(bContext *C, ARegion *ar)
|
|||||||
|
|
||||||
/* sets red alert if button holds a string it can't find */
|
/* sets red alert if button holds a string it can't find */
|
||||||
/* XXX weak: search_func adds all partial matches... */
|
/* XXX weak: search_func adds all partial matches... */
|
||||||
void ui_but_search_refresh(uiBut *but)
|
void ui_but_search_refresh(uiBut *but, const bool is_template_ID)
|
||||||
{
|
{
|
||||||
uiSearchItems *items;
|
uiSearchItems *items;
|
||||||
int x1;
|
int x1;
|
||||||
|
|
||||||
/* possibly very large lists (such as ID datablocks) only
|
/* possibly very large lists (such as ID datablocks),
|
||||||
* only validate string RNA buts (not pointers) */
|
* only validate string and pointer RNA buts */
|
||||||
if (but->rnaprop && RNA_property_type(but->rnaprop) != PROP_STRING) {
|
if (but->rnaprop && !ELEM(RNA_property_type(but->rnaprop), PROP_STRING, PROP_POINTER)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1447,7 +1447,8 @@ void ui_but_search_refresh(uiBut *but)
|
|||||||
UI_but_flag_enable(but, UI_BUT_REDALERT);
|
UI_but_flag_enable(but, UI_BUT_REDALERT);
|
||||||
}
|
}
|
||||||
else if (items->more == 0) {
|
else if (items->more == 0) {
|
||||||
if (UI_search_items_find_index(items, but->drawstr) == -1) {
|
const size_t offset = is_template_ID ? 3 : 0;
|
||||||
|
if (UI_search_items_find_index(items, but->drawstr, offset) == -1) {
|
||||||
UI_but_flag_enable(but, UI_BUT_REDALERT);
|
UI_but_flag_enable(but, UI_BUT_REDALERT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -451,6 +451,11 @@ static void template_ID(
|
|||||||
but = uiDefButR(block, UI_BTYPE_TEXT, 0, name, 0, 0, UI_UNIT_X * 6, UI_UNIT_Y,
|
but = uiDefButR(block, UI_BTYPE_TEXT, 0, name, 0, 0, UI_UNIT_X * 6, UI_UNIT_Y,
|
||||||
&idptr, "name", -1, 0, 0, -1, -1, RNA_struct_ui_description(type));
|
&idptr, "name", -1, 0, 0, -1, -1, RNA_struct_ui_description(type));
|
||||||
UI_but_funcN_set(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_RENAME));
|
UI_but_funcN_set(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_RENAME));
|
||||||
|
|
||||||
|
but->search_func = id_search_cb;
|
||||||
|
but->search_arg = template;
|
||||||
|
ui_but_search_refresh(but, true);
|
||||||
|
|
||||||
if (user_alert) UI_but_flag_enable(but, UI_BUT_REDALERT);
|
if (user_alert) UI_but_flag_enable(but, UI_BUT_REDALERT);
|
||||||
|
|
||||||
if (id->lib) {
|
if (id->lib) {
|
||||||
|
Reference in New Issue
Block a user