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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [itcl/] [iwidgets3.0.0/] [generic/] [extfileselectionbox.itk] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
#
2
# Extfileselectionbox
3
# ----------------------------------------------------------------------
4
# Implements a file selection box that is a slightly extended version
5
# of the OSF/Motif standard XmExtfileselectionbox composite widget.
6
# The Extfileselectionbox differs from the Motif standard in that the
7
# filter and selection fields are comboboxes and the files and directory
8
# lists are in a paned window.
9
#
10
# ----------------------------------------------------------------------
11
#  AUTHOR: Mark L. Ulferts               EMAIL: mulferts@spd.dsccc.com
12
#          Anthony L. Parent                    tony.parent@symbios.com
13
#
14
#  @(#) $Id: extfileselectionbox.itk,v 1.1.1.1 2002-01-16 10:24:50 markom Exp $
15
# ----------------------------------------------------------------------
16
#            Copyright (c) 1997 DSC Technologies Corporation
17
# ======================================================================
18
# Permission to use, copy, modify, distribute and license this software
19
# and its documentation for any purpose, and without fee or written
20
# agreement with DSC, is hereby granted, provided that the above copyright
21
# notice appears in all copies and that both the copyright notice and
22
# warranty disclaimer below appear in supporting documentation, and that
23
# the names of DSC Technologies Corporation or DSC Communications
24
# Corporation not be used in advertising or publicity pertaining to the
25
# software without specific, written prior permission.
26
#
27
# DSC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
28
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, AND NON-
29
# INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND THE
30
# AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE,
31
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. IN NO EVENT SHALL
32
# DSC BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
33
# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
34
# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTUOUS ACTION,
35
# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
36
# SOFTWARE.
37
# ======================================================================
38
 
39
#
40
# Usual options.
41
#
42
itk::usual Extfileselectionbox {
43
    keep -activebackground -activerelief -background -borderwidth -cursor \
44
         -elementborderwidth -foreground -highlightcolor -highlightthickness \
45
         -insertbackground -insertborderwidth -insertofftime -insertontime \
46
         -insertwidth -jump -labelfont -selectbackground -selectborderwidth \
47
         -textbackground -textfont -troughcolor
48
}
49
 
50
# ------------------------------------------------------------------
51
#                          EXTFILESELECTIONBOX
52
# ------------------------------------------------------------------
53
class iwidgets::Extfileselectionbox {
54
    inherit itk::Widget
55
 
56
    constructor {args} {}
57
    destructor {}
58
 
59
    itk_option define -childsitepos childSitePos Position s
60
    itk_option define -fileson filesOn FilesOn true
61
    itk_option define -dirson dirsOn DirsOn true
62
    itk_option define -selectionon selectionOn SelectionOn true
63
    itk_option define -filteron filterOn FilterOn true
64
    itk_option define -mask mask Mask {*}
65
    itk_option define -directory directory Directory {}
66
    itk_option define -nomatchstring noMatchString NoMatchString {}
67
    itk_option define -dirsearchcommand dirSearchCommand Command {}
68
    itk_option define -filesearchcommand fileSearchCommand Command {}
69
    itk_option define -selectioncommand selectionCommand Command {}
70
    itk_option define -filtercommand filterCommand Command {}
71
    itk_option define -selectdircommand selectDirCommand Command {}
72
    itk_option define -selectfilecommand selectFileCommand Command {}
73
    itk_option define -invalid invalid Command {bell}
74
    itk_option define -filetype fileType FileType {regular}
75
    itk_option define -width width Width 350
76
    itk_option define -height height Height 300
77
 
78
    public {
79
        method childsite {}
80
        method get {}
81
        method filter {}
82
    }
83
 
84
    public {
85
        method _selectDir {}
86
        method _dblSelectDir {}
87
        method _selectFile {}
88
        method _selectSelection {}
89
        method _selectFilter {}
90
    }
91
 
92
    protected {
93
        method _packComponents {{when later}}
94
        method _updateLists {{when later}}
95
    }
96
 
97
    private {
98
        method _setFilter {}
99
        method _setSelection {}
100
        method _setDirList {}
101
        method _setFileList {}
102
 
103
        method _nPos {}
104
        method _sPos {}
105
        method _ePos {}
106
        method _wPos {}
107
        method _topPos {}
108
        method _bottomPos {}
109
 
110
        variable _packToken ""      ;# non-null => _packComponents pending
111
        variable _updateToken ""    ;# non-null => _updateLists pending
112
        variable _pwd "."           ;# present working dir
113
        variable _interior          ;# original interior setting
114
    }
115
}
116
 
117
#
118
# Provide a lowercased access method for the Extfileselectionbox class.
119
#
120
proc ::iwidgets::extfileselectionbox {pathName args} {
121
    uplevel ::iwidgets::Extfileselectionbox $pathName $args
122
}
123
 
124
#
125
# Use option database to override default resources of base classes.
126
#
127
option add *Extfileselectionbox.borderWidth 2 widgetDefault
128
 
