This file is indexed.

/usr/share/tcltk/iwidgets4.0.1/scripts/fileselectionbox.itk is in iwidgets4 4.0.1-6.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   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
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
#
# Fileselectionbox
# ----------------------------------------------------------------------
# Implements a file selection box in a style similar to the OSF/Motif 
# standard XmFileselectionbox composite widget.  The Fileselectionbox 
# is composed of directory and file scrolled lists as well as filter 
# and selection entry fields.
#
# ----------------------------------------------------------------------
#  AUTHOR: Mark L. Ulferts               EMAIL: mulferts@spd.dsccc.com
#
#  @(#) $Id: fileselectionbox.itk,v 1.3 2001/08/07 19:56:48 smithc Exp $
# ----------------------------------------------------------------------
#            Copyright (c) 1997 DSC Technologies Corporation
# ======================================================================
# Permission to use, copy, modify, distribute and license this software
# and its documentation for any purpose, and without fee or written
# agreement with DSC, is hereby granted, provided that the above copyright
# notice appears in all copies and that both the copyright notice and
# warranty disclaimer below appear in supporting documentation, and that
# the names of DSC Technologies Corporation or DSC Communications
# Corporation not be used in advertising or publicity pertaining to the
# software without specific, written prior permission.
#
# DSC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, AND NON-
# INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND THE
# AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE,
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. IN NO EVENT SHALL
# DSC BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTUOUS ACTION,
# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
# SOFTWARE.
# ======================================================================

#
# Usual options.
#
itk::usual Fileselectionbox {
    keep -activebackground -activerelief -background -borderwidth -cursor \
         -elementborderwidth -foreground -highlightcolor -highlightthickness \
         -insertbackground -insertborderwidth -insertofftime -insertontime \
         -insertwidth -jump -labelfont -selectbackground -selectborderwidth \
         -textbackground -textfont -troughcolor
}

# ------------------------------------------------------------------
#                          FILESELECTIONBOX
# ------------------------------------------------------------------
itcl::class iwidgets::Fileselectionbox {
    inherit itk::Widget

    constructor {args} {}
    destructor {}

    itk_option define -childsitepos childSitePos Position s
    itk_option define -fileson filesOn FilesOn true
    itk_option define -dirson dirsOn DirsOn true
    itk_option define -selectionon selectionOn SelectionOn true
    itk_option define -filteron filterOn FilterOn true
    itk_option define -mask mask Mask {*}
    itk_option define -directory directory Directory {}
    itk_option define -automount automount Automount {}
    itk_option define -nomatchstring noMatchString NoMatchString {}
    itk_option define -dirsearchcommand dirSearchCommand Command {}
    itk_option define -filesearchcommand fileSearchCommand Command {}
    itk_option define -selectioncommand selectionCommand Command {}
    itk_option define -filtercommand filterCommand Command {}
    itk_option define -selectdircommand selectDirCommand Command {}
    itk_option define -selectfilecommand selectFileCommand Command {}
    itk_option define -invalid invalid Command {bell}
    itk_option define -filetype fileType FileType {regular}
    itk_option define -width width Width 350
    itk_option define -height height Height 300

    public {
	method childsite {}
	method get {}
	method filter {}
    }

    public {
	method _selectDir {}
	method _dblSelectDir {}
	method _selectFile {}
	method _selectSelection {}
	method _selectFilter {}
    }

    protected {
	method _packComponents {{when later}}
	method _updateLists {{when later}}
    }

    private {
	method _setFilter {}
	method _setSelection {}
	method _setDirList {}
	method _setFileList {}

	method _nPos {}
	method _sPos {}
	method _ePos {}
	method _wPos {}
	method _topPos {}
	method _centerPos {}
	method _bottomPos {}

	variable _packToken ""      ;# non-null => _packComponents pending
	variable _updateToken ""    ;# non-null => _updateLists pending
	variable _pwd "."           ;# present working dir
	variable _interior          ;# original interior setting
    }
}

#
# Provide a lowercased access method for the Fileselectionbox class.
#
proc ::iwidgets::fileselectionbox {pathName args} {
    uplevel ::iwidgets::Fileselectionbox $pathName $args
}

#
# Use option database to override default resources of base classes.
#
option add *Fileselectionbox.borderWidth 2 widgetDefault

option add *Fileselectionbox.filterLabel Filter widgetDefault
option add *Fileselectionbox.dirsLabel Directories widgetDefault
option add *Fileselectionbox.filesLabel Files widgetDefault
option add *Fileselectionbox.selectionLabel Selection widgetDefault

option add *Fileselectionbox.width 350 widgetDefault
option add *Fileselectionbox.height 300 widgetDefault

