[geary/wip/714104-refine-account-dialog] Convert single-entry popover account row editors to use in-line entrys



commit a65f654c96c453c026d6ed2c7b802cda548597bb
Author: Michael Gratton <mike vee net>
Date:   Wed Dec 12 22:09:25 2018 +1100

    Convert single-entry popover account row editors to use in-line entrys

 src/client/accounts/accounts-editor-edit-pane.vala |  80 ++++++++-------
 .../accounts/accounts-editor-servers-pane.vala     | 112 +++++++--------------
 2 files changed, 83 insertions(+), 109 deletions(-)
---
diff --git a/src/client/accounts/accounts-editor-edit-pane.vala 
b/src/client/accounts/accounts-editor-edit-pane.vala
index d6676d01..4e59991c 100644
--- a/src/client/accounts/accounts-editor-edit-pane.vala
+++ b/src/client/accounts/accounts-editor-edit-pane.vala
@@ -59,7 +59,7 @@ internal class Accounts.EditorEditPane : Gtk.Grid, EditorPane, AccountPane {
         this.pane_content.set_focus_vadjustment(this.pane_adjustment);
 
         this.details_list.set_header_func(Editor.seperator_headers);
-        this.details_list.add(new DisplayNameRow(account));
+        this.details_list.add(new DisplayNameRow(account, this.commands));
 
         this.senders_list.set_header_func(Editor.seperator_headers);
         foreach (Geary.RFC822.MailboxAddress sender in
@@ -270,56 +270,66 @@ internal class Accounts.EditorEditPane : Gtk.Grid, EditorPane, AccountPane {
 }
 
 
-private class Accounts.DisplayNameRow : AccountRow<EditorEditPane,Gtk.Label> {
+private class Accounts.DisplayNameRow : AccountRow<EditorEditPane,Gtk.Entry> {
 
 
-    public DisplayNameRow(Geary.AccountInformation account) {
+    private Application.CommandStack commands;
+
+    public DisplayNameRow(Geary.AccountInformation account,
+                          Application.CommandStack commands) {
         base(
             account,
             // Translators: Label in the account editor for the user's
             // custom name for an account.
             _("Account name"),
-            new Gtk.Label("")
+            new Gtk.Entry()
         );
-        update();
-    }
+        this.activatable = false;
+        this.commands = commands;
 
-    public override void activated(EditorEditPane pane) {
-        EditorPopover popover = new EditorPopover();
-
-        string? value = this.account.display_name;
-        Gtk.Entry entry = new Gtk.Entry();
-        entry.set_text(value ?? "");
-        entry.set_placeholder_text(value ?? "");
-        entry.set_width_chars(20);
-        entry.activate.connect(() => {
-                pane.commands.execute.begin(
-                    new PropertyCommand<string>(
-                        this.account,
-                        this.account,
-                        "label",
-                        entry.get_text(),
-                        // Translators: Tooltip used to undo changing
-                        // the name of an account. The string
-                        // substitution is the old name of the
-                        // account.
-                        _("Change account name back to ā€œ%sā€")
-                    ),
-                    null
-                );
-                popover.popdown();
-            });
-        entry.show();
+        update();
 
-        popover.set_relative_to(this.value);
-        popover.layout.add(entry);
-        popover.popup();
+        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);
     }
 
+    private void commit() {
+        string value = this.value.text.strip();
+        if (value == "") {
+            value = this.account.primary_mailbox.address;
+            this.value.text = this.account.primary_mailbox.address;
+        }
+
+        if (value != this.account.display_name) {
+            this.commands.execute.begin(
+                new PropertyCommand<string>(
+                    this.account,
+                    this.account,
+                    "label",
+                    value,
+                    // Translators: Tooltip used to undo changing
+                    // the name of an account. The string
+                    // substitution is the old name of the
+                    // account.
+                    _("Change account name back to ā€œ%sā€")
+                ),
+                null
+            );
+        }
+
+        if (Geary.String.is_empty(value)) {
+        }
+    }
+
+    private bool on_focus_out() {
+        commit();
+        return Gdk.EVENT_PROPAGATE;
+    }
+
 }
 
 
diff --git a/src/client/accounts/accounts-editor-servers-pane.vala 
b/src/client/accounts/accounts-editor-servers-pane.vala
index 6d488acc..0d919d8d 100644
--- a/src/client/accounts/accounts-editor-servers-pane.vala
+++ b/src/client/accounts/accounts-editor-servers-pane.vala
@@ -384,11 +384,15 @@ private class Accounts.SaveDraftsRow :
 
 
 private class Accounts.ServiceHostRow :
-    ServiceRow<EditorServersPane,Gtk.Label> {
+    ServiceRow<EditorServersPane,Gtk.Entry> {
+
+
+    private Components.NetworkAddressValidator validator;
+
 
     public ServiceHostRow(Geary.AccountInformation account,
                           Geary.ServiceInformation service) {
-        string label = _("Unknown");
+        string label = "";
         switch (service.protocol) {
         case Geary.Protocol.IMAP:
             // Translators: This label describes the host name or IP
@@ -403,30 +407,11 @@ private class Accounts.ServiceHostRow :
             break;
         }
 
-        base(
-            account,
-            service,
-            label,
-            new Gtk.Label("")
-        );
-
+        base(account, service, label, new Gtk.Entry());
         update();
-    }
-
-    public override void activated(EditorServersPane pane) {
-        string? text = get_host_text() ?? "";
-        Gtk.Entry entry = new Gtk.Entry();
-        entry.set_text(text);
-        entry.set_placeholder_text(text);
-        entry.set_width_chars(20);
-        entry.show();
-
-        EditorPopover popover = new EditorPopover();
-        popover.set_relative_to(this.value);
-        popover.layout.add(entry);
-        popover.add_validator(new Components.NetworkAddressValidator(entry));
-        popover.valid_activated.connect(on_popover_activate);
-        popover.popup();
+        this.activatable = false;
+        this.validator = new Components.NetworkAddressValidator(this.value);
+        this.validator.state_changed.connect(on_validation_changed);
     }
 
     public override void update() {
@@ -434,7 +419,7 @@ private class Accounts.ServiceHostRow :
         if (Geary.String.is_empty(value)) {
             value = _("None");
         }
-        this.value.set_text(value);
+        this.value.text = value;
     }
 
     private string? get_host_text() {
@@ -449,21 +434,16 @@ private class Accounts.ServiceHostRow :
         return value;
     }
 
-    private void on_popover_activate(EditorPopover popover) {
-        Components.NetworkAddressValidator validator =
-            (Components.NetworkAddressValidator) Geary.traverse(
-                popover.validators
-            ).first();
-
-        GLib.NetworkAddress? address = validator.validated_address;
-        if (address != null) {
-            this.service.host = address.hostname;
-            this.service.port = address.port != 0
-                ? (uint16) address.port
-                : this.service.get_default_port();
+    private void on_validation_changed() {
+        if (this.validator.state == Components.Validator.Validity.VALID) {
+            GLib.NetworkAddress? address = this.validator.validated_address;
+            if (address != null) {
+                this.service.host = address.hostname;
+                this.service.port = address.port != 0
+                    ? (uint16) address.port
+                    : this.service.get_default_port();
+            }
         }
-
-        popover.popdown();
     }
 
 }
@@ -503,44 +483,31 @@ private class Accounts.ServiceSecurityRow :
 
 
 private class Accounts.ServiceLoginRow :
-    ServiceRow<EditorServersPane,Gtk.Label> {
+    ServiceRow<EditorServersPane,Gtk.Entry> {
+
+
+    public Components.Validator validator;
+
 
     public ServiceLoginRow(Geary.AccountInformation account,
                            Geary.ServiceInformation service) {
         base(
             account,
             service,
-            // Translators: This label describes the authentication
-            // scheme used by an account's IMAP or SMTP service.
+            // Translators: Label for the user's login name for an
+            // IMAP, SMTP, etc service
             _("Login name"),
-            new Gtk.Label("")
+            new Gtk.Entry()
         );
 
-        this.value.ellipsize = Pango.EllipsizeMode.MIDDLE;
         update();
-    }
-
-    public override void activated(EditorServersPane pane) {
-        string? value = null;
-        if (this.service.credentials != null) {
-            value = this.service.credentials.user;
-        }
-        Gtk.Entry entry = new Gtk.Entry();
-        entry.set_text(value ?? "");
-        entry.set_placeholder_text(value ?? "");
-        entry.set_width_chars(20);
-        entry.show();
-
-        EditorPopover popover = new EditorPopover();
-        popover.set_relative_to(this.value);
-        popover.layout.add(entry);
-        popover.add_validator(new Components.Validator(entry));
-        popover.valid_activated.connect(on_popover_activate);
-        popover.popup();
+        this.activatable = false;
+        this.validator = new Components.Validator(this.value);
+        this.validator.state_changed.connect(on_validation_changed);
     }
 
     public override void update() {
-        this.value.set_text(get_login_text());
+        this.value.text = get_login_text();
     }
 
     private string? get_login_text() {
@@ -550,7 +517,6 @@ private class Accounts.ServiceLoginRow :
             Gtk.StyleContext value_style = this.value.get_style_context();
             switch (this.service.credentials.supported_method) {
             case Geary.Credentials.Method.PASSWORD:
-                this.activatable = true;
                 value_style.remove_class(Gtk.STYLE_CLASS_DIM_LABEL);
                 break;
 
@@ -563,7 +529,6 @@ private class Accounts.ServiceLoginRow :
                 // the service's login name.
                 method = _("%s using OAuth2");
 
-                this.activatable = false;
                 value_style.add_class(Gtk.STYLE_CLASS_DIM_LABEL);
                 break;
             }
@@ -577,7 +542,7 @@ private class Accounts.ServiceLoginRow :
         } else if (this.service.protocol == Geary.Protocol.SMTP &&
                    this.service.credentials_requirement ==
                    Geary.Credentials.Requirement.USE_INCOMING) {
-            label = _("Use incoming server login");
+            label = _("Use receiving server login");
         } else {
             // Translators: Label used when no auth scheme is used
             // by an account's IMAP or SMTP service.
@@ -586,12 +551,11 @@ private class Accounts.ServiceLoginRow :
         return label;
     }
 
-    private void on_popover_activate(EditorPopover popover) {
-        Components.Validator validator =
-            Geary.traverse(popover.validators).first();
-       this.service.credentials =
-           this.service.credentials.copy_with_user(validator.target.text);
-        popover.popdown();
+    private void on_validation_changed() {
+        if (this.validator.state == Components.Validator.Validity.VALID) {
+            this.service.credentials =
+                this.service.credentials.copy_with_user(this.value.text);
+        }
     }
 
 }


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