using GLib; using Gtk; /* * * Implements a Widget for GTK containing a list * of selectable items with scrollbar and treeview. * */ public class GtkUtils.List : GLib.Object { TreeView tv; TreeViewColumn col; CellRendererText cr; ListStore ls; public ScrolledWindow widget {get;set;} public signal void action(); construct { widget = new ScrolledWindow(null, null); widget.set_policy(PolicyType.AUTOMATIC, PolicyType.AUTOMATIC); tv = new TreeView(); tv.set_reorderable(true); tv.set_rules_hint(true); tv.model = ls = new ListStore(1, typeof(string)); widget.add(tv); } public void update() { action(); } public List with_title(string title) { tv.insert_column_with_attributes(0, title, new CellRendererText(), "text", 0, null); return this; } public void add(string item) { TreeIter iter; ls.append(ref iter); ls.set(ref iter, 0, item); } public string get() { TreeIter iter; TreeModel model; string str = ""; TreeSelection sel = tv.get_selection(); if (sel.count_selected_rows() == 1) { sel.get_selected(ref model, ref iter); ls.get(ref iter, 0, out str); } return str; } public void clear() { ls.clear(); } }