129
option add *Extfileselectionbox.filterLabel Filter widgetDefault
130
option add *Extfileselectionbox.dirsLabel Directories widgetDefault
131
option add *Extfileselectionbox.filesLabel Files widgetDefault
132
option add *Extfileselectionbox.selectionLabel Selection widgetDefault
133
 
134
option add *Extfileselectionbox.width 350 widgetDefault
135
option add *Extfileselectionbox.height 300 widgetDefault
136
 
137
# ------------------------------------------------------------------
138
#                        CONSTRUCTOR
139
# ------------------------------------------------------------------
140
body iwidgets::Extfileselectionbox::constructor {args} {
141
    #
142
    # Add back to the hull width and height options and make the
143
    # borderwidth zero since we don't need it.
144
    #
145
    itk_option add hull.width hull.height
146
    component hull configure -borderwidth 0
147
 
148
    set _interior $itk_interior
149
 
150
    #
151
    # Create the filter entry.
152
    #
153
    itk_component add filter {
154
        iwidgets::Combobox $itk_interior.filter -unique true \
155
            -command [code $this _selectFilter] -exportselection 0 \
156
            -labelpos nw -completion 0
157
 
158
    } {
159
        usual
160
 
161
        rename -labeltext -filterlabel filterLabel Text
162
    }
163
 
164
    set cmd [$itk_component(filter) cget -command]
165
    set cmd "$cmd;[code $this _selectFilter]"
166
    $itk_component(filter) configure -command "$cmd" -selectioncommand "$cmd";
167
 
168
    #
169
    # Create a paned window for the directory and file lists.
170
    #
171
    itk_component add listpane {
172
      iwidgets::Panedwindow $itk_interior.listpane -orient vertical
173
    }
174
 
175
    $itk_component(listpane) add dirs -margin 5
176
    $itk_component(listpane) add files -margin 5
177
 
178
    #
179
    # Create the directory list.
180
    #
181
    itk_component add dirs {
182
        iwidgets::Scrolledlistbox [$itk_component(listpane) childsite dirs].dirs \
183
            -selectioncommand [code $this _selectDir] \
184
            -selectmode single -exportselection 0 \
185
            -visibleitems 1x1 -labelpos nw \
186
            -hscrollmode static -vscrollmode static \
187
            -dblclickcommand [code $this _dblSelectDir]
188
    } {
189
        usual
190
 
191
        rename -labeltext -dirslabel dirsLabel Text
192
    }
193
    grid $itk_component(dirs) -sticky nsew
194
    grid rowconfigure [$itk_component(listpane) childsite dirs] 0 -weight 1
195
    grid columnconfigure [$itk_component(listpane) childsite dirs] 0 -weight 1
196
 
197
    #
198
    # Create the files list.
199
    #
200
    itk_component add files {
201
        iwidgets::Scrolledlistbox [$itk_component(listpane) childsite files].files \
202
            -selectioncommand [code $this _selectFile] \
203
            -selectmode single -exportselection 0 \
204
            -visibleitems 1x1 -labelpos nw \
205
            -hscrollmode static -vscrollmode static
206
    } {
207
        usual
208
 
209
        rename -labeltext -fileslabel filesLabel Text
210
    }
211
    grid $itk_component(files) -sticky nsew
212
    grid rowconfigure [$itk_component(listpane) childsite files] 0 -weight 1
213
    grid columnconfigure [$itk_component(listpane) childsite files] 0 -weight 1
214
 
215
    #
216
    # Create the selection entry.
217
    #
218
    itk_component add selection {
219
      iwidgets::Combobox $itk_interior.selection -unique true \
220
          -command [code $this _selectSelection] -exportselection 0 \
221
          -labelpos nw -completion 0
222
    } {
223
        usual
224
 
225
        rename -labeltext -selectionlabel selectionLabel Text
226
    }
227
 
228
    #
229
    # Create the child site widget.
230
    #
231
    itk_component add -protected childsite {
232
        frame $itk_interior.fsbchildsite
233
    }
234
 
235
    #
236
    # Set the interior variable to the childsite for derived classes.
237
    #
238
    set itk_interior $itk_component(childsite)
239
 
240
    #
241
    # Explicitly handle configs that may have been ignored earlier.
242
    #
243
    eval itk_initialize $args
244
 
245
    #
246
    # When idle, pack the childsite and update the lists.
247
    #
248
    _packComponents
249
    _updateLists
250
}
251
 
252
# ------------------------------------------------------------------
253
#                           DESTRUCTOR
254
# ------------------------------------------------------------------
255
body iwidgets::Extfileselectionbox::destructor {} {
256
    if {$_packToken != ""} {after cancel $_packToken}
257
    if {$_updateToken != ""} {after cancel $_updateToken}
258
}
259
 
260
# ------------------------------------------------------------------
261
#                             OPTIONS
262
# ------------------------------------------------------------------
263
 
264
# ------------------------------------------------------------------
265
# OPTION: -childsitepos
266
#
267
# Specifies the position of the child site in the selection box.
268
# ------------------------------------------------------------------
269
configbody iwidgets::Extfileselectionbox::childsitepos {
270
    _packComponents
271
}
272
 
