16
16
// along with this program. If not, see <http://www.gnu.org/licenses/>.
21
namespace Slingshot.Widgets {
23
public class Sidebar : TreeView {
25
private TreeStore store;
27
private TreeIter entry_iter;
31
return store.iter_n_children (null);
35
private int _selected;
41
if (value >= 0 && value < cat_size) {
48
private enum Columns {
54
public signal void selection_changed (string entry_name, int nth);
58
store = new TreeStore (Columns.N_COLUMNS, typeof (int), typeof (string));
59
store.set_sort_column_id (1, Gtk.SortType.ASCENDING);
62
set_headers_visible (false);
63
set_show_expanders (false);
64
set_level_indentation (8);
66
set_size_request (145, -1);
67
get_style_context ().add_class ("sidebar");
69
var cell = new CellRendererText ();
70
cell.wrap_mode = Pango.WrapMode.WORD;
71
cell.wrap_width = 110;
74
insert_column_with_attributes (-1, "Filters", cell, "markup", Columns.TEXT);
76
get_selection ().set_mode (SelectionMode.SINGLE);
77
get_selection ().changed.connect (selection_change);
81
public void add_category (string entry_name) {
83
store.append (out entry_iter, null);
84
store.set (entry_iter, Columns.INT, cat_size - 1, Columns.TEXT, Markup.escape_text (entry_name), -1);
90
public void selection_change () {
97
if (get_selection ().get_selected (out model, out sel_iter)) {
98
store.get (sel_iter, Columns.INT, out nth, Columns.TEXT, out name);
100
selection_changed (name, nth);
105
public bool select_nth (int nth) {
110
store.iter_nth_child (out iter, null, nth);
114
get_selection ().select_iter (iter);
119
protected override bool scroll_event (Gdk.EventScroll event) {
121
switch (event.direction.to_string ()) {
122
case "GDK_SCROLL_UP":
123
case "GDK_SCROLL_LEFT":
126
case "GDK_SCROLL_DOWN":
127
case "GDK_SCROLL_RIGHT":
19
public class Slingshot.Widgets.Sidebar : Gtk.TreeView {
21
private Gtk.TreeStore store;
23
private Gtk.TreeIter entry_iter;
27
return store.iter_n_children (null);
31
private int _selected;
37
if (value >= 0 && value < cat_size) {
44
private enum Columns {
50
public signal void selection_changed (string entry_name, int nth);
54
store = new Gtk.TreeStore (Columns.N_COLUMNS, typeof (int), typeof (string));
55
store.set_sort_column_id (1, Gtk.SortType.ASCENDING);
58
set_headers_visible (false);
59
set_show_expanders (false);
60
set_level_indentation (8);
62
set_size_request (145, -1);
63
get_style_context ().add_class ("sidebar");
65
var cell = new Gtk.CellRendererText ();
66
cell.wrap_mode = Pango.WrapMode.WORD;
67
cell.wrap_width = 110;
70
insert_column_with_attributes (-1, "Filters", cell, "markup", Columns.TEXT);
72
get_selection ().set_mode (Gtk.SelectionMode.SINGLE);
73
get_selection ().changed.connect (selection_change);
77
public void add_category (string entry_name) {
79
store.append (out entry_iter, null);
80
store.set (entry_iter, Columns.INT, cat_size - 1, Columns.TEXT, Markup.escape_text (entry_name), -1);
86
public void selection_change () {
89
Gtk.TreeIter sel_iter;
93
if (get_selection ().get_selected (out model, out sel_iter)) {
94
store.get (sel_iter, Columns.INT, out nth, Columns.TEXT, out name);
96
selection_changed (name, nth);
101
public bool select_nth (int nth) {
106
store.iter_nth_child (out iter, null, nth);
110
get_selection ().select_iter (iter);
115
protected override bool scroll_event (Gdk.EventScroll event) {
117
switch (event.direction.to_string ()) {
118
case "GDK_SCROLL_UP":
119
case "GDK_SCROLL_LEFT":
122
case "GDK_SCROLL_DOWN":
123
case "GDK_SCROLL_RIGHT":