author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Wed, 27 Feb 2013 12:34:59 +0000 | |
branch | jv |
changeset 12431 | 9f0c59c742d5 |
parent 12401 | 4714b9640528 |
child 12435 | 1f1faf35be04 |
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 |
|
208 |
||
209 |
focusEventsToIgnore > 0 ifTrue:[ |
|
210 |
focusEventsToIgnore := focusEventsToIgnore - 1. |
|
211 |
" |
|
212 |
xxx == 0 ifTrue:[ |
|
213 |
Transcript showCR:'--> taking focus'. |
|
214 |
self takeFocus. |
|
215 |
self assert: self windowGroup focusView == self. |
|
216 |
hadFocus := true. |
|
217 |
]. |
|
218 |
" |
|
219 |
^self]. |
|
220 |
||
221 |
hadFocus == aBoolean ifTrue:[ |
|
222 |
^self |
|
223 |
]. |
|
224 |
||
225 |
aBoolean |
|
226 |
ifTrue: |
|
227 |
[self selectAll] |
|
228 |
ifFalse: |
|
229 |
[self unselect. |
|
230 |
self hideOptionsWindow]. |
|
231 |
hadFocus := aBoolean. |
|
232 |
^ super hasKeyboardFocus:aBoolean |
|
233 |
||
234 |
"Created: / 08-08-2009 / 23:28:50 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
235 |
"Modified: / 09-08-2009 / 10:14:25 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
236 |
"Modified: / 09-12-2010 / 22:05:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
237 |
! |
|
238 |
||
239 |
keyPress:key x:x y:y |
|
12110
7231e996222a
changed: #keyPress:x:y:view:
Claus Gittinger <cg@exept.de>
parents:
10913
diff
changeset
|
240 |
"Forward certain events to optionsView if any" |
10025 | 241 |
|
12110
7231e996222a
changed: #keyPress:x:y:view:
Claus Gittinger <cg@exept.de>
parents:
10913
diff
changeset
|
242 |
<resource: #keyboard (#CursorDown #CursorUp #Accept #Return #Escape #BackSpace)> |
10025 | 243 |
|
244 |
(optionsView notNil and: |
|
245 |
[(#( #CursorDown #CursorUp ) includes:key)]) |
|
246 |
ifTrue:[^ optionsView keyPress:key x:x y:y]. |
|
247 |
||
248 |
key = #Accept ifTrue:[self hideOptionsWindow]. |
|
249 |
key = #Return ifTrue:[self hideOptionsWindow]. |
|
250 |
key = #Escape ifTrue:[self hideOptionsWindow]. |
|
251 |
key = #BackSpace ifTrue: |
|
252 |
[super |
|
12214
4b7eedbab2a7
- ChangeSetBrowser2: scroll to bottom after opening a changeset
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12128
diff
changeset
|
253 |
"/ keyPress:#Delete x:x y:y; |
10025 | 254 |
keyPress:#BackSpace x:x y:y. |
255 |
^ self startCompletion]. |
|
256 |
||
257 |
||
258 |
||
259 |
^ super |
|
260 |
keyPress:key |
|
261 |
x:x |
|
262 |
y:y |
|
263 |
||
264 |
"Created: / 08-08-2009 / 22:02:13 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
265 |
"Modified: / 09-08-2009 / 14:06:43 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
12214
4b7eedbab2a7
- ChangeSetBrowser2: scroll to bottom after opening a changeset
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12128
diff
changeset
|
266 |
"Modified: / 30-03-2012 / 17:34:40 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10025 | 267 |
! |
268 |
||
269 |
keyPress:key x:x y:y view:aView |
|
270 |
||
271 |
self keyPress: key x:x y:y |
|
272 |
||
273 |
"Created: / 09-12-2010 / 21:32:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
274 |
! ! |
|
275 |
||
276 |
!EditFieldWithCompletion methodsFor:'initialization & release'! |
|
277 |
||
278 |
destroy |
|
279 |
||
280 |
self hideOptionsWindow. |
|
281 |
super destroy. |
|
282 |
||
283 |
"Created: / 08-08-2009 / 22:16:17 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
284 |
"Modified: / 09-08-2009 / 08:50:04 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
285 |
! |
|
286 |
||
287 |
initialize |
|
288 |
||
289 |
super initialize. |
|
290 |
showOptions := true. |
|
291 |
optionsHolder := ValueHolder new. |
|
292 |
focusEventsToIgnore := 0. |
|
10443 | 293 |
completionJob := BackgroundJob |
294 |
named: 'Edit Field Completion Job' |
|
295 |
on:[self doCompletion]. |
|
10025 | 296 |
|
297 |
"Created: / 08-08-2009 / 20:24:05 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
298 |
"Modified: / 09-08-2009 / 08:17:09 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
10443 | 299 |
"Modified: / 03-08-2011 / 17:50:15 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10025 | 300 |
! ! |
301 |
||
302 |
!EditFieldWithCompletion methodsFor:'private'! |
|
303 |
||
304 |
doCompletion |
|
305 |
|oldContents options best| |
|
306 |
||
307 |
oldContents := (self contents ? '') asString. |
|
308 |
options := self entryCompletionBlock |
|
309 |
valueWithOptionalArgument:oldContents |
|
310 |
and:self. |
|
10885 | 311 |
options isNil ifTrue:[ |
312 |
^ self |
|
313 |
]. |
|
10025 | 314 |
best := options first. |
315 |
options := options second. |
|
10885 | 316 |
(options includes:best) ifFalse:[ |
317 |
best := options |
|
318 |
detect:[:e | e asString startsWith:best asString ] |
|
319 |
ifNone:[ best ] |
|
320 |
]. |
|
321 |
options isSortedCollection ifFalse:[ |
|
12236
8ec3d6230b65
- Tools::LintHighlighter
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12221
diff
changeset
|
322 |
options := options asSortedCollection:[:a :b | a displayString < b displayString ] |
10885 | 323 |
]. |
10025 | 324 |
self sensor |
10885 | 325 |
pushUserEvent:#completion:options: |
326 |
for:self |
|
327 |
withArguments:(Array with:best with:options). |
|
10025 | 328 |
|
329 |
"Created: / 26-07-2009 / 17:45:09 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
330 |
"Modified: / 09-08-2009 / 02:51:44 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
10885 | 331 |
"Modified: / 18-11-2011 / 14:33:56 / cg" |
332 |
"Modified (format): / 20-11-2011 / 09:42:25 / cg" |
|
12236
8ec3d6230b65
- Tools::LintHighlighter
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12221
diff
changeset
|
333 |
"Modified: / 20-04-2012 / 18:20:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10025 | 334 |
! |
335 |
||
336 |
hideOptionsWindow |
|
10913 | 337 |
optionsWindow notNil ifTrue:[ |
338 |
optionsWindow destroy. |
|
339 |
optionsWindow := nil. |
|
340 |
] |
|
10025 | 341 |
|
342 |
"Created: / 08-08-2009 / 23:23:45 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
343 |
"Modified: / 09-08-2009 / 09:00:00 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
10913 | 344 |
"Modified: / 29-11-2011 / 11:27:03 / cg" |
10025 | 345 |
! |
346 |
||
347 |
showOptionsWindow |
|
348 |
||
12221
413e98858ddc
- EditFieldWithCompletion
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12214
diff
changeset
|
349 |
| x y w | |
413e98858ddc
- EditFieldWithCompletion
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12214
diff
changeset
|
350 |
|
10025 | 351 |
showOptions ifFalse:[^ self]. |
10913 | 352 |
optionsWindow notNil ifTrue:[ ^ self ]. |
10025 | 353 |
|
354 |
optionsView := SelectionInListModelView new |
|
355 |
textStartLeft: textStartLeft - 2; |
|
356 |
listHolder: optionsHolder; |
|
357 |
action:[:value | self contents:value asString ]; |
|
10445 | 358 |
doubleClickAction:[:index | |
359 |
self contents:(optionsView at:index) asString. |
|
360 |
self hideOptionsWindow. |
|
361 |
self accept |
|
362 |
]; |
|
10025 | 363 |
useIndex: false; |
364 |
" JV: Looks good to me " |
|
365 |
highlightMode: #line; |
|
366 |
font:self font; |
|
367 |
backgroundColor:self backgroundColor; |
|
12221
413e98858ddc
- EditFieldWithCompletion
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12214
diff
changeset
|
368 |
delegate: self; |
413e98858ddc
- EditFieldWithCompletion
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12214
diff
changeset
|
369 |
yourself. |
413e98858ddc
- EditFieldWithCompletion
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12214
diff
changeset
|
370 |
|
413e98858ddc
- EditFieldWithCompletion
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12214
diff
changeset
|
371 |
x := self absoluteLeft + 5" - optionsView textStartLeft". |
413e98858ddc
- EditFieldWithCompletion
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12214
diff
changeset
|
372 |
y := self absoluteTop + self height + 1 + 5. |
413e98858ddc
- EditFieldWithCompletion
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12214
diff
changeset
|
373 |
w := (width * 2) + 0"((optionsView textStartLeft) * 2)". |
10025 | 374 |
|
375 |
optionsWindow := StandardSystemView new |
|
376 |
bePopUpView; |
|
377 |
beSlave; |
|
12221
413e98858ddc
- EditFieldWithCompletion
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12214
diff
changeset
|
378 |
origin:x @ y |
413e98858ddc
- EditFieldWithCompletion
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12214
diff
changeset
|
379 |
extent:(w min: (Screen current width - x)) @ (fontHeight * 10); |
413e98858ddc
- EditFieldWithCompletion
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12214
diff
changeset
|
380 |
yourself. |
10025 | 381 |
|
382 |
ScrollableView |
|
383 |
forView:optionsView |
|
384 |
hasHorizontalScrollBar:false |
|
385 |
hasVerticalScrollBar:true |
|
386 |
miniScrollerH:true |
|
387 |
miniScrollerV:false |
|
388 |
origin:0.0@0.0 |
|
389 |
corner:1.0@1.0 |
|
390 |
in:optionsWindow. |
|
391 |
||
392 |
focusEventsToIgnore := 4. |
|
393 |
optionsWindow open. |
|
394 |
||
395 |
"Created: / 09-08-2009 / 08:12:21 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
396 |
"Modified: / 09-08-2009 / 09:28:47 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
10913 | 397 |
"Modified: / 29-11-2011 / 11:27:13 / cg" |
12221
413e98858ddc
- EditFieldWithCompletion
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12214
diff
changeset
|
398 |
"Modified: / 04-04-2012 / 13:08:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10025 | 399 |
! |
400 |
||
401 |
startCompletion |
|
402 |
||
10443 | 403 |
completionJob restart. |
10025 | 404 |
|
405 |
"Created: / 26-07-2009 / 17:41:41 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
10443 | 406 |
"Modified (format): / 03-08-2011 / 17:50:53 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
10025 | 407 |
! ! |
408 |
||
409 |
!EditFieldWithCompletion class methodsFor:'documentation'! |
|
410 |
||
411 |
version_CVS |
|
12110
7231e996222a
changed: #keyPress:x:y:view:
Claus Gittinger <cg@exept.de>
parents:
10913
diff
changeset
|
412 |
^ '$Header: /cvs/stx/stx/libtool/EditFieldWithCompletion.st,v 1.6 2013-01-17 10:47:17 cg Exp $' |
10025 | 413 |
! |
414 |
||
12431
9f0c59c742d5
Added LintRuleSettingsApplication and LintRuleEditDialog to define user-defined rule sets.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12401
diff
changeset
|
415 |
version_HG |
9f0c59c742d5
Added LintRuleSettingsApplication and LintRuleEditDialog to define user-defined rule sets.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12401
diff
changeset
|
416 |
|
9f0c59c742d5
Added LintRuleSettingsApplication and LintRuleEditDialog to define user-defined rule sets.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12401
diff
changeset
|
417 |
^ '$Changeset: <not expanded> $' |
9f0c59c742d5
Added LintRuleSettingsApplication and LintRuleEditDialog to define user-defined rule sets.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12401
diff
changeset
|
418 |
! |
9f0c59c742d5
Added LintRuleSettingsApplication and LintRuleEditDialog to define user-defined rule sets.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12401
diff
changeset
|
419 |
|
10025 | 420 |
version_SVN |
421 |
^ '§Id: EditFieldWithCompletion.st 7662 2010-12-09 21:05:19Z vranyj1 §' |
|
422 |
! ! |
|
12110
7231e996222a
changed: #keyPress:x:y:view:
Claus Gittinger <cg@exept.de>
parents:
10913
diff
changeset
|
423 |