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
|
72
|
14 |
instanceVariableNames:'directoriesOnly filesOnly directory'
|
12
|
15 |
classVariableNames: ''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Views-Text'
|
|
18 |
!
|
|
19 |
|
|
20 |
!FilenameEditField class methodsFor:'documentation'!
|
|
21 |
|
|
22 |
copyright
|
|
23 |
"
|
|
24 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
25
|
25 |
All Rights Reserved
|
12
|
26 |
|
|
27 |
This software is furnished under a license and may be used
|
|
28 |
only in accordance with the terms of that license and with the
|
|
29 |
inclusion of the above copyright notice. This software may not
|
|
30 |
be provided or otherwise made available to, or used by, any
|
|
31 |
other person. No title to or ownership of the software is
|
|
32 |
hereby transferred.
|
|
33 |
"
|
|
34 |
!
|
|
35 |
|
|
36 |
version
|
|
37 |
"
|
72
|
38 |
$Header: /cvs/stx/stx/libwidg2/Attic/FNmEdtFld.st,v 1.14 1995-09-07 12:47:59 claus Exp $
|
12
|
39 |
"
|
|
40 |
!
|
|
41 |
|
|
42 |
documentation
|
|
43 |
"
|
24
|
44 |
like a normal editField, but does filename-completion on the last word of
|
|
45 |
the contents, when TAB is pressed.
|
43
|
46 |
Filename completion ignores regular files if directoriesOnly is true,
|
|
47 |
and ignores directories, if filesOnly is true. Both default to false.
|
12
|
48 |
"
|
|
49 |
! !
|
|
50 |
|
72
|
51 |
!FilenameEditField class methodsFor:'defaults'!
|
34
|
52 |
|
72
|
53 |
filenameCompletionBlock
|
|
54 |
"return a block which can be used for fileName completion.
|
|
55 |
This has been extracted into a separate method, to allow reuse of
|
|
56 |
this code (for example, for use with regular editFields ..)"
|
67
|
57 |
|
72
|
58 |
^ [:field :inDirectory :directoriesOnly :filesOnly |
|
67
|
59 |
|s f matchSet nMatch name words dir|
|
|
60 |
|
72
|
61 |
s := field contents.
|
67
|
62 |
"
|
|
63 |
find the last word ...
|
|
64 |
"
|
|
65 |
words := s asCollectionOfWords.
|
|
66 |
f := words last asFilename.
|
72
|
67 |
f isAbsolute ifFalse:[
|
|
68 |
inDirectory asString ~= '.' ifTrue:[
|
|
69 |
f := (inDirectory name asFilename construct:f) name asFilename
|
|
70 |
].
|
|
71 |
].
|
|
72 |
f isAbsolute ifTrue:[
|
|
73 |
f := f pathName asFilename.
|
|
74 |
].
|
|
75 |
|
67
|
76 |
matchSet := f filenameCompletion.
|
|
77 |
dir := f directory.
|
72
|
78 |
|
67
|
79 |
directoriesOnly ifTrue:[
|
|
80 |
matchSet := matchSet select:[:aFilename |
|
|
81 |
(dir construct:aFilename) isDirectory
|
|
82 |
].
|
|
83 |
] ifFalse:[
|
|
84 |
filesOnly ifTrue:[
|
|
85 |
matchSet := matchSet select:[:aFilename |
|
|
86 |
(dir construct:aFilename) isDirectory not
|
|
87 |
].
|
|
88 |
]
|
|
89 |
].
|
|
90 |
|
|
91 |
(nMatch := matchSet size) ~~ 1 ifTrue:[
|
|
92 |
"
|
|
93 |
more than one possible completion -
|
|
94 |
"
|
72
|
95 |
field changed:#directory with:f directoryName.
|
|
96 |
field flash.
|
|
97 |
field device beep.
|
67
|
98 |
].
|
|
99 |
"
|
|
100 |
even with more than one possible completion,
|
|
101 |
f's name is now common prefix
|
|
102 |
"
|
|
103 |
name := f asString.
|
|
104 |
nMatch == 1 ifTrue:[
|
|
105 |
"
|
|
106 |
exactly one possible completion -
|
|
107 |
"
|
72
|
108 |
"/ f := dir construct:matchSet first.
|
|
109 |
f := matchSet first asFilename.
|
67
|
110 |
|
|
111 |
directoriesOnly ifTrue:[
|
|
112 |
name := f asString
|
|
113 |
] ifFalse:[
|
|
114 |
f isDirectory ifTrue:[
|
|
115 |
(name endsWith:(Filename separator)) ifFalse:[
|
72
|
116 |
name := f asString , '/'
|
67
|
117 |
].
|
|
118 |
].
|
|
119 |
]
|
|
120 |
].
|
|
121 |
"
|
|
122 |
construct new contents, by taking
|
|
123 |
last words completion
|
|
124 |
"
|
|
125 |
s := ''.
|
|
126 |
1 to:(words size - 1) do:[:idx |
|
|
127 |
s := s , (words at:idx) , ' '
|
|
128 |
].
|
|
129 |
s := s , name.
|
72
|
130 |
field contents:s.
|
|
131 |
field cursorToEndOfLine.
|
67
|
132 |
].
|
72
|
133 |
! !
|
|
134 |
|
|
135 |
!FilenameEditField methodsFor:'initialization'!
|
|
136 |
|
|
137 |
initialize
|
|
138 |
super initialize.
|
|
139 |
directoriesOnly := filesOnly := false.
|
|
140 |
directory := '.' asFilename.
|
|
141 |
|
|
142 |
entryCompletionBlock := [
|
|
143 |
self class
|
|
144 |
filenameCompletionBlock
|
|
145 |
value:self
|
|
146 |
value:directory
|
|
147 |
value:directoriesOnly
|
|
148 |
value:filesOnly
|
|
149 |
].
|
|
150 |
|
|
151 |
"Modified: 7.9.1995 / 10:20:46 / claus"
|
43
|
152 |
!
|
|
153 |
|
34
|
154 |
realize
|
|
155 |
"move the cursor to the end - thats the most interresting part of
|
|
156 |
a filename
|
|
157 |
"
|
|
158 |
super realize.
|
|
159 |
self cursorToEndOfLine.
|
|
160 |
! !
|
|
161 |
|
|
162 |
!FilenameEditField methodsFor:'accessing'!
|
|
163 |
|
72
|
164 |
directory
|
|
165 |
^ directory
|
|
166 |
|
|
167 |
"Modified: 7.9.1995 / 10:12:40 / claus"
|
|
168 |
!
|
|
169 |
|
|
170 |
directory:aFilename
|
|
171 |
directory := aFilename asFilename
|
|
172 |
|
|
173 |
"Modified: 7.9.1995 / 10:12:55 / claus"
|
|
174 |
!
|
|
175 |
|
|
176 |
showsDirectoriesOnly
|
|
177 |
"return if expanding names for directories only"
|
|
178 |
|
|
179 |
^ directoriesOnly
|
|
180 |
|
|
181 |
"Modified: 6.9.1995 / 20:35:30 / claus"
|
|
182 |
!
|
|
183 |
|
|
184 |
showsFilesOnly
|
|
185 |
"return if expanding names for files only"
|
|
186 |
|
|
187 |
^ filesOnly
|
|
188 |
|
|
189 |
"Modified: 6.9.1995 / 20:34:57 / claus"
|
|
190 |
!
|
|
191 |
|
43
|
192 |
directoriesOnly
|
|
193 |
"set to expand names for directories only"
|
|
194 |
|
|
195 |
directoriesOnly := true.
|
|
196 |
!
|
|
197 |
|
|
198 |
filesOnly
|
|
199 |
"set to expand names for files only"
|
|
200 |
|
|
201 |
filesOnly := true.
|
|
202 |
!
|
|
203 |
|
34
|
204 |
initialText:aString selected:aBoolean
|
|
205 |
"move the cursor to the end - thats the most interresting part of
|
|
206 |
a filename
|
|
207 |
"
|
|
208 |
|
|
209 |
super initialText:aString selected:aBoolean.
|
|
210 |
self cursorToEndOfLine.
|
|
211 |
! !
|
|
212 |
|
32
|
213 |
!FilenameEditField methodsFor:'event handling'!
|
12
|
214 |
|
|
215 |
keyPress:key x:x y:y
|
43
|
216 |
"handle tab for filename completion.
|
|
217 |
Bug: it completes the last word; it should complete the
|
|
218 |
word before the cursor."
|
12
|
219 |
|
64
|
220 |
<resource: #keyboard ( #FilenameCompletion ) >
|
|
221 |
|
12
|
222 |
enabled ifTrue:[
|
45
|
223 |
((key == #Tab)
|
43
|
224 |
or:[key == #FilenameCompletion]) ifTrue:[
|
67
|
225 |
entryCompletionBlock value.
|
25
|
226 |
^ self
|
67
|
227 |
]
|
12
|
228 |
].
|
|
229 |
^ super keyPress:key x:x y:y.
|
|
230 |
! !
|