[gnome-contacts] ContactListPane: use constructors to pass a Store
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-contacts] ContactListPane: use constructors to pass a Store
- Date: Sun, 24 Dec 2017 11:28:51 +0000 (UTC)
commit 108440432f6841f01febd122f5959a1b2159ca77
Author: Niels De Graef <nielsdegraef gmail com>
Date: Sun Dec 24 12:28:04 2017 +0100
ContactListPane: use constructors to pass a Store
data/ui/contacts-list-pane.ui | 11 +------
src/contacts-list-pane.vala | 66 +++++++++++++++--------------------------
src/contacts-view.vala | 40 ++++++++++---------------
3 files changed, 41 insertions(+), 76 deletions(-)
---
diff --git a/data/ui/contacts-list-pane.ui b/data/ui/contacts-list-pane.ui
index 268f018..3abcd13 100644
--- a/data/ui/contacts-list-pane.ui
+++ b/data/ui/contacts-list-pane.ui
@@ -45,22 +45,13 @@
</packing>
</child>
<child>
- <object class="GtkScrolledWindow" id="scrolled">
+ <object class="GtkScrolledWindow" id="contacts_view_container">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="hscrollbar_policy">never</property>
<property name="no_show_all">True</property>
- <child>
- <object class="ContactsView" id="contacts_view">
- <property name="visible">True</property>
- <property name="selection_mode">browse</property>
- <style>
- <class name="contacts-view"/>
- </style>
- </object>
- </child>
</object>
<packing>
<property name="left_attach">0</property>
diff --git a/src/contacts-list-pane.vala b/src/contacts-list-pane.vala
index fd1dcf1..18f95f8 100644
--- a/src/contacts-list-pane.vala
+++ b/src/contacts-list-pane.vala
@@ -22,18 +22,10 @@ using Folks;
[GtkTemplate (ui = "/org/gnome/contacts/ui/contacts-list-pane.ui")]
public class Contacts.ListPane : Frame {
- private Store _store;
- public Store store {
- get {
- return _store;
- }
- set {
- _store = value;
- contacts_view.store = _store;
- }
- }
+ private Store store;
[GtkChild]
+ private Gtk.ScrolledWindow contacts_view_container;
private View contacts_view;
[GtkChild]
@@ -72,7 +64,7 @@ public class Contacts.ListPane : Frame {
values = str.split(" ");
}
- contacts_view.set_filter_values (values);
+ this.contacts_view.set_filter_values (values);
}
private bool filter_entry_changed_timeout () {
@@ -90,62 +82,52 @@ public class Contacts.ListPane : Frame {
}
public ListPane (Store contacts_store) {
- Object (store: contacts_store);
- }
+ this.store = contacts_store;
- construct {
- search_tool_item.set_expand (true);
+ // Load the ContactsView and connect the necessary signals
+ this.contacts_view = new View (contacts_store);
+ this.contacts_view_container.add (this.contacts_view);
- contacts_view.selection_changed.connect( (l, contact) => {
- if (!ignore_selection_change)
+ this.contacts_view.selection_changed.connect( (l, contact) => {
+ if (!this.ignore_selection_change)
selection_changed (contact);
});
- /* contact mark handling */
- contacts_view.contacts_marked.connect ((nr_contacts_marked) => {
- if (nr_contacts_marked > 0)
- delete_button.set_sensitive (true);
- else
- delete_button.set_sensitive (false);
-
- if (nr_contacts_marked > 1)
- link_button.set_sensitive (true);
- else
- link_button.set_sensitive (false);
-
- contacts_marked (nr_contacts_marked);
+ this.contacts_view.contacts_marked.connect ((nr_contacts_marked) => {
+ this.delete_button.sensitive = (nr_contacts_marked > 0);
+ this.link_button.sensitive = (nr_contacts_marked > 1);
+ contacts_marked (nr_contacts_marked);
});
- link_button.clicked.connect (() => {
- var marked_contacts = contacts_view.get_marked_contacts ();
+ // Take care of the other widgets
+ this.search_tool_item.set_expand (true);
- link_contacts (marked_contacts);
+ this.link_button.clicked.connect (() => {
+ link_contacts (this.contacts_view.get_marked_contacts ());
});
- delete_button.clicked.connect (() => {
+ this.delete_button.clicked.connect (() => {
var marked_contacts = contacts_view.get_marked_contacts ();
- foreach (var c in marked_contacts) {
- c.hide ();
- }
-
- delete_contacts (marked_contacts);
+ foreach (var c in marked_contacts)
+ c.hide ();
+ delete_contacts (marked_contacts);
});
}
public void select_contact (Contact? contact, bool ignore_change = false) {
if (ignore_change)
ignore_selection_change = true;
- contacts_view.select_contact (contact);
+ this.contacts_view.select_contact (contact);
ignore_selection_change = false;
}
public void show_selection () {
- contacts_view.show_selectors ();
+ this.contacts_view.show_selectors ();
actions_bar.show ();
}
public void hide_selection () {
- contacts_view.hide_selectors ();
+ this.contacts_view.hide_selectors ();
actions_bar.hide ();
}
diff --git a/src/contacts-view.vala b/src/contacts-view.vala
index c790e93..7d8d27c 100644
--- a/src/contacts-view.vala
+++ b/src/contacts-view.vala
@@ -68,38 +68,30 @@ public class Contacts.View : ListBox {
public signal void selection_changed (Contact? contact);
public signal void contacts_marked (int contacts_marked);
- HashMap<Contact,ContactDataRow> contacts;
+ private Map<Contact, ContactDataRow> contacts = new HashMap<Contact, ContactDataRow> ();
int nr_contacts_marked = 0;
string []? filter_values;
bool selectors_visible = false;
- private Store _store;
+ private Store store;
- public Store store {
- get {
- return _store;
- }
- set {
- _store = value;
-
- _store.added.connect (contact_added_cb);
- _store.removed.connect (contact_removed_cb);
- _store.changed.connect (contact_changed_cb);
- foreach (var c in _store.get_contacts ())
- contact_added_cb (_store, c);
- }
- }
+ public View (Store store) {
+ this.selection_mode = Gtk.SelectionMode.BROWSE;
+ this.store = store;
- construct {
- contacts = new HashMap<Contact,ContactDataRow> ();
+ this.store.added.connect (contact_added_cb);
+ this.store.removed.connect (contact_removed_cb);
+ this.store.changed.connect (contact_changed_cb);
+ foreach (var c in this.store.get_contacts ())
+ contact_added_cb (this.store, c);
- this.set_sort_func ((row_a, row_b) => {
- var a = row_a as ContactDataRow;
- var b = row_b as ContactDataRow;
- return compare_data (a, b);
- });
- this.set_filter_func (filter);
+ get_style_context ().add_class ("contacts-view");
+
+ set_sort_func ((a, b) => compare_data (a as ContactDataRow, b as ContactDataRow));
+ set_filter_func (filter);
+
+ show ();
}
private int compare_data (ContactDataRow a_data, ContactDataRow b_data) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]