[gnome-contacts/wip/nielsdg/converge-editor-and-sheet] ContactForm: extract code to create PersonaStore label.



commit 7ff0ee331a89bb31370c1e14c92e36d6cbc30c3c
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Sun Apr 22 19:12:46 2018 +0200

    ContactForm: extract code to create PersonaStore label.
    
    Also fix the wrong persona store labels being hidden in the
    ContactSheet.

 src/contacts-contact-editor.vala |  8 +-------
 src/contacts-contact-form.vala   | 12 ++++++++++++
 src/contacts-contact-sheet.vala  | 15 +++++----------
 3 files changed, 18 insertions(+), 17 deletions(-)
---
diff --git a/src/contacts-contact-editor.vala b/src/contacts-contact-editor.vala
index 8b71448..2a1cb31 100644
--- a/src/contacts-contact-editor.vala
+++ b/src/contacts-contact-editor.vala
@@ -162,13 +162,7 @@ public class Contacts.ContactEditor : ContactForm {
     var personas = this.contact.get_personas_for_display ();
     foreach (var p in personas) {
       if (!is_first_persona) {
-        var store_name = new Label("");
-        store_name.set_markup (Markup.printf_escaped ("<span font='16px bold'>%s</span>",
-                                  Contact.format_persona_store_name_for_contact (p)));
-        store_name.set_halign (Align.START);
-        store_name.xalign = 0.0f;
-        store_name.margin_start = 6;
-        container_grid.attach (store_name, 0, i, 2, 1);
+        this.container_grid.attach (create_persona_store_label (p), 0, i, 2);
         last_store_position = ++i;
       }
 
diff --git a/src/contacts-contact-form.vala b/src/contacts-contact-form.vala
index c07634e..16c0dc9 100644
--- a/src/contacts-contact-form.vala
+++ b/src/contacts-contact-form.vala
@@ -15,6 +15,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+using Folks;
 using Gee;
 using Gtk;
 
@@ -64,4 +65,15 @@ public abstract class Contacts.ContactForm : Grid {
     sorted_props.sort ((owned) compare_properties);
     return sorted_props.to_array ();
   }
+
+  protected Label create_persona_store_label (Persona p) {
+    var store_name = new Label("");
+    store_name.set_markup (Markup.printf_escaped ("<span font='16px bold'>%s</span>",
+                           Contact.format_persona_store_name_for_contact (p)));
+    store_name.set_halign (Align.START);
+    store_name.xalign = 0.0f;
+    store_name.margin_start = 6;
+
+    return store_name;
+  }
 }
diff --git a/src/contacts-contact-sheet.vala b/src/contacts-contact-sheet.vala
index 8d9ed2b..a021507 100644
--- a/src/contacts-contact-sheet.vala
+++ b/src/contacts-contact-sheet.vala
@@ -124,23 +124,18 @@ public class Contacts.ContactSheet : ContactForm {
     var personas = this.contact.get_personas_for_display ();
     /* Cause personas are sorted properly I can do this */
     foreach (var p in personas) {
-      int persona_store_pos = 0;
+      int persona_store_pos = this.last_row;
       if (!is_first_persona) {
-        persona_store_pos = this.last_row;
-        var store_name = new Label("");
-        store_name.set_markup (Markup.printf_escaped ("<span font='16px bold'>%s</span>",
-                               Contact.format_persona_store_name_for_contact (p)));
-        store_name.set_halign (Align.START);
-        store_name.xalign = 0.0f;
-        store_name.margin_start = 6;
-        attach (store_name, 0, this.last_row, 3, 1);
+        attach (create_persona_store_label (p), 0, this.last_row, 3);
         this.last_row++;
       }
-      is_first_persona = false;
 
       foreach (var prop in ContactForm.SORTED_PROPERTIES)
         add_row_for_property (p, prop);
 
+      if (this.last_row != 3)
+        is_first_persona = false;
+
       // Nothing to show in the persona: don't mention it
       if (this.last_row == persona_store_pos + 1)
         get_child_at (0, persona_store_pos).destroy ();


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