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 |
|
|
199 |
^aView == optionsView and:
|
|
200 |
[(#( #CursorDown #CursorUp ) includes: key) not].
|
|
201 |
|
|
202 |
"Created: / 09-12-2010 / 21:31:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
203 |
!
|
|
204 |
|
|
205 |
hasKeyboardFocus:aBoolean
|
|
206 |
|
|
207 |
focusEventsToIgnore > 0 ifTrue:[
|
|
208 |
focusEventsToIgnore := focusEventsToIgnore - 1.
|
|
209 |
"
|
|
210 |
xxx == 0 ifTrue:[
|
|
211 |
Transcript showCR:'--> taking focus'.
|
|
212 |
self takeFocus.
|
|
213 |
self assert: self windowGroup focusView == self.
|
|
214 |
hadFocus := true.
|
|
215 |
].
|
|
216 |
"
|
|
217 |
^self].
|
|
218 |
|
|
219 |
hadFocus == aBoolean ifTrue:[
|
|
220 |
^self
|
|
221 |
].
|
|
222 |
|
|
223 |
aBoolean
|
|
224 |
ifTrue:
|
|
225 |
[self selectAll]
|
|
226 |
ifFalse:
|
|
227 |
[self unselect.
|
|
228 |
self hideOptionsWindow].
|
|
229 |
hadFocus := aBoolean.
|
|
230 |
^ super hasKeyboardFocus:aBoolean
|
|
231 |
|
|
232 |
"Created: / 08-08-2009 / 23:28:50 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
233 |
"Modified: / 09-08-2009 / 10:14:25 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
234 |
"Modified: / 09-12-2010 / 22:05:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
235 |
!
|
|
236 |
|
|
237 |
keyPress:key x:x y:y
|
|
238 |
|
|
239 |
"Forward certain events to optionsView if any"
|
|
240 |
|
|
241 |
(optionsView notNil and:
|
|
242 |
[(#( #CursorDown #CursorUp ) includes:key)])
|
|
243 |
ifTrue:[^ optionsView keyPress:key x:x y:y].
|
|
244 |
|
|
245 |
key = #Accept ifTrue:[self hideOptionsWindow].
|
|
246 |
key = #Return ifTrue:[self hideOptionsWindow].
|
|
247 |
key = #Escape ifTrue:[self hideOptionsWindow].
|
|
248 |
key = #BackSpace ifTrue:
|
|
249 |
[super
|
|
250 |
keyPress:#Delete x:x y:y;
|
|
251 |
keyPress:#BackSpace x:x y:y.
|
|
252 |
^ self startCompletion].
|
|
253 |
|
|
254 |
|
|
255 |
|
|
256 |
^ super
|
|
257 |
keyPress:key
|
|
258 |
x:x
|
|
259 |
y:y
|
|
260 |
|
|
261 |
"Created: / 08-08-2009 / 22:02:13 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
262 |
"Modified: / 09-08-2009 / 14:06:43 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
263 |
"Modified: / 09-02-2010 / 20:47:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
264 |
!
|
|
265 |
|
|
266 |
keyPress:key x:x y:y view:aView
|
|
267 |
|
|
268 |
self keyPress: key x:x y:y
|
|
269 |
|
|
270 |
"Created: / 09-12-2010 / 21:32:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
271 |
! !
|
|
272 |
|
|
273 |
!EditFieldWithCompletion methodsFor:'initialization & release'!
|
|
274 |
|
|
275 |
destroy
|
|
276 |
|
|
277 |
self hideOptionsWindow.
|
|
278 |
super destroy.
|
|
279 |
|
|
280 |
"Created: / 08-08-2009 / 22:16:17 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
281 |
"Modified: / 09-08-2009 / 08:50:04 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
282 |
!
|
|
283 |
|
|
284 |
initialize
|
|
285 |
|
|
286 |
super initialize.
|
|
287 |
showOptions := true.
|
|
288 |
optionsHolder := ValueHolder new.
|
|
289 |
focusEventsToIgnore := 0.
|
10443
|
290 |
completionJob := BackgroundJob
|
|
291 |
named: 'Edit Field Completion Job'
|
|
292 |
on:[self doCompletion].
|
10025
|
293 |
|
|
294 |
"Created: / 08-08-2009 / 20:24:05 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
295 |
"Modified: / 09-08-2009 / 08:17:09 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
10443
|
296 |
"Modified: / 03-08-2011 / 17:50:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
10025
|
297 |
! !
|
|
298 |
|
|
299 |
!EditFieldWithCompletion methodsFor:'private'!
|
|
300 |
|
|
301 |
doCompletion
|
|
302 |
|oldContents options best|
|
|
303 |
|
|
304 |
oldContents := (self contents ? '') asString.
|
|
305 |
options := self entryCompletionBlock
|
|
306 |
valueWithOptionalArgument:oldContents
|
|
307 |
and:self.
|
|
308 |
options ifNil:[ ^ self ].
|
|
309 |
best := options first.
|
|
310 |
options := options second.
|
|
311 |
(options includes: best) ifFalse:
|
|
312 |
[best := options detect:[:e|e asString startsWith: best asString] ifNone:[best]].
|
|
313 |
options isSortedCollection ifFalse:
|
|
314 |
[options := options asSortedCollection:
|
|
315 |
[:a :b|a asString < b asString]].
|
|
316 |
self sensor
|
|
317 |
pushUserEvent: #completion:options: for: self
|
|
318 |
withArguments: (Array with: best with: options).
|
|
319 |
|
|
320 |
"Created: / 26-07-2009 / 17:45:09 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
321 |
"Modified: / 09-08-2009 / 02:51:44 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
322 |
"Modified: / 09-02-2010 / 20:46:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
323 |
!
|
|
324 |
|
|
325 |
hideOptionsWindow
|
|
326 |
optionsWindow
|
|
327 |
ifNotNil:[
|
|
328 |
optionsWindow destroy.
|
|
329 |
optionsWindow := nil.
|
|
330 |
]
|
|
331 |
|
|
332 |
"Created: / 08-08-2009 / 23:23:45 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
333 |
"Modified: / 09-08-2009 / 09:00:00 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
334 |
!
|
|
335 |
|
|
336 |
showOptionsWindow
|
|
337 |
|
|
338 |
showOptions ifFalse:[^ self].
|
|
339 |
optionsWindow ifNotNil:[ ^ self ].
|
|
340 |
|
|
341 |
optionsView := SelectionInListModelView new
|
|
342 |
textStartLeft: textStartLeft - 2;
|
|
343 |
listHolder: optionsHolder;
|
|
344 |
action:[:value | self contents:value asString ];
|
10445
|
345 |
doubleClickAction:[:index |
|
|
346 |
self contents:(optionsView at:index) asString.
|
|
347 |
self hideOptionsWindow.
|
|
348 |
self accept
|
|
349 |
];
|
10025
|
350 |
useIndex: false;
|
|
351 |
" JV: Looks good to me "
|
|
352 |
highlightMode: #line;
|
|
353 |
font:self font;
|
|
354 |
backgroundColor:self backgroundColor;
|
|
355 |
delegate: self.
|
|
356 |
|
|
357 |
optionsWindow := StandardSystemView new
|
|
358 |
bePopUpView;
|
|
359 |
beSlave;
|
|
360 |
origin:(self absoluteLeft + 5" - optionsView textStartLeft")
|
|
361 |
@ (self absoluteTop + self height + 1 + 5)
|
|
362 |
extent:(width + 0"((optionsView textStartLeft) * 2)") @ (fontHeight * 10).
|
|
363 |
|
|
364 |
ScrollableView
|
|
365 |
forView:optionsView
|
|
366 |
hasHorizontalScrollBar:false
|
|
367 |
hasVerticalScrollBar:true
|
|
368 |
miniScrollerH:true
|
|
369 |
miniScrollerV:false
|
|
370 |
origin:0.0@0.0
|
|
371 |
corner:1.0@1.0
|
|
372 |
in:optionsWindow.
|
|
373 |
|
|
374 |
focusEventsToIgnore := 4.
|
|
375 |
optionsWindow open.
|
|
376 |
|
|
377 |
"Created: / 09-08-2009 / 08:12:21 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
378 |
"Modified: / 09-08-2009 / 09:28:47 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
379 |
"Modified: / 09-12-2010 / 22:05:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
380 |
!
|
|
381 |
|
|
382 |
startCompletion
|
|
383 |
|
10443
|
384 |
completionJob restart.
|
10025
|
385 |
|
|
386 |
"Created: / 26-07-2009 / 17:41:41 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
10443
|
387 |
"Modified (format): / 03-08-2011 / 17:50:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
10025
|
388 |
! !
|
|
389 |
|
|
390 |
!EditFieldWithCompletion class methodsFor:'documentation'!
|
|
391 |
|
|
392 |
version_CVS
|
10445
|
393 |
^ '$Header: /cvs/stx/stx/libtool/EditFieldWithCompletion.st,v 1.3 2011-08-04 14:25:07 stefan Exp $'
|
10025
|
394 |
!
|
|
395 |
|
|
396 |
version_SVN
|
|
397 |
^ '§Id: EditFieldWithCompletion.st 7662 2010-12-09 21:05:19Z vranyj1 §'
|
|
398 |
! !
|