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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tix/] [library/] [EFileBox.tcl] - Blame information for rev 1774

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

Line No. Rev Author Line
1 578 markom
# EFileBox.tcl --
2
#
3
#       Implements the Extended File Selection Box widget.
4
#
5
# Copyright (c) 1996, Expert Interface Technologies
6
#
7
# See the file "license.terms" for information on usage and redistribution
8
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
9
#
10
 
11
 
12
#
13
# ToDo
14
#   (1) If user has entered an invalid directory, give an error dialog
15
#
16
 
17
tixWidgetClass tixExFileSelectBox {
18
    -classname TixExFileSelectBox
19
    -superclass tixPrimitive
20
    -method {
21
        filter invoke
22
    }
23
    -flag {
24
        -browsecmd -command -dialog -dir -dircmd -directory
25
        -disablecallback -filetypes -pattern -selection -showhidden -value
26
    }
27
    -forcecall {
28
        -filetypes
29
    }
30
    -configspec {
31
        {-browsecmd browseCmd BrowseCmd ""}
32
        {-command command Command ""}
33
        {-dialog dialog Dialog ""}
34
        {-dircmd dirCmd DirCmd ""}
35
        {-directory directory Directory ""}
36
        {-disablecallback disableCallback DisableCallback 0 tixVerifyBoolean}
37
        {-filetypes fileTypes FileTypes ""}
38
        {-pattern pattern Pattern *}
39
        {-showhidden showHidden ShowHidden 0 tixVerifyBoolean}
40
        {-value value Value ""}
41
    }
42
    -alias {
43
        {-dir -directory}
44
        {-selection -value}
45
    }
46
 
47
    -default {
48
        {*dir.label                     {Directories:}}
49
        {*dir.editable                  true}
50
        {*dir.history                   true}
51
        {*dir*listbox.height            5}
52
        {*file.label                    Files:}
53
        {*file.editable                 true}
54
        {*file.history                  false}
55
        {*file*listbox.height           5}
56
        {*types.label                   {List Files of Type:}}
57
        {*types*listbox.height          3}
58
        {*TixComboBox.labelSide         top}
59
        {*TixComboBox*Label.anchor      w}
60
        {*dir.label.underline           0}
61
        {*file.label.underline          0}
62
        {*types.label.underline         14}
63
        {*TixComboBox.anchor            e}
64
        {*TixHList.height               7}
65
        {*filelist*listbox.height       7}
66
        {*hidden.wrapLength             3c}
67
        {*hidden.justify                left}
68
    }
69
}
70
 
71
proc tixExFileSelectBox:InitWidgetRec {w} {
72
    upvar #0 $w data
73
    global env
74
 
75
    tixChainMethod $w InitWidgetRec
76
 
77
    if {$data(-directory) == ""} {
78
        global env
79
 
80
        if {[info exists env(PWD)]} {
81
            set data(-directory) $env(PWD)
82
        } else {
83
            set data(-directory) [pwd]
84
        }
85
    }
86
    set data(oldDir)    ""
87
    set data(flag)      0
88
}
89
 
90
 
