[gnome-shell] shellMountDialog: Check for changes before creating new buttons



commit 0b51a52c9b683c812b96c970ff1c45cf352907eb
Author: Jonas Dreßler <verdre v0yd nl>
Date:   Mon Jan 27 18:43:40 2020 +0100

    shellMountDialog: Check for changes before creating new buttons
    
    When updating the buttons of the mount dialogs, compare the new buttons
    to the old ones and only create new buttons in case something changed.
    This makes sure key focus isn't reset or lost unnecessarily while a
    dialog is opened.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/961

 js/ui/shellMountOperation.js | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
---
diff --git a/js/ui/shellMountOperation.js b/js/ui/shellMountOperation.js
index 72eabe34dc..59a4e6e0fe 100644
--- a/js/ui/shellMountOperation.js
+++ b/js/ui/shellMountOperation.js
@@ -20,18 +20,23 @@ var WORK_SPINNER_ICON_SIZE = 16;
 const REMEMBER_MOUNT_PASSWORD_KEY = 'remember-mount-password';
 
 /* ------ Common Utils ------- */
-function _setButtonsForChoices(dialog, choices) {
+function _setButtonsForChoices(dialog, oldChoices, choices) {
     let buttons = [];
+    let buttonsChanged = oldChoices.length !== choices.length;
 
     for (let idx = 0; idx < choices.length; idx++) {
         let button = idx;
+
+        buttonsChanged = buttonsChanged || oldChoices[idx] !== choices[idx];
+
         buttons.unshift({
             label: choices[idx],
             action: () => dialog.emit('response', button),
         });
     }
 
-    dialog.setButtons(buttons);
+    if (buttonsChanged)
+        dialog.setButtons(buttons);
 }
 
 function _setLabelsForMessage(content, message) {
@@ -225,13 +230,16 @@ var ShellMountQuestionDialog = GObject.registerClass({
     _init() {
         super._init({ styleClass: 'mount-question-dialog' });
 
+        this._oldChoices = [];
+
         this._content = new Dialog.MessageDialogContent();
         this.contentLayout.add_child(this._content);
     }
 
     update(message, choices) {
         _setLabelsForMessage(this._content, message);
-        _setButtonsForChoices(this, choices);
+        _setButtonsForChoices(this, this._oldChoices, choices);
+        this._oldChoices = choices;
     }
 });
 
@@ -463,6 +471,8 @@ var ShellProcessesDialog = GObject.registerClass({
     _init() {
         super._init({ styleClass: 'processes-dialog' });
 
+        this._oldChoices = [];
+
         this._content = new Dialog.MessageDialogContent();
         this.contentLayout.add_child(this._content);
 
@@ -499,7 +509,8 @@ var ShellProcessesDialog = GObject.registerClass({
     update(message, processes, choices) {
         this._setAppsForPids(processes);
         _setLabelsForMessage(this._content, message);
-        _setButtonsForChoices(this, choices);
+        _setButtonsForChoices(this, this._oldChoices, choices);
+        this._oldChoices = choices;
     }
 });
 


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