1 |
578 |
markom |
#!/bin/sh
|
2 |
|
|
# ----------------------------------------------------------------------
|
3 |
|
|
# DEMO: buttonbox in [incr Widgets]
|
4 |
|
|
# ----------------------------------------------------------------------
|
5 |
|
|
#\
|
6 |
|
|
exec itkwish "$0" ${1+"$@"}
|
7 |
|
|
package require Iwidgets 3.0
|
8 |
|
|
|
9 |
|
|
#
|
10 |
|
|
# Demo script for the Hierarchy class.
|
11 |
|
|
#
|
12 |
|
|
# This demo displays a users file system starting at thier HOME
|
13 |
|
|
# directory. You can change the starting directory by setting the
|
14 |
|
|
# environment variable SHOWDIR.
|
15 |
|
|
#
|
16 |
|
|
if {![info exists env(SHOWDIR)]} {
|
17 |
|
|
set env(SHOWDIR) $env(HOME)
|
18 |
|
|
}
|
19 |
|
|
|
20 |
|
|
# ----------------------------------------------------------------------
|
21 |
|
|
# PROC: get_files file
|
22 |
|
|
#
|
23 |
|
|
# Used as the -querycommand for the hierarchy viewer. Returns the
|
24 |
|
|
# list of files under a particular directory. If the file is "",
|
25 |
|
|
# then the SHOWDIR is used as the directory. Otherwise, the node itself
|
26 |
|
|
# is treated as a directory. The procedure returns a unique id and
|
27 |
|
|
# the text to be displayed for each file. The unique id is the complete
|
28 |
|
|
# path name and the text is the file name.
|
29 |
|
|
# ----------------------------------------------------------------------
|
30 |
|
|
proc get_files {file} {
|
31 |
|
|
global env
|
32 |
|
|
|
33 |
|
|
if {$file == ""} {
|
34 |
|
|
set dir $env(SHOWDIR)
|
35 |
|
|
} else {
|
36 |
|
|
set dir $file
|
37 |
|
|
}
|
38 |
|
|
|
39 |
|
|
if {[catch {cd $dir}] != 0} {
|
40 |
|
|
return ""
|
41 |
|
|
}
|
42 |
|
|
|
43 |
|
|
set rlist ""
|
44 |
|
|
|
45 |
|
|
foreach file [lsort [glob -nocomplain *]] {
|
46 |
|
|
lappend rlist [list [file join $dir $file] $file]
|
47 |
|
|
}
|
48 |
|
|
|
49 |
|
|
return $rlist
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
# ----------------------------------------------------------------------
|
53 |
|
|
# PROC: select_node tags status
|
54 |
|
|
#
|
55 |
|
|
# Select/Deselect the node given the tags and current selection status.
|
56 |
|
|
# The unique id which is the complete file path name is mixed in with
|
57 |
|
|
# all the tags for the node. So, we'll find it by searching for our
|
58 |
|
|
# SHOWDIR and then doing the selection or deselection.
|
59 |
|
|
# ----------------------------------------------------------------------
|
60 |
|
|
proc select_node {tags status} {
|
61 |
|
|
global env
|
62 |
|
|
|
63 |
|
|
set uid [lindex $tags [lsearch -regexp $tags $env(SHOWDIR)]]
|
64 |
|
|
|
65 |
|
|
if {$status} {
|
66 |
|
|
.h selection remove $uid
|
67 |
|
|
} else {
|
68 |
|
|
.h selection add $uid
|
69 |
|
|
}
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
# ----------------------------------------------------------------------
|
73 |
|
|
# PROC: expand_node tags
|
74 |
|
|
#
|
75 |
|
|
# Expand the node given the tags. The unique id which is the complete
|
76 |
|
|
# file path name is mixed in with all the tags for the node. So, we'll
|
77 |
|
|
# find it by searching for our SHOWDIR and then doing the expansion.
|
78 |
|
|
# ----------------------------------------------------------------------
|
79 |
|
|
proc expand_node {tags} {
|
80 |
|
|
global env
|
81 |
|
|
|
82 |
|
|
set uid [lindex $tags [lsearch -regexp $tags $env(SHOWDIR)]]
|
83 |
|
|
|
84 |
|
|
.h expand $uid
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
# ----------------------------------------------------------------------
|
88 |
|
|
# PROC: collapse_node tags
|
89 |
|
|
#
|
90 |
|
|
# Collapse the node given the tags. The unique id which is the complete
|
91 |
|
|
# file path name is mixed in with all the tags for the node. So, we'll
|
92 |
|
|
# find it by searching for our SHOWDIR and then doing the collapse.
|
93 |
|
|
# ----------------------------------------------------------------------
|
94 |
|
|
proc collapse_node {tags} {
|
95 |
|
|
global env
|
96 |
|
|
|
97 |
|
|
set uid [lindex $tags [lsearch -regexp $tags $env(SHOWDIR)]]
|
98 |
|
|
|
99 |
|
|
.h collapse $uid
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
# ----------------------------------------------------------------------
|
103 |
|
|
# PROC: expand_recursive
|
104 |
|
|
#
|
105 |
|
|
# Recursively expand all the file nodes in the hierarchy.
|
106 |
|
|
# ----------------------------------------------------------------------
|
107 |
|
|
proc expand_recursive {node} {
|
108 |
|
|
set files [get_files $node]
|
109 |
|
|
|
110 |
|
|
foreach tagset $files {
|
111 |
|
|
set uid [lindex $tagset 0]
|
112 |
|
|
|
113 |
|
|
.h expand $uid
|
114 |
|
|
|
115 |
|
|
if {[get_files $uid] != {}} {
|
116 |
|
|
expand_recursive $uid
|
117 |
|
|
}
|
118 |
|
|
}
|
119 |
|
|
}
|
120 |
|
|
|
121 |
|
|
# ----------------------------------------------------------------------
|
122 |
|
|
# PROC: expand_all
|
123 |
|
|
#
|
124 |
|
|
# Expand all the file nodes in the hierarchy.
|
125 |
|
|
# ----------------------------------------------------------------------
|
126 |
|
|
proc expand_all {} {
|
127 |
|
|
expand_recursive ""
|
128 |
|
|
}
|
129 |
|
|
|
130 |
|
|
# ----------------------------------------------------------------------
|
131 |
|
|
# PROC: collapse_all
|
132 |
|
|
#
|
133 |
|
|
# Collapse all the nodes in the hierarchy.
|
134 |
|
|
# ----------------------------------------------------------------------
|
135 |
|
|
proc collapse_all {} {
|
136 |
|
|
.h configure -querycommand "get_files %n"
|
137 |
|
|
}
|
138 |
|
|
|
139 |
|
|
#
|
140 |
|
|
# Create the hierarchy mega-widget, adding commands to both the item
|
141 |
|
|
# and background popup menus.
|
142 |
|
|
#
|
143 |
|
|
iwidgets::hierarchy .h -querycommand "get_files %n" -visibleitems 30x15 \
|
144 |
|
|
-labeltext $env(SHOWDIR) -selectcommand "select_node %n %s"
|
145 |
|
|
pack .h -side left -expand yes -fill both
|
146 |
|
|
|
147 |
|
|
.h component itemMenu add command -label "Select" \
|
148 |
|
|
-command {select_node [.h current] 0}
|
149 |
|
|
.h component itemMenu add command -label "Deselect" \
|
150 |
|
|
-command {select_node [.h current] 1}
|
151 |
|
|
.h component itemMenu add separator
|
152 |
|
|
.h component itemMenu add command -label "Expand" \
|
153 |
|
|
-command {expand_node [.h current]}
|
154 |
|
|
.h component itemMenu add command -label "Collapse" \
|
155 |
|
|
-command {collapse_node [.h current]}
|
156 |
|
|
|
157 |
|
|
.h component bgMenu add command -label "Expand All" -command expand_all
|
158 |
|
|
.h component bgMenu add command -label "Collapse All" -command collapse_all
|
159 |
|
|
.h component bgMenu add command -label "Clear Selections" \
|
160 |
|
|
-command {.h selection clear}
|