FileCbx.tcl 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # -*- mode: TCL; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. # $Id: FileCbx.tcl,v 1.5 2004/03/28 02:44:57 hobbs Exp $
  4. #
  5. # tixFileCombobox --
  6. #
  7. # A combobox widget for entering file names, directory names, file
  8. # patterns, etc.
  9. #
  10. #
  11. # Copyright (c) 1993-1999 Ioi Kim Lam.
  12. # Copyright (c) 2000-2001 Tix Project Group.
  13. # Copyright (c) 2004 ActiveState
  14. #
  15. # See the file "license.terms" for information on usage and redistribution
  16. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  17. # tixFileComboBox displays and accepts the DOS pathnames only. It doesn't
  18. # recognize UNC file names or Tix VPATHS.
  19. #
  20. tixWidgetClass tixFileComboBox {
  21. -classname TixFileComboBox
  22. -superclass tixPrimitive
  23. -method {
  24. invoke
  25. }
  26. -flag {
  27. -command -defaultfile -directory -text
  28. }
  29. -forcecall {
  30. -directory
  31. }
  32. -configspec {
  33. {-defaultfile defaultFile DefaultFile ""}
  34. {-directory directory Directory ""}
  35. {-command command Command ""}
  36. {-text text Text ""}
  37. }
  38. -default {
  39. }
  40. }
  41. proc tixFileComboBox:InitWidgetRec {w} {
  42. upvar #0 $w data
  43. tixChainMethod $w InitWidgetRec
  44. if {$data(-directory) eq ""} {
  45. set data(-directory) [pwd]
  46. }
  47. }
  48. proc tixFileComboBox:ConstructWidget {w} {
  49. upvar #0 $w data
  50. tixChainMethod $w ConstructWidget
  51. set data(w:combo) [tixComboBox $w.combo -editable true -dropdown true]
  52. pack $data(w:combo) -expand yes -fill both
  53. }
  54. proc tixFileComboBox:SetBindings {w} {
  55. upvar #0 $w data
  56. tixChainMethod $w SetBindings
  57. $data(w:combo) config -command [list tixFileComboBox:OnComboCmd $w]
  58. }
  59. proc tixFileComboBox:OnComboCmd {w args} {
  60. upvar #0 $w data
  61. set text [string trim [tixEvent value]]
  62. set path [tixFSJoin $data(-directory) $text]
  63. if {[file isdirectory $path]} {
  64. set path [tixFSJoin $path $data(-defaultfile)]
  65. set tail $data(-defaultfile)
  66. } else {
  67. set tail [file tail $path]
  68. }
  69. set norm [tixFSNormalize $path]
  70. tixSetSilent $data(w:combo) $norm
  71. if {[llength $data(-command)]} {
  72. set bind(specs) {%V}
  73. set bind(%V) [list $norm $path $tail ""]
  74. tixEvalCmdBinding $w $data(-command) bind $bind(%V)
  75. }
  76. }
  77. proc tixFileComboBox:config-text {w val} {
  78. upvar #0 $w data
  79. tixSetSilent $data(w:combo) $val
  80. }
  81. proc tixFileComboBox:config-directory {w val} {
  82. upvar #0 $w data
  83. set data(-directory) [tixFSNormalize $val]
  84. return $data(-directory)
  85. }
  86. proc tixFileComboBox:invoke {w} {
  87. upvar #0 $w data
  88. $data(w:combo) invoke
  89. }