summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels De Graef <nielsdegraef@gmail.com>2018-06-24 17:59:37 +0200
committerNiels De Graef <nielsdegraef@gmail.com>2018-06-24 17:59:37 +0200
commitaa234e1b26f5f59f13fb1d8f6ab3b91dda34e1d1 (patch)
treef54902e2e26b4b9b0fef19f5085998b3da135700
parent940d98cda2cacdbed768dabe457159ba697209c9 (diff)
downloadgnome-contacts-wip/nielsdg/cleanup-form.tar.gz
ContactForm: extract common property label.wip/nielsdg/cleanup-form
This provides consistency, and allows us to remove some copy-pasta.
-rw-r--r--src/contacts-contact-editor.vala44
-rw-r--r--src/contacts-contact-form.vala12
-rw-r--r--src/contacts-contact-sheet.vala17
3 files changed, 30 insertions, 43 deletions
diff --git a/src/contacts-contact-editor.vala b/src/contacts-contact-editor.vala
index c641877..fcc49cd 100644
--- a/src/contacts-contact-editor.vala
+++ b/src/contacts-contact-editor.vala
@@ -403,11 +403,7 @@ public class Contacts.ContactEditor : ContactForm {
}
void attach_row_with_entry_labeled (string title, AbstractFieldDetails? details, string value, int row) {
- var title_label = new Label (title);
- title_label.set_hexpand (false);
- title_label.set_halign (Align.START);
- title_label.margin_end = 6;
- container_grid.attach (title_label, 0, row, 1, 1);
+ container_grid.attach (create_property_label (title), 0, row);
var value_entry = new Entry ();
value_entry.set_text (value);
@@ -431,13 +427,7 @@ public class Contacts.ContactEditor : ContactForm {
}
void attach_row_with_text_labeled (string title, AbstractFieldDetails? details, string value, int row) {
- var title_label = new Label (title);
- title_label.set_hexpand (false);
- title_label.set_halign (Align.START);
- title_label.set_valign (Align.START);
- title_label.margin_top = 3;
- title_label.margin_end = 6;
- container_grid.attach (title_label, 0, row, 1, 1);
+ container_grid.attach (create_property_label (title), 0, row);
var sw = new ScrolledWindow (null, null);
sw.set_shadow_type (ShadowType.OUT);
@@ -469,12 +459,8 @@ public class Contacts.ContactEditor : ContactForm {
delegate void AdjustingDateFn();
- void attach_row_for_birthday (string title, AbstractFieldDetails? details, DateTime birthday, int row) {
- var title_label = new Label (title);
- title_label.set_hexpand (false);
- title_label.set_halign (Align.START);
- title_label.margin_end = 6;
- container_grid.attach (title_label, 0, row, 1, 1);
+ private void attach_row_for_birthday (DateTime birthday, int row) {
+ container_grid.attach (create_property_label (_("Birthday")), 0, row);
var box = new Grid ();
box.set_column_spacing (12);
@@ -695,19 +681,17 @@ public class Contacts.ContactEditor : ContactForm {
case "birthday":
var rows = new HashMap<int, RowData?> ();
if (add_empty) {
- var today = new DateTime.now_local ();
- attach_row_for_birthday (_("Birthday"), null, today, row);
- rows.set (row, { null });
- row++;
+ var today = new DateTime.now_local ();
+ attach_row_for_birthday (today, row);
+ rows.set (row, { null });
+ row++;
} else {
- var birthday_details = p as BirthdayDetails;
- if (birthday_details != null) {
- if (birthday_details.birthday != null) {
- attach_row_for_birthday (_("Birthday"), null, birthday_details.birthday, row);
- rows.set (row, { null });
- row++;
- }
- }
+ var birthday_details = p as BirthdayDetails;
+ if (birthday_details != null && birthday_details.birthday != null) {
+ attach_row_for_birthday (birthday_details.birthday, row);
+ rows.set (row, { null });
+ row++;
+ }
}
if (! rows.is_empty) {
has_birthday_row = true;
diff --git a/src/contacts-contact-form.vala b/src/contacts-contact-form.vala
index f44a2fb..3e1c2ea 100644
--- a/src/contacts-contact-form.vala
+++ b/src/contacts-contact-form.vala
@@ -87,4 +87,16 @@ public abstract class Contacts.ContactForm : Grid {
return store_name;
}
+
+ protected Label create_property_label (string text, string? tooltip = null) {
+ var property_label = new Label (text);
+ property_label.xalign = 1.0f;
+ property_label.halign = Align.END;
+ property_label.valign = Align.START;
+ property_label.get_style_context ().add_class ("dim-label");
+ if (tooltip != null)
+ property_label.tooltip_text = tooltip;
+
+ return property_label;
+ }
}
diff --git a/src/contacts-contact-sheet.vala b/src/contacts-contact-sheet.vala
index 66b612e..9556e66 100644
--- a/src/contacts-contact-sheet.vala
+++ b/src/contacts-contact-sheet.vala
@@ -38,11 +38,7 @@ public class Contacts.ContactSheet : ContactForm {
}
private Button add_row_with_button (string label, string value, bool use_link_button = false) {
- var type_label = new Label (label);
- type_label.xalign = 1.0f;
- type_label.set_halign (Align.END);
- type_label.get_style_context ().add_class ("dim-label");
- this.container_grid.attach (type_label, 0, this.last_row);
+ this.container_grid.attach (create_property_label (label), 0, this.last_row);
var value_button = use_link_button? new LinkButton (value) : new Button.with_label (value);
value_button.focus_on_click = false;
@@ -57,13 +53,8 @@ public class Contacts.ContactSheet : ContactForm {
return value_button;
}
- void add_row_with_label (string label_value, string value) {
- var type_label = new Label (label_value);
- type_label.xalign = 1.0f;
- type_label.set_halign (Align.END);
- type_label.set_valign (Align.START);
- type_label.get_style_context ().add_class ("dim-label");
- this.container_grid.attach (type_label, 0, this.last_row, 1, 1);
+ void add_row_with_label (string label, string value) {
+ this.container_grid.attach (create_property_label (label), 0, this.last_row);
var value_label = new Label (value);
value_label.set_line_wrap (true);
@@ -74,7 +65,7 @@ public class Contacts.ContactSheet : ContactForm {
value_label.set_selectable (true);
/* FIXME: hardcode gap to match the button size */
- type_label.margin_top = 3;
+ value_label.margin_top = 3;
value_label.margin_start = 6;
value_label.margin_top = 3;
value_label.margin_bottom = 3;