[gnome-contacts/wip/cdavis/use-entry-row] editor-property: Use AdwEntryRow for entries




commit ad8839396eb9d94df10d9a0596082d177d46b882
Author: Christopher Davis <christopherdavis gnome org>
Date:   Tue Jul 5 18:39:21 2022 -0400

    editor-property: Use AdwEntryRow for entries
    
    Depends on
    https://gitlab.gnome.org/GNOME/libadwaita/-/merge_requests/587

 build-aux/flatpak/org.gnome.Contacts.Devel.json | 33 +++++++++++++++++++++
 src/contacts-editor-property.vala               | 39 ++++++++++++++++++++++---
 2 files changed, 68 insertions(+), 4 deletions(-)
---
diff --git a/build-aux/flatpak/org.gnome.Contacts.Devel.json b/build-aux/flatpak/org.gnome.Contacts.Devel.json
index 443e8547..2afa230a 100644
--- a/build-aux/flatpak/org.gnome.Contacts.Devel.json
+++ b/build-aux/flatpak/org.gnome.Contacts.Devel.json
@@ -170,6 +170,39 @@
                 }
             ]
         },
+        {
+            "name" : "libsass",
+            "buildsystem" : "meson",
+            "sources" : [
+                {
+                    "type" : "git",
+                    "url" : "https://github.com/lazka/libsass.git";,
+                    "branch" : "meson"
+                }
+            ]
+        },
+        {
+            "name" : "sassc",
+            "buildsystem" : "meson",
+            "sources" : [
+                {
+                    "type" : "git",
+                    "url" : "https://github.com/lazka/sassc.git";,
+                    "branch" : "meson"
+                }
+            ]
+        },
+        {
+            "name" : "libadwaita",
+            "buildsystem" : "meson",
+            "sources" : [
+                {
+                    "type" : "git",
+                    "url" : "https://gitlab.gnome.org/GNOME/libadwaita.git";,
+                    "branch" : "wip/cdavis/entry-row-extra-props"
+                }
+            ]
+        },
         {
             "name": "gnome-contacts",
             "buildsystem": "meson",
diff --git a/src/contacts-editor-property.vala b/src/contacts-editor-property.vala
index 3e0ea783..26bda66b 100644
--- a/src/contacts-editor-property.vala
+++ b/src/contacts-editor-property.vala
@@ -17,6 +17,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+using Adw;
 using Folks;
 
 public class Contacts.BirthdayEditor : Gtk.Dialog {
@@ -365,6 +366,36 @@ public class Contacts.EditorPropertyRow : Adw.Bin {
     return entry;
   }
 
+  public Adw.EntryRow set_main_entry_row(string text, string? placeholder = null) {
+    var row = new Adw.EntryRow();
+    row.title = placeholder;
+    row.text = text;
+
+    unowned var icon_name = Utils.get_icon_name_for_property (this.ptype);
+    if (icon_name != null) {
+      row.add_prefix(new Gtk.Image.from_icon_name (icon_name));
+    }
+
+    if (this.removable) {
+      var delete_button = new Gtk.Button.from_icon_name ("user-trash-symbolic");
+      delete_button.tooltip_text = _("Delete field");
+      this.bind_property ("is-empty", delete_button, "sensitive", BindingFlags.SYNC_CREATE | 
BindingFlags.INVERT_BOOLEAN);
+
+      delete_button.clicked.connect ((b) => { this.remove (); });
+
+      row.add_suffix (delete_button);
+    }
+
+    this.is_empty = (text == "");
+    row.changed.connect (() => {
+      this.is_empty = (row.text == "");
+    });
+
+    this.listbox.append (row);
+
+    return row;
+  }
+
   // Adds an extra row for a type combo, to choose between e.g. "Home" or "Work"
   public void add_type_combo (Gee.Set<AbstractFieldDetails> details_set,
                               TypeSet combo_type,
@@ -526,7 +557,7 @@ public class Contacts.EditorProperty : Object, ListModel {
     var box = new EditorPropertyRow ("email-addresses");
     box.sensitive = this.writeable;
 
-    var entry = box.set_main_entry (details.value, _("Add email"));
+    var entry = box.set_main_entry_row (details.value, _("Add email"));
     entry.set_input_purpose (Gtk.InputPurpose.EMAIL);
     entry.changed.connect (() => {
       details.value = entry.get_text ();
@@ -553,7 +584,7 @@ public class Contacts.EditorProperty : Object, ListModel {
     var box = new EditorPropertyRow ("phone-numbers");
     box.sensitive = this.writeable;
 
-    var entry = box.set_main_entry (details.value, _("Add phone number"));
+    var entry = box.set_main_entry_row (details.value, _("Add phone number"));
     entry.set_input_purpose (Gtk.InputPurpose.PHONE);
     entry.changed.connect (() => {
       details.value = entry.text;
@@ -581,7 +612,7 @@ public class Contacts.EditorProperty : Object, ListModel {
     var box = new EditorPropertyRow ("urls");
     box.sensitive = this.writeable;
 
-    var entry = box.set_main_entry (details.value, _("https://example.com";));
+    var entry = box.set_main_entry_row (details.value, _("https://example.com";));
     entry.set_input_purpose (Gtk.InputPurpose.URL);
     entry.changed.connect (() => {
       details.value = entry.get_text ();
@@ -597,7 +628,7 @@ public class Contacts.EditorProperty : Object, ListModel {
     var box = new EditorPropertyRow ("nickname");
     box.sensitive = this.writeable;
 
-    var entry = box.set_main_entry (details.nickname, _("Nickname"));
+    var entry = box.set_main_entry_row (details.nickname, _("Nickname"));
     entry.set_input_purpose (Gtk.InputPurpose.NAME);
     entry.changed.connect (() => {
       details.nickname = entry.text;


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