author | Claus Gittinger <cg@exept.de> |
Thu, 17 Jan 2013 12:18:19 +0100 | |
changeset 12117 | d12665ccf213 |
parent 8798 | 7c48ce02da90 |
child 12401 | 4714b9640528 |
child 13956 | 70b04e6814ba |
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 |
"{ Package: 'stx:libtool' }" |
|
13 |
||
14 |
ComboBoxView subclass:#FilenameEditFieldV2 |
|
15 |
instanceVariableNames:'directoriesOnly filesOnly directory acceptOnExpand activeMenu |
|
16 |
completitionList' |
|
17 |
classVariableNames:'' |
|
18 |
poolDictionaries:'' |
|
19 |
category:'Interface-Tools-File' |
|
20 |
! |
|
21 |
||
22 |
!FilenameEditFieldV2 class methodsFor:'documentation'! |
|
23 |
||
24 |
copyright |
|
25 |
" |
|
5140 | 26 |
COPYRIGHT (c) 2002 by eXept Software AG |
27 |
All Rights Reserved |
|
4363 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
38 |
documentation |
|
39 |
" |
|
40 |
like a normal editField, but does filename-completion on the last word of |
|
41 |
the contents, when TAB is pressed. |
|
42 |
Filename completion ignores regular files if directoriesOnly is true, |
|
43 |
and ignores directories, if filesOnly is true. Both default to false. |
|
44 |
||
45 |
[author:] |
|
46 |
Claus Gittinger |
|
47 |
" |
|
48 |
! ! |
|
49 |
||
50 |
!FilenameEditFieldV2 methodsFor:'accessing'! |
|
51 |
||
52 |
acceptOnExpand |
|
53 |
"return the autoAccept on filename expansion flag. |
|
54 |
The default is true, which means that an expand accepts" |
|
55 |
||
56 |
^ acceptOnExpand |
|
57 |
! |
|
58 |
||
59 |
acceptOnExpand:aBoolean |
|
60 |
"set/clear autoAccept on filename expansion. |
|
61 |
The default is true, which means that an expand accepts" |
|
62 |
||
63 |
acceptOnExpand := aBoolean |
|
64 |
! |
|
65 |
||
66 |
contents:someText |
|
67 |
"redefined to add a trailing file-separator if the displayed |
|
68 |
filename is a directory" |
|
69 |
||
70 |
^ self |
|
71 |
contents:someText |
|
72 |
addSeparatorToDirectories:true |
|
73 |
! |
|
74 |
||
75 |
contents:someText addSeparatorToDirectories:doAddSeparator |
|
76 |
"optionally add a trailing file-separator if the displayed |
|
77 |
filename is a directory." |
|
78 |
||
79 |
|f n| |
|
80 |
||
81 |
n := someText. |
|
82 |
doAddSeparator ifTrue:[ |
|
83 |
directoriesOnly ifFalse:[ |
|
84 |
someText notNil ifTrue:[ |
|
85 |
f := someText asFilename. |
|
86 |
(f exists and:[f isDirectory]) ifTrue:[ |
|
87 |
(f name endsWith:f separator) ifFalse:[ |
|
88 |
n := f name copyWith:f separator |
|
89 |
] |
|
90 |
] |
|
91 |
]. |
|
92 |
]. |
|
93 |
]. |
|
94 |
super contents:n |
|
95 |
! |
|
96 |
||
97 |
directoriesOnly |
|
98 |
"set to expand names for directories only" |
|
99 |
||
100 |
directoriesOnly := true. |
|
101 |
! |
|
102 |
||
103 |
directory |
|
104 |
^ directory |
|
105 |
||
106 |
"Modified: 7.9.1995 / 10:12:40 / claus" |
|
107 |
! |
|
108 |
||
109 |
directory:aFilename |
|
110 |
aFilename isNil ifTrue:[ |
|
111 |
directory := Filename currentDirectory |
|
112 |
] ifFalse:[ |
|
113 |
directory := aFilename asFilename |
|
114 |
] |
|
115 |
"Modified: 7.9.1995 / 10:12:55 / claus" |
|
116 |
! |
|
117 |
||
118 |
filesOnly |
|
119 |
"set to expand names for files only" |
|
120 |
||
121 |
filesOnly := true. |
|
122 |
! |
|
123 |
||
124 |
initialText:aString selected:aBoolean |
|
125 |
"move the cursor to the end - thats the most interesting part of |
|
126 |
a filename |
|
127 |
" |
|
128 |
||
129 |
super initialText:aString selected:aBoolean. |
|
130 |
self cursorToEndOfLine. |
|
131 |
! |
|
132 |
||
133 |
showsDirectoriesOnly |
|
134 |
"return if expanding names for directories only" |
|
135 |
||
136 |
^ directoriesOnly |
|
137 |
||
138 |
"Modified: 6.9.1995 / 20:35:30 / claus" |
|
139 |
! |
|
140 |
||
141 |
showsFilesOnly |
|
142 |
"return if expanding names for files only" |
|
143 |
||
144 |
^ filesOnly |
|
145 |
||
146 |
"Modified: 6.9.1995 / 20:34:57 / claus" |
|
147 |
! ! |
|
148 |
||
149 |
!FilenameEditFieldV2 methodsFor:'initialization'! |
|
150 |
||
151 |
initialize |
|
4743 | 152 |
|myEditor| |
153 |
||
4363 | 154 |
super initialize. |
155 |
||
156 |
acceptOnExpand := true. |
|
157 |
directoriesOnly := filesOnly := false. |
|
158 |
directory := Filename currentDirectory. |
|
159 |
"/ self menuButton visibilityChannel:(false asValue). |
|
4743 | 160 |
myEditor := self editor. |
161 |
||
162 |
myEditor entryCompletionBlock: [:contents | |
|
4363 | 163 |
|newString isMultiMatch canonContents| |
164 |
||
165 |
isMultiMatch := false. |
|
166 |
canonContents := Filename canonicalize:contents. |
|
167 |
newString := Filename |
|
168 |
filenameCompletionFor:canonContents |
|
169 |
directory:directory |
|
170 |
directoriesOnly:directoriesOnly |
|
171 |
filesOnly:filesOnly |
|
172 |
ifMultiple:[:dir | ] |
|
4373 | 173 |
forMultipleDo:[:dir :matchSet | |
174 |
matchSet notEmpty ifTrue:[ |
|
4743 | 175 |
myEditor contents:dir name. |
4373 | 176 |
completitionList := matchSet asList. |
177 |
self action:[: string | | newFile | |
|
4530
d44a82caf67e
error on enter in ComboBoxList gets the items from the upper menues
penk
parents:
4373
diff
changeset
|
178 |
string isString ifTrue:[ |
d44a82caf67e
error on enter in ComboBoxList gets the items from the upper menues
penk
parents:
4373
diff
changeset
|
179 |
newFile := string asFilename. |
5012
47e675b8c9fe
removed unused keyPress method
Claus Gittinger <cg@exept.de>
parents:
4743
diff
changeset
|
180 |
(newFile exists and:[newFile isDirectory]) ifTrue:[ |
47e675b8c9fe
removed unused keyPress method
Claus Gittinger <cg@exept.de>
parents:
4743
diff
changeset
|
181 |
(newFile name endsWith:newFile separator) ifFalse:[ |
47e675b8c9fe
removed unused keyPress method
Claus Gittinger <cg@exept.de>
parents:
4743
diff
changeset
|
182 |
myEditor contents:(newFile name copyWith:newFile separator) |
47e675b8c9fe
removed unused keyPress method
Claus Gittinger <cg@exept.de>
parents:
4743
diff
changeset
|
183 |
]. |
4530
d44a82caf67e
error on enter in ComboBoxList gets the items from the upper menues
penk
parents:
4373
diff
changeset
|
184 |
]. |
d44a82caf67e
error on enter in ComboBoxList gets the items from the upper menues
penk
parents:
4373
diff
changeset
|
185 |
] |
4363 | 186 |
]. |
4373 | 187 |
self pullMenu. |
188 |
completitionList := nil. |
|
189 |
isMultiMatch := true. |
|
4363 | 190 |
]. |
191 |
]. |
|
6250
5b0673ccff1c
refactored intention revealing code:
Claus Gittinger <cg@exept.de>
parents:
6128
diff
changeset
|
192 |
isMultiMatch ifFalse:[ |
4363 | 193 |
newString asFilename pathName = canonContents ifTrue:[ |
194 |
[self flash] fork. |
|
195 |
]. |
|
196 |
||
197 |
self contents:newString addSeparatorToDirectories:isMultiMatch not. |
|
6446 | 198 |
myEditor cursorToEndOfLine. |
4363 | 199 |
] |
200 |
]. |
|
201 |
||
202 |
"Modified: 7.9.1995 / 10:20:46 / claus" |
|
203 |
"Modified: 7.9.1997 / 23:51:47 / cg" |
|
204 |
! |
|
205 |
||
206 |
realize |
|
6446 | 207 |
"move the cursor to the end - thats the most interesting part of a filename |
4363 | 208 |
" |
209 |
super realize. |
|
6446 | 210 |
self editor cursorToEndOfLine. |
4363 | 211 |
|
212 |
"Created: 24.7.1997 / 18:21:51 / cg" |
|
213 |
! ! |
|
214 |
||
215 |
!FilenameEditFieldV2 methodsFor:'menu'! |
|
216 |
||
217 |
processEvent:anEvent |
|
6128 | 218 |
"catch keyEvents in pulled menu (see redefined pullMenu-method). |
219 |
Return true, if I have eaten the event" |
|
220 |
||
12117 | 221 |
<resource: #keyboard (#BackSpace )> |
222 |
||
4363 | 223 |
activeMenu notNil ifTrue:[ |
224 |
anEvent isKeyPressEvent ifTrue:[ |
|
8798
7c48ce02da90
added: #handlesKeyPress:inView:
Claus Gittinger <cg@exept.de>
parents:
6446
diff
changeset
|
225 |
"/ typing into the pulled menu behaves like typing into the field |
7c48ce02da90
added: #handlesKeyPress:inView:
Claus Gittinger <cg@exept.de>
parents:
6446
diff
changeset
|
226 |
"/ followed by a TAB (to reopen the menu) |
7c48ce02da90
added: #handlesKeyPress:inView:
Claus Gittinger <cg@exept.de>
parents:
6446
diff
changeset
|
227 |
(anEvent key isCharacter |
7c48ce02da90
added: #handlesKeyPress:inView:
Claus Gittinger <cg@exept.de>
parents:
6446
diff
changeset
|
228 |
or:[ anEvent key == #BackSpace]) ifTrue:[ |
4363 | 229 |
"/ activeMenu windowGroup removePreEventHook:self. |
8798
7c48ce02da90
added: #handlesKeyPress:inView:
Claus Gittinger <cg@exept.de>
parents:
6446
diff
changeset
|
230 |
field dispatchEvent:anEvent. |
4363 | 231 |
|
232 |
WindowGroup leaveSignal raiseRequest. |
|
233 |
self error:'should not be reached'. |
|
8798
7c48ce02da90
added: #handlesKeyPress:inView:
Claus Gittinger <cg@exept.de>
parents:
6446
diff
changeset
|
234 |
]. |
4363 | 235 |
]. |
236 |
]. |
|
237 |
^ false. |
|
238 |
! |
|
239 |
||
240 |
pullMenu |
|
241 |
"pull the menu - triggered from the button" |
|
242 |
||
6104
8159f0753b92
no acceptOnLostFocus for editfield while menue is open
penk
parents:
5140
diff
changeset
|
243 |
|menu origin plug acceptOnLostFocus| |
4363 | 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. |
8798
7c48ce02da90
added: #handlesKeyPress:inView:
Claus Gittinger <cg@exept.de>
parents:
6446
diff
changeset
|
270 |
menu sensor addEventListener:self. |
4363 | 271 |
menu showAt:origin. |
6104
8159f0753b92
no acceptOnLostFocus for editfield while menue is open
penk
parents:
5140
diff
changeset
|
272 |
field acceptOnLostFocus:acceptOnLostFocus. |
4363 | 273 |
activeMenu := nil. |
274 |
pullDownButton turnOff. |
|
275 |
! ! |
|
276 |
||
277 |
!FilenameEditFieldV2 class methodsFor:'documentation'! |
|
278 |
||
279 |
version |
|
12117 | 280 |
^ '$Header: /cvs/stx/stx/libtool/FilenameEditFieldV2.st,v 1.14 2013-01-17 11:18:19 cg Exp $' |
4363 | 281 |
! ! |
12117 | 282 |