diff options
author | Niels De Graef <nielsdegraef@gmail.com> | 2018-01-18 22:49:45 +0100 |
---|---|---|
committer | Niels De Graef <nielsdegraef@gmail.com> | 2018-01-18 22:49:45 +0100 |
commit | 83e6b544e23101c7ebaa1c925f10e2b4b714071c (patch) | |
tree | ab57acb05a2e9286d903aa6e61bdc0f5d0ac17b9 | |
parent | 1ebe4ffd8b7e289bb33f4f135171745a46e98324 (diff) | |
download | gnome-contacts-83e6b544e23101c7ebaa1c925f10e2b4b714071c.tar.gz |
ContactList: show Favorites separately at the top.
See also [bug 792026](https://bugzilla.gnome.org/show_bug.cgi?id=792026).
-rw-r--r-- | data/ui/style.css | 3 | ||||
-rw-r--r-- | src/contacts-contact-list.vala | 53 |
2 files changed, 48 insertions, 8 deletions
diff --git a/data/ui/style.css b/data/ui/style.css index 7613b3b..693f2b9 100644 --- a/data/ui/style.css +++ b/data/ui/style.css @@ -21,9 +21,6 @@ ContactsListPane.frame:dir(rtl) { /* A single row in the contact list pane */ row.contact-data-row { - border-color: @borders; - border-style: groove; - border-bottom-width: 1px; } /* Background color in contacts pane, similar to .documents-main-view.view */ diff --git a/src/contacts-contact-list.vala b/src/contacts-contact-list.vala index 6e654b7..bc8868e 100644 --- a/src/contacts-contact-list.vala +++ b/src/contacts-contact-list.vala @@ -38,7 +38,8 @@ public class Contacts.ContactList : ListBox { get_style_context (). add_class ("contact-data-row"); Grid grid = new Grid (); - grid.margin = 6; + grid.margin = 3; + grid.margin_start = 9; grid.set_column_spacing (10); this.avatar = new Avatar (Contact.LIST_AVATAR_SIZE); @@ -93,23 +94,65 @@ public class Contacts.ContactList : ListBox { set_sort_func ((a, b) => compare_data (a as ContactDataRow, b as ContactDataRow)); set_filter_func (filter); + set_header_func (update_header); show (); } private int compare_data (ContactDataRow a_data, ContactDataRow b_data) { - if (is_set (a_data.contact.display_name) && is_set (b_data.contact.display_name)) - return a_data.contact.display_name.collate (b_data.contact.display_name); + var a = a_data.contact.individual; + var b = b_data.contact.individual; + + // Always prefer favourites over non-favourites. + if (a.is_favourite != b.is_favourite) + return a.is_favourite? -1 : 1; + + // Both are (non-)favourites: sort by name + if (is_set (a.display_name) && is_set (b.display_name)) + return a.display_name.collate (b.display_name); // Sort empty names last - if (is_set (a_data.contact.display_name)) + if (is_set (a.display_name)) return -1; - if (is_set (b_data.contact.display_name)) + if (is_set (b.display_name)) return 1; return 0; } + private void update_header (ListBoxRow row, ListBoxRow? before) { + var current = ((ContactDataRow) row).contact.individual; + + if (before == null) { + if (current.is_favourite) + row.set_header (create_header_label (_("Favorites"))); + else + row.set_header (create_header_label (_("All Contacts"))); + return; + } + + var previous = ((ContactDataRow) before).contact.individual; + if (!current.is_favourite && previous.is_favourite) { + row.set_header (create_header_label (_("All Contacts"))); + } else { + row.set_header (null); + } + } + + private Label create_header_label (string text) { + var label = new Label (text); + label.halign = Align.START; + label.margin = 3; + label.margin_start = 6; + label.margin_top = 6; + var attrs = new Pango.AttrList (); + attrs.insert (Pango.attr_weight_new (Pango.Weight.BOLD)); + attrs.insert (Pango.attr_scale_new ((Pango.Scale.SMALL + Pango.Scale.MEDIUM) / 2.0)); + attrs.insert (Pango.attr_foreground_alpha_new (30000)); + label.attributes = attrs; + return label; + } + public void set_filter_values (string []? values) { if (filter_values == values) return; |