author | Claus Gittinger <cg@exept.de> |
Mon, 15 Jul 2019 20:00:30 +0200 | |
changeset 6633 | b86193ed635b |
parent 6632 | 8670224f9fd5 |
child 6650 | 340342c01ce4 |
permissions | -rw-r--r-- |
6632 | 1 |
"{ Encoding: utf8 }" |
2 |
||
4788 | 3 |
"{ Package: 'stx:libwidg' }" |
4 |
||
5410
78eefa911c26
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5064
diff
changeset
|
5 |
"{ NameSpace: Smalltalk }" |
78eefa911c26
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5064
diff
changeset
|
6 |
|
4788 | 7 |
Object subclass:#EditTextViewCompletionSupport |
5772 | 8 |
instanceVariableNames:'completionView completionProcess editView autoSelect |
9 |
editViewLostFocusBlock' |
|
4788 | 10 |
classVariableNames:'LastCompletions' |
11 |
poolDictionaries:'' |
|
12 |
category:'Views-Text' |
|
13 |
! |
|
14 |
||
15 |
!EditTextViewCompletionSupport class methodsFor:'documentation'! |
|
16 |
||
17 |
documentation |
|
18 |
" |
|
19 |
An abstract supperclass to support completion in text views. |
|
20 |
Individual completion engines may create a subclass of |
|
21 |
EditTextCompletionSupport and customize it. |
|
22 |
||
5788 | 23 |
Basically, they have to implement #computeCompletions |
4788 | 24 |
|
25 |
[author:] |
|
26 |
Claus Gittinger |
|
27 |
||
28 |
[instance variables:] |
|
29 |
||
30 |
[class variables:] |
|
31 |
||
32 |
[see also:] |
|
33 |
||
34 |
" |
|
35 |
! ! |
|
36 |
||
37 |
!EditTextViewCompletionSupport class methodsFor:'instance creation'! |
|
38 |
||
39 |
for:anEditView |
|
40 |
^ self new editView:anEditView |
|
41 |
! ! |
|
42 |
||
43 |
!EditTextViewCompletionSupport class methodsFor:'queries'! |
|
44 |
||
45 |
isAbstract |
|
5509 | 46 |
^ self == EditTextViewCompletionSupport |
4788 | 47 |
|
48 |
"Created: / 26-09-2013 / 16:22:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
49 |
! ! |
|
50 |
||
51 |
!EditTextViewCompletionSupport methodsFor:'accessing'! |
|
52 |
||
53 |
editView:anEditTextView |
|
54 |
editView := anEditTextView. |
|
55 |
! ! |
|
56 |
||
57 |
!EditTextViewCompletionSupport methodsFor:'events'! |
|
58 |
||
59 |
buttonPress:button x:x y:y |
|
60 |
self closeCompletionView. |
|
61 |
! |
|
62 |
||
63 |
editViewLostFocus |
|
5772 | 64 |
"this is a hack for Windows: |
65 |
on windows, an activate:false event is first sent to my textView, |
|
66 |
then an activate is sent to the completion popup. |
|
67 |
this is done BEFORE the buttonPress event is delivered. |
|
5891 | 68 |
therefore, allow for the activate of the completionMenu and its button event to be processed. |
5772 | 69 |
before forcing it to be closed..." |
70 |
||
4788 | 71 |
completionView notNil ifTrue:[ |
4808
b37597d2df93
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4805
diff
changeset
|
72 |
editView graphicsDevice anyButtonPressed ifTrue:[ |
b37597d2df93
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4805
diff
changeset
|
73 |
editView sensor pushUserEvent:#editViewLostFocus for:self. |
4817
597e3af71218
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4808
diff
changeset
|
74 |
] ifFalse:[ |
597e3af71218
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4808
diff
changeset
|
75 |
self closeCompletionView |
597e3af71218
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4808
diff
changeset
|
76 |
] |
4808
b37597d2df93
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4805
diff
changeset
|
77 |
]. |
4788 | 78 |
! |
79 |
||
80 |
handleKeyPress:key x:x y:y |
|
81 |
"return true, if I have eaten this keypress" |
|
82 |
||
5064
55e4260c1ea1
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5033
diff
changeset
|
83 |
|ch completeImmediate eatCursorLeftOrRight eatCursorUpDown| |
4788 | 84 |
|
5410
78eefa911c26
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5064
diff
changeset
|
85 |
"/ completeImmediate := UserPreferences current immediateCodeCompletion. |
4817
597e3af71218
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4808
diff
changeset
|
86 |
|
4788 | 87 |
"/ open on CTRL- or TAB-key? |
6370 | 88 |
(completionView notNil and:[completionView realized]) ifFalse:[ |
4788 | 89 |
editView hasSelection ifFalse:[ |
90 |
((ch := editView characterBeforeCursor) notNil "/ i.e. not at begin of line |
|
6594 | 91 |
and:[ ch isLetterOrDigitOrUnderline ]) ifTrue:[ |
4788 | 92 |
(key == #Control_L or:[ key == #Ctrl or:[ key == #Control_R or:[ key == #Control]]]) ifTrue:[ |
93 |
UserPreferences current codeCompletionOnControlKey ifTrue:[ |
|
94 |
autoSelect := true. |
|
95 |
self updateCompletionList |
|
96 |
] |
|
97 |
]. |
|
4805
dd3fd2a4f3e9
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4788
diff
changeset
|
98 |
((key == #Tab) and:[editView sensor shiftDown not]) ifTrue:[ |
4788 | 99 |
UserPreferences current codeCompletionOnTabKey ifTrue:[ |
6315 | 100 |
"/ only if the character after the cursor is a separator!! |
101 |
"/ otherwise, we cannot insert tabs |
|
6370 | 102 |
((ch := editView characterAfterCursor) isNil or:[ch isSeparator]) ifTrue:[ |
6315 | 103 |
autoSelect := true. |
104 |
self updateCompletionList. |
|
105 |
^ true |
|
106 |
]. |
|
4788 | 107 |
]. |
108 |
] |
|
109 |
]. |
|
110 |
]. |
|
111 |
^ false. |
|
112 |
]. |
|
113 |
||
6197 | 114 |
editView cursorCol <= 1 ifTrue:[^ false]. |
115 |
||
4788 | 116 |
"/ key for completion view ? (careful: do not forward too many, it would disturb user's typing) |
117 |
key isCharacter ifFalse:[ |
|
118 |
"/ forward to menu |
|
119 |
(completionView notNil) ifTrue:[ |
|
5064
55e4260c1ea1
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5033
diff
changeset
|
120 |
"/never |
4788 | 121 |
eatCursorLeftOrRight := false. |
122 |
"/ completeImmediate not |
|
123 |
"/ or:[ editView sensor shiftDown |
|
124 |
"/ or:[ editView sensor ctrlDown ]]. |
|
5064
55e4260c1ea1
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5033
diff
changeset
|
125 |
"/ only with shift or ctrl |
55e4260c1ea1
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5033
diff
changeset
|
126 |
eatCursorUpDown := |
55e4260c1ea1
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5033
diff
changeset
|
127 |
(UserPreferences current codeCompletionViewKeyboardNavigationNeedsModifier not) |
55e4260c1ea1
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5033
diff
changeset
|
128 |
or:[ editView sensor shiftDown |
5705 | 129 |
or:[ editView sensor ctrlDown]]. |
5064
55e4260c1ea1
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5033
diff
changeset
|
130 |
|
55e4260c1ea1
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5033
diff
changeset
|
131 |
((key == #CursorDown and:[eatCursorUpDown]) |
55e4260c1ea1
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5033
diff
changeset
|
132 |
or:[ (key == #CursorUp and:[eatCursorUpDown]) |
4788 | 133 |
or:[ ((key == #CursorLeft) and:[eatCursorLeftOrRight]) |
134 |
or:[ ((key == #CursorRight) and:[eatCursorLeftOrRight]) |
|
135 |
or:[ ((key == #Return) and:[ completionView hasSelection ]) |
|
136 |
]]]]) ifTrue:[ |
|
5064
55e4260c1ea1
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5033
diff
changeset
|
137 |
"/ forward to completion view |
55e4260c1ea1
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5033
diff
changeset
|
138 |
completionView sensor pushUserEvent:#value for:[ completionView keyPress:key x:0 y:0 ]. |
55e4260c1ea1
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5033
diff
changeset
|
139 |
^ true. |
4788 | 140 |
]. |
141 |
||
142 |
(key == #Control_L or:[ key == #Control_R or:[ key == #Control or:[ key == #Ctrl ]]]) ifTrue:[ |
|
143 |
"/ CTRL is a toggle |
|
5064
55e4260c1ea1
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5033
diff
changeset
|
144 |
"/ self closeCompletionView. |
55e4260c1ea1
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5033
diff
changeset
|
145 |
"/ ^ true. |
55e4260c1ea1
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5033
diff
changeset
|
146 |
^ false "/ don't eat |
4788 | 147 |
]. |
148 |
(key == #Escape) ifTrue:[ |
|
149 |
self closeCompletionView. |
|
150 |
^ true "/ EAT |
|
151 |
]. |
|
152 |
"/ shift does not close |
|
153 |
(key == #Shift_L or:[ key == #Shift_R or:[ key == #Shift]]) ifTrue:[ |
|
154 |
^ false "/ don' eat |
|
155 |
]. |
|
156 |
||
4817
597e3af71218
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4808
diff
changeset
|
157 |
(key == #BackSpace) ifTrue:[ |
597e3af71218
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4808
diff
changeset
|
158 |
^ false "/ don' eat |
597e3af71218
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4808
diff
changeset
|
159 |
]. |
4788 | 160 |
self closeCompletionView. |
161 |
^ false "/ don' eat |
|
162 |
]. |
|
163 |
]. |
|
164 |
^ false. |
|
6197 | 165 |
|
166 |
"Modified: / 24-08-2017 / 21:32:52 / cg" |
|
6370 | 167 |
"Modified: / 03-07-2018 / 13:41:45 / sr" |
6594 | 168 |
"Modified: / 05-06-2019 / 17:06:15 / Claus Gittinger" |
4788 | 169 |
! |
170 |
||
171 |
postKeyPress:key |
|
5410
78eefa911c26
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5064
diff
changeset
|
172 |
|doComplete| |
78eefa911c26
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5064
diff
changeset
|
173 |
|
4788 | 174 |
UserPreferences current immediateCodeCompletion ifFalse:[ |
175 |
"/ only update, if already open |
|
176 |
completionView isNil ifTrue:[^ self]. |
|
177 |
]. |
|
178 |
||
179 |
(key == #BackSpace or:[key == #BasicBackspace]) ifTrue:[ |
|
180 |
autoSelect := false. |
|
181 |
self updateCompletionList. |
|
182 |
^ self |
|
183 |
]. |
|
184 |
||
185 |
key isCharacter ifTrue:[ |
|
5410
78eefa911c26
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5064
diff
changeset
|
186 |
(doComplete := key isSeparator not) ifFalse:[ |
78eefa911c26
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5064
diff
changeset
|
187 |
"/ also on a separator, but only if at the end of a non-empty line |
78eefa911c26
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5064
diff
changeset
|
188 |
doComplete := editView lineStringBeforeCursor withoutSeparators notEmpty. |
78eefa911c26
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5064
diff
changeset
|
189 |
]. |
78eefa911c26
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5064
diff
changeset
|
190 |
doComplete ifFalse:[ |
4788 | 191 |
self closeCompletionView |
5410
78eefa911c26
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5064
diff
changeset
|
192 |
] ifTrue:[ |
4788 | 193 |
autoSelect := false. |
194 |
self updateCompletionList. |
|
195 |
]. |
|
196 |
^ self |
|
197 |
]. |
|
5772 | 198 |
! |
199 |
||
200 |
startTimeoutForEditViewLostFocus |
|
201 |
"see comment in #editViewLostFocus" |
|
202 |
||
203 |
editViewLostFocusBlock isNil ifTrue:[ |
|
204 |
editViewLostFocusBlock := [self editViewLostFocus]. |
|
205 |
]. |
|
206 |
Processor addTimedBlock:editViewLostFocusBlock afterMilliseconds:200. |
|
4788 | 207 |
! ! |
208 |
||
209 |
!EditTextViewCompletionSupport methodsFor:'private'! |
|
210 |
||
6632 | 211 |
computeAndShowCompletions |
212 |
"Actually compute the completions and update the completion view." |
|
213 |
||
214 |
self subclassResponsibility |
|
215 |
||
216 |
"Created: / 15-07-2019 / 17:29:50 / Claus Gittinger" |
|
217 |
! |
|
218 |
||
4824
e3806247e940
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4819
diff
changeset
|
219 |
computeCompletions |
e3806247e940
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4819
diff
changeset
|
220 |
"Actually compute the completions and update the completion view." |
e3806247e940
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4819
diff
changeset
|
221 |
|
e3806247e940
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4819
diff
changeset
|
222 |
self subclassResponsibility |
e3806247e940
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4819
diff
changeset
|
223 |
|
e3806247e940
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4819
diff
changeset
|
224 |
"Created: / 26-09-2013 / 17:35:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
e3806247e940
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4819
diff
changeset
|
225 |
! |
e3806247e940
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4819
diff
changeset
|
226 |
|
4788 | 227 |
release |
228 |
self stopCompletionProcess. |
|
229 |
self closeCompletionView. |
|
230 |
super release |
|
231 |
! |
|
232 |
||
233 |
startCompletionProcess |
|
234 |
"start the code completion process in the background" |
|
235 |
||
6627 | 236 |
|initialList cursorX cursorY p| |
4788 | 237 |
|
238 |
"/ terminate any previous process |
|
6632 | 239 |
self synchronized:[ |
240 |
self stopCompletionProcess. |
|
241 |
]. |
|
242 |
||
4788 | 243 |
(editView sensor hasKeyPressEventFor:nil) ifTrue:[ |
4817
597e3af71218
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4808
diff
changeset
|
244 |
"/ 'cl' printCR. |
4788 | 245 |
self closeCompletionView. |
246 |
^ self |
|
247 |
]. |
|
248 |
((cursorX := editView xOfCursor) isNil |
|
249 |
or:[ (cursorY := editView yOfCursor) isNil ]) ifTrue:[ |
|
250 |
"/ no cursor - user is selecting, or cursor has been scrolled out of sight. |
|
4817
597e3af71218
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4808
diff
changeset
|
251 |
"/ 'cl2' printCR. |
4788 | 252 |
self closeCompletionView. |
253 |
^ self |
|
254 |
]. |
|
255 |
||
4817
597e3af71218
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4808
diff
changeset
|
256 |
completionView isNil ifTrue:[ |
597e3af71218
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4808
diff
changeset
|
257 |
initialList := #( 'Busy...' ). |
597e3af71218
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4808
diff
changeset
|
258 |
"/ 'op1' printCR. |
597e3af71218
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4808
diff
changeset
|
259 |
] ifFalse:[ |
597e3af71218
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4808
diff
changeset
|
260 |
initialList := completionView list. |
597e3af71218
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4808
diff
changeset
|
261 |
"/ 'op2' printCR. |
597e3af71218
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4808
diff
changeset
|
262 |
]. |
597e3af71218
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4808
diff
changeset
|
263 |
self openCompletionView:initialList. |
4788 | 264 |
|
6627 | 265 |
completionProcess := p := |
4788 | 266 |
[ |
6432 | 267 |
[ |
268 |
"/ protect end-user applications from errors |
|
269 |
Error handle:[:ex | |
|
270 |
(ParseError accepts:ex creator) ifFalse:[ |
|
271 |
Smalltalk isSmalltalkDevelopmentSystem ifTrue:[ ex reject ] |
|
272 |
]. |
|
273 |
] do:[ |
|
6632 | 274 |
|startTime| |
275 |
||
276 |
startTime := Timestamp now. |
|
277 |
"/ Wait a while to give user chance finish typing. |
|
278 |
"/ This also reduces CPU consumption by avoiding |
|
279 |
"/ useless computation |
|
280 |
Delay waitForMilliseconds: 200. |
|
281 |
||
6432 | 282 |
(editView topView isDebugView) ifTrue:[ |
283 |
ControlInterrupt ignoreIn:[ |
|
6632 | 284 |
self computeAndShowCompletions. |
6432 | 285 |
]. |
286 |
] ifFalse:[ |
|
6632 | 287 |
self computeAndShowCompletions. |
6432 | 288 |
]. |
6391 | 289 |
]. |
6627 | 290 |
p == completionProcess ifTrue:[ |
291 |
completionProcess := nil |
|
292 |
] |
|
6432 | 293 |
] ifCurtailed:[ |
6433 | 294 |
"/ completionView notNil ifTrue:[ |
295 |
"/ completionView topView destroy |
|
296 |
"/ ]. |
|
6432 | 297 |
]. |
6627 | 298 |
] newProcess. |
299 |
"/ p priority:(Processor activePriority - 1). |
|
300 |
p priorityRange:(Processor activePriority-1 to:Processor activePriority). |
|
301 |
p resume. |
|
4788 | 302 |
|
303 |
"Modified: / 26-09-2013 / 17:36:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
6632 | 304 |
"Modified: / 15-07-2019 / 17:30:55 / Claus Gittinger" |
4788 | 305 |
! |
306 |
||
307 |
stopCompletionProcess |
|
308 |
"kill any background completion process" |
|
309 |
||
310 |
|p| |
|
311 |
||
312 |
(p := completionProcess) notNil ifTrue:[ |
|
313 |
completionProcess := nil. |
|
314 |
p terminate. |
|
315 |
]. |
|
316 |
! |
|
317 |
||
318 |
updateCompletionList |
|
319 |
"called for keypress events" |
|
320 |
||
321 |
self startCompletionProcess. |
|
322 |
! ! |
|
323 |
||
324 |
!EditTextViewCompletionSupport methodsFor:'private-API'! |
|
325 |
||
326 |
closeCompletionView |
|
327 |
|v| |
|
328 |
||
329 |
(v := completionView) notNil ifTrue:[ |
|
330 |
completionView := nil. |
|
6432 | 331 |
|
4788 | 332 |
"/ let it close itself - avoids synchronization problems |
333 |
v sensor |
|
334 |
pushUserEvent:#value |
|
335 |
for:[ v topView destroy ] |
|
336 |
]. |
|
6432 | 337 |
|
338 |
"Modified (format): / 14-09-2018 / 22:08:05 / Claus Gittinger" |
|
4788 | 339 |
! |
340 |
||
341 |
openCompletionView |
|
342 |
"Opens the completion view with an initial list. Called as soon as |
|
343 |
completion is initiated but completion options are not yet computed." |
|
344 |
||
345 |
self openCompletionView: (Array with: 'Busy...') |
|
346 |
||
347 |
"Created: / 26-09-2013 / 17:06:12 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
348 |
! |
|
349 |
||
350 |
openCompletionView: list |
|
351 |
"Makes sure the completion view is opened and with given `list`." |
|
352 |
||
5939 | 353 |
| textCursorPosInTextView textCursorPosOnScreen movePos topView |
354 |
screenBounds screenBoundsCorner |
|
355 |
helpViewsExtent helpViewsWidth helpViewsHeight| |
|
4817
597e3af71218
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4808
diff
changeset
|
356 |
|
5939 | 357 |
"/ move the window away from the text cursor (to not cover what user types in) |
358 |
"/ get the screen-relative position of the text cursor |
|
359 |
textCursorPosInTextView := editView xOfCursor @ editView yOfCursor. |
|
360 |
||
361 |
"/ care for the scroll-offset (xOfCursor/yOFCursor gives me |
|
362 |
textCursorPosInTextView := textCursorPosInTextView - (editView viewOrigin x @ 0). |
|
363 |
||
364 |
textCursorPosOnScreen := editView device |
|
365 |
translatePoint:textCursorPosInTextView |
|
366 |
fromView:editView toView:nil. |
|
367 |
||
4788 | 368 |
"/ currently, we have to stay away a bit, to avoid getting the focus |
5939 | 369 |
"/ this will be somewhat to the down-right of the textCursor |
370 |
movePos := textCursorPosOnScreen + (60 @ (editView font height)). |
|
4788 | 371 |
|
372 |
completionView isNil ifTrue:[ |
|
373 |
completionView := CodeCompletionHelpMenuView new. |
|
374 |
completionView name:'completion'. |
|
375 |
completionView level:0. |
|
376 |
completionView list:list. |
|
377 |
completionView enable:false. |
|
378 |
completionView extent:completionView preferredExtentForContents. |
|
4824
e3806247e940
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4819
diff
changeset
|
379 |
"/ completionView font: editView font. |
4788 | 380 |
topView := CodeCompletionHelpView with:completionView. |
4968
254b5e81199a
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4824
diff
changeset
|
381 |
topView editView:editView. |
4788 | 382 |
] ifFalse:[ |
383 |
completionView list:list. |
|
384 |
topView := completionView topView. |
|
4824
e3806247e940
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4819
diff
changeset
|
385 |
]. |
5939 | 386 |
|
4824
e3806247e940
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4819
diff
changeset
|
387 |
topView ~~ completionView ifTrue:[ |
e3806247e940
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4819
diff
changeset
|
388 |
topView resizeToFit. |
5939 | 389 |
|
5032
395358c11314
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4968
diff
changeset
|
390 |
"/ make sure, the window is visible |
5939 | 391 |
screenBounds := topView device monitorBoundsAt:topView origin. |
392 |
screenBoundsCorner := screenBounds corner. |
|
393 |
||
394 |
helpViewsExtent := topView extent. |
|
395 |
helpViewsWidth := helpViewsExtent x. |
|
396 |
helpViewsHeight := helpViewsExtent y. |
|
397 |
||
398 |
"/ if it does not lie completely inside the screen, move it |
|
399 |
(movePos x + helpViewsWidth) > screenBoundsCorner x ifTrue:[ |
|
400 |
movePos := (textCursorPosOnScreen x - 60 - helpViewsWidth) @ movePos y. |
|
5032
395358c11314
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4968
diff
changeset
|
401 |
]. |
5939 | 402 |
(movePos y + helpViewsHeight) > screenBoundsCorner y ifTrue:[ |
403 |
movePos := movePos x @ (textCursorPosOnScreen y - helpViewsHeight). |
|
5032
395358c11314
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4968
diff
changeset
|
404 |
]. |
5939 | 405 |
movePos y < 0 ifTrue:[ |
406 |
movePos := movePos x @ 0 |
|
407 |
]. |
|
4824
e3806247e940
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4819
diff
changeset
|
408 |
topView origin:movePos. |
4788 | 409 |
]. |
410 |
||
411 |
"Created: / 26-09-2013 / 17:07:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
412 |
! ! |
|
413 |
||
6391 | 414 |
|
4788 | 415 |
!EditTextViewCompletionSupport class methodsFor:'documentation'! |
416 |
||
417 |
version |
|
5410
78eefa911c26
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5064
diff
changeset
|
418 |
^ '$Header$' |
4788 | 419 |
! |
420 |
||
421 |
version_CVS |
|
5410
78eefa911c26
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5064
diff
changeset
|
422 |
^ '$Header$' |
4788 | 423 |
! ! |
424 |