# ------------------------------------------------------------------
#                        CONSTRUCTOR
# ------------------------------------------------------------------
itcl::body iwidgets::Fileselectionbox::constructor {args} {
    #
    # Add back to the hull width and height options and make the
    # borderwidth zero since we don't need it.
    #
    itk_option add hull.width hull.height
    component hull configure -borderwidth 0

    set _interior $itk_interior

    #
    # Create the filter entry.
    #
    itk_component add filter {
        iwidgets::Entryfield $itk_interior.filter -labelpos nw \
	    -command [itcl::code $this _selectFilter] -exportselection 0
    } {
	usual

        rename -labeltext -filterlabel filterLabel Text
    }

    #
    # Create the directory list.
    #
    itk_component add dirs {
        iwidgets::Scrolledlistbox $itk_interior.dirs \
	    -selectioncommand [itcl::code $this _selectDir] \
	    -selectmode single -exportselection 0 \
	    -visibleitems 1x1 -labelpos nw \
	    -hscrollmode static -vscrollmode static \
	    -dblclickcommand [itcl::code $this _dblSelectDir]
    } {
	usual

        rename -labeltext -dirslabel dirsLabel Text
    }

    #
    # Create the files list.
    #
    itk_component add files {
        iwidgets::Scrolledlistbox $itk_interior.files \
	    -selectioncommand [itcl::code $this _selectFile] \
	    -selectmode single -exportselection 0 \
	    -visibleitems 1x1 -labelpos nw \
	    -hscrollmode static -vscrollmode static
    } {
	usual

        rename -labeltext -fileslabel filesLabel Text
    }

    #
    # Create the selection entry.
    #
    itk_component add selection {
      iwidgets::Entryfield $itk_interior.selection -labelpos nw \
	  -command [itcl::code $this _selectSelection] -exportselection 0
    } {
	usual

        rename -labeltext -selectionlabel selectionLabel Text
    }

    #
    # Create the child site widget.
    #
    itk_component add -protected childsite {
        frame $itk_interior.fsbchildsite
    } 

    #
    # Set the interior variable to the childsite for derived classes.
    #
    set itk_interior $itk_component(childsite)

    #
    # Explicitly handle configs that may have been ignored earlier.
    #
    eval itk_initialize $args

    #
    # When idle, pack the childsite and update the lists.
    #
    _packComponents
    _updateLists
}

# ------------------------------------------------------------------
#                           DESTRUCTOR
# ------------------------------------------------------------------
itcl::body iwidgets::Fileselectionbox::destructor {} {
    if {$_packToken != ""} {after cancel $_packToken}
    if {$_updateToken != ""} {after cancel $_updateToken}
}

# ------------------------------------------------------------------
#                             OPTIONS
# ------------------------------------------------------------------

# ------------------------------------------------------------------
# OPTION: -childsitepos
#
# Specifies the position of the child site in the selection box.
# ------------------------------------------------------------------
itcl::configbody iwidgets::Fileselectionbox::childsitepos {
    _packComponents
}

# ------------------------------------------------------------------
# OPTION: -fileson
#
# Specifies whether or not to display the files list.
# ------------------------------------------------------------------
itcl::configbody iwidgets::Fileselectionbox::fileson {
    _packComponents
}

# ------------------------------------------------------------------
# OPTION: -dirson
#
# Specifies whether or not to display the dirs list.
# ------------------------------------------------------------------
itcl::configbody iwidgets::Fileselectionbox::dirson {
    _packComponents
}

# ------------------------------------------------------------------
# OPTION: -selectionon
#
# Specifies whether or not to display the selection entry widget.
# ------------------------------------------------------------------
itcl::configbody iwidgets::Fileselectionbox::selectionon {
    _packComponents
}

# ------------------------------------------------------------------
# OPTION: -filteron
#
# Specifies whether or not to display the filter entry widget.
# ------------------------------------------------------------------
itcl::configbody iwidgets::Fileselectionbox::filteron {
    _packComponents
}

# ------------------------------------------------------------------
# OPTION: -mask
#
# Specifies the initial file mask string.
# ------------------------------------------------------------------
itcl::configbody iwidgets::Fileselectionbox::mask {
    global tcl_platform
    set prefix $_pwd

    #
    # Remove automounter paths.
    #
    if {$tcl_platform(platform) == "unix"} {
        if {$itk_option(-automount) != {}} {
            foreach autoDir $itk_option(-automount) {
                # Use catch because we can't be sure exactly what strings
                # were passed into the -automount option
                catch {
                    if {[regsub ^/$autoDir $prefix {} prefix] != 0} {
                        break
                    }
                }
            }
        }
    }

    set curFilter $itk_option(-mask);
    $itk_component(filter) delete 0 end
    $itk_component(filter) insert 0 [file join $_pwd $itk_option(-mask)]

    #
    # Make sure the right most text is visable.
    #
    $itk_component(filter) xview moveto 1
}

# ------------------------------------------------------------------
# OPTION: -directory
#
# Specifies the initial default directory.
# ------------------------------------------------------------------
itcl::configbody iwidgets::Fileselectionbox::directory {
    if {$itk_option(-directory) != {}} {
        if {! [file exists $itk_option(-directory)]} {
            error "bad directory option \"$itk_option(-directory)\":\
                    directory does not exist"
        }

        set olddir [pwd]
        cd $itk_option(-directory)
        set _pwd [pwd]
        cd $olddir

        configure -mask $itk_option(-mask)
        _selectFilter
    }
}

