From 83aa13d86fcd3d88dbd0a574beefaf43aa3aaac0 Mon Sep 17 00:00:00 2001 From: Niels De Graef Date: Mon, 23 Apr 2018 07:58:51 +0200 Subject: ContactSheet: use a container grid. By using that instead of directly attaching the widgets to itself, we can extract more common code wth ContactEditor into ContactForm. --- data/ui/contacts-contact-pane.ui | 17 +---------------- data/ui/contacts-contact-sheet.ui | 39 +++++++++++++++++---------------------- src/contacts-contact-pane.vala | 9 +++------ src/contacts-contact-sheet.vala | 36 ++++++++++++++++++++++-------------- 4 files changed, 43 insertions(+), 58 deletions(-) diff --git a/data/ui/contacts-contact-pane.ui b/data/ui/contacts-contact-pane.ui index d76e65e..a999b66 100644 --- a/data/ui/contacts-contact-pane.ui +++ b/data/ui/contacts-contact-pane.ui @@ -43,23 +43,8 @@ - + True - True - True - none - never - automatic - - - True - 600 - - - contact-sheet-page diff --git a/data/ui/contacts-contact-sheet.ui b/data/ui/contacts-contact-sheet.ui index 835beb6..4ef64b7 100644 --- a/data/ui/contacts-contact-sheet.ui +++ b/data/ui/contacts-contact-sheet.ui @@ -3,32 +3,27 @@ diff --git a/src/contacts-contact-pane.vala b/src/contacts-contact-pane.vala index ffb5d62..1fabeff 100644 --- a/src/contacts-contact-pane.vala +++ b/src/contacts-contact-pane.vala @@ -39,9 +39,7 @@ public class Contacts.ContactPane : Stack { private Grid none_selected_page; [GtkChild] - private ScrolledWindow contact_sheet_page; - [GtkChild] - private Container contact_sheet_container; + private Container contact_sheet_page; private ContactSheet? sheet = null; [GtkChild] @@ -124,8 +122,7 @@ public class Contacts.ContactPane : Stack { remove_contact_sheet(); this.sheet = new ContactSheet (this.contact, this.store); - this.contact_sheet_container.add (this.sheet); - this.sheet.set_focus_vadjustment (this.contact_sheet_page.get_vadjustment ()); + this.contact_sheet_page.add (this.sheet); set_visible_child (this.contact_sheet_page); var matches = this.store.aggregator.get_potential_matches (this.contact.individual, MatchResult.HIGH); @@ -145,7 +142,7 @@ public class Contacts.ContactPane : Stack { // Remove the suggestion grid that goes along with it. remove_suggestion_grid (); - this.contact_sheet_container.remove (this.sheet); + this.contact_sheet_page.remove (this.sheet); this.sheet.destroy(); this.sheet = null; } diff --git a/src/contacts-contact-sheet.vala b/src/contacts-contact-sheet.vala index a021507..f518a84 100644 --- a/src/contacts-contact-sheet.vala +++ b/src/contacts-contact-sheet.vala @@ -26,9 +26,8 @@ using Gee; */ [GtkTemplate (ui = "/org/gnome/Contacts/ui/contacts-contact-sheet.ui")] public class Contacts.ContactSheet : ContactForm { - [GtkChild] - private Label name_label; + private Grid container_grid; public ContactSheet (Contact contact, Store store) { this.contact = contact; @@ -46,14 +45,14 @@ public class Contacts.ContactSheet : ContactForm { type_label.xalign = 1.0f; type_label.set_halign (Align.END); type_label.get_style_context ().add_class ("dim-label"); - attach (type_label, 0, this.last_row); + this.container_grid.attach (type_label, 0, this.last_row); var value_button = new Button.with_label (value); value_button.focus_on_click = false; value_button.relief = ReliefStyle.NONE; value_button.xalign = 0.0f; value_button.set_hexpand (true); - attach (value_button, 1, this.last_row); + this.container_grid.attach (value_button, 1, this.last_row); this.last_row++; (value_button.get_child () as Label).set_ellipsize (Pango.EllipsizeMode.END); @@ -67,14 +66,14 @@ public class Contacts.ContactSheet : ContactForm { type_label.xalign = 1.0f; type_label.set_halign (Align.END); type_label.get_style_context ().add_class ("dim-label"); - attach (type_label, 0, this.last_row); + this.container_grid.attach (type_label, 0, this.last_row); var value_button = new LinkButton (value); value_button.focus_on_click = false; value_button.relief = ReliefStyle.NONE; value_button.xalign = 0.0f; value_button.set_hexpand (true); - attach (value_button, 1, this.last_row); + this.container_grid.attach (value_button, 1, this.last_row); this.last_row++; (value_button.get_child () as Label).set_ellipsize (Pango.EllipsizeMode.END); @@ -87,7 +86,7 @@ public class Contacts.ContactSheet : ContactForm { type_label.set_halign (Align.END); type_label.set_valign (Align.START); type_label.get_style_context ().add_class ("dim-label"); - attach (type_label, 0, this.last_row, 1, 1); + this.container_grid.attach (type_label, 0, this.last_row, 1, 1); var value_label = new Label (value); value_label.set_line_wrap (true); @@ -103,7 +102,7 @@ public class Contacts.ContactSheet : ContactForm { value_label.margin_top = 3; value_label.margin_bottom = 3; - attach (value_label, 1, this.last_row, 1, 1); + this.container_grid.attach (value_label, 1, this.last_row, 1, 1); this.last_row++; } @@ -111,12 +110,9 @@ public class Contacts.ContactSheet : ContactForm { var image_frame = new Avatar (PROFILE_SIZE, this.contact); image_frame.set_vexpand (false); image_frame.set_valign (Align.START); - attach (image_frame, 0, 0, 1, 3); + this.container_grid.attach (image_frame, 0, 0, 1, 3); - this.contact.keep_widget_uptodate (this.name_label, (w) => { - this.name_label.set_markup (Markup.printf_escaped ("%s", - this.contact.individual.display_name)); - }); + create_name_label (); this.last_row += 3; // Name/Avatar takes up 3 rows bool is_first_persona = true; @@ -126,7 +122,7 @@ public class Contacts.ContactSheet : ContactForm { foreach (var p in personas) { int persona_store_pos = this.last_row; if (!is_first_persona) { - attach (create_persona_store_label (p), 0, this.last_row, 3); + this.container_grid.attach (create_persona_store_label (p), 0, this.last_row, 3); this.last_row++; } @@ -144,6 +140,18 @@ public class Contacts.ContactSheet : ContactForm { show_all (); } + private void create_name_label () { + var name_label = new Label (""); + name_label.ellipsize = Pango.EllipsizeMode.END; + name_label.xalign = 0f; + name_label.selectable = true; + this.container_grid.attach (name_label, 1, 0, 1, 3); + this.contact.keep_widget_uptodate (name_label, (w) => { + name_label.set_markup (Markup.printf_escaped ("%s", + this.contact.individual.display_name)); + }); + } + private void add_row_for_property (Persona persona, string property) { switch (property) { case "email-addresses": -- cgit v1.2.1