From 9a55109d997e681cdc0a67653f78f73c05232c21 Mon Sep 17 00:00:00 2001 From: Niels De Graef Date: Mon, 26 Jun 2017 21:59:46 +0200 Subject: [PATCH] Convert Contacts.ContactEditor to GtkTemplate --- data/Makefile.am | 1 + data/contacts.gresource.xml | 1 + data/ui/app-menu.ui | 46 ------------ data/ui/contacts-contact-editor.ui | 117 +++++++++++++++++++++++++++++ po/POTFILES.in | 1 + src/contacts-contact-editor.vala | 85 +++++++-------------- 6 files changed, 148 insertions(+), 103 deletions(-) create mode 100644 data/ui/contacts-contact-editor.ui diff --git a/data/Makefile.am b/data/Makefile.am index da230ba..9b7d637 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -37,6 +37,7 @@ EXTRA_DIST = \ ui/app-menu.ui \ ui/contacts-address-map.ui \ ui/contacts-avatar-dialog.ui \ + ui/contacts-contact-editor.ui \ ui/contacts-in-app-notification.ui \ ui/contacts-list-pane.ui \ ui/contacts-window.ui \ diff --git a/data/contacts.gresource.xml b/data/contacts.gresource.xml index a40f05a..1f6cd8f 100644 --- a/data/contacts.gresource.xml +++ b/data/contacts.gresource.xml @@ -5,6 +5,7 @@ ui/app-menu.ui ui/contacts-address-map.ui ui/contacts-avatar-dialog.ui + ui/contacts-contact-editor.ui ui/contacts-in-app-notification.ui ui/contacts-list-pane.ui ui/contacts-window.ui diff --git a/data/ui/app-menu.ui b/data/ui/app-menu.ui index 852515a..1ae5152 100644 --- a/data/ui/app-menu.ui +++ b/data/ui/app-menu.ui @@ -22,50 +22,4 @@ - - - edit.add.email-addresses.home - Home email - - - edit.add.email-addresses.work - Work email - - - edit.add.phone-numbers.cell - Mobile phone - - - edit.add.phone-numbers.home - Home phone - - - edit.add.phone-numbers.work - Work phone - - - edit.add.urls - Website - - - edit.add.nickname - Nickname - - - edit.add.birthday - Birthday - - - edit.add.postal-addresses.home - Home address - - - edit.add.postal-addresses.work - Work address - - - edit.add.notes - Notes - - diff --git a/data/ui/contacts-contact-editor.ui b/data/ui/contacts-contact-editor.ui new file mode 100644 index 0000000..7783698 --- /dev/null +++ b/data/ui/contacts-contact-editor.ui @@ -0,0 +1,117 @@ + + + + + + + edit.add.email-addresses.home + Home email + + + edit.add.email-addresses.work + Work email + + + edit.add.phone-numbers.cell + Mobile phone + + + edit.add.phone-numbers.home + Home phone + + + edit.add.phone-numbers.work + Work phone + + + edit.add.urls + Website + + + edit.add.nickname + Nickname + + + edit.add.birthday + Birthday + + + edit.add.postal-addresses.home + Home address + + + edit.add.postal-addresses.work + Work address + + + edit.add.notes + Notes + + + + + diff --git a/po/POTFILES.in b/po/POTFILES.in index ab747aa..097b160 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -4,6 +4,7 @@ data/org.gnome.Contacts.appdata.xml.in data/org.gnome.Contacts.desktop.in data/ui/app-menu.ui data/ui/contacts-avatar-dialog.ui +data/ui/contacts-contact-editor.ui data/ui/contacts-list-pane.ui data/ui/contacts-window.ui src/contacts-accounts-list.vala diff --git a/src/contacts-contact-editor.vala b/src/contacts-contact-editor.vala index c0e9fd7..d380c2e 100644 --- a/src/contacts-contact-editor.vala +++ b/src/contacts-contact-editor.vala @@ -61,14 +61,23 @@ public class Contacts.AddressEditor : Box { } } +[GtkTemplate (ui = "/org/gnome/contacts/ui/contacts-contact-editor.ui")] public class Contacts.ContactEditor : Grid { - Contact contact; + private Contact contact; - Grid container_grid; - weak Widget focus_widget; + private Grid container_grid; + private weak Widget focus_widget; + [GtkChild] + private ScrolledWindow main_sw; + + [GtkChild] + private MenuButton add_detail_button; + + [GtkChild] public Button linked_button; + [GtkChild] public Button remove_button; public struct PropertyData { @@ -751,70 +760,32 @@ public class Contacts.ContactEditor : Grid { } public ContactEditor (SimpleActionGroup editor_actions) { - set_orientation (Orientation.VERTICAL); - - var main_sw = new ScrolledWindow (null, null); - add (main_sw); - - main_sw.set_shadow_type (ShadowType.NONE); - main_sw.set_hexpand (true); - main_sw.set_vexpand (true); - main_sw.set_policy (PolicyType.NEVER, PolicyType.AUTOMATIC); - var hcenter = new Center (); hcenter.max_width = 600; hcenter.xalign = 0.0; - container_grid = new Grid (); - container_grid.set_row_spacing (12); - container_grid.set_column_spacing (12); - container_grid.set_vexpand (true); - container_grid.set_hexpand (true); - container_grid.margin = 36; - container_grid.set_margin_bottom (24); + this.container_grid = new Grid (); + this.container_grid.set_row_spacing (12); + this.container_grid.set_column_spacing (12); + this.container_grid.set_vexpand (true); + this.container_grid.set_hexpand (true); + this.container_grid.margin = 36; + this.container_grid.set_margin_bottom (24); - hcenter.add (container_grid); - main_sw.add (hcenter); - container_grid.set_focus_vadjustment (main_sw.get_vadjustment ()); + hcenter.add (this.container_grid); + this.main_sw.add (hcenter); + this.container_grid.set_focus_vadjustment (this.main_sw.get_vadjustment ()); - main_sw.get_child ().get_style_context ().add_class ("contacts-main-view"); - main_sw.get_child ().get_style_context ().add_class ("view"); + this.main_sw.get_child ().get_style_context ().add_class ("contacts-main-view"); + this.main_sw.get_child ().get_style_context ().add_class ("view"); - var edit_toolbar = new ActionBar (); + this.main_sw.show_all (); - var builder = load_ui ("app-menu.ui"); - var gmenu = builder.get_object ("edit-contact") as MenuModel; + this.add_detail_button.get_popover ().insert_action_group ("edit", editor_actions); - var add_detail_button = new Gtk.MenuButton (); - add_detail_button.use_popover = true; - add_detail_button.set_menu_model (gmenu); - add_detail_button.set_direction (ArrowType.UP); - add_detail_button.get_popover ().insert_action_group ("edit", editor_actions); + this.writable_personas = new HashMap> (); - var box = new Box (Orientation.HORIZONTAL, 6); - box.add (new Label (_("New Detail"))); - box.add (new Image.from_icon_name ("go-down-symbolic", IconSize.BUTTON)); - add_detail_button.add (box); - - edit_toolbar.pack_start (add_detail_button); - - linked_button = new Button.with_label (_("Linked Accounts")); - edit_toolbar.pack_start (linked_button); - - remove_button = new Button.with_label (_("Remove Contact")); - remove_button.get_style_context ().add_class ("destructive-action"); - edit_toolbar.pack_end (remove_button); - - edit_toolbar.show_all (); - add (edit_toolbar); - - container_grid.show_all (); - main_sw.show (); - show_all (); - - writable_personas = new HashMap > (); - - container_grid.size_allocate.connect_after (size_allocate_cb); + this.container_grid.size_allocate.connect_after (size_allocate_cb); } public void edit (Contact c) {