# ------------------------------------------------------------------
# OPTION: -automount
#
# Specifies list of directory prefixes to ignore. Typically, this
# option would be used with values such as:
#   -automount {export tmp_mnt}
# ------------------------------------------------------------------
itcl::configbody iwidgets::Fileselectionbox::automount {
}

# ------------------------------------------------------------------
# OPTION: -nomatchstring
#
# Specifies the string to be displayed in the files list should
# not regular files exist in the directory.
# ------------------------------------------------------------------
itcl::configbody iwidgets::Fileselectionbox::nomatchstring {
}

# ------------------------------------------------------------------
# OPTION: -dirsearchcommand
#
# Specifies a command to be executed to perform a directory search.
# The command will receive the current working directory and filter
# mask as arguments.  The command should return a list of files which
# will be placed into the directory list.
# ------------------------------------------------------------------
itcl::configbody iwidgets::Fileselectionbox::dirsearchcommand {
}

# ------------------------------------------------------------------
# OPTION: -filesearchcommand
#
# Specifies a command to be executed to perform a file search.
# The command will receive the current working directory and filter
# mask as arguments.  The command should return a list of files which
# will be placed into the file list.
# ------------------------------------------------------------------
itcl::configbody iwidgets::Fileselectionbox::filesearchcommand {
}

# ------------------------------------------------------------------
# OPTION: -selectioncommand
#
# Specifies a command to be executed upon pressing return in the
# selection entry widget.
# ------------------------------------------------------------------
itcl::configbody iwidgets::Fileselectionbox::selectioncommand {
}

# ------------------------------------------------------------------
# OPTION: -filtercommand
#
# Specifies a command to be executed upon pressing return in the
# filter entry widget.
# ------------------------------------------------------------------
itcl::configbody iwidgets::Fileselectionbox::filtercommand {
}

# ------------------------------------------------------------------
# OPTION: -selectdircommand
#
# Specifies a command to be executed following selection of a
# directory in the directory list.
# ------------------------------------------------------------------
itcl::configbody iwidgets::Fileselectionbox::selectdircommand {
}

# ------------------------------------------------------------------
# OPTION: -selectfilecommand
#
# Specifies a command to be executed following selection of a
# file in the files list.
# ------------------------------------------------------------------
itcl::configbody iwidgets::Fileselectionbox::selectfilecommand {
}

# ------------------------------------------------------------------
# OPTION: -invalid
#
# Specify a command to executed should the filter contents be
# proven invalid.
# ------------------------------------------------------------------
itcl::configbody iwidgets::Fileselectionbox::invalid {
}

# ------------------------------------------------------------------
# OPTION: -filetype
#
# Specify the type of files which may appear in the file list.
# ------------------------------------------------------------------
itcl::configbody iwidgets::Fileselectionbox::filetype {
    switch $itk_option(-filetype) {
        regular -
        directory -
        any {
        }
        default {
            error "bad filetype option \"$itk_option(-filetype)\":\
                    should be regular, directory, or any"
        }
    }

    _updateLists
}

# ------------------------------------------------------------------
# OPTION: -width
#
# Specifies the width of the file selection box.  The value may be
# specified in any of the forms acceptable to Tk_GetPixels.
# ------------------------------------------------------------------
itcl::configbody iwidgets::Fileselectionbox::width {
    #
    # The width option was added to the hull in the constructor.
    # So, any width value given is passed automatically to the
    # hull.  All we have to do is play with the propagation.
    #
    if {$itk_option(-width) != 0} {
	set propagate 0
    } else {
	set propagate 1
    }

    #
    # Due to a bug in the tk4.2 grid, we have to check the 
    # propagation before setting it.  Setting it to the same
    # value it already is will cause it to toggle.
    #
    if {[grid propagate $itk_component(hull)] != $propagate} {
	grid propagate $itk_component(hull) $propagate
    }
}

# ------------------------------------------------------------------
# OPTION: -height
#
# Specifies the height of the file selection box.  The value may be
# specified in any of the forms acceptable to Tk_GetPixels.
# ------------------------------------------------------------------
itcl::configbody iwidgets::Fileselectionbox::height {
    #
    # The height option was added to the hull in the constructor.
    # So, any height value given is passed automatically to the
    # hull.  All we have to do is play with the propagation.
    #
    if {$itk_option(-height) != 0} {
	set propagate 0
    } else {
	set propagate 1
    }

    #
    # Due to a bug in the tk4.2 grid, we have to check the 
    # propagation before setting it.  Setting it to the same
    # value it already is will cause it to toggle.
    #
    if {[grid propagate $itk_component(hull)] != $propagate} {
	grid propagate $itk_component(hull) $propagate
    }
}

# ------------------------------------------------------------------
#                            METHODS
# ------------------------------------------------------------------

