OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tix/] [library/] [DirBox.tcl] - Blame information for rev 1767

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# DirBox.tcl --
2
#
3
#       Implements the tixDirSelectBox widget.
4
#
5
#          - overrides the -browsecmd and -command options of the
6
#            HList subwidget
7
#
8
# Copyright (c) 1996, Expert Interface Technologies
9
#
10
# See the file "license.terms" for information on usage and redistribution
11
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12
#
13
 
14
tixWidgetClass tixDirSelectBox {
15
    -classname TixDirSelectBox
16
    -superclass tixPrimitive
17
    -method {
18
    }
19
    -flag {
20
        -command -disablecallback -value
21
    }
22
    -configspec {
23
        {-command command Command ""}
24
        {-disablecallback disableCallback DisableCallback 0 tixVerifyBoolean}
25
        {-label label Label "Directory:"}
26
        {-value value Value ""}
27
    }
28
    -forcecall {
29
        -value -label
30
    }
31
    -default {
32
        {*combo*listbox.height          5}
33
        {*combo.label.anchor            w}
34
        {*combo.labelSide               top}
35
        {*combo.hostory                 true}
36
        {*combo.historyLimit            20}
37
    }
38
}
39
 
40
proc tixDirSelectBox:InitWidgetRec {w} {
41
    upvar #0 $w data
42
    tixChainMethod $w InitWidgetRec
43
}
44
 
45
proc tixDirSelectBox:ConstructWidget {w} {
46
    upvar #0 $w data
47
 
48
    tixChainMethod $w ConstructWidget
49
    set data(w:dircbx) [tixFileComboBox $w.dircbx]
50
    set data(w:dirlist)  [tixDirList $w.dirlist]
51
 
52
    pack $data(w:dircbx) -side top -fill x -padx 4 -pady 2
53
    pack $data(w:dirlist) -side top -fill both -expand yes -padx 4 -pady 2
54
 
55
    if ![string comp $data(-value) ""] {
56
        set data(-value) [tixFSPWD]
57
    }
58
}
59
 
60
proc tixDirSelectBox:SetBindings {w} {
61
    upvar #0 $w data
62
 
63
    tixChainMethod $w SetBindings
64
 
65
    $data(w:dircbx) config -command "tixDirSelectBox:Cmd-DirCbx $w"
66
    $data(w:dirlist) config -command "tixDirSelectBox:Cmd-DirList $w"\
67
        -browsecmd "tixDirSelectBox:Browse-DirList $w"
68
}
69
 
70
#----------------------------------------------------------------------
71
# Incoming event: User
72
#----------------------------------------------------------------------
73
 
74
# User activates the FileComboBox
75
#
76
#
77
proc tixDirSelectBox:Cmd-DirCbx {w args} {
78
    upvar #0 $w data
79
 
80
    set fInfo [tixEvent value]
81
    set path [lindex $fInfo 0]
82
 
83
    if {![file exists $path]} {
84
        tk_dialog .tix_error "" "Directory \"$path\" does not exist." \
85
            error 0 Ok
86
        $data(w:dircbx) config \
87
            -text [tixFSDisplayName [tixFSNormDir $data(-value)]] \
88
            -directory $data(-value)
89
        return
90
 
91
        #
92
        # The following code is not used because directories cannot be created
93
        # on Windows
94
        #
95
 
96
        # 1.1 Check for validity. The pathname cannot contain invalid chars
97
        #
98
        if ![tixFSIsValid $path] {
99
            tk_dialog .tix_error "Error" \
100
                "\"$path\" is not a valid directory name" \
101
                error 0 Ok
102
            $data(w:dircbx) config \
103
                -text [tixFSDisplayName [tixFSNormDir $data(-value)]] \
104
                -directory $data(-value)
105
            return
106
        }
107
 
108
        # 1.2 Prompt for creation
109
        #
110
        set choice [tk_dialog .tix_error "" \
111
            "Directory \"$path\" does not exist. Do you want to create it?" \
112
            question 1 Yes No]
113
        if {$choice == 1} {
114
            $data(w:dircbx) config \
115
                -text [tixFSDisplayName [tixFSNormDir $data(-value)]] \
116
                -directory $data(-value)
117
            return
118
        } else {
119
            if ![tixFSCreateDirs $path] {
120
                tk_dialog .tix_error "Error" \
121
                    "Cannot create directory \"$path\". Permission denied" \
122
                    error 0 Ok
123
                $data(w:dircbx) config \
124
                    -text [tixFSDisplayName [tixFSNormDir $data(-value)]] \
125
                    -directory $data(-value)
126
                return
127
            }
128
            tixDirSelectBox:SetValue $w $path 1 1
129
        }
130
    } elseif {![file isdirectory $path]} {
131
        # 2.1: Can't choose a non-directory file
132
        #
133
        tk_dialog .tix_error "Error" \
134
            "\"$path\" is not a directory." \
135
            error 0 Ok
136
        $data(w:dircbx) config \
137
            -text [tixFSDisplayName [tixFSNormDir $data(-value)]] \
138
            -directory $data(-value)
139
        return
140
    } else {
141
        # OK. It is an existing directory
142
        #
143
        tixDirSelectBox:SetValue $w $path 1 1
144
    }
145
}
146
 
147
# User activates the dir list
148
#
149
#
150
proc tixDirSelectBox:Cmd-DirList {w args} {
151
    upvar #0 $w data
152
 
153
    set dir $data(-value)
154
    catch {
155
        set dir [tixEvent flag V]
156
    }
157
    set dir [tixFSNormDir $dir]
158
    tixDirSelectBox:SetValue $w $dir 0 0
159
}
160
 
161
# User browses the dir list
162
#
163
#
164
proc tixDirSelectBox:Browse-DirList {w args} {
165
    upvar #0 $w data
166
 
167
    set dir $data(-value)
168
    catch {
169
        set dir [tixEvent flag V]
170
    }
171
    set dir [tixFSNormDir $dir]
172
    tixDirSelectBox:SetValue $w $dir 0 0
173
}
174
 
175
#----------------------------------------------------------------------
176
# Incoming event: Application
177
#----------------------------------------------------------------------
178
proc tixDirSelectBox:config-value {w value} {
179
    upvar #0 $w data
180
    set value [tixFSNormDir $value]
181
 
182
    tixDirSelectBox:SetValue $w $value 1 1
183
    return $value
184
}
185
 
186
proc tixDirSelectBox:config-label {w value} {
187
    upvar #0 $w data
188
 
189
    $data(w:dircbx) subwidget combo config -label $value
190
}
191
 
192
#----------------------------------------------------------------------
193
#
194
#                       Internal functions
195
#
196
#----------------------------------------------------------------------
197
 
198
# Arguments:
199
#       callback:Bool   Should we invoke the the -command.
200
#       setlist:Bool    Should we set the -value of the DirList subwidget.
201
#
202
proc tixDirSelectBox:SetValue {w dir callback setlist} {
203
    upvar #0 $w data
204
 
205
    set data(-value) $dir
206
    $data(w:dircbx) config -text [tixFSDisplayName $dir] \
207
        -directory [tixFSDisplayName $dir]
208
    if {$setlist && [file isdirectory $dir]} {
209
        tixSetSilent $data(w:dirlist) $dir
210
    }
211
 
212
    if {$callback} {
213
        if {!$data(-disablecallback) && ![tixStrEq $data(-command) ""]} {
214
            set bind(specs) {%V}
215
            set bind(%V)    $data(-value)
216
 
217
            tixEvalCmdBinding $w $data(-command) bind $data(-value)
218
        }
219
    }
220
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.