273
# ------------------------------------------------------------------
274
# OPTION: -fileson
275
#
276
# Specifies whether or not to display the files list.
277
# ------------------------------------------------------------------
278
configbody iwidgets::Extfileselectionbox::fileson {
279
    if {$itk_option(-fileson)} {
280
        $itk_component(listpane) show files
281
 
282
        _updateLists
283
 
284
    } else {
285
        $itk_component(listpane) hide files
286
    }
287
}
288
 
289
# ------------------------------------------------------------------
290
# OPTION: -dirson
291
#
292
# Specifies whether or not to display the dirs list.
293
# ------------------------------------------------------------------
294
configbody iwidgets::Extfileselectionbox::dirson {
295
    if {$itk_option(-dirson)} {
296
        $itk_component(listpane) show dirs
297
 
298
        _updateLists
299
 
300
    } else {
301
        $itk_component(listpane) hide dirs
302
    }
303
}
304
 
305
# ------------------------------------------------------------------
306
# OPTION: -selectionon
307
#
308
# Specifies whether or not to display the selection entry widget.
309
# ------------------------------------------------------------------
310
configbody iwidgets::Extfileselectionbox::selectionon {
311
    _packComponents
312
}
313
 
314
# ------------------------------------------------------------------
315
# OPTION: -filteron
316
#
317
# Specifies whether or not to display the filter entry widget.
318
# ------------------------------------------------------------------
319
configbody iwidgets::Extfileselectionbox::filteron {
320
    _packComponents
321
}
322
 
323
# ------------------------------------------------------------------
324
# OPTION: -mask
325
#
326
# Specifies the initial file mask string.
327
# ------------------------------------------------------------------
328
configbody iwidgets::Extfileselectionbox::mask {
329
    global tcl_platform
330
    set prefix $_pwd
331
 
332
    #
333
    # Remove automounter paths.
334
    #
335
    if {$tcl_platform(platform) == "unix"} {
336
            regsub {^/(tmp_mnt|export)} $prefix {} prefix;
337
    }
338
 
339
    set curFilter $itk_option(-mask);
340
    $itk_component(filter) delete entry 0 end
341
    $itk_component(filter) insert entry 0 [file join $_pwd $itk_option(-mask)]
342
 
343
    #
344
    # Make sure the right most text is visable.
345
    #
346
    [$itk_component(filter) component entry] xview moveto 1
347
}
348
 
349
# ------------------------------------------------------------------
350
# OPTION: -directory
351
#
352
# Specifies the initial default directory.
353
# ------------------------------------------------------------------
354
configbody iwidgets::Extfileselectionbox::directory {
355
    if {$itk_option(-directory) != {}} {
356
        if {! [file exists $itk_option(-directory)]} {
357
            error "bad directory option \"$itk_option(-directory)\":\
358
                    directory does not exist"
359
        }
360
 
361
        set olddir [pwd]
362
        cd $itk_option(-directory)
363
        set _pwd [pwd]
364
        cd $olddir
365
 
366
        configure -mask $itk_option(-mask)
367
        _selectFilter
368
    }
369
}
370
 
371
# ------------------------------------------------------------------
372
# OPTION: -nomatchstring
373
#
374
# Specifies the string to be displayed in the files list should
375
# not regular files exist in the directory.
376
# ------------------------------------------------------------------
377
configbody iwidgets::Extfileselectionbox::nomatchstring {
378
}
379
 
380
# ------------------------------------------------------------------
381
# OPTION: -dirsearchcommand
382
#
383
# Specifies a command to be executed to perform a directory search.
384
# The command will receive the current working directory and filter
385
# mask as arguments.  The command should return a list of files which
386
# will be placed into the directory list.
387
# ------------------------------------------------------------------
388
configbody iwidgets::Extfileselectionbox::dirsearchcommand {
389
}
390
 
391
# ------------------------------------------------------------------
392
# OPTION: -filesearchcommand
393
#
394
# Specifies a command to be executed to perform a file search.
395
# The command will receive the current working directory and filter
396
# mask as arguments.  The command should return a list of files which
397
# will be placed into the file list.
398
# ------------------------------------------------------------------
399
configbody iwidgets::Extfileselectionbox::filesearchcommand {
400
}
401
 
402
# ------------------------------------------------------------------
403
# OPTION: -selectioncommand
404
#
405
# Specifies a command to be executed upon pressing return in the
406
# selection entry widget.
407
# ------------------------------------------------------------------
408
configbody iwidgets::Extfileselectionbox::selectioncommand {
409
}
410
 
411
# ------------------------------------------------------------------
412
# OPTION: -filtercommand
413
#
414
# Specifies a command to be executed upon pressing return in the
415
# filter entry widget.
416
# ------------------------------------------------------------------
417
configbody iwidgets::Extfileselectionbox::filtercommand {
418
}
419
 
420
# ------------------------------------------------------------------
421
# OPTION: -selectdircommand
422
#
423
# Specifies a command to be executed following selection of a
424
# directory in the directory list.
425
# ------------------------------------------------------------------
426
configbody iwidgets::Extfileselectionbox::selectdircommand {
427
}
428
 
