home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / tcl / xf2.3-p / xf2 / xf2.3 / src / xffsBox.tcl < prev    next >
Encoding:
Text File  |  1994-05-22  |  32.0 KB  |  975 lines

  1. # XFNoParsing
  2. # Program: template
  3. # Description: file selector box
  4. #
  5. # $Header: xffsBox.tcl[2.3] Wed Mar 10 12:05:54 1993 garfield@garfield frozen $
  6.  
  7. global xfFSBox
  8. set xfFSBox(activeBackground) ""
  9. set xfFSBox(activeForeground) ""
  10. set xfFSBox(background) ""
  11. set xfFSBox(font) ""
  12. set xfFSBox(foreground) ""
  13. set xfFSBox(scrollActiveForeground) ""
  14. set xfFSBox(scrollBackground) ""
  15. set xfFSBox(scrollForeground) ""
  16. set xfFSBox(showPixmap) 0
  17. set xfFSBox(name) ""
  18. set xfFSBox(path) [pwd]
  19. set xfFSBox(pattern) *
  20. set xfFSBox(all) 0
  21. set xfFSBox(button) 0
  22. set xfFSBox(extensions) 0
  23. set xfFSBox(internalPath) [pwd]
  24.  
  25. proc XFFSBox {{xfFSBoxMessage "Select file:"} {xfFSBoxFileName ""} {xfFSBoxActionOk ""} {xfFSBoxActionCancel ""}} {# xf ignore me 5
  26. ##########
  27. # Procedure: XFFSBox
  28. # Description: show file selector box
  29. # Arguments: xfFSBoxMessage - the text to display
  30. #            xfFSBoxFileName - a file name that should be selected
  31. #            xfFSBoxActionOk - the action that should be performed on ok
  32. #            xfFSBoxActionCancel - the action that should be performed on cancel
  33. # Returns: the filename that was selected, or nothing
  34. # Sideeffects: none
  35. ##########
  36. # global xfFSBox(activeBackground) - active background color
  37. # global xfFSBox(activeForeground) - active foreground color
  38. # global xfFSBox(background) - background color
  39. # global xfFSBox(font) - text font
  40. # global xfFSBox(foreground) - foreground color
  41. # global xfFSBox(extensions) - scan directory for extensions
  42. # global xfFSBox(scrollActiveForeground) - scrollbar active background color
  43. # global xfFSBox(scrollBackground) - scrollbar background color
  44. # global xfFSBox(scrollForeground) - scrollbar foreground color
  45. # global xfFSBox(scrollSide) - side where scrollbar is located
  46.  
  47.   global xfFSBox
  48.  
  49.   set tmpButtonOpt ""
  50.   set tmpFrameOpt ""
  51.   set tmpMessageOpt ""
  52.   set tmpScaleOpt ""
  53.   set tmpScrollOpt ""
  54.   if {"$xfFSBox(activeBackground)" != ""} {
  55.     append tmpButtonOpt "-activebackground \"$xfFSBox(activeBackground)\" "
  56.   }
  57.   if {"$xfFSBox(activeForeground)" != ""} {
  58.     append tmpButtonOpt "-activeforeground \"$xfFSBox(activeForeground)\" "
  59.   }
  60.   if {"$xfFSBox(background)" != ""} {
  61.     append tmpButtonOpt "-background \"$xfFSBox(background)\" "
  62.     append tmpFrameOpt "-background \"$xfFSBox(background)\" "
  63.     append tmpMessageOpt "-background \"$xfFSBox(background)\" "
  64.   }
  65.   if {"$xfFSBox(font)" != ""} {
  66.     append tmpButtonOpt "-font \"$xfFSBox(font)\" "
  67.     append tmpMessageOpt "-font \"$xfFSBox(font)\" "
  68.   }
  69.   if {"$xfFSBox(foreground)" != ""} {
  70.     append tmpButtonOpt "-foreground \"$xfFSBox(foreground)\" "
  71.     append tmpMessageOpt "-foreground \"$xfFSBox(foreground)\" "
  72.   }
  73.   if {"$xfFSBox(scrollActiveForeground)" != ""} {
  74.     append tmpScrollOpt "-activeforeground \"$xfFSBox(scrollActiveForeground)\" "
  75.   }
  76.   if {"$xfFSBox(scrollBackground)" != ""} {
  77.     append tmpScrollOpt "-background \"$xfFSBox(scrollBackground)\" "
  78.   }
  79.   if {"$xfFSBox(scrollForeground)" != ""} {
  80.     append tmpScrollOpt "-foreground \"$xfFSBox(scrollForeground)\" "
  81.   }
  82.  
  83.   if {[file exists [file tail $xfFSBoxFileName]] &&
  84.       [XFIsAFile [file tail $xfFSBoxFileName]]} {
  85.     set xfFSBox(name) [file tail $xfFSBoxFileName]
  86.   } {
  87.     set xfFSBox(name) ""
  88.   }
  89.   if {[file exists $xfFSBoxFileName] && [XFIsADir $xfFSBoxFileName]} {
  90.     set xfFSBox(path) $xfFSBoxFileName
  91.   } {
  92.     if {"[file dirname $xfFSBoxFileName]" != "."} {
  93.       set xfFSBox(path) [file dirname $xfFSBoxFileName]
  94.     }
  95.   }
  96.   if {$xfFSBox(showPixmap)} {
  97.     set xfFSBox(path) [string trimleft $xfFSBox(path) @]
  98.   }
  99.   if {"$xfFSBox(path)" != "" && [file exists $xfFSBox(path)] &&
  100.       [XFIsADir $xfFSBox(path)]} {
  101.     set xfFSBox(internalPath) $xfFSBox(path)
  102.   } {
  103.     if {"$xfFSBox(internalPath)" == "" ||
  104.         ![file exists $xfFSBox(internalPath)]} {
  105.       set xfFSBox(internalPath) [pwd]
  106.     }
  107.   }
  108.   # build widget structure
  109.  
  110.   XFTmpltToplevel .xfFSBox 350x300 {XF file select}
  111.  
  112.   label .xfFSBox.message1 \
  113.     -anchor c \
  114.     -relief raised \
  115.     -text "$xfFSBoxMessage"
  116.   catch ".xfFSBox.message1 config $tmpMessageOpt"
  117.  
  118.   frame .xfFSBox.frame1 \
  119.     -borderwidth 0 \
  120.     -relief raised
  121.   catch ".xfFSBox.frame1 config $tmpFrameOpt"
  122.  
  123.   button .xfFSBox.frame1.ok \
  124.     -text "OK" \
  125.     -command "
  126.       global xfFSBox
  127.       set xfFSBox(name) \[.xfFSBox.file.file get\]
  128.       if {$xfFSBox(showPixmap)} {
  129.         set xfFSBox(path) @\[.xfFSBox.path.path get\]
  130.       } {
  131.         set xfFSBox(path) \[.xfFSBox.path.path get\]
  132.       }
  133.       set xfFSBox(internalPath) \[.xfFSBox.path.path get\]
  134.       $xfFSBoxActionOk
  135.       if {\"\[info commands XFDestroy\]\" != \"\"} {
  136.         catch {XFDestroy .xfFSBox}
  137.       } {
  138.         catch {destroy .xfFSBox}
  139.       }"
  140.   catch ".xfFSBox.frame1.ok config $tmpButtonOpt"
  141.  
  142.   button .xfFSBox.frame1.rescan \
  143.     -text "Rescan" \
  144.     -command {
  145.       global xfFSBox
  146.       XFFSBoxFSShow [.xfFSBox.path.path get] \
  147.         [.xfFSBox.pattern.pattern get] $xfFSBox(all)}
  148.   catch ".xfFSBox.frame1.rescan config $tmpButtonOpt"
  149.  
  150.   button .xfFSBox.frame1.cancel \
  151.     -text "Cancel" \
  152.     -command "
  153.       global xfFSBox
  154.       set xfFSBox(name) {}
  155.       set xfFSBox(path) {}
  156.       $xfFSBoxActionCancel
  157.       if {\"\[info commands XFDestroy\]\" != \"\"} {
  158.         catch {XFDestroy .xfFSBox}
  159.       } {
  160.         catch {destroy .xfFSBox}
  161.       }"
  162.   catch ".xfFSBox.frame1.cancel config $tmpButtonOpt"
  163.  
  164.   if {$xfFSBox(showPixmap)} {
  165.     frame .xfFSBox.frame2 \
  166.       -borderwidth 0 \
  167.       -relief raised
  168.     catch ".xfFSBox.frame2 config $tmpFrameOpt"
  169.  
  170.     scrollbar .xfFSBox.frame2.scrollbar3 \
  171.       -command {.xfFSBox.frame2.canvas2 xview} \
  172.       -orient {horizontal} \
  173.       -relief {raised}
  174.     catch ".xfFSBox.frame2.scrollbar3 config $tmpScrollOpt"
  175.  
  176.     scrollbar .xfFSBox.frame2.scrollbar1 \
  177.       -command {.xfFSBox.frame2.canvas2 yview} \
  178.       -relief {raised}
  179.     catch ".xfFSBox.frame2.scrollbar1 config $tmpScrollOpt"
  180.  
  181.     canvas .xfFSBox.frame2.canvas2 \
  182.       -confine {true} \
  183.       -relief {raised} \
  184.       -scrollregion {0c 0c 20c 20c} \
  185.       -width {100} \
  186.       -xscrollcommand {.xfFSBox.frame2.scrollbar3 set} \
  187.       -yscrollcommand {.xfFSBox.frame2.scrollbar1 set}
  188.     catch ".xfFSBox.frame2.canvas2 config $tmpFrameOpt"
  189.  
  190.     .xfFSBox.frame2.canvas2 addtag currentBitmap withtag [.xfFSBox.frame2.canvas2 create bitmap 5 5 -anchor nw]
  191.   }
  192.  
  193.   frame .xfFSBox.path \
  194.     -borderwidth 0 \
  195.     -relief raised
  196.   catch ".xfFSBox.path config $tmpFrameOpt"
  197.  
  198.   frame .xfFSBox.path.paths \
  199.     -borderwidth 2 \
  200.     -relief raised
  201.   catch ".xfFSBox.path.paths config $tmpFrameOpt"
  202.  
  203.   menubutton .xfFSBox.path.paths.paths \
  204.     -borderwidth 0 \
  205.     -menu ".xfFSBox.path.paths.paths.menu" \
  206.     -relief flat \
  207.     -text "Pathname:"
  208.   catch ".xfFSBox.path.paths.paths config $tmpButtonOpt"
  209.  
  210.   menu .xfFSBox.path.paths.paths.menu
  211.   catch ".xfFSBox.path.paths.paths.menu config $tmpButtonOpt"
  212.  
  213.   .xfFSBox.path.paths.paths.menu add command \
  214.      -label "[string trimright $xfFSBox(internalPath) {/@}]" \
  215.      -command "
  216.        global xfFSBox
  217.        XFFSBoxFSShow \[.xfFSBox.path.path get\] \
  218.          \[.xfFSBox.pattern.pattern get\] \$xfFSBox(all)
  219.        .xfFSBox.path.path delete 0 end
  220.        .xfFSBox.path.path insert 0 [string trimright $xfFSBox(internalPath) {/@}]"
  221.  
  222.   entry .xfFSBox.path.path \
  223.     -relief raised
  224.   catch ".xfFSBox.path.path config $tmpMessageOpt"
  225.  
  226.   if {![XFIsADir $xfFSBox(internalPath)]} {
  227.     set $xfFSBox(internalPath) [pwd]
  228.   }
  229.   .xfFSBox.path.path insert 0 $xfFSBox(internalPath)
  230.  
  231.   frame .xfFSBox.pattern \
  232.     -borderwidth 0 \
  233.     -relief raised
  234.   catch ".xfFSBox.pattern config $tmpFrameOpt"
  235.  
  236.   frame .xfFSBox.pattern.patterns \
  237.     -borderwidth 2 \
  238.     -relief raised
  239.   catch ".xfFSBox.pattern.patterns config $tmpFrameOpt"
  240.  
  241.   menubutton .xfFSBox.pattern.patterns.patterns \
  242.     -borderwidth 0 \
  243.     -menu ".xfFSBox.pattern.patterns.patterns.menu" \
  244.     -relief flat \
  245.     -text "Selection pattern:"
  246.   catch ".xfFSBox.pattern.patterns.patterns config $tmpButtonOpt"
  247.  
  248.   menu .xfFSBox.pattern.patterns.patterns.menu
  249.   catch ".xfFSBox.pattern.patterns.patterns.menu config $tmpButtonOpt"
  250.  
  251.   .xfFSBox.pattern.patterns.patterns.menu add checkbutton \
  252.     -label "Scan extensions" \
  253.     -variable xfFSBox(extensions) \
  254.     -command {
  255.       global xfFSBox
  256.       XFFSBoxFSShow [.xfFSBox.path.path get] \
  257.         [.xfFSBox.pattern.pattern get] $xfFSBox(all)}
  258.  
  259.   entry .xfFSBox.pattern.pattern \
  260.     -relief raised
  261.   catch ".xfFSBox.pattern.pattern config $tmpMessageOpt"
  262.  
  263.   .xfFSBox.pattern.pattern insert 0 $xfFSBox(pattern)
  264.   
  265.   frame .xfFSBox.files \
  266.     -borderwidth 0 \
  267.     -relief raised
  268.   catch ".xfFSBox.files config $tmpFrameOpt"
  269.  
  270.   scrollbar .xfFSBox.files.vscroll \
  271.     -relief raised \
  272.     -command ".xfFSBox.files.files yview"
  273.   catch ".xfFSBox.files.vscroll config $tmpScrollOpt"
  274.  
  275.   scrollbar .xfFSBox.files.hscroll \
  276.     -orient horiz \
  277.     -relief raised \
  278.     -command ".xfFSBox.files.files xview"
  279.   catch ".xfFSBox.files.hscroll config $tmpScrollOpt"
  280.  
  281.   listbox .xfFSBox.files.files \
  282.     -exportselection false \
  283.     -relief raised \
  284.     -xscrollcommand ".xfFSBox.files.hscroll set" \
  285.     -yscrollcommand ".xfFSBox.files.vscroll set"
  286.   catch ".xfFSBox.files.files config $tmpMessageOpt"
  287.  
  288.   frame .xfFSBox.file \
  289.     -borderwidth 0 \
  290.     -relief raised
  291.   catch ".xfFSBox.file config $tmpFrameOpt"
  292.  
  293.   label .xfFSBox.file.labelfile \
  294.     -relief raised \
  295.     -text "Filename:"
  296.   catch ".xfFSBox.file.labelfile config $tmpMessageOpt"
  297.  
  298.   entry .xfFSBox.file.file \
  299.     -relief raised
  300.   catch ".xfFSBox.file.file config $tmpMessageOpt"
  301.  
  302.   .xfFSBox.file.file delete 0 end
  303.   .xfFSBox.file.file insert 0 $xfFSBox(name)
  304.   
  305.   checkbutton .xfFSBox.pattern.all \
  306.     -offvalue 0 \
  307.     -onvalue 1 \
  308.     -text "Show all files" \
  309.     -variable xfFSBox(all) \
  310.     -command {
  311.       global xfFSBox
  312.       XFFSBoxFSShow [.xfFSBox.path.path get] \
  313.         [.xfFSBox.pattern.pattern get] $xfFSBox(all)}
  314.   catch ".xfFSBox.pattern.all config $tmpButtonOpt"
  315.  
  316.   XFFSBoxFSShow $xfFSBox(internalPath) $xfFSBox(pattern) $xfFSBox(all)
  317.  
  318.   # bindings
  319.   bind .xfFSBox.files.files <Double-Button-1> "
  320.     XFFSBoxFSFileSelectDouble %W $xfFSBox(showPixmap) \{$xfFSBoxActionOk\} %y"
  321.   bind .xfFSBox.files.files <ButtonPress-1> "
  322.     XFFSBoxFSFileSelect %W $xfFSBox(showPixmap) %y"
  323.   bind .xfFSBox.files.files <Button1-Motion> "
  324.     XFFSBoxFSFileSelect %W $xfFSBox(showPixmap) %y"
  325.   bind .xfFSBox.files.files <Shift-Button1-Motion> "
  326.     XFFSBoxFSFileSelect %W $xfFSBox(showPixmap) %y"
  327.   bind .xfFSBox.files.files <Shift-ButtonPress-1> "
  328.     XFFSBoxFSFileSelect %W $xfFSBox(showPixmap) %y"
  329.  
  330.   bind .xfFSBox.path.path <Tab> {
  331.     XFFSBoxFSNameComplete path}
  332.   bind .xfFSBox.path.path <Return> {
  333.     global tkVersion
  334.     global xfFSBox
  335.     XFFSBoxFSShow [.xfFSBox.path.path get] \
  336.       [.xfFSBox.pattern.pattern get] $xfFSBox(all)
  337.     XFFSBoxFSInsertPath
  338.     if {$tkVersion >= 3.0} {
  339.       .xfFSBox.file.file icursor end
  340.     } {
  341.       .xfFSBox.file.file cursor end
  342.     }
  343.     focus .xfFSBox.file.file}
  344.   catch "bind .xfFSBox.path.path <Up> {}"
  345.   bind .xfFSBox.path.path <Down> {
  346.     global tkVersion
  347.     if {$tkVersion >= 3.0} {
  348.       .xfFSBox.file.file icursor end
  349.     } {
  350.       .xfFSBox.file.file cursor end
  351.     }
  352.     focus .xfFSBox.file.file}
  353.  
  354.   bind .xfFSBox.file.file <Tab> {
  355.     XFFSBoxFSNameComplete file}
  356.   bind .xfFSBox.file.file <Return> "
  357.     global xfFSBox
  358.     set xfFSBox(name) \[.xfFSBox.file.file get\]
  359.     if {$xfFSBox(showPixmap)} {
  360.       set xfFSBox(path) @\[.xfFSBox.path.path get\]
  361.     } {
  362.       set xfFSBox(path) \[.xfFSBox.path.path get\]
  363.     }
  364.     set xfFSBox(internalPath) \[.xfFSBox.path.path get\]
  365.     $xfFSBoxActionOk
  366.     if {\"\[info commands XFDestroy\]\" != \"\"} {
  367.       catch {XFDestroy .xfFSBox}
  368.     } {
  369.       catch {destroy .xfFSBox}
  370.     }"
  371.   bind .xfFSBox.file.file <Up> {
  372.     global tkVersion
  373.     if {$tkVersion >= 3.0} {
  374.       .xfFSBox.path.path icursor end
  375.     } {
  376.       .xfFSBox.path.path cursor end
  377.     }
  378.     focus .xfFSBox.path.path}
  379.   bind .xfFSBox.file.file <Down> {
  380.     global tkVersion
  381.     if {$tkVersion >= 3.0} {
  382.       .xfFSBox.pattern.pattern icursor end
  383.     } {
  384.       .xfFSBox.pattern.pattern cursor end
  385.     }
  386.     focus .xfFSBox.pattern.pattern}
  387.  
  388.   bind .xfFSBox.pattern.pattern <Return> {
  389.     global xfFSBox
  390.     XFFSBoxFSShow [.xfFSBox.path.path get] \
  391.       [.xfFSBox.pattern.pattern get] $xfFSBox(all)}
  392.   bind .xfFSBox.pattern.pattern <Up> {
  393.     global tkVersion
  394.     if {$tkVersion >= 3.0} {
  395.       .xfFSBox.file.file icursor end
  396.     } {
  397.       .xfFSBox.file.file cursor end
  398.     }
  399.     focus .xfFSBox.file.file}
  400.   catch "bind .xfFSBox.pattern.pattern <Down> {}"
  401.  
  402.   # packing
  403.   pack append .xfFSBox.files \
  404.               .xfFSBox.files.vscroll "$xfFSBox(scrollSide) filly" \
  405.               .xfFSBox.files.hscroll {bottom fillx} \
  406.               .xfFSBox.files.files {left fill expand}
  407.   pack append .xfFSBox.file \
  408.               .xfFSBox.file.labelfile {left} \
  409.               .xfFSBox.file.file {left fill expand}
  410.   pack append .xfFSBox.frame1 \
  411.               .xfFSBox.frame1.ok {left fill expand} \
  412.               .xfFSBox.frame1.rescan {left fill expand} \
  413.               .xfFSBox.frame1.cancel {left fill expand}
  414.   pack append .xfFSBox.path.paths \
  415.               .xfFSBox.path.paths.paths {left}
  416.   pack append .xfFSBox.pattern.patterns \
  417.               .xfFSBox.pattern.patterns.patterns {left}
  418.   pack append .xfFSBox.path \
  419.               .xfFSBox.path.paths {left} \
  420.               .xfFSBox.path.path {left fill expand}
  421.   pack append .xfFSBox.pattern \
  422.               .xfFSBox.pattern.patterns {left} \
  423.               .xfFSBox.pattern.all {right fill} \
  424.               .xfFSBox.pattern.pattern {left fill expand}
  425.   if {$xfFSBox(showPixmap)} {
  426.     pack append .xfFSBox.frame2 \
  427.                 .xfFSBox.frame2.scrollbar1 {left filly} \
  428.                 .xfFSBox.frame2.canvas2 {top expand fill} \
  429.                 .xfFSBox.frame2.scrollbar3 {top fillx} 
  430.  
  431.     pack append .xfFSBox \
  432.                 .xfFSBox.message1 {top fill} \
  433.                 .xfFSBox.frame1 {bottom fill} \
  434.                 .xfFSBox.pattern {bottom fill} \
  435.                 .xfFSBox.file {bottom fill} \
  436.                 .xfFSBox.path {bottom fill} \
  437.                 .xfFSBox.frame2 {right fill} \
  438.                 .xfFSBox.files {left fill expand}
  439.   } {
  440.     pack append .xfFSBox \
  441.                 .xfFSBox.message1 {top fill} \
  442.                 .xfFSBox.frame1 {bottom fill} \
  443.                 .xfFSBox.pattern {bottom fill} \
  444.                 .xfFSBox.file {bottom fill} \
  445.                 .xfFSBox.path {bottom fill} \
  446.                 .xfFSBox.files {left fill expand}
  447.   }
  448.  
  449.   if {"$xfFSBoxActionOk" == "" && "$xfFSBoxActionCancel" == ""} {
  450.     # wait for the box to be destroyed
  451.     update idletask
  452.     grab .xfFSBox
  453.     tkwait window .xfFSBox
  454.  
  455.     if {"[string trim $xfFSBox(path)]" != "" ||
  456.         "[string trim $xfFSBox(name)]" != ""} {
  457.       if {"[string trimleft [string trim $xfFSBox(name)] /]" == ""} {
  458.         return [string trimright [string trim $xfFSBox(path)] /]
  459.       } {
  460.         return [string trimright [string trim $xfFSBox(path)] /]/[string trimleft [string trim $xfFSBox(name)] /]
  461.       }
  462.     }
  463.   }
  464. }
  465.  
  466. ##########
  467. # Procedure: XFFSBoxFSFileSelect
  468. # Description: select file name
  469. # Arguments: xfFSBoxW - the widget
  470. #            xfFSBoxShowPixmap - show pixmaps
  471. #            xfFSBoxY - the y position in the listbox
  472. # Returns: none
  473. # Sideeffects: none
  474. ##########
  475. proc XFFSBoxFSFileSelect {xfFSBoxW xfFSBoxShowPixmap xfFSBoxY} {# xf ignore me 6
  476.   global xfFSBox
  477.  
  478.   XFFSBoxBindSelectOne $xfFSBoxW $xfFSBoxY
  479.   set xfFSBoxNearest [$xfFSBoxW nearest $xfFSBoxY]
  480.   if {$xfFSBoxNearest >= 0} {
  481.     set xfFSBoxTmpEntry [$xfFSBoxW get $xfFSBoxNearest]
  482.     if {"[string index $xfFSBoxTmpEntry \
  483.           [expr [string length $xfFSBoxTmpEntry]-1]]" == "/" ||
  484.         "[string index $xfFSBoxTmpEntry \
  485.           [expr [string length $xfFSBoxTmpEntry]-1]]" == "@"} {
  486.       set xfFSBoxFileName [string range $xfFSBoxTmpEntry 0 \
  487.             [expr [string length $xfFSBoxTmpEntry]-2]]
  488.       if {![XFIsADir [string trimright $xfFSBox(internalPath)/$xfFSBoxFileName @]] &&
  489.           ![XFIsASymlink [string trimright $xfFSBox(internalPath)/$xfFSBoxFileName @]]} {
  490.         set xfFSBoxFileName $xfFSBoxTmpEntry
  491.       }
  492.     } {
  493.       if {"[string index $xfFSBoxTmpEntry \
  494.             [expr [string length $xfFSBoxTmpEntry]-1]]" == "*"} {
  495.         set xfFSBoxFileName [string range $xfFSBoxTmpEntry 0 \
  496.           [expr [string length $xfFSBoxTmpEntry]-2]]
  497.         if {![file executable $xfFSBox(internalPath)/$xfFSBoxFileName]} {
  498.           set xfFSBoxFileName $xfFSBoxTmpEntry
  499.         }
  500.       } {
  501.         set xfFSBoxFileName $xfFSBoxTmpEntry
  502.       }
  503.     }
  504.     if {![XFIsADir [string trimright $xfFSBox(internalPath)/$xfFSBoxFileName @]]} {
  505.       set xfFSBox(name) $xfFSBoxFileName
  506.       .xfFSBox.file.file delete 0 end
  507.       .xfFSBox.file.file insert 0 $xfFSBox(name)
  508.       if {$xfFSBoxShowPixmap} {
  509.         catch ".xfFSBox.frame2.canvas2 itemconfigure currentBitmap -bitmap \"@$xfFSBox(internalPath)/$xfFSBox(name)\""
  510.       }
  511.     }
  512.   }
  513. }
  514.  
  515. ##########
  516. # Procedure: XFFSBoxFSFileSelectDouble
  517. # Description: select file when double clicked
  518. # Arguments: xfFSBoxW - the widget
  519. #            xfFSBoxShowPixmap - show pixmaps
  520. #            xfFSBoxAction - the action bound to the ok button
  521. #            xfFSBoxY - the y position in the listbox
  522. # Returns: none
  523. # Sideeffects: none
  524. ##########
  525. proc XFFSBoxFSFileSelectDouble {xfFSBoxW xfFSBoxShowPixmap xfFSBoxAction xfFSBoxY} {# xf ignore me 6
  526.   global xfFSBox
  527.  
  528.   XFFSBoxBindSelectOne $xfFSBoxW $xfFSBoxY
  529.   set xfFSBoxNearest [$xfFSBoxW nearest $xfFSBoxY]
  530.   if {$xfFSBoxNearest >= 0} {
  531.     set xfFSBoxTmpEntry [$xfFSBoxW get $xfFSBoxNearest]
  532.     if {"$xfFSBoxTmpEntry" == "../"} {
  533.       set xfFSBoxTmpEntry [string trimright [string trim $xfFSBox(internalPath)] "@/"]
  534.       if {"$xfFSBoxTmpEntry" == ""} {
  535.         return
  536.       }
  537.       XFFSBoxFSShow [file dirname $xfFSBoxTmpEntry] \
  538.         [.xfFSBox.pattern.pattern get] $xfFSBox(all)
  539.       .xfFSBox.path.path delete 0 end
  540.       .xfFSBox.path.path insert 0 $xfFSBox(internalPath)
  541.     } {
  542.       if {"[string index $xfFSBoxTmpEntry \
  543.             [expr [string length $xfFSBoxTmpEntry]-1]]" == "/" ||
  544.           "[string index $xfFSBoxTmpEntry \
  545.             [expr [string length $xfFSBoxTmpEntry]-1]]" == "@"} {
  546.         set xfFSBoxFileName [string range $xfFSBoxTmpEntry 0 \
  547.               [expr [string length $xfFSBoxTmpEntry]-2]]
  548.         if {![XFIsADir [string trimright $xfFSBox(internalPath)/$xfFSBoxFileName @]] &&
  549.             ![XFIsASymlink [string trimright $xfFSBox(internalPath)/$xfFSBoxFileName @]]} {
  550.           set xfFSBoxFileName $xfFSBoxTmpEntry
  551.         }
  552.       } {
  553.         if {"[string index $xfFSBoxTmpEntry \
  554.               [expr [string length $xfFSBoxTmpEntry]-1]]" == "*"} {
  555.           set xfFSBoxFileName [string range $xfFSBoxTmpEntry 0 \
  556.                 [expr [string length $xfFSBoxTmpEntry]-2]]
  557.           if {![file executable $xfFSBox(internalPath)/$xfFSBoxFileName]} {
  558.             set xfFSBoxFileName $xfFSBoxTmpEntry
  559.           }
  560.         } {
  561.           set xfFSBoxFileName $xfFSBoxTmpEntry
  562.         }
  563.       }
  564.       if {[XFIsADir [string trimright $xfFSBox(internalPath)/$xfFSBoxFileName @]]} {
  565.         set xfFSBox(internalPath) "[string trimright $xfFSBox(internalPath) {/@}]/$xfFSBoxFileName"
  566.         XFFSBoxFSShow $xfFSBox(internalPath) \
  567.           [.xfFSBox.pattern.pattern get] $xfFSBox(all)
  568.         .xfFSBox.path.path delete 0 end
  569.         .xfFSBox.path.path insert 0 $xfFSBox(internalPath)
  570.       } {
  571.         set xfFSBox(name) $xfFSBoxFileName
  572.         if {$xfFSBoxShowPixmap} {
  573.           set xfFSBox(path) @$xfFSBox(internalPath)
  574.         } {
  575.           set xfFSBox(path) $xfFSBox(internalPath)
  576.         }
  577.         if {"$xfFSBoxAction" != ""} {
  578.           eval "global xfFSBox; $xfFSBoxAction"
  579.         }
  580.         if {"[info commands XFDestroy]" != ""} {
  581.           catch {XFDestroy .xfFSBox}
  582.         } {
  583.           catch {destroy .xfFSBox}
  584.         }
  585.       }
  586.     }
  587.   }
  588. }
  589.  
  590. ##########
  591. # Procedure: XFFSBoxFSInsertPath
  592. # Description: insert current pathname into menu
  593. # Arguments: none
  594. # Returns: none
  595. # Sideeffects: none
  596. ##########
  597. proc XFFSBoxFSInsertPath {} {# xf ignore me 6
  598.   global xfFSBox
  599.  
  600.   set xfFSBoxLast [.xfFSBox.path.paths.paths.menu index last]
  601.   set xfFSBoxNewEntry [string trimright [.xfFSBox.path.path get] "/@"]
  602.   for {set xfFSBoxCounter 0} {$xfFSBoxCounter <= $xfFSBoxLast} {incr xfFSBoxCounter 1} {
  603.     if {"$xfFSBoxNewEntry" == \
  604.           "[lindex [.xfFSBox.path.paths.paths.menu entryconfigure \
  605.                     $xfFSBoxCounter -label] 4]"} {
  606.       return
  607.     }
  608.   }
  609.   if {$xfFSBoxLast < 9} {
  610.     .xfFSBox.path.paths.paths.menu add command \
  611.       -label "$xfFSBoxNewEntry" \
  612.       -command "
  613.         global xfFSBox
  614.         XFFSBoxFSShow $xfFSBoxNewEntry \
  615.           \[.xfFSBox.pattern.pattern get\] \$xfFSBox(all)
  616.         .xfFSBox.path.path delete 0 end
  617.         .xfFSBox.path.path insert 0 $xfFSBoxNewEntry"
  618.   } {
  619.     for {set xfFSBoxCounter 0} {$xfFSBoxCounter < $xfFSBoxLast} {incr xfFSBoxCounter 1} {
  620.       .xfFSBox.path.paths.paths.menu entryconfigure \
  621.         $xfFSBoxCounter -label \
  622.           [lindex [.xfFSBox.path.paths.paths.menu entryconfigure \
  623.             [expr $xfFSBoxCounter+1] -label] 4]
  624.       .xfFSBox.path.paths.paths.menu entryconfigure $xfFSBoxCounter \
  625.         -command "
  626.           global xfFSBox
  627.           XFFSBoxFSShow [lindex [.xfFSBox.path.paths.paths.menu entryconfigure \
  628.             [expr $xfFSBoxCounter+1] -label] 4] \
  629.             \[.xfFSBox.pattern.pattern get\] \$xfFSBox(all)
  630.           .xfFSBox.path.path delete 0 end
  631.           .xfFSBox.path.path insert 0 [lindex \
  632.             [.xfFSBox.path.paths.paths.menu entryconfigure \
  633.               [expr $xfFSBoxCounter+1] -label] 4]"
  634.     }
  635.     .xfFSBox.path.paths.paths.menu entryconfigure $xfFSBoxLast \
  636.       -label "$xfFSBoxNewEntry"
  637.     .xfFSBox.path.paths.paths.menu entryconfigure $xfFSBoxCounter \
  638.       -command "
  639.         global xfFSBox
  640.         XFFSBoxFSShow \[.xfFSBox.path.path get\] \
  641.           \[.xfFSBox.pattern.pattern get\] \$xfFSBox(all)
  642.         .xfFSBox.path.path delete 0 end
  643.         .xfFSBox.path.path insert 0 $xfFSBoxNewEntry"
  644.   }
  645. }
  646.  
  647. ##########
  648. # Procedure: XFFSBoxFSNameComplete
  649. # Description: perform name completion for fs box
  650. # Arguments: xfFSBoxType - the type we want to complete (path or file)
  651. # Returns: none
  652. # Sideeffects: none
  653. ##########
  654. proc XFFSBoxFSNameComplete {xfFSBoxType} {# xf ignore me 6
  655.   global tkVersion
  656.   global xfFSBox
  657.  
  658.   set xfFSBoxNewFile ""
  659.   if {"$xfFSBoxType" == "path"} {
  660.     set xfFSBoxDirName [file dirname [.xfFSBox.path.path get]]
  661.     set xfFSBoxFileName [file tail [.xfFSBox.path.path get]]
  662.   } {
  663.     set xfFSBoxDirName [file dirname [.xfFSBox.path.path get]/]
  664.     set xfFSBoxFileName [file tail [.xfFSBox.file.file get]]
  665.   }
  666.  
  667.   set xfFSBoxNewFile ""
  668.   if {[XFIsADir [string trimright $xfFSBoxDirName @]]} {
  669.     catch "glob -nocomplain $xfFSBoxDirName/${xfFSBoxFileName}*" xfFSBoxResult
  670.     foreach xfFSBoxCounter $xfFSBoxResult {
  671.       if {"$xfFSBoxNewFile" == ""} {
  672.         set xfFSBoxNewFile [file tail $xfFSBoxCounter]
  673.       } {
  674.         if {"[string index [file tail $xfFSBoxCounter] 0]" !=
  675.             "[string index $xfFSBoxNewFile 0]"} {
  676.           set xfFSBoxNewFile ""
  677.           break
  678.         }
  679.         set xfFSBoxCounter1 0
  680.         set xfFSBoxTmpFile1 $xfFSBoxNewFile
  681.         set xfFSBoxTmpFile2 [file tail $xfFSBoxCounter]
  682.         set xfFSBoxLength1 [string length $xfFSBoxTmpFile1]
  683.         set xfFSBoxLength2 [string length $xfFSBoxTmpFile2]
  684.         set xfFSBoxNewFile ""
  685.         if {$xfFSBoxLength1 > $xfFSBoxLength2} {
  686.           set xfFSBoxLength1 $xfFSBoxLength2
  687.         }
  688.         while {$xfFSBoxCounter1 < $xfFSBoxLength1} {
  689.           if {"[string index $xfFSBoxTmpFile1 $xfFSBoxCounter1]" == \
  690.                 "[string index $xfFSBoxTmpFile2 $xfFSBoxCounter1]"} {
  691.             append xfFSBoxNewFile [string index $xfFSBoxTmpFile1 $xfFSBoxCounter1]
  692.           } {
  693.             break
  694.           }
  695.           incr xfFSBoxCounter1 1
  696.         }
  697.       }
  698.     }
  699.   }
  700.   if {"$xfFSBoxNewFile" != ""} {
  701.     if {[XFIsADir [string trimright $xfFSBoxDirName/$xfFSBoxNewFile @]] ||
  702.         ![XFIsAFile [string trimright $xfFSBoxDirName/$xfFSBoxNewFile @]]} {
  703.       if {[XFIsADir [string trimright $xfFSBoxDirName/$xfFSBoxNewFile @]]} {
  704.         if {"$xfFSBoxDirName" == "/"} {
  705.           .xfFSBox.path.path delete 0 end
  706.           .xfFSBox.path.path insert 0 "/[string trimright [string trim $xfFSBoxNewFile /] @]/"
  707.         } {
  708.           .xfFSBox.path.path delete 0 end
  709.           .xfFSBox.path.path insert 0 "[string trimright $xfFSBoxDirName /]/[string trimright [string trim $xfFSBoxNewFile /] @]/"
  710.         }
  711.         XFFSBoxFSShow [.xfFSBox.path.path get] \
  712.           [.xfFSBox.pattern.pattern get] $xfFSBox(all)
  713.         XFFSBoxFSInsertPath
  714.       } {
  715.         .xfFSBox.path.path delete 0 end
  716.         .xfFSBox.path.path insert 0 "[string trimright $xfFSBoxDirName /]/[string trimright [string trim $xfFSBoxNewFile /] @]"
  717.       }
  718.     } {
  719.       .xfFSBox.path.path delete 0 end
  720.       .xfFSBox.path.path insert 0 "[string trimright $xfFSBoxDirName {@/}]/"
  721.       .xfFSBox.file.file delete 0 end
  722.       .xfFSBox.file.file insert 0 $xfFSBoxNewFile
  723.       if {$tkVersion >= 3.0} {
  724.         .xfFSBox.file.file icursor end
  725.       } {
  726.         .xfFSBox.file.file cursor end
  727.       }
  728.       focus .xfFSBox.file.file
  729.     }
  730.   }
  731. }
  732.  
  733. ##########
  734. # Procedure: XFFSBoxFSShow
  735. # Description: show the file list
  736. # Arguments: xfFSBoxPath - the path to show
  737. #            xfFSBoxPattern - selection pattern
  738. #            xfFSBoxAll - show all files
  739. # Returns: none
  740. # Sideeffects: none
  741. ##########
  742. proc XFFSBoxFSShow {xfFSBoxPath xfFSBoxPattern xfFSBoxAll} {# xf ignore me 6
  743.   global xfFSBox
  744.  
  745.   set tmpButtonOpt ""
  746.   if {"$xfFSBox(activeBackground)" != ""} {
  747.     append tmpButtonOpt "-activebackground \"$xfFSBox(activeBackground)\" "
  748.   }
  749.   if {"$xfFSBox(activeForeground)" != ""} {
  750.     append tmpButtonOpt "-activeforeground \"$xfFSBox(activeForeground)\" "
  751.   }
  752.   if {"$xfFSBox(background)" != ""} {
  753.     append tmpButtonOpt "-background \"$xfFSBox(background)\" "
  754.   }
  755.   if {"$xfFSBox(font)" != ""} {
  756.     append tmpButtonOpt "-font \"$xfFSBox(font)\" "
  757.   }
  758.   if {"$xfFSBox(foreground)" != ""} {
  759.     append tmpButtonOpt "-foreground \"$xfFSBox(foreground)\" "
  760.   }
  761.  
  762.   set xfFSBox(pattern) $xfFSBoxPattern
  763.   if {[file exists $xfFSBoxPath] && [file readable $xfFSBoxPath] &&
  764.       [XFIsADir $xfFSBoxPath]} {
  765.     set xfFSBox(internalPath) $xfFSBoxPath
  766.   } {
  767.     if {[file exists $xfFSBoxPath] && [file readable $xfFSBoxPath] &&
  768.         [XFIsAFile $xfFSBoxPath]} {
  769.       set xfFSBox(internalPath) [file dirname $xfFSBoxPath]
  770.       .xfFSBox.file.file delete 0 end
  771.       .xfFSBox.file.file insert 0 [file tail $xfFSBoxPath]
  772.       set xfFSBoxPath $xfFSBox(internalPath)
  773.     } {
  774.       while {"$xfFSBoxPath" != "" && "$xfFSBoxPath" != "/" &&
  775.              ![file isdirectory $xfFSBoxPath]} {
  776.         set xfFSBox(internalPath) [file dirname $xfFSBoxPath]
  777.          set xfFSBoxPath $xfFSBox(internalPath)
  778.       }
  779.     }
  780.   }
  781.   if {"$xfFSBoxPath" == ""} {
  782.     set xfFSBoxPath "/"
  783.     set xfFSBox(internalPath) "/"
  784.   }
  785.   .xfFSBox.path.path delete 0 end
  786.   .xfFSBox.path.path insert 0 $xfFSBox(internalPath)
  787.  
  788.   if {[.xfFSBox.files.files size] > 0} {
  789.     .xfFSBox.files.files delete 0 end
  790.   }
  791.   if {$xfFSBoxAll} {
  792.     if {[catch "exec ls -F -a $xfFSBoxPath" xfFSBoxResult]} {
  793.       puts stderr "$xfFSBoxResult"
  794.     }
  795.   } {
  796.     if {[catch "exec ls -F $xfFSBoxPath" xfFSBoxResult]} {
  797.       puts stderr "$xfFSBoxResult"
  798.     }
  799.   }
  800.   set xfFSBoxElementList [lsort $xfFSBoxResult]
  801.  
  802.   foreach xfFSBoxCounter [winfo children .xfFSBox.pattern.patterns.patterns] {
  803.     if {[string length [info commands XFDestroy]] > 0} {
  804.       catch {XFDestroy $xfFSBoxCounter}
  805.     } {
  806.       catch {destroy $xfFSBoxCounter}
  807.     }
  808.   }
  809.   menu .xfFSBox.pattern.patterns.patterns.menu
  810.   catch ".xfFSBox.pattern.patterns.patterns.menu config $tmpButtonOpt"
  811.  
  812.   if {$xfFSBox(extensions)} {
  813.     .xfFSBox.pattern.patterns.patterns.menu add command \
  814.       -label "*" \
  815.       -command {
  816.         global xfFSBox
  817.         set xfFSBox(pattern) "*"
  818.         .xfFSBox.pattern.pattern delete 0 end
  819.         .xfFSBox.pattern.pattern insert 0 $xfFSBox(pattern)
  820.         XFFSBoxFSShow [.xfFSBox.path.path get] $xfFSBox(pattern) \
  821.           $xfFSBox(all)}
  822.   }
  823.  
  824.   if {"$xfFSBoxPath" != "/"} {
  825.     .xfFSBox.files.files insert end "../"
  826.   }
  827.   foreach xfFSBoxCounter $xfFSBoxElementList {
  828.     if {[string match $xfFSBoxPattern $xfFSBoxCounter] ||
  829.         [XFIsADir [string trimright $xfFSBoxPath/$xfFSBoxCounter "/@"]]} {
  830.       if {"$xfFSBoxCounter" != "../" &&
  831.           "$xfFSBoxCounter" != "./"} {
  832.         .xfFSBox.files.files insert end $xfFSBoxCounter
  833.       }
  834.     }
  835.  
  836.     if {$xfFSBox(extensions)} {
  837.       catch "file rootname $xfFSBoxCounter" xfFSBoxRootName
  838.       catch "file extension $xfFSBoxCounter" xfFSBoxExtension
  839.       set xfFSBoxExtension [string trimright $xfFSBoxExtension "/*@"]
  840.       if {"$xfFSBoxExtension" != "" && "$xfFSBoxRootName" != ""} {
  841.         set xfFSBoxInsert 1
  842.         set xfFSBoxLast [.xfFSBox.pattern.patterns.patterns.menu index last]
  843.         for {set xfFSBoxCounter1 0} {$xfFSBoxCounter1 <= $xfFSBoxLast} {incr xfFSBoxCounter1 1} {
  844.           if {"*$xfFSBoxExtension" == \
  845.                 "[lindex [.xfFSBox.pattern.patterns.patterns.menu entryconfigure \
  846.                         $xfFSBoxCounter1 -label] 4]"} {
  847.             set xfFSBoxInsert 0
  848.           }
  849.         }
  850.     if {$xfFSBoxInsert} {
  851.           .xfFSBox.pattern.patterns.patterns.menu add command \
  852.             -label "*$xfFSBoxExtension" \
  853.             -command "
  854.               global xfFSBox
  855.               set xfFSBox(pattern) \"*$xfFSBoxExtension\"
  856.               .xfFSBox.pattern.pattern delete 0 end
  857.               .xfFSBox.pattern.pattern insert 0 \$xfFSBox(pattern)
  858.               XFFSBoxFSShow \[.xfFSBox.path.path get\] \$xfFSBox(pattern) \
  859.                 \$xfFSBox(all)"
  860.         }
  861.       }
  862.     }
  863.   }
  864.   if {$xfFSBox(extensions)} {
  865.     .xfFSBox.pattern.patterns.patterns.menu add separator
  866.   }
  867.   if {$xfFSBox(extensions) || 
  868.       "[.xfFSBox.pattern.patterns.patterns.menu index last]" == "none"} {
  869.     .xfFSBox.pattern.patterns.patterns.menu add checkbutton \
  870.       -label "Scan extensions" \
  871.       -variable "xfFSBox(extensions)" \
  872.       -command {
  873.         global xfFSBox
  874.         XFFSBoxFSShow [.xfFSBox.path.path get] \
  875.           [.xfFSBox.pattern.pattern get] $xfFSBox(all)}
  876.   }
  877. }
  878.  
  879. ##########
  880. # Procedure: XFFSBoxBindSelectOne
  881. # Description: action to select the current list item
  882. # Arguments: xfFSBoxW - the widget
  883. #            xfFSBoxY - the y position in the listbox
  884. # Returns: none
  885. # Sideeffects: none
  886. ##########
  887. proc XFFSBoxBindSelectOne {xfFSBoxW xfFSBoxY} {# xf ignore me 6
  888.  
  889.   set xfFSBoxNearest [$xfFSBoxW nearest $xfFSBoxY]
  890.   if {$xfFSBoxNearest >= 0} {
  891.     $xfFSBoxW select from $xfFSBoxNearest
  892.     $xfFSBoxW select to $xfFSBoxNearest
  893.   }
  894. }
  895.  
  896. proc XFIsADir {pathName} {# xf ignore me 5
  897. ##########
  898. # Procedure: XFIsADir
  899. # Description: check if name is a directory (including symbolic links)
  900. # Arguments: pathName - the path to check
  901. # Returns: 1 if its a directory, otherwise 0
  902. # Sideeffects: none
  903. ##########
  904.  
  905.   if {[file isdirectory $pathName]} {
  906.     return 1
  907.   } {
  908.     catch "file type $pathName" fileType
  909.     if {"$fileType" == "link"} {
  910.       if {[catch "file readlink $pathName" linkName]} {
  911.         return 0
  912.       }
  913.       catch "file type $linkName" fileType
  914.       while {"$fileType" == "link"} {
  915.         if {[catch "file readlink $linkName" linkName]} {
  916.           return 0
  917.         }
  918.         catch "file type $linkName" fileType
  919.       }
  920.       return [file isdirectory $linkName]
  921.     }
  922.   }
  923.   return 0
  924. }
  925.  
  926. proc XFIsAFile {fileName} {# xf ignore me 5
  927. ##########
  928. # Procedure: XFIsAFile
  929. # Description: check if filename is a file (including symbolic links)
  930. # Arguments: fileName - the filename to check
  931. # Returns: 1 if its a file, otherwise 0
  932. # Sideeffects: none
  933. ##########
  934.  
  935.   if {[file isfile $fileName]} {
  936.     return 1
  937.   } {
  938.     catch "file type $fileName" fileType
  939.     if {"$fileType" == "link"} {
  940.       if {[catch "file readlink $fileName" linkName]} {
  941.         return 0
  942.       }
  943.       catch "file type $linkName" fileType
  944.       while {"$fileType" == "link"} {
  945.         if {[catch "file readlink $linkName" linkName]} {
  946.           return 0
  947.         }
  948.         catch "file type $linkName" fileType
  949.       }
  950.       return [file isfile $linkName]
  951.     }
  952.   }
  953.   return 0
  954. }
  955.  
  956. proc XFIsASymlink {fileName} {# xf ignore me 5
  957. ##########
  958. # Procedure: XFIsASymlink
  959. # Description: check if filename is a symbolic link
  960. # Arguments: fileName - the path/filename to check
  961. # Returns: none
  962. # Sideeffects: none
  963. ##########
  964.  
  965.   catch "file type $fileName" fileType
  966.   if {"$fileType" == "link"} {
  967.     return 1
  968.   }
  969.   return 0
  970. }
  971.  
  972. # eof
  973.  
  974.