Add undo support for account editor text entries
Add an EntryUndo instance to all editor rows that use Gtk.Entry values.
This commit is contained in:
parent
8000e7ca63
commit
dae817b037
3 changed files with 46 additions and 14 deletions
|
|
@ -517,11 +517,19 @@ private abstract class Accounts.AddPaneRow<Value> :
|
|||
private abstract class Accounts.EntryRow : AddPaneRow<Gtk.Entry> {
|
||||
|
||||
|
||||
protected EntryRow(string label, string? placeholder = null) {
|
||||
private Components.EntryUndo undo;
|
||||
|
||||
|
||||
protected EntryRow(string label,
|
||||
string? initial_value = null,
|
||||
string? placeholder = null) {
|
||||
base(label, new Gtk.Entry());
|
||||
|
||||
this.value.text = initial_value ?? "";
|
||||
this.value.placeholder_text = placeholder ?? "";
|
||||
this.value.width_chars = 32;
|
||||
|
||||
this.undo = new Components.EntryUndo(this.value);
|
||||
}
|
||||
|
||||
public override bool focus(Gtk.DirectionType direction) {
|
||||
|
|
@ -548,12 +556,12 @@ private class Accounts.NameRow : EntryRow {
|
|||
public NameRow(string default_name) {
|
||||
// Translators: Label for the person's actual name when adding
|
||||
// an account
|
||||
base(_("Your name"));
|
||||
base(_("Your name"), default_name.strip());
|
||||
this.validator = new Components.Validator(this.value);
|
||||
if (default_name.strip() != "") {
|
||||
// Set the text after hooking up the validator, so if the
|
||||
// string is non-null it will already be valid
|
||||
this.value.set_text(default_name);
|
||||
if (this.value.text != "") {
|
||||
// Validate if the string is non-empty so it will be good
|
||||
// to go from the start
|
||||
this.value.activate();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -566,6 +574,7 @@ private class Accounts.EmailRow : EntryRow {
|
|||
public EmailRow() {
|
||||
base(
|
||||
_("Email address"),
|
||||
null,
|
||||
// Translators: Placeholder for the default sender address
|
||||
// when adding an account
|
||||
_("person@example.com")
|
||||
|
|
@ -634,7 +643,7 @@ private class Accounts.HostnameRow : EntryRow {
|
|||
break;
|
||||
}
|
||||
|
||||
base(label, placeholder);
|
||||
base(label, null, placeholder);
|
||||
this.type = type;
|
||||
|
||||
this.validator = new Components.NetworkAddressValidator(this.value, 0);
|
||||
|
|
|
|||
|
|
@ -264,6 +264,7 @@ internal class Accounts.EditorEditPane :
|
|||
private class Accounts.DisplayNameRow : AccountRow<EditorEditPane,Gtk.Entry> {
|
||||
|
||||
|
||||
private Components.EntryUndo value_undo;
|
||||
private Application.CommandStack commands;
|
||||
private GLib.Cancellable? cancellable;
|
||||
|
||||
|
|
@ -284,12 +285,19 @@ private class Accounts.DisplayNameRow : AccountRow<EditorEditPane,Gtk.Entry> {
|
|||
|
||||
update();
|
||||
|
||||
// Hook up after updating the value so the default value isn't
|
||||
// undoable
|
||||
this.value_undo = new Components.EntryUndo(this.value);
|
||||
|
||||
this.value.focus_out_event.connect(on_focus_out);
|
||||
}
|
||||
|
||||
public override void update() {
|
||||
this.value.set_placeholder_text(this.account.primary_mailbox.address);
|
||||
this.value.set_text(this.account.display_name);
|
||||
this.value.placeholder_text = this.account.primary_mailbox.address;
|
||||
// Only update if changed to avoid adding more undo edits
|
||||
if (this.value.text != this.account.display_name) {
|
||||
this.value.text = this.account.display_name;
|
||||
}
|
||||
}
|
||||
|
||||
private void commit() {
|
||||
|
|
@ -434,7 +442,9 @@ internal class Accounts.MailboxEditorPopover : EditorPopover {
|
|||
|
||||
|
||||
private Gtk.Entry name_entry = new Gtk.Entry();
|
||||
private Components.EntryUndo name_undo;
|
||||
private Gtk.Entry address_entry = new Gtk.Entry();
|
||||
private Components.EntryUndo address_undo;
|
||||
private Components.EmailValidator address_validator;
|
||||
private Gtk.Button remove_button;
|
||||
|
||||
|
|
@ -460,6 +470,8 @@ internal class Accounts.MailboxEditorPopover : EditorPopover {
|
|||
this.name_entry.activate.connect(on_activate);
|
||||
this.name_entry.show();
|
||||
|
||||
this.name_undo = new Components.EntryUndo(this.name_entry);
|
||||
|
||||
this.address_entry.input_purpose = Gtk.InputPurpose.EMAIL;
|
||||
this.address_entry.set_text(address ?? "");
|
||||
this.address_entry.set_placeholder_text(
|
||||
|
|
@ -473,6 +485,8 @@ internal class Accounts.MailboxEditorPopover : EditorPopover {
|
|||
this.address_entry.activate.connect(on_activate);
|
||||
this.address_entry.show();
|
||||
|
||||
this.address_undo = new Components.EntryUndo(this.address_entry);
|
||||
|
||||
this.address_validator =
|
||||
new Components.EmailValidator(this.address_entry);
|
||||
|
||||
|
|
|
|||
|
|
@ -711,6 +711,7 @@ private class Accounts.ServiceHostRow :
|
|||
}
|
||||
}
|
||||
|
||||
private Components.EntryUndo value_undo;
|
||||
private Application.CommandStack commands;
|
||||
private GLib.Cancellable? cancellable;
|
||||
|
||||
|
|
@ -741,9 +742,11 @@ private class Accounts.ServiceHostRow :
|
|||
this.validator = new Components.NetworkAddressValidator(this.value);
|
||||
|
||||
// Update after the validator is wired up to ensure the value
|
||||
// is validated
|
||||
// is validated, wire up undo after updating so the default
|
||||
// value isn't undoable.
|
||||
setup_validator();
|
||||
update();
|
||||
this.value_undo = new Components.EntryUndo(this.value);
|
||||
}
|
||||
|
||||
public override void update() {
|
||||
|
|
@ -862,6 +865,7 @@ private class Accounts.ServiceLoginRow :
|
|||
}
|
||||
}
|
||||
|
||||
private Components.EntryUndo value_undo;
|
||||
private Application.CommandStack commands;
|
||||
private GLib.Cancellable? cancellable;
|
||||
private ServicePasswordRow? password_row;
|
||||
|
|
@ -894,9 +898,11 @@ private class Accounts.ServiceLoginRow :
|
|||
}
|
||||
|
||||
// Update after the validator is wired up to ensure the value
|
||||
// is validated
|
||||
update();
|
||||
// is validated, wire up undo after updating so the default
|
||||
// value isn't undoable.
|
||||
setup_validator();
|
||||
update();
|
||||
this.value_undo = new Components.EntryUndo(this.value);
|
||||
}
|
||||
|
||||
public override void update() {
|
||||
|
|
@ -983,6 +989,7 @@ private class Accounts.ServicePasswordRow :
|
|||
}
|
||||
}
|
||||
|
||||
private Components.EntryUndo value_undo;
|
||||
private Application.CommandStack commands;
|
||||
private GLib.Cancellable? cancellable;
|
||||
|
||||
|
|
@ -1008,9 +1015,11 @@ private class Accounts.ServicePasswordRow :
|
|||
this.validator = new Components.Validator(this.value);
|
||||
|
||||
// Update after the validator is wired up to ensure the value
|
||||
// is validated
|
||||
update();
|
||||
// is validated, wire up undo after updating so the default
|
||||
// value isn't undoable.
|
||||
setup_validator();
|
||||
update();
|
||||
this.value_undo = new Components.EntryUndo(this.value);
|
||||
}
|
||||
|
||||
public override void update() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue