author | penk |
Fri, 07 Feb 2003 10:47:14 +0100 | |
changeset 4530 | d44a82caf67e |
parent 4373 | 7db8da324742 |
child 4628 | 8c6fe703d40c |
permissions | -rw-r--r-- |
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 | ] |
|
4373 | 215 |
forMultipleDo:[:dir :matchSet | |
216 |
matchSet notEmpty ifTrue:[ |
|
217 |
self editor contents:dir name. |
|
218 |
completitionList := matchSet asList. |
|
219 |
self action:[: string | | newFile | |
|
4530
d44a82caf67e
error on enter in ComboBoxList gets the items from the upper menues
penk
parents:
4373
diff
changeset
|
220 |
string isString ifTrue:[ |
d44a82caf67e
error on enter in ComboBoxList gets the items from the upper menues
penk
parents:
4373
diff
changeset
|
221 |
newFile := string asFilename. |
d44a82caf67e
error on enter in ComboBoxList gets the items from the upper menues
penk
parents:
4373
diff
changeset
|
222 |
(newFile name endsWith:newFile separator) ifFalse:[ |
d44a82caf67e
error on enter in ComboBoxList gets the items from the upper menues
penk
parents:
4373
diff
changeset
|
223 |
self editor contents:(newFile name copyWith:newFile separator) |
d44a82caf67e
error on enter in ComboBoxList gets the items from the upper menues
penk
parents:
4373
diff
changeset
|
224 |
]. |
d44a82caf67e
error on enter in ComboBoxList gets the items from the upper menues
penk
parents:
4373
diff
changeset
|
225 |
] |
4363 | 226 |
]. |
4373 | 227 |
self pullMenu. |
228 |
completitionList := nil. |
|
229 |
isMultiMatch := true. |
|
4363 | 230 |
]. |
231 |
]. |
|
232 |
isMultiMatch not ifTrue:[ |
|
233 |
newString asFilename pathName = canonContents ifTrue:[ |
|
234 |
[self flash] fork. |
|
235 |
]. |
|
236 |
||
237 |
self contents:newString addSeparatorToDirectories:isMultiMatch not. |
|
238 |
self cursorToEndOfLine. |
|
239 |
] |
|
240 |
]. |
|
241 |
||
242 |
"Modified: 7.9.1995 / 10:20:46 / claus" |
|
243 |
"Modified: 7.9.1997 / 23:51:47 / cg" |
|
244 |
! |
|
245 |
||
246 |
realize |
|
247 |
"move the cursor to the end - thats the most interesting part of |
|
248 |
a filename |
|
249 |
" |
|
250 |
super realize. |
|
251 |
self cursorToEndOfLine. |
|
252 |
||
253 |
"Created: 24.7.1997 / 18:21:51 / cg" |
|
254 |
! ! |
|
255 |
||
256 |
!FilenameEditFieldV2 methodsFor:'menu'! |
|
257 |
||
258 |
processEvent:anEvent |
|
259 |
"catch keyEvents in pulled menu (see redefined pullMenu-method)" |
|
260 |
||
261 |
activeMenu notNil ifTrue:[ |
|
262 |
anEvent isKeyPressEvent ifTrue:[ |
|
263 |
anEvent key isCharacter ifTrue:[ |
|
264 |
"/ activeMenu windowGroup removePreEventHook:self. |
|
265 |
||
266 |
self windowGroup focusView:field. |
|
267 |
self windowGroup sensor pushEvent:anEvent. |
|
268 |
WindowGroup leaveSignal raiseRequest. |
|
269 |
self error:'should not be reached'. |
|
270 |
] |
|
271 |
]. |
|
272 |
]. |
|
273 |
^ false. |
|
274 |
! |
|
275 |
||
276 |
pullMenu |
|
277 |
"pull the menu - triggered from the button" |
|
278 |
||
279 |
|menu origin plug| |
|
280 |
||
281 |
||
282 |
completitionList notNil ifTrue:[ |
|
283 |
self list:completitionList |
|
284 |
] ifFalse:[ |
|
285 |
self list:(listHolder value collect:[:el| el path]). |
|
286 |
]. |
|
287 |
menu := self createPullDownMenuForList:list. |
|
288 |
||
289 |
menu backgroundColor:self editor backgroundColor. |
|
290 |
||
291 |
origin := device translatePoint:(0 @ self height) fromView:self toView:nil. |
|
292 |
||
293 |
"/ need a callBack when the menu becomes visible, to add an eventHook to |
|
294 |
"/ its windowGroup. |
|
295 |
"/ cannot do this here, since the windowgroup is created later and there is no other |
|
296 |
"/ callback or hook from modal views. |
|
297 |
||
298 |
menu addDependent:(plug := Plug new |
|
299 |
respondTo:#'update:with:from:' |
|
300 |
with:[:a :b :c | menu windowGroup notNil |
|
301 |
ifTrue:[menu windowGroup addPreEventHook:self]. |
|
302 |
menu removeDependent:plug]). |
|
303 |
activeMenu := menu. |
|
304 |
menu showAt:origin. |
|
305 |
activeMenu := nil. |
|
306 |
pullDownButton turnOff. |
|
307 |
! ! |
|
308 |
||
309 |
!FilenameEditFieldV2 class methodsFor:'documentation'! |
|
310 |
||
311 |
version |
|
4530
d44a82caf67e
error on enter in ComboBoxList gets the items from the upper menues
penk
parents:
4373
diff
changeset
|
312 |
^ '$Header: /cvs/stx/stx/libtool/FilenameEditFieldV2.st,v 1.4 2003-02-07 09:47:14 penk Exp $' |
4363 | 313 |
! ! |