429
# ------------------------------------------------------------------
430
# OPTION: -selectfilecommand
431
#
432
# Specifies a command to be executed following selection of a
433
# file in the files list.
434
# ------------------------------------------------------------------
435
configbody iwidgets::Extfileselectionbox::selectfilecommand {
436
}
437
 
438
# ------------------------------------------------------------------
439
# OPTION: -invalid
440
#
441
# Specify a command to executed should the filter contents be
442
# proven invalid.
443
# ------------------------------------------------------------------
444
configbody iwidgets::Extfileselectionbox::invalid {
445
}
446
 
447
# ------------------------------------------------------------------
448
# OPTION: -filetype
449
#
450
# Specify the type of files which may appear in the file list.
451
# ------------------------------------------------------------------
452
configbody iwidgets::Extfileselectionbox::filetype {
453
    switch $itk_option(-filetype) {
454
        regular -
455
        directory -
456
        any {
457
        }
458
        default {
459
            error "bad filetype option \"$itk_option(-filetype)\":\
460
                    should be regular, directory, or any"
461
        }
462
    }
463
 
464
    _updateLists
465
}
466
 
467
# ------------------------------------------------------------------
468
# OPTION: -width
469
#
470
# Specifies the width of the file selection box.  The value may be
471
# specified in any of the forms acceptable to Tk_GetPixels.
472
# ------------------------------------------------------------------
473
configbody iwidgets::Extfileselectionbox::width {
474
    #
475
    # The width option was added to the hull in the constructor.
476
    # So, any width value given is passed automatically to the
477
    # hull.  All we have to do is play with the propagation.
478
    #
479
    if {$itk_option(-width) != 0} {
480
        set propagate 0
481
    } else {
482
        set propagate 1
483
    }
484
 
485
    #
486
    # Due to a bug in the tk4.2 grid, we have to check the
487
    # propagation before setting it.  Setting it to the same
488
    # value it already is will cause it to toggle.
489
    #
490
    if {[grid propagate $itk_component(hull)] != $propagate} {
491
        grid propagate $itk_component(hull) $propagate
492
    }
493
}
494
 
495
# ------------------------------------------------------------------
496
# OPTION: -height
497
#
498
# Specifies the height of the file selection box.  The value may be
499
# specified in any of the forms acceptable to Tk_GetPixels.
500
# ------------------------------------------------------------------
501
configbody iwidgets::Extfileselectionbox::height {
502
    #
503
    # The height option was added to the hull in the constructor.
504
    # So, any height value given is passed automatically to the
505
    # hull.  All we have to do is play with the propagation.
506
    #
507
    if {$itk_option(-height) != 0} {
508
        set propagate 0
509
    } else {
510
        set propagate 1
511
    }
512
 
513
    #
514
    # Due to a bug in the tk4.2 grid, we have to check the
515
    # propagation before setting it.  Setting it to the same
516
    # value it already is will cause it to toggle.
517
    #
518
    if {[grid propagate $itk_component(hull)] != $propagate} {
519
        grid propagate $itk_component(hull) $propagate
520
    }
521
}
522
 
523
# ------------------------------------------------------------------
524
#                            METHODS
525
# ------------------------------------------------------------------
526
 
527
# ------------------------------------------------------------------
528
# METHOD: childsite
529
#
530
# Returns the path name of the child site widget.
531
# ------------------------------------------------------------------
532
body iwidgets::Extfileselectionbox::childsite {} {
533
    return $itk_component(childsite)
534
}
535
 
536
# ------------------------------------------------------------------
537
# METHOD: get
538
#
539
# Returns the current selection.
540
# ------------------------------------------------------------------
541
body iwidgets::Extfileselectionbox::get {} {
542
    return [$itk_component(selection) get]
543
}
544
 
545
# ------------------------------------------------------------------
546
# METHOD: filter
547
#
548
# The user has pressed Return in the filter.  Make sure the contents
549
# contain a valid directory before setting default to directory.
550
# Use the invalid option to warn the user of any problems.
551
# ------------------------------------------------------------------
552
body iwidgets::Extfileselectionbox::filter {} {
553
    set newdir [file dirname [$itk_component(filter) get]]
554
 
555
    if {! [file exists $newdir]} {
556
        uplevel #0 "$itk_option(-invalid)"
557
        return
558
    }
559
 
560
    set _pwd $newdir;
561
    if {$_pwd == "."} {set _pwd [pwd]};
562
 
563
    _updateLists
564
}
565
 
566
# ------------------------------------------------------------------
567
# PRIVATE METHOD: _updateLists ?now?
568
#
569
# Updates the contents of both the file and directory lists, as well
570
# resets the positions of the filter, and lists.
571
# ------------------------------------------------------------------
572
body iwidgets::Extfileselectionbox::_updateLists {{when "later"}} {
573
    switch -- $when {
574
        later {
575
            if {$_updateToken == ""} {
576
                set _updateToken [after idle [code $this _updateLists now]]
577
            }
578
        }
579
        now {
580
            if {$itk_option(-dirson)} {_setDirList}
581
            if {$itk_option(-fileson)} {_setFileList}
582
 
583
            if {$itk_option(-filteron)} {
584
              _setFilter
585
            }
586
            if {$itk_option(-selectionon)} {
587
                $itk_component(selection) icursor end
588
            }
589
            if {$itk_option(-dirson)} {
590
                $itk_component(dirs) justify left
591
            }
592
            if {$itk_option(-fileson)} {
593
                $itk_component(files) justify left
594
            }
595
            set _updateToken ""
596
        }
597
        default {
598
            error "bad option \"$when\": should be later or now"
599
        }
600
    }
601
}
602
 
