js: Use StPasswordEntry for password entry fields
Use the new StPasswordEntry for password entry fields and remove all direct handling of clutter text of the entry via clutter_text_set_password_char to show/hide the password text. StPasswordEntry will provides a peek-password-icon which will allow to show/hide the password present in the field to the user in subsequent commits. https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/619
This commit is contained in:
parent
97b81a2319
commit
b0b8ab6c73
@ -98,14 +98,24 @@ var AuthPrompt = GObject.registerClass({
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.add_child(this._label);
|
this.add_child(this._label);
|
||||||
this._entry = new St.Entry({
|
this._entry = null;
|
||||||
|
|
||||||
|
this._textEntry = new St.Entry({
|
||||||
|
style_class: 'login-dialog-prompt-entry',
|
||||||
|
can_focus: true,
|
||||||
|
x_expand: false,
|
||||||
|
y_expand: true,
|
||||||
|
});
|
||||||
|
ShellEntry.addContextMenu(this._textEntry, { actionMode: Shell.ActionMode.NONE });
|
||||||
|
this._passwordEntry = new St.PasswordEntry({
|
||||||
style_class: 'login-dialog-prompt-entry',
|
style_class: 'login-dialog-prompt-entry',
|
||||||
can_focus: true,
|
can_focus: true,
|
||||||
x_expand: false,
|
x_expand: false,
|
||||||
y_expand: true,
|
y_expand: true,
|
||||||
});
|
});
|
||||||
ShellEntry.addContextMenu(this._entry, { isPassword: true, actionMode: Shell.ActionMode.NONE });
|
|
||||||
|
|
||||||
|
ShellEntry.addContextMenu(this._passwordEntry, { actionMode: Shell.ActionMode.NONE });
|
||||||
|
this._entry = this._passwordEntry;
|
||||||
this.add_child(this._entry);
|
this.add_child(this._entry);
|
||||||
|
|
||||||
this._entry.grab_key_focus();
|
this._entry.grab_key_focus();
|
||||||
@ -195,7 +205,17 @@ var AuthPrompt = GObject.registerClass({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_onAskQuestion(verifier, serviceName, question, passwordChar) {
|
_updateEntry(secret) {
|
||||||
|
if (secret && (this._entry != this._passwordEntry)) {
|
||||||
|
this.replace_child(this._entry, this._passwordEntry);
|
||||||
|
this._entry = this._passwordEntry;
|
||||||
|
} else if (!secret && (this._entry != this._textEntry)) {
|
||||||
|
this.replace_child(this._entry, this._textEntry);
|
||||||
|
this._entry = this._textEntry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_onAskQuestion(verifier, serviceName, question, secret) {
|
||||||
if (this._queryingService)
|
if (this._queryingService)
|
||||||
this.clear();
|
this.clear();
|
||||||
|
|
||||||
@ -205,10 +225,11 @@ var AuthPrompt = GObject.registerClass({
|
|||||||
this._preemptiveAnswer = null;
|
this._preemptiveAnswer = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.setPasswordChar(passwordChar);
|
|
||||||
|
this._updateEntry(secret);
|
||||||
this.setQuestion(question);
|
this.setQuestion(question);
|
||||||
|
|
||||||
if (passwordChar) {
|
if (secret) {
|
||||||
if (this._userVerifier.reauthenticating)
|
if (this._userVerifier.reauthenticating)
|
||||||
this.nextButton.label = _("Unlock");
|
this.nextButton.label = _("Unlock");
|
||||||
else
|
else
|
||||||
@ -358,11 +379,6 @@ var AuthPrompt = GObject.registerClass({
|
|||||||
this.stopSpinning();
|
this.stopSpinning();
|
||||||
}
|
}
|
||||||
|
|
||||||
setPasswordChar(passwordChar) {
|
|
||||||
this._entry.clutter_text.set_password_char(passwordChar);
|
|
||||||
this._entry.menu.isPassword = passwordChar != '';
|
|
||||||
}
|
|
||||||
|
|
||||||
setQuestion(question) {
|
setQuestion(question) {
|
||||||
this._label.set_text(question);
|
this._label.set_text(question);
|
||||||
|
|
||||||
|
@ -485,7 +485,7 @@ var ShellUserVerifier = class {
|
|||||||
if (!this.serviceIsForeground(serviceName))
|
if (!this.serviceIsForeground(serviceName))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this.emit('ask-question', serviceName, question, '');
|
this.emit('ask-question', serviceName, question, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onSecretInfoQuery(client, serviceName, secretQuestion) {
|
_onSecretInfoQuery(client, serviceName, secretQuestion) {
|
||||||
@ -498,7 +498,7 @@ var ShellUserVerifier = class {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.emit('ask-question', serviceName, secretQuestion, '\u25cf');
|
this.emit('ask-question', serviceName, secretQuestion, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onReset() {
|
_onReset() {
|
||||||
|
@ -70,11 +70,12 @@ class KeyringDialog extends ModalDialog.ModalDialog {
|
|||||||
y_align: Clutter.ActorAlign.CENTER });
|
y_align: Clutter.ActorAlign.CENTER });
|
||||||
label.set_text(_("Password:"));
|
label.set_text(_("Password:"));
|
||||||
label.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
|
label.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
|
||||||
this._passwordEntry = new St.Entry({ style_class: 'prompt-dialog-password-entry',
|
this._passwordEntry = new St.PasswordEntry({
|
||||||
text: '',
|
style_class: 'prompt-dialog-password-entry',
|
||||||
can_focus: true,
|
text: '',
|
||||||
x_expand: true });
|
can_focus: true,
|
||||||
this._passwordEntry.clutter_text.set_password_char('\u25cf'); // ● U+25CF BLACK CIRCLE
|
x_expand: true,
|
||||||
|
});
|
||||||
ShellEntry.addContextMenu(this._passwordEntry, { isPassword: true });
|
ShellEntry.addContextMenu(this._passwordEntry, { isPassword: true });
|
||||||
this._passwordEntry.clutter_text.connect('activate', this._onPasswordActivate.bind(this));
|
this._passwordEntry.clutter_text.connect('activate', this._onPasswordActivate.bind(this));
|
||||||
|
|
||||||
@ -102,11 +103,12 @@ class KeyringDialog extends ModalDialog.ModalDialog {
|
|||||||
x_align: Clutter.ActorAlign.START,
|
x_align: Clutter.ActorAlign.START,
|
||||||
y_align: Clutter.ActorAlign.CENTER });
|
y_align: Clutter.ActorAlign.CENTER });
|
||||||
label.set_text(_("Type again:"));
|
label.set_text(_("Type again:"));
|
||||||
this._confirmEntry = new St.Entry({ style_class: 'prompt-dialog-password-entry',
|
this._confirmEntry = new St.PasswordEntry({
|
||||||
text: '',
|
style_class: 'prompt-dialog-password-entry',
|
||||||
can_focus: true,
|
text: '',
|
||||||
x_expand: true });
|
can_focus: true,
|
||||||
this._confirmEntry.clutter_text.set_password_char('\u25cf'); // ● U+25CF BLACK CIRCLE
|
x_expand: true,
|
||||||
|
});
|
||||||
ShellEntry.addContextMenu(this._confirmEntry, { isPassword: true });
|
ShellEntry.addContextMenu(this._confirmEntry, { isPassword: true });
|
||||||
this._confirmEntry.clutter_text.connect('activate', this._onConfirmActivate.bind(this));
|
this._confirmEntry.clutter_text.connect('activate', this._onConfirmActivate.bind(this));
|
||||||
if (rtl) {
|
if (rtl) {
|
||||||
|
@ -54,10 +54,17 @@ class NetworkSecretDialog extends ModalDialog.ModalDialog {
|
|||||||
|
|
||||||
let reactive = secret.key != null;
|
let reactive = secret.key != null;
|
||||||
|
|
||||||
secret.entry = new St.Entry({ style_class: 'prompt-dialog-password-entry',
|
let entryParams = {
|
||||||
text: secret.value, can_focus: reactive,
|
style_class: 'prompt-dialog-password-entry',
|
||||||
reactive,
|
text: secret.value,
|
||||||
x_expand: true });
|
can_focus: reactive,
|
||||||
|
reactive,
|
||||||
|
x_expand: true,
|
||||||
|
};
|
||||||
|
if (secret.password)
|
||||||
|
secret.entry = new St.PasswordEntry(entryParams);
|
||||||
|
else
|
||||||
|
secret.entry = new St.Entry(entryParams);
|
||||||
ShellEntry.addContextMenu(secret.entry,
|
ShellEntry.addContextMenu(secret.entry,
|
||||||
{ isPassword: secret.password });
|
{ isPassword: secret.password });
|
||||||
|
|
||||||
@ -93,9 +100,6 @@ class NetworkSecretDialog extends ModalDialog.ModalDialog {
|
|||||||
layout.attach(secret.entry, 1, pos, 1, 1);
|
layout.attach(secret.entry, 1, pos, 1, 1);
|
||||||
}
|
}
|
||||||
pos++;
|
pos++;
|
||||||
|
|
||||||
if (secret.password)
|
|
||||||
secret.entry.clutter_text.set_password_char('\u25cf');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
contentBox.messageBox.add(secretTable);
|
contentBox.messageBox.add(secretTable);
|
||||||
|
@ -90,7 +90,7 @@ var AuthenticationDialog = GObject.registerClass({
|
|||||||
y_align: Clutter.ActorAlign.CENTER,
|
y_align: Clutter.ActorAlign.CENTER,
|
||||||
});
|
});
|
||||||
this._passwordBox.add_child(this._passwordLabel);
|
this._passwordBox.add_child(this._passwordLabel);
|
||||||
this._passwordEntry = new St.Entry({
|
this._passwordEntry = new St.PasswordEntry({
|
||||||
style_class: 'prompt-dialog-password-entry',
|
style_class: 'prompt-dialog-password-entry',
|
||||||
text: "",
|
text: "",
|
||||||
can_focus: true,
|
can_focus: true,
|
||||||
@ -278,10 +278,7 @@ var AuthenticationDialog = GObject.registerClass({
|
|||||||
else
|
else
|
||||||
this._passwordLabel.set_text(request);
|
this._passwordLabel.set_text(request);
|
||||||
|
|
||||||
if (echoOn)
|
this._passwordEntry.password_visible = echoOn;
|
||||||
this._passwordEntry.clutter_text.set_password_char('');
|
|
||||||
else
|
|
||||||
this._passwordEntry.clutter_text.set_password_char('\u25cf'); // ● U+25CF BLACK CIRCLE
|
|
||||||
|
|
||||||
this._passwordBox.show();
|
this._passwordBox.show();
|
||||||
this._passwordEntry.set_text('');
|
this._passwordEntry.set_text('');
|
||||||
|
@ -326,11 +326,12 @@ var ShellMountPasswordDialog = GObject.registerClass({
|
|||||||
this._pimLabel = new St.Label({ style_class: 'prompt-dialog-password-label',
|
this._pimLabel = new St.Label({ style_class: 'prompt-dialog-password-label',
|
||||||
text: _("PIM Number"),
|
text: _("PIM Number"),
|
||||||
y_align: Clutter.ActorAlign.CENTER });
|
y_align: Clutter.ActorAlign.CENTER });
|
||||||
this._pimEntry = new St.Entry({ style_class: 'prompt-dialog-password-entry',
|
this._pimEntry = new St.PasswordEntry({
|
||||||
can_focus: true,
|
style_class: 'prompt-dialog-password-entry',
|
||||||
x_expand: true });
|
can_focus: true,
|
||||||
|
x_expand: true,
|
||||||
|
});
|
||||||
this._pimEntry.clutter_text.connect('activate', this._onEntryActivate.bind(this));
|
this._pimEntry.clutter_text.connect('activate', this._onEntryActivate.bind(this));
|
||||||
this._pimEntry.clutter_text.set_password_char('\u25cf'); // ● U+25CF BLACK CIRCLE
|
|
||||||
ShellEntry.addContextMenu(this._pimEntry, { isPassword: true });
|
ShellEntry.addContextMenu(this._pimEntry, { isPassword: true });
|
||||||
|
|
||||||
if (rtl) {
|
if (rtl) {
|
||||||
@ -355,11 +356,12 @@ var ShellMountPasswordDialog = GObject.registerClass({
|
|||||||
this._passwordLabel = new St.Label({ style_class: 'prompt-dialog-password-label',
|
this._passwordLabel = new St.Label({ style_class: 'prompt-dialog-password-label',
|
||||||
text: _("Password"),
|
text: _("Password"),
|
||||||
y_align: Clutter.ActorAlign.CENTER });
|
y_align: Clutter.ActorAlign.CENTER });
|
||||||
this._passwordEntry = new St.Entry({ style_class: 'prompt-dialog-password-entry',
|
this._passwordEntry = new St.PasswordEntry({
|
||||||
can_focus: true,
|
style_class: 'prompt-dialog-password-entry',
|
||||||
x_expand: true });
|
can_focus: true,
|
||||||
|
x_expand: true,
|
||||||
|
});
|
||||||
this._passwordEntry.clutter_text.connect('activate', this._onEntryActivate.bind(this));
|
this._passwordEntry.clutter_text.connect('activate', this._onEntryActivate.bind(this));
|
||||||
this._passwordEntry.clutter_text.set_password_char('\u25cf'); // ● U+25CF BLACK CIRCLE
|
|
||||||
ShellEntry.addContextMenu(this._passwordEntry, { isPassword: true });
|
ShellEntry.addContextMenu(this._passwordEntry, { isPassword: true });
|
||||||
this.setInitialKeyFocus(this._passwordEntry);
|
this.setInitialKeyFocus(this._passwordEntry);
|
||||||
this._workSpinner = new Animation.Spinner(WORK_SPINNER_ICON_SIZE, {
|
this._workSpinner = new Animation.Spinner(WORK_SPINNER_ICON_SIZE, {
|
||||||
|
Loading…
Reference in New Issue
Block a user