Show address fields when adding the first contact

The new contact dialog iterates over the list of address fields, which
are declared as static in the Contact class. Static data in Vala is
implemented by initializing the data during class_init(), or in other
words, the first time that the class is instantiated. When adding the
first contact, there are no instances of Contact, and so the address
fields have not been initialized. This leads to a blank space in the new
contact dialog, where the list of address fields should be.

Ensure that class_init() of the Contact class has been called by
calling g_type_class_ref() on the Type before iterating over the address
fields.

https://bugzilla.gnome.org/show_bug.cgi?id=702810
This commit is contained in:
David King 2014-12-17 14:25:17 +00:00 committed by David King
parent 434bee9bef
commit c5ca1689f5

View file

@ -187,6 +187,14 @@ public class Contacts.NewContactDialog : Dialog {
sub_grid.set_hexpand (true); sub_grid.set_hexpand (true);
entries.add (sub_grid); entries.add (sub_grid);
/* Ensure that class_init() of Contact has been called, to initialize the
* static members, including postal_element_props. */
var contact_type = Type.from_name ("ContactsContact");
if (contact_type != 0) {
// Type has been registered, make sure that class_init() has been called.
contact_type.class_ref ();
}
for (int i = 0; i < Contact.postal_element_props.length; i++) { for (int i = 0; i < Contact.postal_element_props.length; i++) {
var entry = new Entry (); var entry = new Entry ();
entry.set ("placeholder-text", Contact.postal_element_names[i]); entry.set ("placeholder-text", Contact.postal_element_names[i]);