-
Notifications
You must be signed in to change notification settings - Fork 8
/
treeview.rb
executable file
·107 lines (90 loc) · 2.38 KB
/
treeview.rb
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env ruby
# muquit@muquit.com Apr-20-2014
require [File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'mrdialog'].join('/')
require 'pp'
begin
ME = File.basename($0)
if ENV['CHANGE_TITLE']
if ME =~ /(.+)\.rb$/
base = $1
puts "\033]0;mrdialog - #{base}\007"
end
end
text = <<-EOF
This example is taken from dialog/samples/treeview1
shell script.
EOF
items = []
Struct.new("TreeviewData", :tag, :item, :status, :depth)
data = Struct::TreeviewData.new
data.tag = "tag1"
data.item = "Item number 1"
data.status = false
data.depth = 0
items.push(data.to_a)
data = Struct::TreeviewData.new
data.tag = "tag2"
data.item = "Item number 2"
data.status = false
data.depth = 1
items.push(data.to_a)
data = Struct::TreeviewData.new
data.tag = "tag3"
data.item = "Item number 3"
data.status = true
data.depth = 2
items.push(data.to_a)
data = Struct::TreeviewData.new
data.tag = "tag4"
data.item = "Item number 4"
data.status = false
data.depth = 1
items.push(data.to_a)
data = Struct::TreeviewData.new
data.tag = "tag5"
data.item = "Item number 5"
data.status = false
data.depth = 2
items.push(data.to_a)
data = Struct::TreeviewData.new
data.tag = "tag6"
data.item = "Item number 6"
data.status = false
data.depth = 3
items.push(data.to_a)
data = Struct::TreeviewData.new
data.tag = "tag7"
data.item = "Item number 7"
data.status = false
data.depth = 3
items.push(data.to_a)
data = Struct::TreeviewData.new
data.tag = "tag8"
data.item = "Item number 8"
data.status = false
data.depth = 4
items.push(data.to_a)
data = Struct::TreeviewData.new
data.tag = "tag9"
data.item = "Item number 9"
data.status = false
data.depth = 1
items.push(data.to_a)
dialog = MRDialog.new
dialog.clear = true
dialog.title = "TREEVIEW"
dialog.logger = Logger.new(ENV["HOME"] + "/dialog_" + ME + ".log")
height = 0
width = 0
listheight = 0
selected_tag = dialog.treeview(text, items, height, width, listheight)
exit_code = dialog.exit_code
puts "Exit code: #{exit_code}"
if exit_code == 0
puts "Selecetd tag: #{selected_tag}"
end
rescue => e
puts "#{$!}"
t = e.backtrace.join("\n\t")
puts "Error: #{t}"
end