[gnome-contacts] Split out TreeView from list pane into its own widget
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-contacts] Split out TreeView from list pane into its own widget
- Date: Wed, 17 Aug 2011 15:48:00 +0000 (UTC)
commit 7d45c18854a216a41be0bf6468beca49da2750e3
Author: Alexander Larsson <alexl redhat com>
Date: Wed Aug 17 13:50:37 2011 +0200
Split out TreeView from list pane into its own widget
src/contacts-list-pane.vala | 90 ++++--------------------------------------
src/contacts-view.vala | 91 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 99 insertions(+), 82 deletions(-)
---
diff --git a/src/contacts-list-pane.vala b/src/contacts-list-pane.vala
index 4d05eda..39aec5f 100644
--- a/src/contacts-list-pane.vala
+++ b/src/contacts-list-pane.vala
@@ -23,73 +23,13 @@ using Folks;
public class Contacts.ListPane : Frame {
private Store contacts_store;
private View contacts_view;
- private TreeView contacts_tree_view;
+ private ViewWidget list;
public Entry filter_entry;
private uint filter_entry_changed_id;
- private CellRendererShape shape;
public signal void selection_changed (Contact? contact);
public signal void create_new ();
- private void setup_contacts_view (TreeView tree_view) {
- tree_view.set_headers_visible (false);
-
- var selection = tree_view.get_selection ();
- selection.set_mode (SelectionMode.BROWSE);
- selection.changed.connect (contacts_selection_changed);
-
- var column = new TreeViewColumn ();
-
- var text = new CellRendererText ();
- text.set_alignment (0, 0);
- column.pack_start (text, true);
- text.set ("weight", Pango.Weight.BOLD, "scale", 1.28, "width", 24);
- column.set_cell_data_func (text, (column, cell, model, iter) => {
- Contact contact;
-
- model.get (iter, 0, out contact);
-
- string letter = "";
- if (contacts_view.is_first (iter)) {
- letter = contact.initial_letter.to_string ();
- }
- cell.set ("text", letter);
- });
-
- var icon = new CellRendererPixbuf ();
- column.pack_start (icon, false);
- column.set_cell_data_func (icon, (column, cell, model, iter) => {
- Contact contact;
-
- model.get (iter, 0, out contact);
-
- cell.set ("pixbuf", contact.avatar);
- });
-
- tree_view.append_column (column);
-
- column = new TreeViewColumn ();
-
- shape = new CellRendererShape ();
-
- Pango.cairo_context_set_shape_renderer (tree_view.get_pango_context (), shape.render_shape);
-
- column.pack_start (shape, false);
- column.set_cell_data_func (shape, (column, cell, model, iter) => {
- Contact contact;
-
- model.get (iter, 0, out contact);
-
- cell.set ("wrap_width", 230,
- "name", contact.display_name,
- "presence", contact.presence_type,
- "message", contact.presence_message,
- "is_phone", contact.is_phone);
- });
-
- tree_view.append_column (column);
- }
-
private void refilter () {
string []? values;
string str = filter_entry.get_text ();
@@ -126,18 +66,6 @@ public class Contacts.ListPane : Frame {
filter_entry.set_text ("");
}
- private void contacts_selection_changed (TreeSelection selection) {
- TreeIter iter;
- TreeModel model;
-
- Contact? contact = null;
- if (selection.get_selected (out model, out iter)) {
- model.get (iter, 0, out contact);
- }
-
- selection_changed (contact);
- }
-
public ListPane (Store contacts_store) {
this.contacts_store = contacts_store;
this.contacts_view = new View (contacts_store);
@@ -190,19 +118,17 @@ public class Contacts.ListPane : Frame {
grid.attach (toolbar, 0, 0, 1, 1);
grid.attach (scrolled, 0, 1, 1, 1);
- contacts_tree_view = new TreeView.with_model (contacts_view.model);
- setup_contacts_view (contacts_tree_view);
- scrolled.add (contacts_tree_view);
+ list = new ViewWidget (contacts_view);
+ list.selection_changed.connect( (l, contact) => {
+ selection_changed (contact);
+ });
+
+ scrolled.add (list);
this.show_all ();
}
public void select_contact (Contact contact) {
- TreeIter iter;
- if (contacts_view.lookup_iter (contact, out iter)) {
- contacts_tree_view.get_selection ().select_iter (iter);
- contacts_tree_view.scroll_to_cell (contacts_view.model.get_path (iter),
- null, true, 0.0f, 0.0f);
- }
+ list.select_contact (contact);
}
}
diff --git a/src/contacts-view.vala b/src/contacts-view.vala
index 4e98aab..e12314f 100644
--- a/src/contacts-view.vala
+++ b/src/contacts-view.vala
@@ -237,3 +237,94 @@ public class Contacts.View : GLib.Object {
return data.visible;
}
}
+
+
+public class Contacts.ViewWidget : TreeView {
+ public View view;
+ private CellRendererShape shape;
+
+ public signal void selection_changed (Contact? contact);
+
+ public ViewWidget (View view) {
+ this.view = view;
+
+ set_model (view.model);
+ set_headers_visible (false);
+
+ var selection = get_selection ();
+ selection.set_mode (SelectionMode.BROWSE);
+ selection.changed.connect (contacts_selection_changed);
+
+ var column = new TreeViewColumn ();
+
+ var text = new CellRendererText ();
+ text.set_alignment (0, 0);
+ column.pack_start (text, true);
+ text.set ("weight", Pango.Weight.BOLD, "scale", 1.28, "width", 24);
+ column.set_cell_data_func (text, (column, cell, model, iter) => {
+ Contact contact;
+
+ view.model.get (iter, 0, out contact);
+
+ string letter = "";
+ if (view.is_first (iter)) {
+ letter = contact.initial_letter.to_string ();
+ }
+ cell.set ("text", letter);
+ });
+
+ var icon = new CellRendererPixbuf ();
+ column.pack_start (icon, false);
+ column.set_cell_data_func (icon, (column, cell, model, iter) => {
+ Contact contact;
+
+ model.get (iter, 0, out contact);
+
+ cell.set ("pixbuf", contact.avatar);
+ });
+
+ append_column (column);
+
+ column = new TreeViewColumn ();
+
+ shape = new CellRendererShape ();
+
+ Pango.cairo_context_set_shape_renderer (get_pango_context (), shape.render_shape);
+
+ column.pack_start (shape, false);
+ column.set_cell_data_func (shape, (column, cell, model, iter) => {
+ Contact contact;
+
+ model.get (iter, 0, out contact);
+
+ cell.set ("wrap_width", 230,
+ "name", contact.display_name,
+ "presence", contact.presence_type,
+ "message", contact.presence_message,
+ "is_phone", contact.is_phone);
+ });
+
+ append_column (column);
+ }
+
+ private void contacts_selection_changed (TreeSelection selection) {
+ TreeIter iter;
+ TreeModel model;
+
+ Contact? contact = null;
+ if (selection.get_selected (out model, out iter)) {
+ model.get (iter, 0, out contact);
+ }
+
+ selection_changed (contact);
+ }
+
+ public void select_contact (Contact contact) {
+ TreeIter iter;
+ if (view.lookup_iter (contact, out iter)) {
+ get_selection ().select_iter (iter);
+ scroll_to_cell (view.model.get_path (iter),
+ null, true, 0.0f, 0.0f);
+ }
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]