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
This commit is contained in:
Jonas Dreßler 2020-01-27 18:43:40 +01:00 committed by Florian Müllner
parent 7224afd32a
commit 0b51a52c9b

View File

@ -20,17 +20,22 @@ var WORK_SPINNER_ICON_SIZE = 16;
const REMEMBER_MOUNT_PASSWORD_KEY = 'remember-mount-password'; const REMEMBER_MOUNT_PASSWORD_KEY = 'remember-mount-password';
/* ------ Common Utils ------- */ /* ------ Common Utils ------- */
function _setButtonsForChoices(dialog, choices) { function _setButtonsForChoices(dialog, oldChoices, choices) {
let buttons = []; let buttons = [];
let buttonsChanged = oldChoices.length !== choices.length;
for (let idx = 0; idx < choices.length; idx++) { for (let idx = 0; idx < choices.length; idx++) {
let button = idx; let button = idx;
buttonsChanged = buttonsChanged || oldChoices[idx] !== choices[idx];
buttons.unshift({ buttons.unshift({
label: choices[idx], label: choices[idx],
action: () => dialog.emit('response', button), action: () => dialog.emit('response', button),
}); });
} }
if (buttonsChanged)
dialog.setButtons(buttons); dialog.setButtons(buttons);
} }
@ -225,13 +230,16 @@ var ShellMountQuestionDialog = GObject.registerClass({
_init() { _init() {
super._init({ styleClass: 'mount-question-dialog' }); super._init({ styleClass: 'mount-question-dialog' });
this._oldChoices = [];
this._content = new Dialog.MessageDialogContent(); this._content = new Dialog.MessageDialogContent();
this.contentLayout.add_child(this._content); this.contentLayout.add_child(this._content);
} }
update(message, choices) { update(message, choices) {
_setLabelsForMessage(this._content, message); _setLabelsForMessage(this._content, message);
_setButtonsForChoices(this, choices); _setButtonsForChoices(this, this._oldChoices, choices);
this._oldChoices = choices;
} }
}); });
@ -463,6 +471,8 @@ var ShellProcessesDialog = GObject.registerClass({
_init() { _init() {
super._init({ styleClass: 'processes-dialog' }); super._init({ styleClass: 'processes-dialog' });
this._oldChoices = [];
this._content = new Dialog.MessageDialogContent(); this._content = new Dialog.MessageDialogContent();
this.contentLayout.add_child(this._content); this.contentLayout.add_child(this._content);
@ -499,7 +509,8 @@ var ShellProcessesDialog = GObject.registerClass({
update(message, processes, choices) { update(message, processes, choices) {
this._setAppsForPids(processes); this._setAppsForPids(processes);
_setLabelsForMessage(this._content, message); _setLabelsForMessage(this._content, message);
_setButtonsForChoices(this, choices); _setButtonsForChoices(this, this._oldChoices, choices);
this._oldChoices = choices;
} }
}); });