91
#----------------------------------------------------------------------
92
#               Construct widget
93
#----------------------------------------------------------------------
94
proc tixExFileSelectBox:ConstructWidget {w} {
95
    upvar #0 $w data
96
 
97
    tixChainMethod $w ConstructWidget
98
 
99
    # listbox frame
100
    set lf [frame $w.lf]
101
 
102
    # The pane that contains the two listboxes
103
    #
104
    set pane  [tixPanedWindow $lf.pane -orientation horizontal]
105
    set fpane [$pane add 1 -size 160]
106
    set dpane [$pane add 2 -size 160]
107
 
108
    $dpane config -relief flat
109
    $fpane config -relief flat
110
 
111
    # The File List Pane
112
    #
113
    set data(w:file)  [tixComboBox $fpane.file\
114
        -command "tixExFileSelectBox:Cmd-FileCombo $w"\
115
        -prunehistory true \
116
        -options { \
117
            label.anchor w \
118
        }]
119
    set data(w:filelist) [tixScrolledListBox $fpane.filelist \
120
        -command "tixExFileSelectBox:Cmd-FileList $w 1"\
121
        -browsecmd "tixExFileSelectBox:Cmd-FileList $w 0"]
122
    pack $data(w:file)  -padx 8 -pady 4 -side top -fill x
123
    pack $data(w:filelist) -padx 8 -pady 4 -side top -fill both -expand yes
124
 
125
    # The Directory Pane
126
    #
127
    set data(w:dir)   [tixComboBox $dpane.dir \
128
        -command "tixExFileSelectBox:Cmd-DirCombo $w"\
129
        -prunehistory true \
130
        -options { \
131
            label.anchor w \
132
        }]
133
    set data(w:dirlist) [tixDirList  $dpane.dirlist \
134
        -command "tixExFileSelectBox:Cmd-DirList $w"\
135
        -browsecmd "tixExFileSelectBox:Browse-DirList $w"]
136
    pack $data(w:dir)   -padx 8 -pady 4 -side top -fill x
137
    pack $data(w:dirlist) -padx 8 -pady 4 -side top -fill both -expand yes
138
 
139
    # The file types listbox
140
    #
141
    set data(w:types) [tixComboBox $lf.types\
142
        -command "tixExFileSelectBox:Cmd-TypeCombo $w" \
143
        -options { \
144
            label.anchor w \
145
        }]
146
 
147
    pack $data(w:types)  -padx 12 -pady 4 -side bottom -fill x -anchor w
148
    pack $pane -side top -padx 4 -pady 4 -expand yes -fill both
149
 
150
    # Buttons to the right
151
    #
152
    set bf [frame $w.bf]
153
    set data(w:ok)     [button $bf.ok -text OK\
154
        -underline 0 -command "tixExFileSelectBox:Ok $w"]
155
    set data(w:cancel) [button $bf.cancel -text Cancel\
156
        -underline 0 -command "tixExFileSelectBox:Cancel $w"]
157
    set data(w:hidden) [checkbutton $bf.hidden -text "Show Hidden Files"\
158
        -underline 0\
159
        -variable [format %s(-showhidden) $w] -onvalue 1 -offvalue 0\
160
        -command "tixExFileSelectBox:SetShowHidden $w"]
161
 
162
    pack $data(w:ok) $data(w:cancel) $data(w:hidden)\
163
        -side top -fill x -padx 6 -pady 3
164
 
165
    pack $bf -side right -fill both -pady 6
166
    pack $lf -side left -expand yes -fill both
167
 
168
    tixDoWhenMapped $w "tixExFileSelectBox:Map $w"
169
 
170
    if {$data(-filetypes) == ""} {
171
        $data(w:types) config -state disabled
172
    }
173
}
174
 
175
 
176
#----------------------------------------------------------------------
177
# Configuration
178
#----------------------------------------------------------------------
179
proc tixExFileSelectBox:config-showhidden {w value} {
180
    upvar #0 $w data
181
 
182
    set data(-showhidden) $value
183
    tixExFileSelectBox:SetShowHidden $w
184
}
185
 
186
# Update both DirList and {file list and dir combo}
187
#
188
#
189
proc tixExFileSelectBox:config-directory {w value} {
190
    upvar #0 $w data
191
 
192
    if {![tixIsAbsPath $value]} {
193
        return $data(-directory)
194
    }
195
 
196
    set data(-directory) [tixFSAbsPath $value]
197
    tixSetSilent $data(w:dirlist) $data(-directory)
198
    tixSetSilent $data(w:dir) $data(-directory)
199
    tixWidgetDoWhenIdle tixExFileSelectBox:LoadFiles $w reload
200
 
201
    return $data(-directory)
202
}
203
 
204
proc tixExFileSelectBox:config-filetypes {w value} {
205
    upvar #0 $w data
206
 
207
    $data(w:types) subwidget listbox delete 0 end
208
 
209
    foreach name [array names data] {
210
        if [string match type,* $name] {
211
            catch {unset data($name)}
212
        }
213
    }
214
 
215
    if {$value == ""} {
216
        $data(w:types) config -state disabled
217
    } else {
218
        $data(w:types) config -state normal
219
 
220
        foreach type $value {
221
            $data(w:types) insert end [lindex $type 1]
222
            set data(type,[lindex $type 1]) [lindex $type 0]
223
        }
224
        tixSetSilent $data(w:types) ""
225
    }
226
}
227
 
