[gnome-shell] modalDialog: do not launch disabled button actions



commit 4c55a6f43633dddd4461282d72655d76e12805e5
Author: StÃphane DÃmurget <stephane demurget free fr>
Date:   Sun Nov 18 21:29:46 2012 +0100

    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

 js/ui/modalDialog.js  |   49 +++++++++++++++++++++++++++----------------------
 js/ui/unlockDialog.js |    1 -
 2 files changed, 27 insertions(+), 23 deletions(-)
---
diff --git a/js/ui/modalDialog.js b/js/ui/modalDialog.js
index 2ee2579..065ce9e 100644
--- a/js/ui/modalDialog.js
+++ b/js/ui/modalDialog.js
@@ -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 (!buttonInfo)
+            return false;
+
+        let button = buttonInfo['button'];
+        let action = buttonInfo['action'];
 
-        if (action) {
+        if (action && button.reactive) {
             action();
             return true;
         }
diff --git a/js/ui/unlockDialog.js b/js/ui/unlockDialog.js
index 9996385..98ff22a 100644
--- a/js/ui/unlockDialog.js
+++ b/js/ui/unlockDialog.js
@@ -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);
         }));



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]