603
# ------------------------------------------------------------------
604
# PRIVATE METHOD: _setFilter
605
#
606
# Set the filter to the current selection in the directory list plus
607
# any existing mask in the filter.  Translate the two special cases
608
# of '.', and '..' directory names to full path names..
609
# ------------------------------------------------------------------
610
body iwidgets::Extfileselectionbox::_setFilter {} {
611
    global tcl_platform
612
    set prefix [$itk_component(dirs) getcurselection]
613
    set curFilter [file tail [$itk_component(filter) get]]
614
 
615
    while {[regexp {\.$} $prefix]} {
616
        if {[file tail $prefix] == "."} {
617
            if {$prefix == "."} {
618
                if {$_pwd == "."} {
619
                    set _pwd [pwd]
620
                } elseif {$_pwd == ".."} {
621
                    set _pwd [file dirname [pwd]]
622
                }
623
                set prefix $_pwd
624
            } else {
625
                set prefix [file dirname $prefix]
626
            }
627
        } elseif {[file tail $prefix] == ".."} {
628
            if {$prefix != ".."} {
629
                set prefix [file dirname [file dirname $prefix]]
630
            } else {
631
                if {$_pwd == "."} {
632
                    set _pwd [pwd]
633
                } elseif {$_pwd == ".."} {
634
                    set _pwd [file dirname [pwd]]
635
                }
636
                set prefix [file dirname $_pwd]
637
            }
638
        } else {
639
            break
640
        }
641
    }
642
 
643
    if { [file pathtype $prefix] != "absolute" } {
644
        set prefix [file join $_pwd $prefix]
645
    }
646
 
647
    #
648
    # Remove automounter paths.
649
    #
650
    if {$tcl_platform(platform) == "unix"} {
651
            regsub {^/(tmp_mnt|export)} $prefix {} prefix
652
    }
653
 
654
    $itk_component(filter) delete entry 0 end
655
    $itk_component(filter) insert entry 0 [file join $prefix $curFilter]
656
 
657
    if {[info level -1] != "_selectDir"} {
658
        $itk_component(filter) insert list 0 [file join $prefix $curFilter]
659
    }
660
 
661
    #
662
    # Make sure insertion cursor is at the end.
663
    #
664
    $itk_component(filter) icursor end
665
 
666
    #
667
    # Make sure the right most text is visable.
668
    #
669
    [$itk_component(filter) component entry] xview moveto 1
670
}
671
 
672
# ------------------------------------------------------------------
673
# PRIVATE METHOD: _setSelection
674
#
675
# Set the contents of the selection entry to either the current
676
# selection of the file or directory list dependent on which lists
677
# are currently mapped.  For the file list, avoid seleciton of the
678
# no match string.  As for the directory list, translate file names.
679
# ------------------------------------------------------------------
680
body iwidgets::Extfileselectionbox::_setSelection {} {
681
    global tcl_platform
682
    $itk_component(selection) delete entry 0 end
683
 
684
    if {$itk_option(-fileson)} {
685
        set selection [$itk_component(files) getcurselection]
686
 
687
        if {$selection != $itk_option(-nomatchstring)} {
688
            if {[file pathtype $selection] != "absolute"} {
689
                set selection [file join $_pwd $selection]
690
            }
691
 
692
            #
693
            # Remove automounter paths.
694
            #
695
            if {$tcl_platform(platform) == "unix"} {
696
                regsub {^/(tmp_mnt|export)} $selection {} selection;
697
            }
698
 
699
            $itk_component(selection) insert entry 0 $selection
700
        } else {
701
            $itk_component(files) selection clear 0 end
702
        }
703
 
704
    } else {
705
        set selection [$itk_component(dirs) getcurselection]
706
 
707
        if {[file tail $selection] == "."} {
708
            if {$selection != "."} {
709
                set selection [file dirname $selection]
710
            } else {
711
                set selection $_pwd
712
            }
713
        } elseif {[file tail $selection] == ".."} {
714
            if {$selection != ".."} {
715
                set selection [file dirname [file dirname $selection]]
716
            } else {
717
                set selection [file join $_pwd ..]
718
            }
719
        }
720
 
721
        #
722
        # Remove automounter paths.
723
        #
724
        if {$tcl_platform(platform) == "unix"} {
725
            regsub {^/(tmp_mnt|export)} $selection {} selection;
726
        }
727
 
728
        $itk_component(selection) insert entry 0 $selection
729
    }
730
 
731
    $itk_component(selection) insert list 0 $selection
732
    $itk_component(selection) icursor end
733
 
734
    #
735
    # Make sure the right most text is visable.
736
    #
737
    [$itk_component(selection) component entry] xview moveto 1
738
}
739
 