228
#----------------------------------------------------------------------
229
# MISC Methods
230
#----------------------------------------------------------------------
231
proc tixExFileSelectBox:SetShowHidden {w} {
232
    upvar #0 $w data
233
 
234
    $data(w:dirlist) config -showhidden $data(-showhidden)
235
 
236
    tixWidgetDoWhenIdle tixExFileSelectBox:LoadFiles $w reload
237
}
238
 
239
# User activates the dir combobox
240
#
241
#
242
proc tixExFileSelectBox:Cmd-DirCombo {w args} {
243
    upvar #0 $w data
244
 
245
    set dir [tixEvent flag V]
246
    if {![tixIsAbsPath $dir]} {
247
        return
248
    }
249
    set dir [tixFSAbsPath $dir]
250
 
251
    if {![file isdirectory $dir]} {
252
        return
253
    }
254
 
255
    $data(w:dirlist) config -value $dir
256
    set data(-directory) $dir
257
}
258
 
259
# User activates the dir list
260
#
261
#
262
proc tixExFileSelectBox:Cmd-DirList {w args} {
263
    upvar #0 $w data
264
 
265
    set dir $data(-directory)
266
    catch {
267
        set dir [tixEvent flag V]
268
    }
269
    set dir [tixFSAbsPath $dir]
270
 
271
    tixSetSilent $data(w:dir) $dir
272
    set data(-directory) $dir
273
 
274
    tixWidgetDoWhenIdle tixExFileSelectBox:LoadFiles $w noreload
275
}
276
 
277
# User activates the dir list
278
#
279
#
280
proc tixExFileSelectBox:Browse-DirList {w args} {
281
    upvar #0 $w data
282
 
283
    set dir [tixEvent flag V]
284
    tixExFileSelectBox:Cmd-DirList $w $dir
285
}
286
 
287
proc tixExFileSelectBox:IsPattern {w string} {
288
    foreach char [split $string ""] {
289
        if {$char == "*" || $char == "?" || $char == "\{"  || $char == "\[" } {
290
            return 1
291
        }
292
    }
293
    return 0
294
}
295
 
296
proc tixExFileSelectBox:Cmd-FileCombo {w value} {
297
    upvar #0 $w data
298
 
299
    if {[tixEvent type] == "<Return>"} {
300
        tixExFileSelectBox:Ok $w
301
    }
302
}
303
 
304
proc tixExFileSelectBox:Ok {w} {
305
    upvar #0 $w data
306
 
307
    set value [string trim [$data(w:file) subwidget entry get]]
308
    if {$value == ""} {
309
        set value $data(-pattern)
310
    }
311
    tixSetSilent $data(w:file) $value
312
 
313
    if [tixExFileSelectBox:IsPattern $w $value] {
314
        set data(-pattern) $value
315
        tixWidgetDoWhenIdle tixExFileSelectBox:LoadFiles $w reload
316
    } else {
317
        if [tixIsAbsPath $value] {
318
            set intName [tixFileIntName $value]
319
        } else {
320
            set intName [tixSubFolder [tixFileIntName $data(-directory)] \
321
                [tixFileIntName $value]]
322
        }
323
        set data(-value) [tixNativeName $intName]
324
        tixExFileSelectBox:Invoke $w
325
    }
326
}
327
 
328
proc tixExFileSelectBox:Cancel {w} {
329
    upvar #0 $w data
330
 
331
    if {$data(-dialog) != ""} {
332
        eval $data(-dialog) popdown
333
    }
334
}
335
 
