12
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
25
|
3 |
All Rights Reserved
|
12
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
EditField subclass:#FilenameEditField
|
43
|
14 |
instanceVariableNames:'directoriesOnly filesOnly'
|
12
|
15 |
classVariableNames: ''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Views-Text'
|
|
18 |
!
|
|
19 |
|
|
20 |
FilenameEditField comment:'
|
|
21 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
25
|
22 |
All Rights Reserved
|
12
|
23 |
|
64
|
24 |
$Header: /cvs/stx/stx/libwidg2/Attic/FNmEdtFld.st,v 1.11 1995-07-03 02:34:42 claus Exp $
|
12
|
25 |
'!
|
|
26 |
|
|
27 |
!FilenameEditField class methodsFor:'documentation'!
|
|
28 |
|
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
25
|
32 |
All Rights Reserved
|
12
|
33 |
|
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
|
42 |
|
|
43 |
version
|
|
44 |
"
|
64
|
45 |
$Header: /cvs/stx/stx/libwidg2/Attic/FNmEdtFld.st,v 1.11 1995-07-03 02:34:42 claus Exp $
|
12
|
46 |
"
|
|
47 |
!
|
|
48 |
|
|
49 |
documentation
|
|
50 |
"
|
24
|
51 |
like a normal editField, but does filename-completion on the last word of
|
|
52 |
the contents, when TAB is pressed.
|
43
|
53 |
Filename completion ignores regular files if directoriesOnly is true,
|
|
54 |
and ignores directories, if filesOnly is true. Both default to false.
|
12
|
55 |
"
|
|
56 |
! !
|
|
57 |
|
34
|
58 |
!FilenameEditField methodsFor:'initialization'!
|
|
59 |
|
43
|
60 |
initialize
|
|
61 |
super initialize.
|
|
62 |
directoriesOnly := filesOnly := false.
|
|
63 |
!
|
|
64 |
|
34
|
65 |
realize
|
|
66 |
"move the cursor to the end - thats the most interresting part of
|
|
67 |
a filename
|
|
68 |
"
|
|
69 |
super realize.
|
|
70 |
self cursorToEndOfLine.
|
|
71 |
! !
|
|
72 |
|
|
73 |
!FilenameEditField methodsFor:'accessing'!
|
|
74 |
|
43
|
75 |
directoriesOnly
|
|
76 |
"set to expand names for directories only"
|
|
77 |
|
|
78 |
directoriesOnly := true.
|
|
79 |
!
|
|
80 |
|
|
81 |
filesOnly
|
|
82 |
"set to expand names for files only"
|
|
83 |
|
|
84 |
filesOnly := true.
|
|
85 |
!
|
|
86 |
|
34
|
87 |
initialText:aString selected:aBoolean
|
|
88 |
"move the cursor to the end - thats the most interresting part of
|
|
89 |
a filename
|
|
90 |
"
|
|
91 |
|
|
92 |
super initialText:aString selected:aBoolean.
|
|
93 |
self cursorToEndOfLine.
|
|
94 |
! !
|
|
95 |
|
32
|
96 |
!FilenameEditField methodsFor:'event handling'!
|
12
|
97 |
|
|
98 |
keyPress:key x:x y:y
|
43
|
99 |
"handle tab for filename completion.
|
|
100 |
Bug: it completes the last word; it should complete the
|
|
101 |
word before the cursor."
|
12
|
102 |
|
64
|
103 |
<resource: #keyboard ( #FilenameCompletion ) >
|
|
104 |
|
43
|
105 |
|s f matchSet nMatch name words dir|
|
12
|
106 |
|
|
107 |
enabled ifTrue:[
|
45
|
108 |
((key == #Tab)
|
43
|
109 |
or:[key == #FilenameCompletion]) ifTrue:[
|
25
|
110 |
s := self contents.
|
|
111 |
"
|
|
112 |
find the last word ...
|
|
113 |
"
|
|
114 |
words := s asCollectionOfWords.
|
|
115 |
f := words last asFilename.
|
|
116 |
matchSet := f filenameCompletion.
|
49
|
117 |
dir := f directory.
|
43
|
118 |
directoriesOnly ifTrue:[
|
|
119 |
matchSet := matchSet select:[:aFilename |
|
|
120 |
(dir construct:aFilename) isDirectory
|
|
121 |
].
|
|
122 |
] ifFalse:[
|
|
123 |
filesOnly ifTrue:[
|
|
124 |
matchSet := matchSet select:[:aFilename |
|
|
125 |
(dir construct:aFilename) isDirectory not
|
|
126 |
].
|
|
127 |
]
|
|
128 |
].
|
|
129 |
|
34
|
130 |
(nMatch := matchSet size) ~~ 1 ifTrue:[
|
25
|
131 |
"
|
|
132 |
more than one possible completion -
|
|
133 |
"
|
49
|
134 |
self changed:#directory with:f directoryName.
|
25
|
135 |
device beep
|
|
136 |
].
|
|
137 |
"
|
|
138 |
even with more than one possible completion,
|
|
139 |
f's name is now common prefix
|
|
140 |
"
|
|
141 |
name := f asString.
|
34
|
142 |
nMatch == 1 ifTrue:[
|
25
|
143 |
"
|
|
144 |
exactly one possible completion -
|
|
145 |
"
|
43
|
146 |
f := dir construct:matchSet first.
|
|
147 |
|
|
148 |
directoriesOnly ifTrue:[
|
|
149 |
name := f asString
|
|
150 |
] ifFalse:[
|
|
151 |
f isDirectory ifTrue:[
|
|
152 |
(name endsWith:(Filename separator)) ifFalse:[
|
|
153 |
name := (f construct:'') asString
|
|
154 |
].
|
25
|
155 |
].
|
43
|
156 |
]
|
25
|
157 |
].
|
|
158 |
"
|
|
159 |
construct new contents, by taking
|
|
160 |
last words completion
|
|
161 |
"
|
|
162 |
s := ''.
|
|
163 |
1 to:(words size - 1) do:[:idx |
|
|
164 |
s := s , (words at:idx) , ' '
|
|
165 |
].
|
|
166 |
s := s , name.
|
|
167 |
self contents:s.
|
|
168 |
self cursorToEndOfLine.
|
|
169 |
^ self
|
|
170 |
].
|
12
|
171 |
].
|
|
172 |
^ super keyPress:key x:x y:y.
|
|
173 |
! !
|