# ------------------------------------------------------------------
# METHOD: childsite
#
# Returns the path name of the child site widget.
# ------------------------------------------------------------------
itcl::body iwidgets::Fileselectionbox::childsite {} {
    return $itk_component(childsite)
}

# ------------------------------------------------------------------
# METHOD: get
#
# Returns the current selection.
# ------------------------------------------------------------------
itcl::body iwidgets::Fileselectionbox::get {} {
    return [$itk_component(selection) get]
}

# ------------------------------------------------------------------
# METHOD: filter
#
# The user has pressed Return in the filter.  Make sure the contents
# contain a valid directory before setting default to directory.
# Use the invalid option to warn the user of any problems.
# ------------------------------------------------------------------
itcl::body iwidgets::Fileselectionbox::filter {} {
    set newdir [file dirname [$itk_component(filter) get]]

    if {! [file exists $newdir]} {
	uplevel #0 "$itk_option(-invalid)"
	return
    }

    set _pwd $newdir;
    if {$_pwd == "."} {set _pwd [pwd]};

    _updateLists
}

# ------------------------------------------------------------------
# PRIVATE METHOD: _updateLists ?now?
#
# Updates the contents of both the file and directory lists, as well
# resets the positions of the filter, and lists.
# ------------------------------------------------------------------
itcl::body iwidgets::Fileselectionbox::_updateLists {{when "later"}} {
    switch -- $when {
        later {
            if {$_updateToken == ""} {
                set _updateToken [after idle [itcl::code $this _updateLists now]]
            }
        }
        now {
            if {$itk_option(-dirson)} {_setDirList}
            if {$itk_option(-fileson)} {_setFileList}

            if {$itk_option(-filteron)} {
              _setFilter
            }
            if {$itk_option(-selectionon)} {
                $itk_component(selection) icursor end
            }
            if {$itk_option(-dirson)} {
                $itk_component(dirs) justify left
            }
            if {$itk_option(-fileson)} {
                $itk_component(files) justify left
            }
            set _updateToken ""
        }
        default {
            error "bad option \"$when\": should be later or now"
        }
    }
}

# ------------------------------------------------------------------
# PRIVATE METHOD: _setFilter
#
# Set the filter to the current selection in the directory list plus
# any existing mask in the filter.  Translate the two special cases
# of '.', and '..' directory names to full path names..
# ------------------------------------------------------------------
itcl::body iwidgets::Fileselectionbox::_setFilter {} {
    global tcl_platform
    set prefix [$itk_component(dirs) getcurselection]
    set curFilter [file tail [$itk_component(filter) get]]

    while {[regexp {\.$} $prefix]} {
	if {[file tail $prefix] == "."} {
	    if {$prefix == "."} {
		if {$_pwd == "."} {
		    set _pwd [pwd]
		} elseif {$_pwd == ".."} {
		    set _pwd [file dirname [pwd]]
		}
		set prefix $_pwd
	    } else {
		set prefix [file dirname $prefix]
	    }
	} elseif {[file tail $prefix] == ".."} {
	    if {$prefix != ".."} {
		set prefix [file dirname [file dirname $prefix]]
	    } else {
		if {$_pwd == "."} {
		    set _pwd [pwd]
		} elseif {$_pwd == ".."} {
		    set _pwd [file dirname [pwd]]
		}
		set prefix [file dirname $_pwd]
	    }
	} else {
	    break
	}
    }

    if { [file pathtype $prefix] != "absolute" } {
        set prefix [file join $_pwd $prefix]
    }

    #
    # Remove automounter paths.
    #
    if {$tcl_platform(platform) == "unix"} {
        if {$itk_option(-automount) != {}} {
            foreach autoDir $itk_option(-automount) {
                # Use catch because we can't be sure exactly what strings
                # were passed into the -automount option
                catch {
                    if {[regsub ^/$autoDir $prefix {} prefix] != 0} {
                        break
                    }
                }
            }
        }
    }

    $itk_component(filter) delete 0 end
    $itk_component(filter) insert 0 [file join $prefix $curFilter]

    #
    # Make sure insertion cursor is at the end.
    #
    $itk_component(filter) icursor end

    #
    # Make sure the right most text is visable.
    #
    $itk_component(filter) xview moveto 1
}