336
proc tixExFileSelectBox:Invoke {w} {
337
    upvar #0 $w data
338
 
339
    # Save some old history
340
    #
341
    $data(w:dir)  addhistory [$data(w:dir) cget -value]
342
    $data(w:file) addhistory $data(-pattern)
343
    $data(w:file) addhistory $data(-value)
344
    if {$data(-dialog) != ""} {
345
        eval $data(-dialog) popdown
346
    }
347
    if {$data(-command) != "" && !$data(-disablecallback)} {
348
        set bind(specs) "%V"
349
        set bind(%V) $data(-value)
350
        tixEvalCmdBinding $w $data(-command) bind $data(-value)
351
    }
352
}
353
 
354
proc tixExFileSelectBox:Cmd-FileList {w invoke args} {
355
    upvar #0 $w data
356
 
357
    set index [lindex [$data(w:filelist) subwidget listbox curselection] 0]
358
    if {$index == ""} {
359
        set index 0
360
    }
361
 
362
    set file [$data(w:filelist) subwidget listbox get $index]
363
    tixSetSilent $data(w:file) $file
364
 
365
    set data(-value) [tixNativeName [tixSubFolder \
366
        [tixFileIntName $data(-directory)] [tixFileIntName $file]]]
367
 
368
    if {$invoke == 1} {
369
        tixExFileSelectBox:Invoke $w
370
    } else {
371
        if {$data(-browsecmd) != ""} {
372
            tixEvalCmdBinding $w $data(-browsecmd) "" $data(-value)
373
        }
374
    }
375
}
376
 
377
proc tixExFileSelectBox:Cmd-TypeCombo {w args} {
378
    upvar #0 $w data
379
 
380
    set value [tixEvent flag V]
381
 
382
    if [info exists data(type,$value)] {
383
        set data(-pattern) $data(type,$value)
384
        tixSetSilent $data(w:file) $data(-pattern)
385
        tixWidgetDoWhenIdle tixExFileSelectBox:LoadFiles $w reload
386
    }
387
}
388
 
389
proc tixExFileSelectBox:LoadFiles {w flag} {
390
    upvar #0 $w data
391
 
392
    if {$flag != "reload" && $data(-directory) == $data(oldDir)} {
393
        return
394
    }
395
 
396
    if {![winfo ismapped [winfo toplevel $w]]} {
397
        tixDoWhenMapped [winfo toplevel $w] \
398
            "tixExFileSelectBox:LoadFiles $w $flag"
399
        return
400
    }
401
 
402
    set listbox [$data(w:filelist) subwidget listbox]
403
    $listbox delete 0 end
404
 
405
    set data(-value) ""
406
 
407
    tixBusy $w on [$data(w:dirlist) subwidget hlist]
408
 
409
    set intDir [tixFileIntName $data(-directory)]
410
    foreach name [tixListDir $intDir 0 1 0 \
411
        $data(-showhidden) $data(-pattern)] {
412
 
413
        $listbox insert end [tixFileDisplayName [tixSubFolder $intDir $name]]
414
    }
415
 
416
    if {$data(oldDir) != $data(-directory)} {
417
        # Otherwise if the user has already selected a file and then presses
418
        # "show hidden", the selection won't be wiped out.
419
        tixSetSilent $data(w:file) $data(-pattern)
420
    }
421
    set data(oldDir) $data(-directory)
422
 
423
    tixWidgetDoWhenIdle tixBusy $w off [$data(w:dirlist) subwidget hlist]
424
}
425
 
426
#
427
# Called when thd listbox is first mapped
428
proc tixExFileSelectBox:Map {w} {
429
    if {![winfo exists $w]} {
430
        return
431
    }
432
 
433
    upvar #0 $w data
434
 
435
    set bind(specs) "%V"
436
    set bind(%V) $data(-value)
437
    tixEvalCmdBinding $w bind \
438
        "tixExFileSelectBox:Cmd-DirList $w" $data(-directory)
439
}
440
 
441
#----------------------------------------------------------------------
442
# Public commands
443
#
444
#----------------------------------------------------------------------
445
proc tixExFileSelectBox:invoke {w} {
446
    tixExFileSelectBox:Invoke $w
447
}
448
 
449
proc tixExFileSelectBox:filter {w} {
450
    tixExFileSelectBox:LoadFiles $w reload
451
}
452
 

powered by: WebSVN 2.1.0

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