[gnome-contacts/wip/cdavis/use-entry-row] editor-property: Use AdwEntryRow for entries
- From: Christopher Davis <christopherdavis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-contacts/wip/cdavis/use-entry-row] editor-property: Use AdwEntryRow for entries
- Date: Thu, 7 Jul 2022 14:04:54 +0000 (UTC)
commit d9688e111a9f489e3f6d7ab47abf9cad8334859a
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
data/ui/style.css | 13 -----------
src/contacts-editor-property.vala | 48 +++++++++++++++++++++++----------------
2 files changed, 28 insertions(+), 33 deletions(-)
---
diff --git a/data/ui/style.css b/data/ui/style.css
index 4e1c9712..63be3c81 100644
--- a/data/ui/style.css
+++ b/data/ui/style.css
@@ -74,14 +74,6 @@ flowboxchild.circular {
margin: 12px 12px;
}
- .contacts-editor-property entry.contacts-editor-main-widget image {
- margin: 9px 12px;
- }
-
- .contacts-editor-property entry.contacts-editor-main-widget {
- padding: 4px 6px 4px 0; /* left padding is for the icon */
- }
-
.contacts-editor-property button.contacts-editor-main-widget {
padding: 10px 0;
}
@@ -92,11 +84,6 @@ flowboxchild.circular {
padding-bottom: 6px;
}
- .contacts-editor-address entry,
- .contacts-editor-role entry {
- padding: 6px 3px;
- }
-
/* Widget to edit a birthday (_not_ the row itself) */
.contacts-editor-birthday {
margin: 12px;
diff --git a/src/contacts-editor-property.vala b/src/contacts-editor-property.vala
index 3e0ea783..fe6aed6a 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 {
@@ -339,30 +340,37 @@ public class Contacts.EditorPropertyRow : Adw.Bin {
}
/**
- * Wrapper around set_main_widget() with some extra styling for GtkEntries,
- * as well as making sure the "is-empty" property is updated.
+ * An alternative to set_main_widget() that creates and adds an AdwEntryRow
+ * to the list, and makes sure the "is-empty" property is updated.
*/
- public Gtk.Entry set_main_entry (string text, string? placeholder = null) {
- var entry = new Gtk.Entry ();
- entry.text = text;
- entry.placeholder_text = placeholder;
- entry.add_css_class ("flat");
-
- // Set the icon as part of the GtkEntry, to avoid it being outside of the
- // margin
+ 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) {
- entry.primary_icon_name = icon_name;
- entry.primary_icon_tooltip_text = Utils.get_display_name_for_property (this.ptype);
+ 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.set_main_widget (entry, false);
this.is_empty = (text == "");
- entry.changed.connect (() => {
- this.is_empty = (entry.text == "");
+ row.changed.connect (() => {
+ this.is_empty = (row.text == "");
});
- return entry;
+ this.listbox.append (row);
+
+ return row;
}
// Adds an extra row for a type combo, to choose between e.g. "Home" or "Work"
@@ -526,7 +534,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 +561,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 +589,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 +605,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]