Class: MittensUi::TableView
- Inherits:
-
Core
- Object
- Core
- MittensUi::TableView
show all
- Defined in:
- lib/mittens_ui/table_view.rb
Instance Attribute Summary
Attributes inherited from Core
#core_widget
Instance Method Summary
collapse
Methods inherited from Core
#hidden?, #hide, #remove, #show
Methods included from Helpers
#icon_map, #list_system_icons, #set_margin_from_opts_for
Constructor Details
#initialize(options = {}) ⇒ TableView
Returns a new instance of TableView.
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
|
# File 'lib/mittens_ui/table_view.rb', line 6
def initialize(options={})
= options[:headers] || []
data = options[:data] || []
unless is_data_valid?(, data)
exit 1
end
init_column_headers()
init_list_store
@scrolled_window = Gtk::ScrolledWindow.new
calc_min_height = (data.size ** 2 ) * 10
@scrolled_window.min_content_height = calc_min_height
@tree_view = Gtk::TreeView.new(@list_store)
@tree_view.selection.set_mode(:single)
@columns.each { |col| @tree_view.append_column(col) }
init_sortable_columns
init_data_rows(data)
@scrolled_window.add(@tree_view)
super(@tree_view, options)
end
|
Instance Method Details
#add(data, direction = :append) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/mittens_ui/table_view.rb', line 36
def add(data, direction=:append)
return if data.size.zero?
case direction
when :append
iter = @list_store.append
when :prepend
iter = @list_store.prepend
else
iter = @list_store.append
end
data.each_with_index do |item, idx|
iter[idx] = item
end
end
|
#clear ⇒ Object
53
54
55
|
# File 'lib/mittens_ui/table_view.rb', line 53
def clear
@list_store.clear
end
|
#remove_selected ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/mittens_ui/table_view.rb', line 69
def remove_selected
iter = @tree_view.selection.selected
values = []
if iter.nil?
return values
end
@list_store.n_columns.times do |x|
values << @list_store.get_value(iter, x)
end
@list_store.remove(iter)
return values
end
|
#render ⇒ Object
57
58
59
60
|
# File 'lib/mittens_ui/table_view.rb', line 57
def render
$vertical_box.pack_start(@scrolled_window)
return self
end
|
#row_clicked ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/mittens_ui/table_view.rb', line 87
def row_clicked
@tree_view.signal_connect("row-activated") do |tv, path, column|
row = tv.selection.selected
values = []
@list_store.n_columns.times { |x| values << row.get_value(x) if row }
yield(values)
end
end
|
#row_count ⇒ Object
62
63
64
65
66
67
|
# File 'lib/mittens_ui/table_view.rb', line 62
def row_count
count = 0
@list_store.each { |item| count += 1 }
return count
end
|