-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsidebar.tcl
77 lines (62 loc) · 1.95 KB
/
sidebar.tcl
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
package require Tk 8.5
package require snit 2.2
namespace eval dbluejay {
# Single-column hierarchical ttk::treeview and scrollbar listing various
# interesting and uninteresting items contained within a TDBC-handled database.
snit::widget dbsidebar {
hulltype ttk::frame
delegate method * to hull
delegate option * to hull
component tree ;# ttk::treeview
component scroll ;# ttk::scrollbar
# TDBC database handle to introspect.
option -db -default {} -configuremethod Set_db
method Set_db {opt val} {
set options($opt) $val
after idle [mymethod update]
}
# no personality by default (empty string for all "methods")
# See the header comment in personality.tcl for further information.
option -personality -default ::dbluejay::personality::none
constructor {args} {
install tree using ttk::treeview $win.tree -columns {
} -show tree
install scroll using ttk::scrollbar $win.scroll -command [
list $tree yview
]
$tree configure -yscrollcommand [list $scroll set]
grid $tree $scroll -sticky ns
grid configure $tree -sticky nsew
grid rowconfigure $win 0 -weight 1
grid columnconfigure $win 0 -weight 1
$self configurelist $args
}
# Erase and repopulate the tree with those interesting and uninteresting
# database items. Returns true if something was actually done, false if
# -db was empty and therefore nothing was done
method update {} {
if {[info command [$self cget -db]] eq {}} {
return false
}
$tree delete [$tree children {}]
foreach frob [[$self cget -personality] frobs] {
set frobroot [$tree insert {} end -text [
dict get $frob name
] -open true]
foreach fritem [
[$self cget -personality] [
dict get $frob method
] [$self cget -db]
] {
set fritemroot [$tree insert $frobroot end -text [
dict get $fritem name
]]
foreach subfrob [dict get $fritem subfrobs] {
$tree insert $fritemroot end -text $subfrob
}
}
}
return true
}
}
} ;# namespace eval dbluejay