740
# ------------------------------------------------------------------
741
# PRIVATE METHOD: _setDirList
742
#
743
# Clear the directory list and dependent on whether the user has
744
# defined their own search procedure or not fill the list with their
745
# results or those of a glob.  Select the first element if it exists.
746
# ------------------------------------------------------------------
747
body iwidgets::Extfileselectionbox::_setDirList {} {
748
    $itk_component(dirs) clear
749
 
750
    if {$itk_option(-dirsearchcommand) == {}} {
751
        set cwd $_pwd
752
 
753
        foreach i [lsort [glob -nocomplain \
754
                              [file join $cwd .*] [file join $cwd *]]] {
755
            if {[file isdirectory $i]} {
756
                set insert "[file tail $i]"
757
                $itk_component(dirs) insert end "$insert"
758
            }
759
        }
760
 
761
    } else {
762
        set mask [file tail [$itk_component(filter) get]]
763
 
764
        foreach file [uplevel #0 $itk_option(-dirsearchcommand) $_pwd $mask] {
765
            $itk_component(dirs) insert end $file
766
        }
767
    }
768
 
769
    if {[$itk_component(dirs) size]} {
770
        $itk_component(dirs) selection clear 0 end
771
        $itk_component(dirs) selection set 0
772
    }
773
}
774
 
775
# ------------------------------------------------------------------
776
# PRIVATE METHOD: _setFileList
777
#
778
# Clear the file list and dependent on whether the user has defined
779
# their own search procedure or not fill the list with their results
780
# or those of a 'glob'.  If the files list has no contents, then set
781
# the files list to the 'nomatchstring'.  Clear all selections.
782
# ------------------------------------------------------------------
783
body iwidgets::Extfileselectionbox::_setFileList {} {
784
    $itk_component(files) clear
785
    set mask [file tail [$itk_component(filter) get]]
786
 
787
    if {$itk_option(-filesearchcommand) == {}} {
788
        if {$mask == "*"} {
789
            set files [lsort [glob -nocomplain \
790
                                  [file join $_pwd .*] [file join $_pwd *]]]
791
        } else {
792
            set files [lsort [glob -nocomplain [file join $_pwd $mask]]]
793
        }
794
 
795
        foreach i $files {
796
            if {($itk_option(-filetype) == "regular" && \
797
                    ! [file isdirectory $i]) || \
798
                    ($itk_option(-filetype) == "directory" && \
799
                    [file isdirectory $i]) || \
800
                    ($itk_option(-filetype) == "any")} {
801
                set insert "[file tail $i]"
802
                $itk_component(files) insert end "$insert"
803
            }
804
        }
805
 
806
    } else {
807
        foreach file [uplevel #0 $itk_option(-filesearchcommand) $_pwd $mask] {
808
            $itk_component(files) insert end $file
809
        }
810
    }
811
 
812
    if {[$itk_component(files) size] == 0} {
813
        if {$itk_option(-nomatchstring) != {}} {
814
            $itk_component(files) insert end $itk_option(-nomatchstring)
815
        }
816
    }
817
 
818
    $itk_component(files) selection clear 0 end
819
}
820
 
821
# ------------------------------------------------------------------
822
# PRIVATE METHOD: _selectDir
823
#
824
# For a selection in the directory list, set the filter and possibly
825
# the selection entry based on the fileson option.
826
# ------------------------------------------------------------------
827
body iwidgets::Extfileselectionbox::_selectDir {} {
828
    _setFilter
829
 
830
    if {$itk_option(-fileson)} {} {
831
        _setSelection
832
    }
833
 
834
    if {$itk_option(-selectdircommand) != {}} {
835
        uplevel #0 $itk_option(-selectdircommand)
836
    }
837
}
838
 
839
# ------------------------------------------------------------------
840
# PRIVATE METHOD: _dblSelectDir
841
#
842
# For a double click event in the directory list, select the
843
# directory, set the default to the selection, and update both the
844
# file and directory lists.
845
# ------------------------------------------------------------------
846
body iwidgets::Extfileselectionbox::_dblSelectDir {} {
847
    filter
848
}
849
 
850
# ------------------------------------------------------------------
851
# PRIVATE METHOD: _selectFile
852
#
853
# The user has selected a file.  Put the current selection in the
854
# file list in the selection entry widget.
855
# ------------------------------------------------------------------
856
body iwidgets::Extfileselectionbox::_selectFile {} {
857
    _setSelection
858
 
859
    if {$itk_option(-selectfilecommand) != {}} {
860
        uplevel #0 $itk_option(-selectfilecommand)
861
    }
862
}
863
 
864
# ------------------------------------------------------------------
865
# PRIVATE METHOD: _selectSelection
866
#
867
# The user has pressed Return in the selection entry widget.  Call
868
# the defined selection command if it exists.
869
# ------------------------------------------------------------------
870
body iwidgets::Extfileselectionbox::_selectSelection {} {
871
    if {$itk_option(-selectioncommand) != {}} {
872
        uplevel #0 $itk_option(-selectioncommand)
873
    }
874
}
875
 
