author | Claus Gittinger <cg@exept.de> |
Mon, 18 May 2015 16:49:06 +0200 | |
changeset 15642 | 239bbe1c7328 |
parent 14985 | 8c2d0c3191db |
child 15566 | 184cea584be5 |
child 16433 | 1d9bd92bc6a7 |
permissions | -rw-r--r-- |
10025 | 1 |
" |
2 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
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 |
"{ Package: 'stx:libtool' }" |
|
13 |
||
14 |
EditField subclass:#EditFieldWithCompletion |
|
15 |
instanceVariableNames:'showOptions optionsHolder optionsView optionsWindow |
|
10443 | 16 |
focusEventsToIgnore hadFocus completionJob' |
10025 | 17 |
classVariableNames:'' |
18 |
poolDictionaries:'' |
|
19 |
category:'Views-Text' |
|
20 |
! |
|
21 |
||
22 |
!EditFieldWithCompletion class methodsFor:'documentation'! |
|
23 |
||
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
27 |
All Rights Reserved |
|
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 |
documentation to be added. |
|
41 |
||
42 |
[author:] |
|
43 |
Jan Vrany (janfrog@bruxa) |
|
44 |
||
45 |
[instance variables:] |
|
46 |
||
47 |
[class variables:] |
|
48 |
||
49 |
[see also:] |
|
50 |
||
51 |
" |
|
52 |
! |
|
53 |
||
54 |
example_1 |
|
55 |
||
56 |
|top field label value| |
|
57 |
||
58 |
top := StandardSystemView new. |
|
59 |
top |
|
60 |
extent:300 @ 300; |
|
61 |
label:'Live class completion field'. |
|
62 |
value := '' asValue. |
|
63 |
field := (EditFieldWithCompletion new) |
|
64 |
origin:10 @ 135 corner:280 @ 165; |
|
65 |
entryCompletionBlock:[:content | Smalltalk classnameCompletion:content ]; |
|
66 |
model:value. |
|
67 |
label := (Label new) |
|
68 |
origin:10 @ 95 corner:280 @ 115; |
|
69 |
labelChannel:value. |
|
70 |
top |
|
71 |
add:field; |
|
72 |
add:label. |
|
73 |
top open |
|
74 |
! |
|
75 |
||
76 |
examples |
|
77 |
" |
|
78 |
Opens a LiveCompletionEditField on a class name |
|
79 |
[exBegin] |
|
80 |
LiveCompletionEditField example_1 |
|
81 |
[exEnd] |
|
82 |
" |
|
83 |
! ! |
|
84 |
||
85 |
!EditFieldWithCompletion methodsFor:'accepting'! |
|
86 |
||
87 |
accept |
|
88 |
||
89 |
self unselect. |
|
90 |
super accept. |
|
91 |
||
92 |
"Created: / 27-07-2009 / 09:38:45 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
93 |
"Modified: / 12-02-2010 / 11:56:33 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
94 |
! ! |
|
95 |
||
96 |
!EditFieldWithCompletion methodsFor:'accessing-behavior'! |
|
97 |
||
98 |
showOptions |
|
99 |
^ showOptions |
|
100 |
! |
|
101 |
||
102 |
showOptions:aBoolean |
|
103 |
showOptions := aBoolean. |
|
104 |
! ! |
|
105 |
||
106 |
!EditFieldWithCompletion methodsFor:'accessing-dimensions'! |
|
107 |
||
108 |
absoluteLeft |
|
109 |
||
110 |
| absoluteLeft view | |
|
111 |
absoluteLeft := 1. |
|
112 |
view := self. |
|
113 |
[ view notNil ] whileTrue: |
|
114 |
[absoluteLeft := absoluteLeft + view left - 1. |
|
115 |
view := view superView]. |
|
116 |
^absoluteLeft |
|
117 |
||
118 |
"Created: / 08-08-2009 / 22:30:07 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
119 |
! |
|
120 |
||
121 |
absoluteTop |
|
122 |
||
123 |
| absoluteTop view | |
|
124 |
absoluteTop := 1. |
|
125 |
view := self. |
|
126 |
[ view notNil ] whileTrue: |
|
127 |
[absoluteTop := absoluteTop + view top - 1. |
|
128 |
view := view superView]. |
|
129 |
^absoluteTop |
|
130 |
||
131 |
"Created: / 08-08-2009 / 22:30:16 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
132 |
! ! |
|
133 |
||
134 |
!EditFieldWithCompletion methodsFor:'accessing-mvc'! |
|
135 |
||
136 |
optionsHolder |
|
137 |
||
138 |
^ optionsHolder |
|
139 |
||
140 |
"Created: / 09-08-2009 / 08:14:02 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
141 |
! |
|
142 |
||
143 |
optionsHolder:aValueHolder |
|
144 |
"set the 'options' value holder (automatically generated)" |
|
145 |
||
146 |
optionsHolder := aValueHolder. |
|
147 |
||
148 |
"Created: / 09-08-2009 / 08:14:24 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
149 |
! ! |
|
150 |
||
151 |
!EditFieldWithCompletion methodsFor:'event handling'! |
|
152 |
||
153 |
completion:best options:options |
|
154 |
|newContent oldContent| |
|
155 |
" |
|
156 |
oldContent := ((self contents ? '') asString). |
|
157 |
newContent := ((best isNil or:[ best = oldContent ]) |
|
158 |
and:[ options isNilOrEmptyCollection not ]) |
|
159 |
ifTrue:[ |
|
160 |
options first |
|
161 |
""options inject:options anyOne |
|
162 |
into:[:shortest :each | |
|
163 |
shortest asString size > each asString size ifTrue:[ |
|
164 |
each |
|
165 |
] ifFalse:[ shortest ] |
|
166 |
]"" |
|
167 |
] |
|
168 |
ifFalse:[ best ]. |
|
169 |
self contents:newContent asString. |
|
170 |
self cursorCol:oldContent size + 1. |
|
171 |
oldContent size < newContent size ifTrue:[ |
|
172 |
self |
|
173 |
selectFromLine:1 |
|
174 |
col:oldContent size + 1 |
|
175 |
toLine:1 |
|
176 |
col:newContent size |
|
177 |
]. |
|
178 |
" |
|
179 |
options size > 1 ifTrue:[ |
|
180 |
optionsHolder value:options. |
|
181 |
self showOptionsWindow |
|
182 |
] |
|
183 |
||
184 |
"Created: / 08-08-2009 / 22:02:29 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
185 |
"Modified: / 09-08-2009 / 08:16:41 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
186 |
"Modified: / 13-02-2010 / 09:51:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
187 |
! |
|
188 |
||
189 |
handleNonCommandKey: char |
|
190 |
||
191 |
super handleNonCommandKey: char. |
|
192 |
self startCompletion |
|
193 |
||
194 |
"Modified: / 26-07-2009 / 17:41:22 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
195 |
! |
|
196 |
||
197 |
handlesKeyPress:key inView:aView |
|
198 |
||
12110
7231e996222a
changed: #keyPress:x:y:view:
Claus Gittinger <cg@exept.de>
parents:
10913
diff
changeset
|
199 |
<resource: #keyboard (#CursorDown #CursorUp)> |
7231e996222a
changed: #keyPress:x:y:view:
Claus Gittinger <cg@exept.de>
parents:
10913
diff
changeset
|
200 |
|
10025 | 201 |
^aView == optionsView and: |
202 |
[(#( #CursorDown #CursorUp ) includes: key) not]. |
|
203 |
||
204 |
"Created: / 09-12-2010 / 21:31:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
205 |
! |
|
206 |
||
207 |
hasKeyboardFocus:aBoolean |
|
14985
8c2d0c3191db
class: EditFieldWithCompletion
Claus Gittinger <cg@exept.de>
parents:
13871
diff
changeset
|
208 |
#todo. "/ @jan: please explain what you are doing here... |
10025 | 209 |
|
210 |
focusEventsToIgnore > 0 ifTrue:[ |
|
211 |
focusEventsToIgnore := focusEventsToIgnore - 1. |
|
212 |
" |
|
213 |
xxx == 0 ifTrue:[ |
|
214 |
Transcript showCR:'--> taking focus'. |
|
215 |
self takeFocus. |
|
216 |
self assert: self windowGroup focusView == self. |
|
217 |
hadFocus := true. |
|
218 |
]. |
|
219 |
" |
|
220 |
^self]. |
|
221 |
||
222 |
hadFocus == aBoolean ifTrue:[ |
|
223 |
^self |
|
224 |
]. |
|
225 |
||
226 |
aBoolean |
|
227 |
ifTrue: |
|
228 |
[self selectAll] |
|
229 |
ifFalse: |
|
230 |
[self unselect. |
|
231 |
self hideOptionsWindow]. |
|
232 |
hadFocus := aBoolean. |
|
233 |
^ super hasKeyboardFocus:aBoolean |
|
234 |
||
235 |
"Created: / 08-08-2009 / 23:28:50 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
236 |
"Modified: / 09-08-2009 / 10:14:25 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
237 |
"Modified: / 09-12-2010 / 22:05:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
238 |
! |
|
239 |
||
240 |
keyPress:key x:x y:y |
|
12110
7231e996222a
changed: #keyPress:x:y:view:
Claus Gittinger <cg@exept.de>
parents:
10913
diff
changeset
|
241 |
"Forward certain events to optionsView if any" |
10025 | 242 |
|
12389
83d4d24d847c
class: EditFieldWithCompletion
Stefan Vogel <sv@exept.de>
parents:
12110
diff
changeset
|
243 |
<resource: #keyboard (#CursorDown #CursorUp #Accept #Return #Escape #BackSpace #Delete)> |
10025 | 244 |
|
12389
83d4d24d847c
class: EditFieldWithCompletion
Stefan Vogel <sv@exept.de>
parents:
12110
diff
changeset
|
245 |
(optionsView notNil |
83d4d24d847c
class: EditFieldWithCompletion
Stefan Vogel <sv@exept.de>
parents:
12110
diff
changeset
|
246 |
and:[#(CursorDown CursorUp) includes:key]) ifTrue:[ |
83d4d24d847c
class: EditFieldWithCompletion
Stefan Vogel <sv@exept.de>
parents:
12110
diff
changeset
|
247 |
optionsView keyPress:key x:x y:y. |
83d4d24d847c
class: EditFieldWithCompletion
Stefan Vogel <sv@exept.de>
parents:
12110
diff
changeset
|
248 |
^ self. |
83d4d24d847c
class: EditFieldWithCompletion
Stefan Vogel <sv@exept.de>
parents:
12110
diff
changeset
|
249 |
]. |
10025 | 250 |
|
251 |
key = #Accept ifTrue:[self hideOptionsWindow]. |
|
252 |
key = #Return ifTrue:[self hideOptionsWindow]. |
|
253 |
key = #Escape ifTrue:[self hideOptionsWindow]. |
|
12389
83d4d24d847c
class: EditFieldWithCompletion
Stefan Vogel <sv@exept.de>
parents:
12110
diff
changeset
|
254 |
(key = #BackSpace or:[key = #Delete]) ifTrue:[ |
83d4d24d847c
class: EditFieldWithCompletion
Stefan Vogel <sv@exept.de>
parents:
12110
diff
changeset
|
255 |
super keyPress:key x:x y:y. |
83d4d24d847c
class: EditFieldWithCompletion
Stefan Vogel <sv@exept.de>
parents:
12110
diff
changeset
|
256 |
self startCompletion. |
83d4d24d847c
class: EditFieldWithCompletion
Stefan Vogel <sv@exept.de>
parents:
12110
diff
changeset
|
257 |
^ self. |
83d4d24d847c
class: EditFieldWithCompletion
Stefan Vogel <sv@exept.de>
parents:
12110
diff
changeset
|
258 |
]. |
10025 | 259 |
|
12389
83d4d24d847c
class: EditFieldWithCompletion
Stefan Vogel <sv@exept.de>
parents:
12110
diff
changeset
|
260 |
super keyPress:key x:x y:y |
10025 | 261 |
|
262 |
"Created: / 08-08-2009 / 22:02:13 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
263 |
"Modified: / 09-08-2009 / 14:06:43 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
264 |
"Modified: / 09-02-2010 / 20:47:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
265 |
! |
|
266 |
||
267 |
keyPress:key x:x y:y view:aView |
|
268 |
||
269 |
self keyPress: key x:x y:y |
|
270 |
||
271 |
"Created: / 09-12-2010 / 21:32:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
272 |
! ! |
|
273 |
||
274 |
!EditFieldWithCompletion methodsFor:'initialization & release'! |
|
275 |
||
276 |
destroy |
|
277 |
||
278 |
self hideOptionsWindow. |
|
279 |
super destroy. |
|
280 |
||
281 |
"Created: / 08-08-2009 / 22:16:17 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
282 |
"Modified: / 09-08-2009 / 08:50:04 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
283 |
! |
|
284 |
||
285 |
initialize |
|
286 |
||
287 |
super initialize. |
|
288 |
showOptions := true. |
|
289 |
optionsHolder := ValueHolder new. |
|
290 |
focusEventsToIgnore := 0. |
|
10443 | 291 |
completionJob := BackgroundJob |
292 |
named: 'Edit Field Completion Job' |
|
293 |
on:[self doCompletion]. |
|
10025 | 294 |
|
295 |
"Created: / 08-08-2009 / 20:24:05 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
296 |
"Modified: / 09-08-2009 / 08:17:09 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
10443 | 297 |
"Modified: / 03-08-2011 / 17:50:15 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10025 | 298 |
! ! |
299 |
||
300 |
!EditFieldWithCompletion methodsFor:'private'! |
|
301 |
||
302 |
doCompletion |
|
303 |
|oldContents options best| |
|
304 |
||
305 |
oldContents := (self contents ? '') asString. |
|
306 |
options := self entryCompletionBlock |
|
307 |
valueWithOptionalArgument:oldContents |
|
308 |
and:self. |
|
10885 | 309 |
options isNil ifTrue:[ |
310 |
^ self |
|
311 |
]. |
|
10025 | 312 |
best := options first. |
313 |
options := options second. |
|
10885 | 314 |
(options includes:best) ifFalse:[ |
315 |
best := options |
|
316 |
detect:[:e | e asString startsWith:best asString ] |
|
317 |
ifNone:[ best ] |
|
318 |
]. |
|
319 |
options isSortedCollection ifFalse:[ |
|
13871 | 320 |
options := options asSortedCollection:[:a :b | a displayString < b displayString ] |
10885 | 321 |
]. |
10025 | 322 |
self sensor |
10885 | 323 |
pushUserEvent:#completion:options: |
324 |
for:self |
|
325 |
withArguments:(Array with:best with:options). |
|
10025 | 326 |
|
327 |
"Created: / 26-07-2009 / 17:45:09 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
328 |
"Modified: / 09-08-2009 / 02:51:44 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
10885 | 329 |
"Modified: / 18-11-2011 / 14:33:56 / cg" |
330 |
"Modified (format): / 20-11-2011 / 09:42:25 / cg" |
|
13871 | 331 |
"Modified: / 20-04-2012 / 18:20:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10025 | 332 |
! |
333 |
||
334 |
hideOptionsWindow |
|
10913 | 335 |
optionsWindow notNil ifTrue:[ |
336 |
optionsWindow destroy. |
|
337 |
optionsWindow := nil. |
|
338 |
] |
|
10025 | 339 |
|
340 |
"Created: / 08-08-2009 / 23:23:45 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
341 |
"Modified: / 09-08-2009 / 09:00:00 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
10913 | 342 |
"Modified: / 29-11-2011 / 11:27:03 / cg" |
10025 | 343 |
! |
344 |
||
345 |
showOptionsWindow |
|
346 |
||
13871 | 347 |
| x y w | |
348 |
||
10025 | 349 |
showOptions ifFalse:[^ self]. |
10913 | 350 |
optionsWindow notNil ifTrue:[ ^ self ]. |
10025 | 351 |
|
352 |
optionsView := SelectionInListModelView new |
|
353 |
textStartLeft: textStartLeft - 2; |
|
354 |
listHolder: optionsHolder; |
|
355 |
action:[:value | self contents:value asString ]; |
|
10445 | 356 |
doubleClickAction:[:index | |
357 |
self contents:(optionsView at:index) asString. |
|
358 |
self hideOptionsWindow. |
|
359 |
self accept |
|
360 |
]; |
|
10025 | 361 |
useIndex: false; |
362 |
" JV: Looks good to me " |
|
363 |
highlightMode: #line; |
|
364 |
font:self font; |
|
365 |
backgroundColor:self backgroundColor; |
|
13871 | 366 |
delegate: self; |
367 |
yourself. |
|
368 |
||
369 |
x := self absoluteLeft + 5" - optionsView textStartLeft". |
|
370 |
y := self absoluteTop + self height + 1 + 5. |
|
371 |
w := (width * 2) + 0"((optionsView textStartLeft) * 2)". |
|
10025 | 372 |
|
373 |
optionsWindow := StandardSystemView new |
|
374 |
bePopUpView; |
|
375 |
beSlave; |
|
13871 | 376 |
origin:x @ y |
377 |
extent:(w min: (Screen current width - x)) @ (fontHeight * 10); |
|
378 |
yourself. |
|
10025 | 379 |
|
380 |
ScrollableView |
|
381 |
forView:optionsView |
|
382 |
hasHorizontalScrollBar:false |
|
383 |
hasVerticalScrollBar:true |
|
384 |
miniScrollerH:true |
|
385 |
miniScrollerV:false |
|
386 |
origin:0.0@0.0 |
|
387 |
corner:1.0@1.0 |
|
388 |
in:optionsWindow. |
|
389 |
||
390 |
focusEventsToIgnore := 4. |
|
391 |
optionsWindow open. |
|
392 |
||
393 |
"Created: / 09-08-2009 / 08:12:21 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
394 |
"Modified: / 09-08-2009 / 09:28:47 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
10913 | 395 |
"Modified: / 29-11-2011 / 11:27:13 / cg" |
13871 | 396 |
"Modified: / 04-04-2012 / 13:08:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10025 | 397 |
! |
398 |
||
399 |
startCompletion |
|
400 |
||
10443 | 401 |
completionJob restart. |
10025 | 402 |
|
403 |
"Created: / 26-07-2009 / 17:41:41 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
10443 | 404 |
"Modified (format): / 03-08-2011 / 17:50:53 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10025 | 405 |
! ! |
406 |
||
407 |
!EditFieldWithCompletion class methodsFor:'documentation'! |
|
408 |
||
409 |
version_CVS |
|
14985
8c2d0c3191db
class: EditFieldWithCompletion
Claus Gittinger <cg@exept.de>
parents:
13871
diff
changeset
|
410 |
^ '$Header: /cvs/stx/stx/libtool/EditFieldWithCompletion.st,v 1.9 2014-12-03 23:37:48 cg Exp $' |
10025 | 411 |
! |
412 |
||
413 |
version_SVN |
|
14985
8c2d0c3191db
class: EditFieldWithCompletion
Claus Gittinger <cg@exept.de>
parents:
13871
diff
changeset
|
414 |
^ '$Id: EditFieldWithCompletion.st,v 1.9 2014-12-03 23:37:48 cg Exp $' |
10025 | 415 |
! ! |
12110
7231e996222a
changed: #keyPress:x:y:view:
Claus Gittinger <cg@exept.de>
parents:
10913
diff
changeset
|
416 |