author | Claus Gittinger <cg@exept.de> |
Thu, 11 Nov 2004 10:13:06 +0100 | |
changeset 6128 | 14b9f89c457f |
parent 6104 | 8159f0753b92 |
child 6250 | 5b0673ccff1c |
permissions | -rw-r--r-- |
4363 | 1 |
" |
5140 | 2 |
COPYRIGHT (c) 2002 by eXept Software AG |
3 |
All Rights Reserved |
|
4363 | 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 |
" |
|
5140 | 27 |
COPYRIGHT (c) 2002 by eXept Software AG |
28 |
All Rights Reserved |
|
4363 | 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:'initialization'! |
|
151 |
||
152 |
initialize |
|
4743 | 153 |
|myEditor| |
154 |
||
4363 | 155 |
super initialize. |
156 |
||
157 |
acceptOnExpand := true. |
|
158 |
directoriesOnly := filesOnly := false. |
|
159 |
directory := Filename currentDirectory. |
|
160 |
"/ self menuButton visibilityChannel:(false asValue). |
|
4743 | 161 |
myEditor := self editor. |
162 |
||
163 |
myEditor entryCompletionBlock: [:contents | |
|
4363 | 164 |
|newString isMultiMatch canonContents| |
165 |
||
166 |
isMultiMatch := false. |
|
167 |
canonContents := Filename canonicalize:contents. |
|
168 |
newString := Filename |
|
169 |
filenameCompletionFor:canonContents |
|
170 |
directory:directory |
|
171 |
directoriesOnly:directoriesOnly |
|
172 |
filesOnly:filesOnly |
|
173 |
ifMultiple:[:dir | ] |
|
4373 | 174 |
forMultipleDo:[:dir :matchSet | |
175 |
matchSet notEmpty ifTrue:[ |
|
4743 | 176 |
myEditor contents:dir name. |
4373 | 177 |
completitionList := matchSet asList. |
178 |
self action:[: string | | newFile | |
|
4530
d44a82caf67e
error on enter in ComboBoxList gets the items from the upper menues
penk
parents:
4373
diff
changeset
|
179 |
string isString ifTrue:[ |
d44a82caf67e
error on enter in ComboBoxList gets the items from the upper menues
penk
parents:
4373
diff
changeset
|
180 |
newFile := string asFilename. |
5012
47e675b8c9fe
removed unused keyPress method
Claus Gittinger <cg@exept.de>
parents:
4743
diff
changeset
|
181 |
(newFile exists and:[newFile isDirectory]) ifTrue:[ |
47e675b8c9fe
removed unused keyPress method
Claus Gittinger <cg@exept.de>
parents:
4743
diff
changeset
|
182 |
(newFile name endsWith:newFile separator) ifFalse:[ |
47e675b8c9fe
removed unused keyPress method
Claus Gittinger <cg@exept.de>
parents:
4743
diff
changeset
|
183 |
myEditor contents:(newFile name copyWith:newFile separator) |
47e675b8c9fe
removed unused keyPress method
Claus Gittinger <cg@exept.de>
parents:
4743
diff
changeset
|
184 |
]. |
4530
d44a82caf67e
error on enter in ComboBoxList gets the items from the upper menues
penk
parents:
4373
diff
changeset
|
185 |
]. |
d44a82caf67e
error on enter in ComboBoxList gets the items from the upper menues
penk
parents:
4373
diff
changeset
|
186 |
] |
4363 | 187 |
]. |
4373 | 188 |
self pullMenu. |
189 |
completitionList := nil. |
|
190 |
isMultiMatch := true. |
|
4363 | 191 |
]. |
192 |
]. |
|
193 |
isMultiMatch not ifTrue:[ |
|
194 |
newString asFilename pathName = canonContents ifTrue:[ |
|
195 |
[self flash] fork. |
|
196 |
]. |
|
197 |
||
198 |
self contents:newString addSeparatorToDirectories:isMultiMatch not. |
|
199 |
self cursorToEndOfLine. |
|
200 |
] |
|
201 |
]. |
|
202 |
||
203 |
"Modified: 7.9.1995 / 10:20:46 / claus" |
|
204 |
"Modified: 7.9.1997 / 23:51:47 / cg" |
|
205 |
! |
|
206 |
||
207 |
realize |
|
208 |
"move the cursor to the end - thats the most interesting part of |
|
209 |
a filename |
|
210 |
" |
|
211 |
super realize. |
|
212 |
self cursorToEndOfLine. |
|
213 |
||
214 |
"Created: 24.7.1997 / 18:21:51 / cg" |
|
215 |
! ! |
|
216 |
||
217 |
!FilenameEditFieldV2 methodsFor:'menu'! |
|
218 |
||
219 |
processEvent:anEvent |
|
6128 | 220 |
"catch keyEvents in pulled menu (see redefined pullMenu-method). |
221 |
Return true, if I have eaten the event" |
|
222 |
||
4363 | 223 |
|
224 |
activeMenu notNil ifTrue:[ |
|
225 |
anEvent isKeyPressEvent ifTrue:[ |
|
226 |
anEvent key isCharacter ifTrue:[ |
|
227 |
"/ activeMenu windowGroup removePreEventHook:self. |
|
228 |
||
229 |
self windowGroup focusView:field. |
|
230 |
self windowGroup sensor pushEvent:anEvent. |
|
231 |
WindowGroup leaveSignal raiseRequest. |
|
232 |
self error:'should not be reached'. |
|
233 |
] |
|
234 |
]. |
|
235 |
]. |
|
236 |
^ false. |
|
237 |
! |
|
238 |
||
239 |
pullMenu |
|
240 |
"pull the menu - triggered from the button" |
|
241 |
||
6104
8159f0753b92
no acceptOnLostFocus for editfield while menue is open
penk
parents:
5140
diff
changeset
|
242 |
|menu origin plug acceptOnLostFocus| |
4363 | 243 |
|
244 |
||
245 |
completitionList notNil ifTrue:[ |
|
246 |
self list:completitionList |
|
247 |
] ifFalse:[ |
|
248 |
self list:(listHolder value collect:[:el| el path]). |
|
249 |
]. |
|
250 |
menu := self createPullDownMenuForList:list. |
|
251 |
||
252 |
menu backgroundColor:self editor backgroundColor. |
|
253 |
||
254 |
origin := device translatePoint:(0 @ self height) fromView:self toView:nil. |
|
255 |
||
256 |
"/ need a callBack when the menu becomes visible, to add an eventHook to |
|
257 |
"/ its windowGroup. |
|
258 |
"/ cannot do this here, since the windowgroup is created later and there is no other |
|
259 |
"/ callback or hook from modal views. |
|
260 |
||
261 |
menu addDependent:(plug := Plug new |
|
262 |
respondTo:#'update:with:from:' |
|
263 |
with:[:a :b :c | menu windowGroup notNil |
|
264 |
ifTrue:[menu windowGroup addPreEventHook:self]. |
|
265 |
menu removeDependent:plug]). |
|
266 |
activeMenu := menu. |
|
6104
8159f0753b92
no acceptOnLostFocus for editfield while menue is open
penk
parents:
5140
diff
changeset
|
267 |
"prevent editfield from acceptOnLostFocus events so no accept happen while menue is open" |
8159f0753b92
no acceptOnLostFocus for editfield while menue is open
penk
parents:
5140
diff
changeset
|
268 |
acceptOnLostFocus := field acceptOnLostFocus. |
8159f0753b92
no acceptOnLostFocus for editfield while menue is open
penk
parents:
5140
diff
changeset
|
269 |
field acceptOnLostFocus:false. |
4363 | 270 |
menu showAt:origin. |
6104
8159f0753b92
no acceptOnLostFocus for editfield while menue is open
penk
parents:
5140
diff
changeset
|
271 |
field acceptOnLostFocus:acceptOnLostFocus. |
4363 | 272 |
activeMenu := nil. |
273 |
pullDownButton turnOff. |
|
274 |
! ! |
|
275 |
||
276 |
!FilenameEditFieldV2 class methodsFor:'documentation'! |
|
277 |
||
278 |
version |
|
6128 | 279 |
^ '$Header: /cvs/stx/stx/libtool/FilenameEditFieldV2.st,v 1.10 2004-11-11 09:13:06 cg Exp $' |
4363 | 280 |
! ! |