876
# ------------------------------------------------------------------
877
# PRIVATE METHOD: _selectFilter
878
#
879
# The user has pressed Return in the filter entry widget.  Call the
880
# defined selection command if it exists, otherwise just filter.
881
# ------------------------------------------------------------------
882
body iwidgets::Extfileselectionbox::_selectFilter {} {
883
    if {$itk_option(-filtercommand) != {}} {
884
        uplevel #0 $itk_option(-filtercommand)
885
    } else {
886
        filter
887
    }
888
}
889
 
890
# ------------------------------------------------------------------
891
# PRIVATE METHOD: _packComponents
892
#
893
# Pack the selection, items, and child site widgets based on options.
894
# Using the -in option of pack, put the childsite around the frame
895
# in the hull for n, s, e, and w positions.  Make sure and raise
896
# the child site since using the 'in' option may obscure the site.
897
# ------------------------------------------------------------------
898
body iwidgets::Extfileselectionbox::_packComponents {{when "later"}} {
899
    if {$when == "later"} {
900
        if {$_packToken == ""} {
901
            set _packToken [after idle [code $this _packComponents now]]
902
        }
903
        return
904
    } elseif {$when != "now"} {
905
        error "bad option \"$when\": should be now or later"
906
    }
907
 
908
    set _packToken ""
909
 
910
    #
911
    # Forget about any previous placements via the grid and
912
    # reset all the possible minsizes and weights for all
913
    # the rows and columns.
914
    #
915
    foreach component {childsite listpane filter selection} {
916
        grid forget $itk_component($component)
917
    }
918
 
919
    for {set row 0} {$row < 6} {incr row} {
920
        grid rowconfigure $_interior $row -minsize 0 -weight 0
921
    }
922
 
923
    for {set col 0} {$col < 3} {incr col} {
924
        grid columnconfigure $_interior $col -minsize 0 -weight 0
925
    }
926
 
927
    #
928
    # Place all the components based on the childsite poisition
929
    # option.
930
    #
931
    switch $itk_option(-childsitepos) {
932
        n { _nPos }
933
 
934
        w { _wPos }
935
 
936
        s { _sPos }
937
 
938
        e { _ePos }
939
 
940
        top { _topPos }
941
 
942
        bottom { _bottomPos }
943
 
944
        default {
945
            error "bad childsitepos option \"$itk_option(-childsitepos)\":\
946
                    should be n, e, s, w, top, or bottom"
947
        }
948
    }
949
}
950
 
951
# ------------------------------------------------------------------
952
# PRIVATE METHOD: _nPos
953
#
954
# Position the childsite to the north and all the other components
955
# appropriately based on the individual "on" options.
956
# ------------------------------------------------------------------
957
body iwidgets::Extfileselectionbox::_nPos {} {
958
    grid $itk_component(childsite) -row 0 -column 0 \
959
        -columnspan 1 -rowspan 1 -sticky nsew -padx 5
960
 
961
    if {$itk_option(-filteron)} {
962
        grid $itk_component(filter) -row 1 -column 0 \
963
            -columnspan 1 -sticky ew -padx 5
964
        grid rowconfigure $_interior 2 -minsize 7
965
    }
966
 
967
    grid $itk_component(listpane) -row 3 -column 0 \
968
            -columnspan 1 -sticky nsew
969
 
970
    grid rowconfigure $_interior 3 -weight 1
971
 
972
    if {$itk_option(-selectionon)} {
973
        grid rowconfigure $_interior 4 -minsize 7
974
        grid $itk_component(selection) -row 5 -column 0 \
975
            -columnspan 1 -sticky ew -padx 5
976
    }
977
 
978
    grid columnconfigure $_interior 0 -weight 1
979
}
980
 
981
# ------------------------------------------------------------------
982
# PRIVATE METHOD: _sPos
983
#
984
# Position the childsite to the south and all the other components
985
# appropriately based on the individual "on" options.
986
# ------------------------------------------------------------------
987
body iwidgets::Extfileselectionbox::_sPos {} {
988
    if {$itk_option(-filteron)} {
989
        grid $itk_component(filter) -row 0 -column 0 \
990
            -columnspan 1 -sticky ew -padx 5
991
        grid rowconfigure $_interior 1 -minsize 7
992
    }
993
 
994
    grid $itk_component(listpane) -row 2 -column 0 \
995
            -columnspan 1 -sticky nsew
996
 
997
    grid rowconfigure $_interior 2 -weight 1
998
 
999
    if {$itk_option(-selectionon)} {
1000
        grid rowconfigure $_interior 3 -minsize 7
1001
        grid $itk_component(selection) -row 4 -column 0 \
1002
            -columnspan 1 -sticky ew -padx 5
1003
    }
1004
 
1005
    grid $itk_component(childsite) -row 5 -column 0 \
1006
        -columnspan 1 -rowspan 1 -sticky nsew -padx 5
1007
 
1008
    grid columnconfigure $_interior 0 -weight 1
1009
}
1010
 
