modalDialog: do not launch disabled button actions
The "Sign In" button of the login dialog has its look disabled when the entry is empty, but it can still be triggered by the Enter key. This fixes the modal dialog so it does not trigger the action of an insensitive button, and also means we do not need to connect to the "activate" signal of the entry anymore. https://bugzilla.gnome.org/show_bug.cgi?id=687113
This commit is contained in:
parent
c10e4c3117
commit
4c55a6f436
@ -58,7 +58,7 @@ const ModalDialog = new Lang.Class({
|
||||
|
||||
this._group.connect('destroy', Lang.bind(this, this._onGroupDestroy));
|
||||
|
||||
this._actionKeys = {};
|
||||
this._buttonKeys = {};
|
||||
this._group.connect('key-release-event', Lang.bind(this, this._onKeyReleaseEvent));
|
||||
|
||||
this._backgroundBin = new St.Bin();
|
||||
@ -113,13 +113,9 @@ const ModalDialog = new Lang.Class({
|
||||
this._group.destroy();
|
||||
},
|
||||
|
||||
setActionKey: function(key, action) {
|
||||
this._actionKeys[key] = action;
|
||||
},
|
||||
|
||||
clearButtons: function() {
|
||||
this.buttonLayout.destroy_all_children();
|
||||
this._actionKeys = {};
|
||||
this._buttonKeys = {};
|
||||
},
|
||||
|
||||
setButtons: function(buttons) {
|
||||
@ -139,12 +135,11 @@ const ModalDialog = new Lang.Class({
|
||||
else
|
||||
x_alignment = St.Align.MIDDLE;
|
||||
|
||||
let button = this.addButton(buttonInfo, { expand: true,
|
||||
x_fill: false,
|
||||
y_fill: false,
|
||||
x_align: x_alignment,
|
||||
y_align: St.Align.MIDDLE });
|
||||
buttonInfo.button = button;
|
||||
this.addButton(buttonInfo, { expand: true,
|
||||
x_fill: false,
|
||||
y_fill: false,
|
||||
x_align: x_alignment,
|
||||
y_align: St.Align.MIDDLE });
|
||||
}
|
||||
},
|
||||
|
||||
@ -154,27 +149,31 @@ const ModalDialog = new Lang.Class({
|
||||
let key = buttonInfo['key'];
|
||||
let isDefault = buttonInfo['default'];
|
||||
|
||||
if (isDefault && !key) {
|
||||
this._actionKeys[Clutter.KEY_KP_Enter] = action;
|
||||
this._actionKeys[Clutter.KEY_ISO_Enter] = action;
|
||||
key = Clutter.KEY_Return;
|
||||
}
|
||||
let keys;
|
||||
|
||||
if (key)
|
||||
keys = [key];
|
||||
else if (isDefault)
|
||||
keys = [Clutter.KEY_Return, Clutter.KEY_KP_Enter, Clutter.KEY_ISO_Enter];
|
||||
else
|
||||
keys = [];
|
||||
|
||||
let button = new St.Button({ style_class: 'modal-dialog-button',
|
||||
reactive: true,
|
||||
can_focus: true,
|
||||
label: label });
|
||||
|
||||
button.connect('clicked', action);
|
||||
|
||||
buttonInfo['button'] = button;
|
||||
|
||||
if (isDefault)
|
||||
button.add_style_pseudo_class('default');
|
||||
|
||||
if (!this._initialKeyFocusDestroyId)
|
||||
this._initialKeyFocus = button;
|
||||
|
||||
if (key)
|
||||
this._actionKeys[key] = action;
|
||||
for (let i in keys)
|
||||
this._buttonKeys[keys[i]] = buttonInfo;
|
||||
|
||||
this.buttonLayout.add(button, layoutInfo);
|
||||
|
||||
@ -183,9 +182,15 @@ const ModalDialog = new Lang.Class({
|
||||
|
||||
_onKeyReleaseEvent: function(object, event) {
|
||||
let symbol = event.get_key_symbol();
|
||||
let action = this._actionKeys[symbol];
|
||||
let buttonInfo = this._buttonKeys[symbol];
|
||||
|
||||
if (action) {
|
||||
if (!buttonInfo)
|
||||
return false;
|
||||
|
||||
let button = buttonInfo['button'];
|
||||
let action = buttonInfo['action'];
|
||||
|
||||
if (action && button.reactive) {
|
||||
action();
|
||||
return true;
|
||||
}
|
||||
|
@ -151,7 +151,6 @@ const UnlockDialog = new Lang.Class({
|
||||
this._promptEntry.clutter_text.set_password_char('\u25cf');
|
||||
ShellEntry.addContextMenu(this._promptEntry, { isPassword: true });
|
||||
this.setInitialKeyFocus(this._promptEntry);
|
||||
this._promptEntry.clutter_text.connect('activate', Lang.bind(this, this._doUnlock));
|
||||
this._promptEntry.clutter_text.connect('text-changed', Lang.bind(this, function() {
|
||||
this._updateOkButtonSensitivity(this._promptEntry.text.length > 0);
|
||||
}));
|
||||
|
Loading…
Reference in New Issue
Block a user