# ------------------------------------------------------------------
# PRIVATE METHOD: _setSelection
#
# Set the contents of the selection entry to either the current
# selection of the file or directory list dependent on which lists
# are currently mapped.  For the file list, avoid seleciton of the
# no match string.  As for the directory list, translate file names.
# ------------------------------------------------------------------
itcl::body iwidgets::Fileselectionbox::_setSelection {} {
    global tcl_platform
    $itk_component(selection) delete 0 end

    if {$itk_option(-fileson)} {
        set selection [$itk_component(files) getcurselection]

        if {$selection != $itk_option(-nomatchstring)} {
	    if {[file pathtype $selection] != "absolute"} {
		set selection [file join $_pwd $selection]
	    }

	    #
	    # Remove automounter paths.
	    #
        if {$tcl_platform(platform) == "unix"} {
            if {$itk_option(-automount) != {}} {
                foreach autoDir $itk_option(-automount) {
                    # Use catch because we can't be sure exactly what strings
                    # were passed into the -automount option
                    catch {
                        if {[regsub ^/$autoDir $selection {} selection] != 0} {
                            break
                        }
                    }
                }
            }
        }

	    $itk_component(selection) insert 0 $selection
        } else {
	    $itk_component(files) selection clear 0 end
	}

    } else {
        set selection [$itk_component(dirs) getcurselection]

	if {[file tail $selection] == "."} {
	    if {$selection != "."} {
		set selection [file dirname $selection]
	    } else {
		set selection $_pwd
	    }
	} elseif {[file tail $selection] == ".."} {
	    if {$selection != ".."} {
		set selection [file dirname [file dirname $selection]]
	    } else {
		set selection [file join $_pwd ..]
	    }
	} else {
	    set selection [file join $_pwd $selection]
	}

	#
    # Remove automounter paths.
	#
    if {$tcl_platform(platform) == "unix"} {
        if {$itk_option(-automount) != {}} {
            foreach autoDir $itk_option(-automount) {
                # Use catch because we can't be sure exactly what strings
                # were passed into the -automount option
                catch {
                    if {[regsub ^/$autoDir $selection {} selection] != 0} {
                        break
                    }
                }
            }
        }
    }

	$itk_component(selection) delete 0 end
        $itk_component(selection) insert 0 $selection
    }

    $itk_component(selection) icursor end

    #
    # Make sure the right most text is visable.
    #
    $itk_component(selection) xview moveto 1
}

# ------------------------------------------------------------------
# PRIVATE METHOD: _setDirList
#
# Clear the directory list and dependent on whether the user has
# defined their own search procedure or not fill the list with their
# results or those of a glob.  Select the first element if it exists.
# ------------------------------------------------------------------
itcl::body iwidgets::Fileselectionbox::_setDirList {} {
    $itk_component(dirs) clear

    if {$itk_option(-dirsearchcommand) == {}} {
        foreach i [lsort [glob -nocomplain \
			      [file join $_pwd .*] [file join $_pwd *]]] {
            if {[file isdirectory $i]} {
		$itk_component(dirs) insert end [file tail "$i"]
            }
        }

    } else {
        set mask [file tail [$itk_component(filter) get]]

        foreach file [uplevel #0 $itk_option(-dirsearchcommand) $_pwd $mask] {
            $itk_component(dirs) insert end $file
        }
    }

    if {[$itk_component(dirs) size]} {
        $itk_component(dirs) selection clear 0 end
        $itk_component(dirs) selection set 0
    }
}

# ------------------------------------------------------------------
# PRIVATE METHOD: _setFileList
#
# Clear the file list and dependent on whether the user has defined
# their own search procedure or not fill the list with their results
# or those of a 'glob'.  If the files list has no contents, then set
# the files list to the 'nomatchstring'.  Clear all selections.
# ------------------------------------------------------------------
itcl::body iwidgets::Fileselectionbox::_setFileList {} {
    $itk_component(files) clear
    set mask [file tail [$itk_component(filter) get]]

    if {$itk_option(-filesearchcommand) == {}} {
	if {$mask == "*"} {
	    set files [lsort [glob -nocomplain \
				  [file join $_pwd .*] [file join $_pwd *]]]
	} else {
	    set files [lsort [glob -nocomplain [file join $_pwd $mask]]]
	}

        foreach i $files {
            if {($itk_option(-filetype) == "regular" && \
		    ! [file isdirectory $i]) || \
		    ($itk_option(-filetype) == "directory" && \
		    [file isdirectory $i]) || \
		    ($itk_option(-filetype) == "any")} {
		$itk_component(files) insert end [file tail "$i"]
            }
        }

    } else {
        foreach file [uplevel #0 $itk_option(-filesearchcommand) $_pwd $mask] {
            $itk_component(files) insert end $file
        }
    }

    if {[$itk_component(files) size] == 0} {
	if {$itk_option(-nomatchstring) != {}} {
	    $itk_component(files) insert end $itk_option(-nomatchstring)
	}
    }

    $itk_component(files) selection clear 0 end
}

# ------------------------------------------------------------------
# PRIVATE METHOD: _selectDir
#
# For a selection in the directory list, set the filter and possibly
# the selection entry based on the fileson option.
# ------------------------------------------------------------------
itcl::body iwidgets::Fileselectionbox::_selectDir {} {
    _setFilter

    if {$itk_option(-fileson)} {} {
        _setSelection
    }

    if {$itk_option(-selectdircommand) != {}} {
        uplevel #0 $itk_option(-selectdircommand)
    }
}

# ------------------------------------------------------------------
# PRIVATE METHOD: _dblSelectDir
#
# For a double click event in the directory list, select the
# directory, set the default to the selection, and update both the
# file and directory lists.
# ------------------------------------------------------------------
itcl::body iwidgets::Fileselectionbox::_dblSelectDir {} {
    filter
}

