[gnome-contacts] Use GtkTemplate for ContactPane.
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-contacts] Use GtkTemplate for ContactPane.
- Date: Sun, 2 Jul 2017 09:20:35 +0000 (UTC)
commit 4af34f277c4f836d330de1a22cac8ea32c0fd64c
Author: Niels De Graef <nielsdegraef gmail com>
Date: Sun Jul 2 11:16:41 2017 +0200
Use GtkTemplate for ContactPane.
* Use a GtkStack rather than a GtkNotebook.
* Also added some documentation.
data/Makefile.am | 1 +
data/contacts.gresource.xml | 1 +
data/ui/contacts-contact-pane.ui | 66 +++++++++++++++++
data/ui/contacts-window.ui | 1 -
po/POTFILES.in | 1 +
src/contacts-contact-pane.vala | 146 ++++++++++++++------------------------
6 files changed, 122 insertions(+), 94 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index 6474499..28e5191 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -40,6 +40,7 @@ EXTRA_DIST = \
ui/contacts-address-map.ui \
ui/contacts-avatar-dialog.ui \
ui/contacts-contact-editor.ui \
+ ui/contacts-contact-pane.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 1f6cd8f..52be8a9 100644
--- a/data/contacts.gresource.xml
+++ b/data/contacts.gresource.xml
@@ -6,6 +6,7 @@
<file compressed="true" preprocess="xml-stripblanks">ui/contacts-address-map.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/contacts-avatar-dialog.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/contacts-contact-editor.ui</file>
+ <file compressed="true" preprocess="xml-stripblanks">ui/contacts-contact-pane.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/contacts-in-app-notification.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/contacts-list-pane.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/contacts-window.ui</file>
diff --git a/data/ui/contacts-contact-pane.ui b/data/ui/contacts-contact-pane.ui
new file mode 100644
index 0000000..1672a98
--- /dev/null
+++ b/data/ui/contacts-contact-pane.ui
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <requires lib="gtk+" version="3.20"/>
+ <template class="ContactsContactPane" parent="GtkStack">
+ <property name="visible">True</property>
+ <property name="visible-child">none_selected_page</property>
+ <child>
+ <object class="GtkGrid" id="none_selected_page">
+ <property name="visible">True</property>
+ <property name="width_request">500</property>
+ <property name="orientation">vertical</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">True</property>
+ <property name="icon_name">avatar-default-symbolic</property>
+ <property name="vexpand">True</property>
+ <property name="valign">end</property>
+ <property name="pixel_size">144</property>
+ <style>
+ <class name="contacts-watermark"/>
+ </style>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Select a contact</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="valign">start</property>
+ <property name="margin_bottom">70</property>
+ <style>
+ <class name="contacts-watermark"/>
+ </style>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="name">none-selected-page</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkScrolledWindow" id="contact_sheet_page">
+ <property name="visible">True</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="shadow_type">none</property>
+ <property name="hscrollbar_policy">never</property>
+ <property name="vscrollbar_policy">automatic</property>
+ </object>
+ <packing>
+ <property name="name">contact-sheet-page</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkBox" id="contact_editor_page">
+ <property name="visible">True</property>
+ </object>
+ <packing>
+ <property name="name">contact-editor-page</property>
+ </packing>
+ </child>
+ </template>
+</interface>
diff --git a/data/ui/contacts-window.ui b/data/ui/contacts-window.ui
index f90fa12..b7c6cc1 100644
--- a/data/ui/contacts-window.ui
+++ b/data/ui/contacts-window.ui
@@ -31,7 +31,6 @@
<property name="can_focus">False</property>
<child>
<object class="ContactsContactPane" id="contact_pane">
- <property name="show_tabs">False</property>
<property name="visible">True</property>
<property name="hexpand">True</property>
<signal name="will-delete" handler="contact_pane_delete_contact_cb"
object="ContactsWindow" after="no" swapped="no"/>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 097b160..304862d 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -5,6 +5,7 @@ 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-contact-pane.ui
data/ui/contacts-list-pane.ui
data/ui/contacts-window.ui
src/contacts-accounts-list.vala
diff --git a/src/contacts-contact-pane.vala b/src/contacts-contact-pane.vala
index 4a66a5f..5a85f87 100644
--- a/src/contacts-contact-pane.vala
+++ b/src/contacts-contact-pane.vala
@@ -1,4 +1,3 @@
-/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 8 -*- */
/*
* Copyright (C) 2011 Alexander Larsson <alexl redhat com>
*
@@ -22,9 +21,15 @@ using Gee;
const int PROFILE_SIZE = 96;
-public class Contacts.ContactPane : Notebook {
- private Store _store;
+/**
+ * The ContactPage is the right pane. It consists of 3 possible pages:
+ * a page if nothing is selected, a ContactSheet to view contact information,
+ * and a ContactEditor to edit contact information.
+ */
+[GtkTemplate (ui = "/org/gnome/contacts/ui/contacts-contact-pane.ui")]
+public class Contacts.ContactPane : Stack {
+ private Store _store;
public Store store {
get {
return _store;
@@ -43,13 +48,15 @@ public class Contacts.ContactPane : Notebook {
public Contact? contact;
- /* 3 pages, first */
- private Grid none_selected_view;
+ [GtkChild]
+ private Grid none_selected_page;
- /* second page */
+ [GtkChild]
+ private ScrolledWindow contact_sheet_page;
private ContactSheet sheet;
- /* third page */
+ [GtkChild]
+ private Box contact_editor_page;
private ContactEditor editor;
private SimpleActionGroup edit_contact_actions;
@@ -86,7 +93,7 @@ public class Contacts.ContactPane : Notebook {
return;
sheet.update (contact);
- set_current_page (1);
+ set_visible_child (this.contact_sheet_page);
var matches = contact.store.aggregator.get_potential_matches (contact.individual, MatchResult.HIGH);
foreach (var ind in matches.keys) {
@@ -201,75 +208,61 @@ public class Contacts.ContactPane : Notebook {
}
if (contact == null)
- show_none_selected_view ();
+ set_visible_child (this.none_selected_page);
}
construct {
- this.show_border = false;
-
this.edit_contact_actions = new SimpleActionGroup ();
this.edit_contact_actions.add_action_entries (action_entries, this);
- /* starts with none_selected_view 'til someone select something */
- show_none_selected_view ();
-
- var main_sw = new ScrolledWindow (null, null);
-
- 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);
+ // contact editor page
+ sheet = new ContactSheet ();
+ sheet.hexpand = true;
+ sheet.vexpand = true;
+ sheet.margin = 36;
+ sheet.set_margin_bottom (24);
var hcenter = new Center ();
hcenter.max_width = 600;
hcenter.xalign = 0.0;
-
- sheet = new ContactSheet ();
+ hcenter.show ();
hcenter.add (sheet);
- sheet.set_hexpand (true);
- sheet.set_vexpand (true);
- sheet.margin = 36;
- sheet.set_margin_bottom (24);
-
- main_sw.add (hcenter);
- sheet.set_focus_vadjustment (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.contact_sheet_page.add (hcenter);
+ sheet.set_focus_vadjustment (this.contact_sheet_page.get_vadjustment ());
- main_sw.show_all ();
- insert_page (main_sw, null, 1);
+ this.contact_sheet_page.get_child ().get_style_context ().add_class ("contacts-main-view");
+ this.contact_sheet_page.get_child ().get_style_context ().add_class ("view");
- suggestion_grid = null;
+ this.suggestion_grid = null;
/* edit mode widgetry, third page */
- on_edit_mode = false;
- editor = new ContactEditor (this.edit_contact_actions);
- editor.linked_button.clicked.connect (linked_accounts);
- editor.remove_button.clicked.connect (delete_contact);
- insert_page (editor, null, 2);
+ this.on_edit_mode = false;
+ this.editor = new ContactEditor (this.edit_contact_actions);
+ this.editor.linked_button.clicked.connect (linked_accounts);
+ this.editor.remove_button.clicked.connect (delete_contact);
+ this.contact_editor_page.add (this.editor);
/* enable/disable actions*/
var birthday_action = this.edit_contact_actions.lookup_action ("add.birthday") as SimpleAction;
- editor.bind_property ("has-birthday-row",
- birthday_action, "enabled",
- BindingFlags.SYNC_CREATE |
- BindingFlags.INVERT_BOOLEAN);
+ this.editor.bind_property ("has-birthday-row",
+ birthday_action, "enabled",
+ BindingFlags.SYNC_CREATE |
+ BindingFlags.INVERT_BOOLEAN);
var nickname_action = this.edit_contact_actions.lookup_action ("add.nickname") as SimpleAction;
- editor.bind_property ("has-nickname-row",
- nickname_action, "enabled",
- BindingFlags.DEFAULT |
- BindingFlags.SYNC_CREATE |
- BindingFlags.INVERT_BOOLEAN);
+ this.editor.bind_property ("has-nickname-row",
+ nickname_action, "enabled",
+ BindingFlags.DEFAULT |
+ BindingFlags.SYNC_CREATE |
+ BindingFlags.INVERT_BOOLEAN);
var notes_action = this.edit_contact_actions.lookup_action ("add.notes") as SimpleAction;
- editor.bind_property ("has-notes-row",
- notes_action, "enabled",
- BindingFlags.DEFAULT |
- BindingFlags.SYNC_CREATE |
- BindingFlags.INVERT_BOOLEAN);
+ this.editor.bind_property ("has-notes-row",
+ notes_action, "enabled",
+ BindingFlags.DEFAULT |
+ BindingFlags.SYNC_CREATE |
+ BindingFlags.INVERT_BOOLEAN);
}
void on_add_detail (GLib.SimpleAction action, GLib.Variant? parameter) {
@@ -302,39 +295,6 @@ public class Contacts.ContactPane : Notebook {
}
}
- void show_none_selected_view () {
- if (none_selected_view == null) {
- none_selected_view = new Grid ();
- none_selected_view.set_size_request (500, -1);
- none_selected_view.set_orientation (Orientation.VERTICAL);
- none_selected_view.set_vexpand (true);
- none_selected_view.set_hexpand (true);
-
- var icon_theme = IconTheme.get_default ();
- var pix = icon_theme.load_icon ("avatar-default-symbolic", 144, 0);
-
- var image = new Image.from_pixbuf (pix);
- image.get_style_context ().add_class ("contacts-watermark");
- image.set_vexpand (true);
- image.set_valign (Align.END);
- none_selected_view.add (image);
-
- var label = new Gtk.Label ("");
- label.set_markup ("<span font=\"12\">%s</span>".printf (_("Select a contact")));
- label.get_style_context ().add_class ("contacts-watermark");
- label.set_vexpand (true);
- label.set_hexpand (true);
- label.set_valign (Align.START);
- label.margin_bottom = 70;
- none_selected_view.add (label);
-
- none_selected_view.show_all ();
- insert_page (none_selected_view, null, 0);
- }
-
- set_current_page (0);
- }
-
public void set_edit_mode (bool on_edit, bool drop_changes = false) {
if (on_edit == on_edit_mode)
return;
@@ -356,7 +316,7 @@ public class Contacts.ContactPane : Notebook {
editor.clear ();
editor.edit (contact);
editor.show_all ();
- set_current_page (2);
+ set_visible_child (this.contact_editor_page);
} else {
on_edit_mode = false;
/* saving changes */
@@ -404,11 +364,11 @@ public class Contacts.ContactPane : Notebook {
editor.clear ();
if (contact != null) {
- sheet.clear ();
- sheet.update (contact);
- set_current_page (1);
+ sheet.clear ();
+ sheet.update (contact);
+ set_visible_child (this.contact_sheet_page);
} else {
- show_none_selected_view ();
+ set_visible_child (this.none_selected_page);
}
}
}
@@ -425,7 +385,7 @@ public class Contacts.ContactPane : Notebook {
editor.set_new_contact ();
- set_current_page (2);
+ set_visible_child (this.contact_editor_page);
}
public void create_contact () {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]