4363
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
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 |
"{ Package: 'stx:libtool' }"
|
|
14 |
|
|
15 |
ComboBoxView subclass:#FilenameEditFieldV2
|
|
16 |
instanceVariableNames:'directoriesOnly filesOnly directory acceptOnExpand activeMenu
|
|
17 |
completitionList'
|
|
18 |
classVariableNames:''
|
|
19 |
poolDictionaries:''
|
|
20 |
category:'Interface-Tools-File'
|
|
21 |
!
|
|
22 |
|
|
23 |
!FilenameEditFieldV2 class methodsFor:'documentation'!
|
|
24 |
|
|
25 |
copyright
|
|
26 |
"
|
|
27 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
|
28 |
All Rights Reserved
|
|
29 |
|
|
30 |
This software is furnished under a license and may be used
|
|
31 |
only in accordance with the terms of that license and with the
|
|
32 |
inclusion of the above copyright notice. This software may not
|
|
33 |
be provided or otherwise made available to, or used by, any
|
|
34 |
other person. No title to or ownership of the software is
|
|
35 |
hereby transferred.
|
|
36 |
"
|
|
37 |
!
|
|
38 |
|
|
39 |
documentation
|
|
40 |
"
|
|
41 |
like a normal editField, but does filename-completion on the last word of
|
|
42 |
the contents, when TAB is pressed.
|
|
43 |
Filename completion ignores regular files if directoriesOnly is true,
|
|
44 |
and ignores directories, if filesOnly is true. Both default to false.
|
|
45 |
|
|
46 |
[author:]
|
|
47 |
Claus Gittinger
|
|
48 |
"
|
|
49 |
! !
|
|
50 |
|
|
51 |
!FilenameEditFieldV2 methodsFor:'accessing'!
|
|
52 |
|
|
53 |
acceptOnExpand
|
|
54 |
"return the autoAccept on filename expansion flag.
|
|
55 |
The default is true, which means that an expand accepts"
|
|
56 |
|
|
57 |
^ acceptOnExpand
|
|
58 |
!
|
|
59 |
|
|
60 |
acceptOnExpand:aBoolean
|
|
61 |
"set/clear autoAccept on filename expansion.
|
|
62 |
The default is true, which means that an expand accepts"
|
|
63 |
|
|
64 |
acceptOnExpand := aBoolean
|
|
65 |
!
|
|
66 |
|
|
67 |
contents:someText
|
|
68 |
"redefined to add a trailing file-separator if the displayed
|
|
69 |
filename is a directory"
|
|
70 |
|
|
71 |
^ self
|
|
72 |
contents:someText
|
|
73 |
addSeparatorToDirectories:true
|
|
74 |
!
|
|
75 |
|
|
76 |
contents:someText addSeparatorToDirectories:doAddSeparator
|
|
77 |
"optionally add a trailing file-separator if the displayed
|
|
78 |
filename is a directory."
|
|
79 |
|
|
80 |
|f n|
|
|
81 |
|
|
82 |
n := someText.
|
|
83 |
doAddSeparator ifTrue:[
|
|
84 |
directoriesOnly ifFalse:[
|
|
85 |
someText notNil ifTrue:[
|
|
86 |
f := someText asFilename.
|
|
87 |
(f exists and:[f isDirectory]) ifTrue:[
|
|
88 |
(f name endsWith:f separator) ifFalse:[
|
|
89 |
n := f name copyWith:f separator
|
|
90 |
]
|
|
91 |
]
|
|
92 |
].
|
|
93 |
].
|
|
94 |
].
|
|
95 |
super contents:n
|
|
96 |
!
|
|
97 |
|
|
98 |
directoriesOnly
|
|
99 |
"set to expand names for directories only"
|
|
100 |
|
|
101 |
directoriesOnly := true.
|
|
102 |
!
|
|
103 |
|
|
104 |
directory
|
|
105 |
^ directory
|
|
106 |
|
|
107 |
"Modified: 7.9.1995 / 10:12:40 / claus"
|
|
108 |
!
|
|
109 |
|
|
110 |
directory:aFilename
|
|
111 |
aFilename isNil ifTrue:[
|
|
112 |
directory := Filename currentDirectory
|
|
113 |
] ifFalse:[
|
|
114 |
directory := aFilename asFilename
|
|
115 |
]
|
|
116 |
"Modified: 7.9.1995 / 10:12:55 / claus"
|
|
117 |
!
|
|
118 |
|
|
119 |
filesOnly
|
|
120 |
"set to expand names for files only"
|
|
121 |
|
|
122 |
filesOnly := true.
|
|
123 |
!
|
|
124 |
|
|
125 |
initialText:aString selected:aBoolean
|
|
126 |
"move the cursor to the end - thats the most interesting part of
|
|
127 |
a filename
|
|
128 |
"
|
|
129 |
|
|
130 |
super initialText:aString selected:aBoolean.
|
|
131 |
self cursorToEndOfLine.
|
|
132 |
!
|
|
133 |
|
|
134 |
showsDirectoriesOnly
|
|
135 |
"return if expanding names for directories only"
|
|
136 |
|
|
137 |
^ directoriesOnly
|
|
138 |
|
|
139 |
"Modified: 6.9.1995 / 20:35:30 / claus"
|
|
140 |
!
|
|
141 |
|
|
142 |
showsFilesOnly
|
|
143 |
"return if expanding names for files only"
|
|
144 |
|
|
145 |
^ filesOnly
|
|
146 |
|
|
147 |
"Modified: 6.9.1995 / 20:34:57 / claus"
|
|
148 |
! !
|
|
149 |
|
|
150 |
!FilenameEditFieldV2 methodsFor:'event handling'!
|
|
151 |
|
|
152 |
keyPress:key x:x y:y
|
|
153 |
"handle tab for filename completion.
|
|
154 |
Bug: it completes the last word; it should complete the
|
|
155 |
word before the cursor."
|
|
156 |
|
|
157 |
<resource: #keyboard ( #Tab #FilenameCompletion ) >
|
|
158 |
|
|
159 |
|oldContents newContents|
|
|
160 |
|
|
161 |
self editor enabled ifTrue:[
|
|
162 |
((key == self editor entryCompletionCharacter)
|
|
163 |
or:[key == #FilenameCompletion]) ifTrue:[
|
|
164 |
oldContents := self contents.
|
|
165 |
oldContents isNil ifTrue:[
|
|
166 |
oldContents := ''
|
|
167 |
] ifFalse:[
|
|
168 |
oldContents := oldContents asString
|
|
169 |
].
|
|
170 |
self editor entryCompletionBlock value:oldContents.
|
|
171 |
|
|
172 |
newContents := self contents.
|
|
173 |
newContents isNil ifTrue:[
|
|
174 |
newContents := ''
|
|
175 |
] ifFalse:[
|
|
176 |
newContents := newContents asString
|
|
177 |
].
|
|
178 |
newContents ~= oldContents ifTrue:[
|
|
179 |
self textChanged.
|
|
180 |
acceptOnExpand ifTrue:[
|
|
181 |
self accept
|
|
182 |
]
|
|
183 |
].
|
|
184 |
^ self
|
|
185 |
] ifFalse:[
|
|
186 |
self list:nil.
|
|
187 |
pullDownButton turnOff.
|
|
188 |
]
|
|
189 |
].
|
|
190 |
^ super keyPress:key x:x y:y.
|
|
191 |
|
|
192 |
"Modified: 7.3.1996 / 13:16:49 / cg"
|
|
193 |
! !
|
|
194 |
|
|
195 |
!FilenameEditFieldV2 methodsFor:'initialization'!
|
|
196 |
|
|
197 |
initialize
|
|
198 |
super initialize.
|
|
199 |
|
|
200 |
acceptOnExpand := true.
|
|
201 |
directoriesOnly := filesOnly := false.
|
|
202 |
directory := Filename currentDirectory.
|
|
203 |
"/ self menuButton visibilityChannel:(false asValue).
|
|
204 |
self editor entryCompletionBlock: [:contents |
|
|
205 |
|newString isMultiMatch canonContents|
|
|
206 |
|
|
207 |
isMultiMatch := false.
|
|
208 |
canonContents := Filename canonicalize:contents.
|
|
209 |
newString := Filename
|
|
210 |
filenameCompletionFor:canonContents
|
|
211 |
directory:directory
|
|
212 |
directoriesOnly:directoriesOnly
|
|
213 |
filesOnly:filesOnly
|
|
214 |
ifMultiple:[:dir | ]
|
|
215 |
forMultipleDo:[:dir :matchSet |
|
|
216 |
completitionList := matchSet asList.
|
|
217 |
self action:[: string | | newFile |
|
|
218 |
newFile := string asFilename.
|
|
219 |
(newFile name endsWith:newFile separator) ifFalse:[
|
|
220 |
self editor contents:(newFile name copyWith:newFile separator)
|
|
221 |
].
|
|
222 |
].
|
|
223 |
self pullMenu.
|
|
224 |
completitionList := nil.
|
|
225 |
isMultiMatch := true.
|
|
226 |
].
|
|
227 |
isMultiMatch not ifTrue:[
|
|
228 |
newString asFilename pathName = canonContents ifTrue:[
|
|
229 |
[self flash] fork.
|
|
230 |
].
|
|
231 |
|
|
232 |
self contents:newString addSeparatorToDirectories:isMultiMatch not.
|
|
233 |
self cursorToEndOfLine.
|
|
234 |
]
|
|
235 |
].
|
|
236 |
|
|
237 |
"Modified: 7.9.1995 / 10:20:46 / claus"
|
|
238 |
"Modified: 7.9.1997 / 23:51:47 / cg"
|
|
239 |
!
|
|
240 |
|
|
241 |
realize
|
|
242 |
"move the cursor to the end - thats the most interesting part of
|
|
243 |
a filename
|
|
244 |
"
|
|
245 |
super realize.
|
|
246 |
self cursorToEndOfLine.
|
|
247 |
|
|
248 |
"Created: 24.7.1997 / 18:21:51 / cg"
|
|
249 |
! !
|
|
250 |
|
|
251 |
!FilenameEditFieldV2 methodsFor:'menu'!
|
|
252 |
|
|
253 |
processEvent:anEvent
|
|
254 |
"catch keyEvents in pulled menu (see redefined pullMenu-method)"
|
|
255 |
|
|
256 |
activeMenu notNil ifTrue:[
|
|
257 |
anEvent isKeyPressEvent ifTrue:[
|
|
258 |
anEvent key isCharacter ifTrue:[
|
|
259 |
"/ activeMenu windowGroup removePreEventHook:self.
|
|
260 |
|
|
261 |
self windowGroup focusView:field.
|
|
262 |
self windowGroup sensor pushEvent:anEvent.
|
|
263 |
WindowGroup leaveSignal raiseRequest.
|
|
264 |
self error:'should not be reached'.
|
|
265 |
]
|
|
266 |
].
|
|
267 |
].
|
|
268 |
^ false.
|
|
269 |
!
|
|
270 |
|
|
271 |
pullMenu
|
|
272 |
"pull the menu - triggered from the button"
|
|
273 |
|
|
274 |
|menu origin plug|
|
|
275 |
|
|
276 |
|
|
277 |
completitionList notNil ifTrue:[
|
|
278 |
self list:completitionList
|
|
279 |
] ifFalse:[
|
|
280 |
self list:(listHolder value collect:[:el| el path]).
|
|
281 |
].
|
|
282 |
menu := self createPullDownMenuForList:list.
|
|
283 |
|
|
284 |
menu backgroundColor:self editor backgroundColor.
|
|
285 |
|
|
286 |
origin := device translatePoint:(0 @ self height) fromView:self toView:nil.
|
|
287 |
|
|
288 |
"/ need a callBack when the menu becomes visible, to add an eventHook to
|
|
289 |
"/ its windowGroup.
|
|
290 |
"/ cannot do this here, since the windowgroup is created later and there is no other
|
|
291 |
"/ callback or hook from modal views.
|
|
292 |
|
|
293 |
menu addDependent:(plug := Plug new
|
|
294 |
respondTo:#'update:with:from:'
|
|
295 |
with:[:a :b :c | menu windowGroup notNil
|
|
296 |
ifTrue:[menu windowGroup addPreEventHook:self].
|
|
297 |
menu removeDependent:plug]).
|
|
298 |
activeMenu := menu.
|
|
299 |
menu showAt:origin.
|
|
300 |
activeMenu := nil.
|
|
301 |
pullDownButton turnOff.
|
|
302 |
! !
|
|
303 |
|
|
304 |
!FilenameEditFieldV2 class methodsFor:'documentation'!
|
|
305 |
|
|
306 |
version
|
4364
|
307 |
^ '$Header: /cvs/stx/stx/libtool/FilenameEditFieldV2.st,v 1.2 2002-12-11 15:23:55 penk Exp $'
|
4363
|
308 |
! !
|