# ------------------------------------------------------------------
# PRIVATE METHOD: _selectFile
#
# The user has selected a file.  Put the current selection in the
# file list in the selection entry widget.
# ------------------------------------------------------------------
itcl::body iwidgets::Fileselectionbox::_selectFile {} {
    _setSelection

    if {$itk_option(-selectfilecommand) != {}} {
        uplevel #0 $itk_option(-selectfilecommand)
    }
}

# ------------------------------------------------------------------
# PRIVATE METHOD: _selectSelection
#
# The user has pressed Return in the selection entry widget.  Call
# the defined selection command if it exists.
# ------------------------------------------------------------------
itcl::body iwidgets::Fileselectionbox::_selectSelection {} {
    if {$itk_option(-selectioncommand) != {}} {
        uplevel #0 $itk_option(-selectioncommand)
    }
}

# ------------------------------------------------------------------
# PRIVATE METHOD: _selectFilter
#
# The user has pressed Return in the filter entry widget.  Call the
# defined selection command if it exists, otherwise just filter.
# ------------------------------------------------------------------
itcl::body iwidgets::Fileselectionbox::_selectFilter {} {
    if {$itk_option(-filtercommand) != {}} {
        uplevel #0 $itk_option(-filtercommand)
    } else {
        filter
    }
}

# ------------------------------------------------------------------
# PRIVATE METHOD: _packComponents
#
# Pack the selection, items, and child site widgets based on options.
# Using the -in option of pack, put the childsite around the frame
# in the hull for n, s, e, and w positions.  Make sure and raise 
# the child site since using the 'in' option may obscure the site.
# ------------------------------------------------------------------
itcl::body iwidgets::Fileselectionbox::_packComponents {{when "later"}} {
    if {$when == "later"} {
        if {$_packToken == ""} {
            set _packToken [after idle [itcl::code $this _packComponents now]]
        }
        return
    } elseif {$when != "now"} {
        error "bad option \"$when\": should be now or later"
    }

    set _packToken ""

    #
    # Forget about any previous placements via the grid and
    # reset all the possible minsizes and weights for all
    # the rows and columns.
    #
    foreach component {childsite filter dirs files selection} {
	grid forget $itk_component($component)
    }

    for {set row 0} {$row < 6} {incr row} {
	grid rowconfigure $_interior $row -minsize 0 -weight 0
    }

    for {set col 0} {$col < 4} {incr col} {
	grid columnconfigure $_interior $col -minsize 0 -weight 0
    }

    #
    # Place all the components based on the childsite poisition
    # option.
    #
    switch $itk_option(-childsitepos) {
        n { _nPos }

        w { _wPos }

        s { _sPos }

        e { _ePos }

	center { _centerPos }

	top { _topPos }

	bottom { _bottomPos }

        default {
            error "bad childsitepos option \"$itk_option(-childsitepos)\":\
                    should be n, e, s, w, center, top, or bottom"
        }
    }
}

# ------------------------------------------------------------------
# PRIVATE METHOD: _nPos
#
# Position the childsite to the north and all the other components
# appropriately based on the individual "on" options.
# ------------------------------------------------------------------
itcl::body iwidgets::Fileselectionbox::_nPos {} {
    grid $itk_component(childsite) -row 0 -column 0 \
	-columnspan 3 -rowspan 1 -sticky nsew

    if {$itk_option(-filteron)} {
	grid $itk_component(filter) -row 1 -column 0 \
	    -columnspan 3 -sticky ew
	grid rowconfigure $_interior 2 -minsize 7
    }

    if {$itk_option(-dirson)} {
	grid $itk_component(dirs) -row 3 -column 0 \
	    -columnspan 1 -sticky nsew
    } 
    if {$itk_option(-fileson)} {
	grid $itk_component(files) -row 3 -column 2 \
	    -columnspan 1 -sticky nsew
    } 
    if {$itk_option(-dirson)} {
	if {$itk_option(-fileson)} {
	    grid columnconfigure $_interior 1 -minsize 7
	} else {
	    grid configure $itk_component(dirs) -columnspan 3 -column 0
	}
    } else {
	if {$itk_option(-fileson)} {
	    grid configure $itk_component(files) -columnspan 3 -column 0
	}
    }

    grid rowconfigure $_interior 3 -weight 1

    if {$itk_option(-selectionon)} {
	grid rowconfigure $_interior 4 -minsize 7
	grid $itk_component(selection) -row 5 -column 0 \
	    -columnspan 3 -sticky ew
    }

    grid columnconfigure $_interior 0 -weight 1
    grid columnconfigure $_interior 2 -weight 1
}

