/
Gtk.IconView.vala
64 lines (52 loc) · 1.61 KB
/
Gtk.IconView.vala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
public class Application : Gtk.Window {
public Application () {
// Prepare Gtk.Window:
this.title = "My Gtk.IconView";
this.window_position = Gtk.WindowPosition.CENTER;
this.destroy.connect (Gtk.main_quit);
this.set_default_size (400, 400);
// The Model:
Gtk.ListStore model = new Gtk.ListStore (2, typeof (Gdk.Pixbuf), typeof (string));
Gtk.TreeIter iter;
// The IconView:
Gtk.IconView view = new Gtk.IconView.with_model (model);
view.set_pixbuf_column (0);
view.set_text_column (1);
this.add (view);
// Data:
Gtk.IconTheme icon_theme = Gtk.IconTheme.get_default ();
try {
model.append (out iter);
Gdk.Pixbuf pixbuf = icon_theme.load_icon ("help-about", 20, 0);
model.set (iter, 0, pixbuf, 1, "Dialog");
model.append (out iter);
pixbuf = icon_theme.load_icon ("document-print", 20, 0);
model.set (iter, 0, pixbuf, 1, "Print");
model.append (out iter);
pixbuf = icon_theme.load_icon ("help-about", 20, 0);
model.set (iter, 0, pixbuf, 1, "Help");
} catch (Error e) {
// TODO
assert_not_reached ();
}
view.selection_changed.connect (() => {
List<Gtk.TreePath> paths = view.get_selected_items ();
Value title;
Value icon;
foreach (Gtk.TreePath path in paths) {
bool tmp = model.get_iter (out iter, path);
assert (tmp == true);
model.get_value (iter, 0, out icon);
model.get_value (iter, 1, out title);
print ("%s: %p\n", (string) title, ((Gdk.Pixbuf) icon));
}
});
}
public static int main (string[] args) {
Gtk.init (ref args);
Application app = new Application ();
app.show_all ();
Gtk.main ();
return 0;
}
}