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:
Julian Eisel
2016-09-19 02:25:59 +02:00
parent 976e591e93
commit c2d7d4764e
6 changed files with 14 additions and 29 deletions

View File

@@ -161,13 +161,13 @@ enum {
UI_BUT_NODE_LINK = (1 << 8), UI_BUT_NODE_LINK = (1 << 8),
UI_BUT_NODE_ACTIVE = (1 << 9), UI_BUT_NODE_ACTIVE = (1 << 9),
UI_BUT_DRAG_LOCK = (1 << 10), 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_COLOR_LOCK = (1 << 12),
UI_BUT_ANIMATED = (1 << 13), UI_BUT_ANIMATED = (1 << 13),
UI_BUT_ANIMATED_KEY = (1 << 14), UI_BUT_ANIMATED_KEY = (1 << 14),
UI_BUT_DRIVEN = (1 << 15), UI_BUT_DRIVEN = (1 << 15),
UI_BUT_REDALERT = (1 << 16), 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_LAST_ACTIVE = (1 << 18),
UI_BUT_UNDO = (1 << 19), UI_BUT_UNDO = (1 << 19),
UI_BUT_IMMEDIATE = (1 << 20), UI_BUT_IMMEDIATE = (1 << 20),

View File

@@ -3121,7 +3121,7 @@ static uiBut *ui_def_but(
but->a2 = a2; but->a2 = a2;
but->tip = tip; but->tip = tip;
but->lockstr = block->lockstr; but->disabled_info = block->lockstr;
but->dt = block->dt; but->dt = block->dt;
but->pie_dir = UI_RADIAL_NONE; 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) static void ui_def_but_rna__disable(uiBut *but)
{ {
but->flag |= UI_BUT_DISABLED; 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) 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) { if (!ot) {
but->flag |= UI_BUT_DISABLED; but->flag |= UI_BUT_DISABLED;
but->lockstr = ""; but->disabled_info = "";
} }
return but; return but;

View File

@@ -2248,9 +2248,7 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data,
bool buf_paste_alloc = false; bool buf_paste_alloc = false;
bool show_report = false; /* use to display errors parsing paste input */ bool show_report = false; /* use to display errors parsing paste input */
if (mode == 'v' && (but->flag & UI_BUT_DISABLED)) { BLI_assert((but->flag & UI_BUT_DISABLED) == 0); /* caller should check */
return;
}
if (mode == 'c') { if (mode == 'c') {
/* disallow copying from any passwords */ /* 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) if (but->flag & UI_BUT_DISABLED)
return WM_UI_HANDLER_CONTINUE; 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)) { if ((data->state == BUTTON_STATE_HIGHLIGHT) || (event->type == EVT_DROP)) {
/* handle copy-paste */ /* handle copy-paste */
if (ELEM(event->type, CKEY, VKEY) && event->val == KM_PRESS && 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) { switch (but->type) {
case UI_BTYPE_BUT: case UI_BTYPE_BUT:
retval = ui_do_but_BUT(C, but, data, event); retval = ui_do_but_BUT(C, but, data, event);

View File

@@ -271,7 +271,8 @@ struct uiBut {
uiButToolTipFunc tip_func; uiButToolTipFunc tip_func;
void *tip_argN; void *tip_argN;
const char *lockstr; /* info on why button is disabled, displayed in tooltip */
const char *disabled_info;
BIFIconID icon; BIFIconID icon;
char dt; /* drawtype: UI_EMBOSS, UI_EMBOSS_NONE ... etc, copied from the block */ char dt; /* drawtype: UI_EMBOSS, UI_EMBOSS_NONE ... etc, copied from the block */

View File

@@ -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 = 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->flag |= UI_BUT_DISABLED;
but->lockstr = ""; but->disabled_info = "";
} }
/* operator items */ /* operator items */

View File

@@ -466,8 +466,8 @@ static uiTooltipData *ui_tooltip_data_from_button(bContext *C, uiBut *but)
disabled_msg = CTX_wm_operator_poll_msg_get(C); disabled_msg = CTX_wm_operator_poll_msg_get(C);
} }
/* alternatively, buttons can store some reasoning too */ /* alternatively, buttons can store some reasoning too */
else if (but->lockstr) { else if (but->disabled_info) {
disabled_msg = but->lockstr; disabled_msg = but->disabled_info;
} }
if (disabled_msg && disabled_msg[0]) { if (disabled_msg && disabled_msg[0]) {