# ------------------------------------------------------------------
# PRIVATE METHOD: _sPos
#
# Position the childsite to the south and all the other components
# appropriately based on the individual "on" options.
# ------------------------------------------------------------------
itcl::body iwidgets::Fileselectionbox::_sPos {} {
    if {$itk_option(-filteron)} {
	grid $itk_component(filter) -row 0 -column 0 \
	    -columnspan 3 -sticky ew
	grid rowconfigure $_interior 1 -minsize 7
    }

    if {$itk_option(-dirson)} {
	grid $itk_component(dirs) -row 2 -column 0 \
	    -columnspan 1 -sticky nsew
    }
    if {$itk_option(-fileson)} {
	grid $itk_component(files) -row 2 -column 2 \
	    -columnspan 1 -sticky nsew
    }
    if {$itk_option(-dirson)} {
	if {$itk_option(-fileson)} {
	    grid columnconfigure $_interior 1 -minsize 7
	} else {
	    grid configure $itk_component(dirs) -columnspan 3 -column 0
	}
    } else {
	if {$itk_option(-fileson)} {
	    grid configure $itk_component(files) -columnspan 3 -column 0
	}
    }
    
    grid rowconfigure $_interior 2 -weight 1

    if {$itk_option(-selectionon)} {
	grid rowconfigure $_interior 3 -minsize 7
	grid $itk_component(selection) -row 4 -column 0 \
	    -columnspan 3 -sticky ew
    }
    
    grid $itk_component(childsite) -row 5 -column 0 \
	-columnspan 3 -rowspan 1 -sticky nsew
    grid columnconfigure $_interior 0 -weight 1
    grid columnconfigure $_interior 2 -weight 1
}

# ------------------------------------------------------------------
# PRIVATE METHOD: _ePos
#
# Position the childsite to the east and all the other components
# appropriately based on the individual "on" options.
# ------------------------------------------------------------------
itcl::body iwidgets::Fileselectionbox::_ePos {} {
    if {$itk_option(-filteron)} {
	grid $itk_component(filter) -row 0 -column 0 \
	    -columnspan 3 -sticky ew
	grid rowconfigure $_interior 1 -minsize 7
    }

    if {$itk_option(-dirson)} {
	grid $itk_component(dirs) -row 2 -column 0 \
	    -columnspan 1 -sticky nsew
    }
    if {$itk_option(-fileson)} {
	grid $itk_component(files) -row 2 -column 2 \
	    -columnspan 1 -sticky nsew
    }
    if {$itk_option(-dirson)} {
	if {$itk_option(-fileson)} {
	    grid columnconfigure $_interior 1 -minsize 7
	} else {
	    grid configure $itk_component(dirs) -columnspan 3 -column 0
	}
    } else {
	if {$itk_option(-fileson)} {
	    grid configure $itk_component(files) -columnspan 3 -column 0
	}
    }

    grid rowconfigure $_interior 2 -weight 1

    if {$itk_option(-selectionon)} {
	grid rowconfigure $_interior 3 -minsize 7
	grid $itk_component(selection) -row 4 -column 0 \
	    -columnspan 3 -sticky ew
    }

    grid $itk_component(childsite) -row 0 -column 3 \
	-rowspan 5 -columnspan 1 -sticky nsew
    grid columnconfigure $_interior 0 -weight 1
    grid columnconfigure $_interior 2 -weight 1
}

# ------------------------------------------------------------------
# PRIVATE METHOD: _wPos
#
# Position the childsite to the west and all the other components
# appropriately based on the individual "on" options.
# ------------------------------------------------------------------
itcl::body iwidgets::Fileselectionbox::_wPos {} {
    grid $itk_component(childsite) -row 0 -column 0 \
	-rowspan 5 -columnspan 1 -sticky nsew

    if {$itk_option(-filteron)} {
	grid $itk_component(filter) -row 0 -column 1 \
	    -columnspan 3 -sticky ew
	grid rowconfigure $_interior 1 -minsize 7
    } 

    if {$itk_option(-dirson)} {
	grid $itk_component(dirs) -row 2 -column 1 \
	    -columnspan 1 -sticky nsew
    }
    if {$itk_option(-fileson)} {
	grid $itk_component(files) -row 2 -column 3 \
	    -columnspan 1 -sticky nsew
    }
    if {$itk_option(-dirson)} {
	if {$itk_option(-fileson)} {
	    grid columnconfigure $_interior 2 -minsize 7
	} else {
	    grid configure $itk_component(dirs) -columnspan 3 -column 1
	}
    } else {
	if {$itk_option(-fileson)} {
	    grid configure $itk_component(files) -columnspan 3 -column 1
	}
    }

    grid rowconfigure $_interior 2 -weight 1

    if {$itk_option(-selectionon)} {
	grid rowconfigure $_interior 3 -minsize 7
	grid $itk_component(selection) -row 4 -column 1 \
	    -columnspan 3 -sticky ew
    }

    grid columnconfigure $_interior 1 -weight 1
    grid columnconfigure $_interior 3 -weight 1
}