1011
# ------------------------------------------------------------------
1012
# PRIVATE METHOD: _ePos
1013
#
1014
# Position the childsite to the east and all the other components
1015
# appropriately based on the individual "on" options.
1016
# ------------------------------------------------------------------
1017
body iwidgets::Extfileselectionbox::_ePos {} {
1018
    if {$itk_option(-filteron)} {
1019
        grid $itk_component(filter) -row 0 -column 0 \
1020
            -columnspan 1 -sticky ew -padx 5
1021
        grid rowconfigure $_interior 1 -minsize 7
1022
    }
1023
 
1024
    grid $itk_component(listpane) -row 2 -column 0 \
1025
            -columnspan 1 -sticky nsew
1026
 
1027
    grid rowconfigure $_interior 2 -weight 1
1028
 
1029
    if {$itk_option(-selectionon)} {
1030
        grid rowconfigure $_interior 3 -minsize 7
1031
        grid $itk_component(selection) -row 4 -column 0 \
1032
            -columnspan 1 -sticky ew -padx 5
1033
    }
1034
 
1035
    grid $itk_component(childsite) -row 0 -column 1 \
1036
        -rowspan 5 -columnspan 1 -sticky nsew
1037
 
1038
    grid columnconfigure $_interior 0 -weight 1
1039
}
1040
 
1041
# ------------------------------------------------------------------
1042
# PRIVATE METHOD: _wPos
1043
#
1044
# Position the childsite to the west and all the other components
1045
# appropriately based on the individual "on" options.
1046
# ------------------------------------------------------------------
1047
body iwidgets::Extfileselectionbox::_wPos {} {
1048
    grid $itk_component(childsite) -row 0 -column 0 \
1049
        -rowspan 5 -columnspan 1 -sticky nsew
1050
 
1051
    if {$itk_option(-filteron)} {
1052
        grid $itk_component(filter) -row 0 -column 1 \
1053
            -columnspan 1 -sticky ew -padx 5
1054
        grid rowconfigure $_interior 1 -minsize 7
1055
    }
1056
 
1057
    grid $itk_component(listpane) -row 2 -column 1 \
1058
            -columnspan 1 -sticky nsew
1059
 
1060
    grid rowconfigure $_interior 2 -weight 1
1061
 
1062
    if {$itk_option(-selectionon)} {
1063
        grid rowconfigure $_interior 3 -minsize 7
1064
        grid $itk_component(selection) -row 4 -column 1 \
1065
            -columnspan 1 -sticky ew -padx 5
1066
    }
1067
 
1068
    grid columnconfigure $_interior 1 -weight 1
1069
}
1070
 
1071
# ------------------------------------------------------------------
1072
# PRIVATE METHOD: _topPos
1073
#
1074
# Position the childsite below the filter but above the lists and
1075
# all the other components appropriately based on the individual
1076
# "on" options.
1077
# ------------------------------------------------------------------
1078
body iwidgets::Extfileselectionbox::_topPos {} {
1079
    if {$itk_option(-filteron)} {
1080
        grid $itk_component(filter) -row 0 -column 0 \
1081
            -columnspan 1 -sticky ew -padx 5
1082
    }
1083
 
1084
    grid $itk_component(childsite) -row 1 -column 0 \
1085
        -columnspan 1 -rowspan 1 -sticky nsew -padx 5
1086
 
1087
    grid $itk_component(listpane) -row 2 -column 0 -sticky nsew
1088
 
1089
    grid rowconfigure $_interior 2 -weight 1
1090
 
1091
    if {$itk_option(-selectionon)} {
1092
        grid rowconfigure $_interior 3 -minsize 7
1093
        grid $itk_component(selection) -row 4 -column 0 \
1094
            -columnspan 1 -sticky ew -padx 5
1095
    }
1096
 
1097
    grid columnconfigure $_interior 0 -weight 1
1098
}
1099
 
1100
# ------------------------------------------------------------------
1101
# PRIVATE METHOD: _bottomPos
1102
#
1103
# Position the childsite below the lists and above the selection
1104
# and all the other components appropriately based on the individual
1105
# "on" options.
1106
# ------------------------------------------------------------------
1107
body iwidgets::Extfileselectionbox::_bottomPos {} {
1108
    if {$itk_option(-filteron)} {
1109
        grid $itk_component(filter) -row 0 -column 0 \
1110
            -columnspan 1 -sticky ew -padx 5
1111
        grid rowconfigure $_interior 1 -minsize 7
1112
    }
1113
 
1114
    grid $itk_component(listpane) -row 2 -column 0 -sticky nsew
1115
 
1116
    grid rowconfigure $_interior 2 -weight 1
1117
 
1118
    grid $itk_component(childsite) -row 3 -column 0 \
1119
        -columnspan 1 -rowspan 1 -sticky nsew -padx 5
1120
 
1121
    if {$itk_option(-selectionon)} {
1122
        grid $itk_component(selection) -row 4 -column 0 \
1123
            -columnspan 1 -sticky ew -padx 5
1124
    }
1125
 
1126
    grid columnconfigure $_interior 0 -weight 1
1127
}

powered by: WebSVN 2.1.0

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