Various cleanups related to button locking
* Rename uiBut.lockstr to disabled_info * Remove unreachable code * Replace duplicated check with assert * Replace overly ambitious check with assert * Add comments
This commit is contained in:
parent
976e591e93
commit
c2d7d4764e
Notes:
blender-bot
2023-02-14 10:37:50 +01:00
Referenced by issue #49408, differents material shadings under Cycles+viewport in material mode,
|
@ -161,13 +161,13 @@ enum {
|
|||
UI_BUT_NODE_LINK = (1 << 8),
|
||||
UI_BUT_NODE_ACTIVE = (1 << 9),
|
||||
UI_BUT_DRAG_LOCK = (1 << 10),
|
||||
UI_BUT_DISABLED = (1 << 11),
|
||||
UI_BUT_DISABLED = (1 << 11), /* grayed out and uneditable */
|
||||
UI_BUT_COLOR_LOCK = (1 << 12),
|
||||
UI_BUT_ANIMATED = (1 << 13),
|
||||
UI_BUT_ANIMATED_KEY = (1 << 14),
|
||||
UI_BUT_DRIVEN = (1 << 15),
|
||||
UI_BUT_REDALERT = (1 << 16),
|
||||
UI_BUT_INACTIVE = (1 << 17),
|
||||
UI_BUT_INACTIVE = (1 << 17), /* grayed out but still editable */
|
||||
UI_BUT_LAST_ACTIVE = (1 << 18),
|
||||
UI_BUT_UNDO = (1 << 19),
|
||||
UI_BUT_IMMEDIATE = (1 << 20),
|
||||
|
|
|
@ -3121,7 +3121,7 @@ static uiBut *ui_def_but(
|
|||
but->a2 = a2;
|
||||
but->tip = tip;
|
||||
|
||||
but->lockstr = block->lockstr;
|
||||
but->disabled_info = block->lockstr;
|
||||
but->dt = block->dt;
|
||||
but->pie_dir = UI_RADIAL_NONE;
|
||||
|
||||
|
@ -3218,7 +3218,7 @@ void ui_def_but_icon(uiBut *but, const int icon, const int flag)
|
|||
static void ui_def_but_rna__disable(uiBut *but)
|
||||
{
|
||||
but->flag |= UI_BUT_DISABLED;
|
||||
but->lockstr = "";
|
||||
but->disabled_info = "";
|
||||
}
|
||||
|
||||
static void ui_def_but_rna__menu(bContext *UNUSED(C), uiLayout *layout, void *but_p)
|
||||
|
@ -3543,7 +3543,7 @@ static uiBut *ui_def_but_operator_ptr(uiBlock *block, int type, wmOperatorType *
|
|||
|
||||
if (!ot) {
|
||||
but->flag |= UI_BUT_DISABLED;
|
||||
but->lockstr = "";
|
||||
but->disabled_info = "";
|
||||
}
|
||||
|
||||
return but;
|
||||
|
|
|
@ -2248,9 +2248,7 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data,
|
|||
bool buf_paste_alloc = false;
|
||||
bool show_report = false; /* use to display errors parsing paste input */
|
||||
|
||||
if (mode == 'v' && (but->flag & UI_BUT_DISABLED)) {
|
||||
return;
|
||||
}
|
||||
BLI_assert((but->flag & UI_BUT_DISABLED) == 0); /* caller should check */
|
||||
|
||||
if (mode == 'c') {
|
||||
/* disallow copying from any passwords */
|
||||
|
@ -6974,6 +6972,9 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent *
|
|||
if (but->flag & UI_BUT_DISABLED)
|
||||
return WM_UI_HANDLER_CONTINUE;
|
||||
|
||||
/* if but->pointype is set, but->poin should be too */
|
||||
BLI_assert(!but->pointype || but->poin);
|
||||
|
||||
if ((data->state == BUTTON_STATE_HIGHLIGHT) || (event->type == EVT_DROP)) {
|
||||
/* handle copy-paste */
|
||||
if (ELEM(event->type, CKEY, VKEY) && event->val == KM_PRESS &&
|
||||
|
@ -7098,23 +7099,6 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent *
|
|||
}
|
||||
}
|
||||
|
||||
/* verify if we can edit this button */
|
||||
if (ELEM(event->type, LEFTMOUSE, RETKEY)) {
|
||||
if (but->flag & UI_BUT_DISABLED) {
|
||||
if (but->lockstr) {
|
||||
WM_report(RPT_INFO, but->lockstr);
|
||||
button_activate_state(C, but, BUTTON_STATE_EXIT);
|
||||
return WM_UI_HANDLER_BREAK;
|
||||
}
|
||||
}
|
||||
else if (but->pointype && but->poin == NULL) {
|
||||
/* there's a pointer needed */
|
||||
BKE_reportf(NULL, RPT_WARNING, "DoButton pointer error: %s", but->str);
|
||||
button_activate_state(C, but, BUTTON_STATE_EXIT);
|
||||
return WM_UI_HANDLER_BREAK;
|
||||
}
|
||||
}
|
||||
|
||||
switch (but->type) {
|
||||
case UI_BTYPE_BUT:
|
||||
retval = ui_do_but_BUT(C, but, data, event);
|
||||
|
|
|
@ -271,7 +271,8 @@ struct uiBut {
|
|||
uiButToolTipFunc tip_func;
|
||||
void *tip_argN;
|
||||
|
||||
const char *lockstr;
|
||||
/* info on why button is disabled, displayed in tooltip */
|
||||
const char *disabled_info;
|
||||
|
||||
BIFIconID icon;
|
||||
char dt; /* drawtype: UI_EMBOSS, UI_EMBOSS_NONE ... etc, copied from the block */
|
||||
|
|
|
@ -745,7 +745,7 @@ static void ui_item_disabled(uiLayout *layout, const char *name)
|
|||
|
||||
but = uiDefBut(block, UI_BTYPE_LABEL, 0, name, 0, 0, w, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
|
||||
but->flag |= UI_BUT_DISABLED;
|
||||
but->lockstr = "";
|
||||
but->disabled_info = "";
|
||||
}
|
||||
|
||||
/* operator items */
|
||||
|
|
|
@ -466,8 +466,8 @@ static uiTooltipData *ui_tooltip_data_from_button(bContext *C, uiBut *but)
|
|||
disabled_msg = CTX_wm_operator_poll_msg_get(C);
|
||||
}
|
||||
/* alternatively, buttons can store some reasoning too */
|
||||
else if (but->lockstr) {
|
||||
disabled_msg = but->lockstr;
|
||||
else if (but->disabled_info) {
|
||||
disabled_msg = but->disabled_info;
|
||||
}
|
||||
|
||||
if (disabled_msg && disabled_msg[0]) {
|
||||
|
|
Loading…
Reference in New Issue