# ------------------------------------------------------------------
# PRIVATE METHOD: _topPos
#
# Position the childsite below the filter but above the lists and 
# all the other components appropriately based on the individual 
# "on" options.
# ------------------------------------------------------------------
itcl::body iwidgets::Fileselectionbox::_topPos {} {
    if {$itk_option(-filteron)} {
	grid $itk_component(filter) -row 0 -column 0 \
	    -columnspan 3 -sticky ew
    }

    grid $itk_component(childsite) -row 1 -column 0 \
	-columnspan 3 -rowspan 1 -sticky nsew

    if {$itk_option(-dirson)} {
	grid $itk_component(dirs) -row 2 -column 0 -sticky nsew
    }
    if {$itk_option(-fileson)} {
	grid $itk_component(files) -row 2 -column 2 -sticky nsew
    }
    if {$itk_option(-dirson)} {
	if {$itk_option(-fileson)} {
	    grid columnconfigure $_interior 1 -minsize 7
	} else {
	    grid configure $itk_component(dirs) -columnspan 3 -column 0
	}
    } else {
	if {$itk_option(-fileson)} {
	    grid configure $itk_component(files) -columnspan 3 -column 0
	}
    }

    grid rowconfigure $_interior 2 -weight 1

    if {$itk_option(-selectionon)} {
	grid rowconfigure $_interior 3 -minsize 7
	grid $itk_component(selection) -row 4 -column 0 \
	    -columnspan 3 -sticky ew
    }

    grid columnconfigure $_interior 0 -weight 1
    grid columnconfigure $_interior 2 -weight 1
}

# ------------------------------------------------------------------
# PRIVATE METHOD: _centerPos
#
# Position the childsite between the lists and all the other 
# components appropriately based on the individual "on" options.
# ------------------------------------------------------------------
itcl::body iwidgets::Fileselectionbox::_centerPos {} {
    if {$itk_option(-filteron)} {
	grid $itk_component(filter) -row 0 -column 0 \
	    -columnspan 3 -sticky ew
	grid rowconfigure $_interior 1 -minsize 7
    }

    if {$itk_option(-dirson)} {
	grid $itk_component(dirs) -row 2 -column 0 \
	    -columnspan 1 -sticky nsew
    }
    if {$itk_option(-fileson)} {
	grid $itk_component(files) -row 2 -column 2 \
	    -columnspan 1 -sticky nsew
    }
    grid $itk_component(childsite) -row 2 \
	-columnspan 1 -rowspan 1 -sticky nsew

    if {$itk_option(-dirson)} {
	if {$itk_option(-fileson)} {
	    grid configure $itk_component(childsite) -column 1
	    grid columnconfigure $_interior 0 -weight 1
	    grid columnconfigure $_interior 2 -weight 1

	} else {
	    grid configure $itk_component(dirs) -columnspan 2 -column 0
	    grid configure $itk_component(childsite) -column 2
	    grid columnconfigure $_interior 0 -weight 1
	    grid columnconfigure $_interior 1 -weight 1
	}
    } else {
	grid configure $itk_component(childsite) -column 0
	if {$itk_option(-fileson)} {
	    grid configure $itk_component(files) -columnspan 2 \
		-column 1
	    grid columnconfigure $_interior 1 -weight 1
	    grid columnconfigure $_interior 2 -weight 1
	} else {
	    grid columnconfigure $_interior 0 -weight 1
	}
    }

    grid rowconfigure $_interior 2 -weight 1

    if {$itk_option(-selectionon)} {
	grid rowconfigure $_interior 3 -minsize 7
	grid $itk_component(selection) -row 4 -column 0 \
	    -columnspan 3 -sticky ew
    }
}

# ------------------------------------------------------------------
# PRIVATE METHOD: _bottomPos
#
# Position the childsite below the lists and above the selection
# and all the other components appropriately based on the individual 
# "on" options.
# ------------------------------------------------------------------
itcl::body iwidgets::Fileselectionbox::_bottomPos {} {
    if {$itk_option(-filteron)} {
	grid $itk_component(filter) -row 0 -column 0 \
	    -columnspan 3 -sticky ew
	grid rowconfigure $_interior 1 -minsize 7
    }

    if {$itk_option(-dirson)} {
	grid $itk_component(dirs) -row 2 -column 0 -sticky nsew
    }
    if {$itk_option(-fileson)} {
	grid $itk_component(files) -row 2 -column 2 -sticky nsew
    }
    if {$itk_option(-dirson)} {
	if {$itk_option(-fileson)} {
	    grid columnconfigure $_interior 1 -minsize 7
	} else {
	    grid configure $itk_component(dirs) -columnspan 3 -column 0
	}
    } else {
	if {$itk_option(-fileson)} {
	    grid configure $itk_component(files) -columnspan 3 -column 0
	}
    }
    grid rowconfigure $_interior 2 -weight 1

    grid $itk_component(childsite) -row 3 -column 0 \
	-columnspan 3 -rowspan 1 -sticky nsew

    if {$itk_option(-selectionon)} {
	grid $itk_component(selection) -row 4 -column 0 \
	    -columnspan 3 -sticky ew
    }

    grid columnconfigure $_interior 0 -weight 1
    grid columnconfigure $_interior 2 -weight 1
}