Debian Codegraph @

plugin/activity_gtk/model_selector.rb

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 module Plugin::ActivityGtk
4 class ModelSelector < Gtk::TreeView
5 ICON = 0
6 MODEL_KIND = 1
7 TITLE = 2
8 MODEL = 3
9 def initialize(*rest)
10 super
11 initialize_model
12 initialize_column
13 set_headers_visible(false)
14 ssc(:row_activated, &self.class.open_block)
15 end
16
17 def self.open_block
18 ->(treeview, path, _column) {
19 iter = treeview.model.get_iter(path)
20 Plugin.call(:open, iter[MODEL])
21 false
22 }
23 end
24
25 def set(models)
26 model.clear
27 models.each do |record|
28 iter = model.append
29 if record.respond_to? :icon
30 iter[ICON] = record.icon.load_pixbuf(width: 24, height: 24) do |loaded_icon|
31 iter[ICON] = loaded_icon
32 end
33 end
34 iter[MODEL_KIND] = record.class.spec[:name]
35 iter[TITLE] = record.title
36 iter[MODEL] = record
37 end
38 end
39
40 private
41
42 def initialize_model
43 set_model(Gtk::ListStore.new(GdkPixbuf::Pixbuf, String, String, Diva::Model))
44 end
45
46 def initialize_column
47 initialize_column_icon
48 initialize_column_type
49 initialize_column_title
50 end
51
52 def initialize_column_icon
53 col = Gtk::TreeViewColumn.new('icon', Gtk::CellRendererPixbuf.new, pixbuf: 0)
54 col.resizable = false
55 append_column(col)
56 end
57
58 def initialize_column_type
59 col = Gtk::TreeViewColumn.new('kind', Gtk::CellRendererText.new, text: 1)
60 col.resizable = false
61 append_column(col)
62 end
63
64 def initialize_column_title
65 col = Gtk::TreeViewColumn.new('title', Gtk::CellRendererText.new, text: 2)
66 col.resizable = false
67 append_column(col)
68 end
69 end
70 end