[geary/mjog/233-entry-undo: 3/4] Add undo support for account editor text entries
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/mjog/233-entry-undo: 3/4] Add undo support for account editor text entries
- Date: Thu, 7 Nov 2019 01:41:50 +0000 (UTC)
commit bbef117d8500c29f82d0d1935455f2d0e2e5b61e
Author: Michael Gratton <mike vee net>
Date: Thu Nov 7 09:55:30 2019 +1100
Add undo support for account editor text entries
Add an EntryUndo instance to all editor rows that use Gtk.Entry values.
src/client/accounts/accounts-editor-add-pane.vala | 23 +++++++++++++++-------
src/client/accounts/accounts-editor-edit-pane.vala | 18 +++++++++++++++--
.../accounts/accounts-editor-servers-pane.vala | 19 +++++++++++++-----
3 files changed, 46 insertions(+), 14 deletions(-)
---
diff --git a/src/client/accounts/accounts-editor-add-pane.vala
b/src/client/accounts/accounts-editor-add-pane.vala
index 9a0d4400..cfbb3276 100644
--- a/src/client/accounts/accounts-editor-add-pane.vala
+++ b/src/client/accounts/accounts-editor-add-pane.vala
@@ -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);
diff --git a/src/client/accounts/accounts-editor-edit-pane.vala
b/src/client/accounts/accounts-editor-edit-pane.vala
index 5cfcfdbb..0c052b44 100644
--- a/src/client/accounts/accounts-editor-edit-pane.vala
+++ b/src/client/accounts/accounts-editor-edit-pane.vala
@@ -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);
diff --git a/src/client/accounts/accounts-editor-servers-pane.vala
b/src/client/accounts/accounts-editor-servers-pane.vala
index 1eb402c9..7bfa6f09 100644
--- a/src/client/accounts/accounts-editor-servers-pane.vala
+++ b/src/client/accounts/accounts-editor-servers-pane.vala
@@ -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() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]