author | Claus Gittinger <cg@exept.de> |
Fri, 02 Aug 2019 17:46:21 +0200 | |
changeset 6659 | bf9e461b517c |
parent 6657 | 90673a5bc399 |
child 6666 | 7aa9f3c69ba2 |
permissions | -rw-r--r-- |
6659 | 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:[ |
6650 | 90 |
ch := editView characterBeforeCursor. |
91 |
(ch notNil "/ i.e. not at begin of line |
|
6594 | 92 |
and:[ ch isLetterOrDigitOrUnderline ]) ifTrue:[ |
4788 | 93 |
(key == #Control_L or:[ key == #Ctrl or:[ key == #Control_R or:[ key == #Control]]]) ifTrue:[ |
94 |
UserPreferences current codeCompletionOnControlKey ifTrue:[ |
|
95 |
autoSelect := true. |
|
96 |
self updateCompletionList |
|
97 |
] |
|
98 |
]. |
|
4805
dd3fd2a4f3e9
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4788
diff
changeset
|
99 |
((key == #Tab) and:[editView sensor shiftDown not]) ifTrue:[ |
4788 | 100 |
UserPreferences current codeCompletionOnTabKey ifTrue:[ |
6315 | 101 |
"/ only if the character after the cursor is a separator!! |
102 |
"/ otherwise, we cannot insert tabs |
|
6370 | 103 |
((ch := editView characterAfterCursor) isNil or:[ch isSeparator]) ifTrue:[ |
6315 | 104 |
autoSelect := true. |
105 |
self updateCompletionList. |
|
106 |
^ true |
|
107 |
]. |
|
4788 | 108 |
]. |
109 |
] |
|
110 |
]. |
|
111 |
]. |
|
112 |
^ false. |
|
113 |
]. |
|
114 |
||
6197 | 115 |
editView cursorCol <= 1 ifTrue:[^ false]. |
116 |
||
4788 | 117 |
"/ key for completion view ? (careful: do not forward too many, it would disturb user's typing) |
118 |
key isCharacter ifFalse:[ |
|
119 |
"/ forward to menu |
|
120 |
(completionView notNil) ifTrue:[ |
|
5064
55e4260c1ea1
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5033
diff
changeset
|
121 |
"/never |
4788 | 122 |
eatCursorLeftOrRight := false. |
123 |
"/ completeImmediate not |
|
124 |
"/ or:[ editView sensor shiftDown |
|
125 |
"/ or:[ editView sensor ctrlDown ]]. |
|
5064
55e4260c1ea1
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5033
diff
changeset
|
126 |
"/ only with shift or ctrl |
55e4260c1ea1
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5033
diff
changeset
|
127 |
eatCursorUpDown := |
55e4260c1ea1
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5033
diff
changeset
|
128 |
(UserPreferences current codeCompletionViewKeyboardNavigationNeedsModifier not) |
55e4260c1ea1
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5033
diff
changeset
|
129 |
or:[ editView sensor shiftDown |
5705 | 130 |
or:[ editView sensor ctrlDown]]. |
5064
55e4260c1ea1
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5033
diff
changeset
|
131 |
|
55e4260c1ea1
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5033
diff
changeset
|
132 |
((key == #CursorDown and:[eatCursorUpDown]) |
55e4260c1ea1
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5033
diff
changeset
|
133 |
or:[ (key == #CursorUp and:[eatCursorUpDown]) |
4788 | 134 |
or:[ ((key == #CursorLeft) and:[eatCursorLeftOrRight]) |
135 |
or:[ ((key == #CursorRight) and:[eatCursorLeftOrRight]) |
|
136 |
or:[ ((key == #Return) and:[ completionView hasSelection ]) |
|
137 |
]]]]) ifTrue:[ |
|
5064
55e4260c1ea1
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5033
diff
changeset
|
138 |
"/ forward to completion view |
55e4260c1ea1
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5033
diff
changeset
|
139 |
completionView sensor pushUserEvent:#value for:[ completionView keyPress:key x:0 y:0 ]. |
55e4260c1ea1
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5033
diff
changeset
|
140 |
^ true. |
4788 | 141 |
]. |
142 |
||
143 |
(key == #Control_L or:[ key == #Control_R or:[ key == #Control or:[ key == #Ctrl ]]]) ifTrue:[ |
|
144 |
"/ CTRL is a toggle |
|
5064
55e4260c1ea1
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5033
diff
changeset
|
145 |
"/ self closeCompletionView. |
55e4260c1ea1
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5033
diff
changeset
|
146 |
"/ ^ true. |
55e4260c1ea1
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5033
diff
changeset
|
147 |
^ false "/ don't eat |
4788 | 148 |
]. |
149 |
(key == #Escape) ifTrue:[ |
|
150 |
self closeCompletionView. |
|
151 |
^ true "/ EAT |
|
152 |
]. |
|
153 |
"/ shift does not close |
|
154 |
(key == #Shift_L or:[ key == #Shift_R or:[ key == #Shift]]) ifTrue:[ |
|
155 |
^ false "/ don' eat |
|
156 |
]. |
|
157 |
||
4817
597e3af71218
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4808
diff
changeset
|
158 |
(key == #BackSpace) ifTrue:[ |
597e3af71218
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4808
diff
changeset
|
159 |
^ false "/ don' eat |
597e3af71218
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4808
diff
changeset
|
160 |
]. |
4788 | 161 |
self closeCompletionView. |
162 |
^ false "/ don' eat |
|
163 |
]. |
|
164 |
]. |
|
165 |
^ false. |
|
6197 | 166 |
|
167 |
"Modified: / 24-08-2017 / 21:32:52 / cg" |
|
6370 | 168 |
"Modified: / 03-07-2018 / 13:41:45 / sr" |
6594 | 169 |
"Modified: / 05-06-2019 / 17:06:15 / Claus Gittinger" |
4788 | 170 |
! |
171 |
||
172 |
postKeyPress:key |
|
6650 | 173 |
|doComplete ch| |
5410
78eefa911c26
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5064
diff
changeset
|
174 |
|
4788 | 175 |
UserPreferences current immediateCodeCompletion ifFalse:[ |
176 |
"/ only update, if already open |
|
177 |
completionView isNil ifTrue:[^ self]. |
|
178 |
]. |
|
179 |
||
6650 | 180 |
"/ (completionView notNil and:[completionView realized]) ifTrue:[^ self]. |
181 |
editView hasSelection ifTrue:[^ self]. |
|
182 |
ch := editView characterBeforeCursor. |
|
183 |
(ch notNil and:[ch isLetterOrDigitOrUnderline]) ifFalse:[^ self]. |
|
184 |
||
4788 | 185 |
(key == #BackSpace or:[key == #BasicBackspace]) ifTrue:[ |
186 |
autoSelect := false. |
|
187 |
self updateCompletionList. |
|
188 |
^ self |
|
189 |
]. |
|
190 |
||
191 |
key isCharacter ifTrue:[ |
|
5410
78eefa911c26
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5064
diff
changeset
|
192 |
(doComplete := key isSeparator not) ifFalse:[ |
78eefa911c26
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5064
diff
changeset
|
193 |
"/ 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
|
194 |
doComplete := editView lineStringBeforeCursor withoutSeparators notEmpty. |
78eefa911c26
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5064
diff
changeset
|
195 |
]. |
78eefa911c26
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5064
diff
changeset
|
196 |
doComplete ifFalse:[ |
4788 | 197 |
self closeCompletionView |
5410
78eefa911c26
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5064
diff
changeset
|
198 |
] ifTrue:[ |
4788 | 199 |
autoSelect := false. |
200 |
self updateCompletionList. |
|
201 |
]. |
|
202 |
^ self |
|
203 |
]. |
|
5772 | 204 |
! |
205 |
||
206 |
startTimeoutForEditViewLostFocus |
|
207 |
"see comment in #editViewLostFocus" |
|
208 |
||
209 |
editViewLostFocusBlock isNil ifTrue:[ |
|
210 |
editViewLostFocusBlock := [self editViewLostFocus]. |
|
211 |
]. |
|
212 |
Processor addTimedBlock:editViewLostFocusBlock afterMilliseconds:200. |
|
4788 | 213 |
! ! |
214 |
||
215 |
!EditTextViewCompletionSupport methodsFor:'private'! |
|
216 |
||
6632 | 217 |
computeAndShowCompletions |
6657 | 218 |
"compute completions, then push an event to show them" |
219 |
||
220 |
|completions| |
|
6632 | 221 |
|
6657 | 222 |
completions := self computeCompletions. |
223 |
completions notEmptyOrNil ifTrue:[ |
|
224 |
self assert:completions isArray. |
|
225 |
self assert:completions size == 4. |
|
226 |
editView sensor |
|
227 |
pushUserEvent:#'suggestionsArrived:implementations:actions:autoSelect:' |
|
228 |
for:self |
|
229 |
withArguments:completions |
|
230 |
]. |
|
6632 | 231 |
|
6657 | 232 |
"Created: / 15-07-2019 / 17:29:54 / Claus Gittinger" |
233 |
"Modified: / 24-07-2019 / 07:53:35 / Claus Gittinger" |
|
6632 | 234 |
! |
235 |
||
4824
e3806247e940
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4819
diff
changeset
|
236 |
computeCompletions |
6659 | 237 |
"compute the completions. |
238 |
Don't know how to do this here." |
|
4824
e3806247e940
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4819
diff
changeset
|
239 |
|
6659 | 240 |
^ nil |
4824
e3806247e940
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4819
diff
changeset
|
241 |
|
e3806247e940
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4819
diff
changeset
|
242 |
"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
|
243 |
! |
e3806247e940
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4819
diff
changeset
|
244 |
|
4788 | 245 |
release |
246 |
self stopCompletionProcess. |
|
247 |
self closeCompletionView. |
|
248 |
super release |
|
249 |
! |
|
250 |
||
251 |
startCompletionProcess |
|
252 |
"start the code completion process in the background" |
|
253 |
||
6627 | 254 |
|initialList cursorX cursorY p| |
4788 | 255 |
|
256 |
"/ terminate any previous process |
|
6632 | 257 |
self synchronized:[ |
258 |
self stopCompletionProcess. |
|
259 |
]. |
|
260 |
||
4788 | 261 |
(editView sensor hasKeyPressEventFor:nil) ifTrue:[ |
4817
597e3af71218
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4808
diff
changeset
|
262 |
"/ 'cl' printCR. |
4788 | 263 |
self closeCompletionView. |
264 |
^ self |
|
265 |
]. |
|
266 |
((cursorX := editView xOfCursor) isNil |
|
267 |
or:[ (cursorY := editView yOfCursor) isNil ]) ifTrue:[ |
|
268 |
"/ 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
|
269 |
"/ 'cl2' printCR. |
4788 | 270 |
self closeCompletionView. |
271 |
^ self |
|
272 |
]. |
|
273 |
||
4817
597e3af71218
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4808
diff
changeset
|
274 |
completionView isNil ifTrue:[ |
597e3af71218
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4808
diff
changeset
|
275 |
initialList := #( 'Busy...' ). |
597e3af71218
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4808
diff
changeset
|
276 |
"/ 'op1' printCR. |
597e3af71218
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4808
diff
changeset
|
277 |
] ifFalse:[ |
597e3af71218
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4808
diff
changeset
|
278 |
initialList := completionView list. |
597e3af71218
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4808
diff
changeset
|
279 |
"/ 'op2' printCR. |
597e3af71218
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4808
diff
changeset
|
280 |
]. |
597e3af71218
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4808
diff
changeset
|
281 |
self openCompletionView:initialList. |
4788 | 282 |
|
6627 | 283 |
completionProcess := p := |
4788 | 284 |
[ |
6432 | 285 |
[ |
286 |
"/ protect end-user applications from errors |
|
287 |
Error handle:[:ex | |
|
288 |
(ParseError accepts:ex creator) ifFalse:[ |
|
289 |
Smalltalk isSmalltalkDevelopmentSystem ifTrue:[ ex reject ] |
|
290 |
]. |
|
291 |
] do:[ |
|
6632 | 292 |
|startTime| |
293 |
||
294 |
startTime := Timestamp now. |
|
295 |
"/ Wait a while to give user chance finish typing. |
|
296 |
"/ This also reduces CPU consumption by avoiding |
|
297 |
"/ useless computation |
|
298 |
Delay waitForMilliseconds: 200. |
|
299 |
||
6432 | 300 |
(editView topView isDebugView) ifTrue:[ |
301 |
ControlInterrupt ignoreIn:[ |
|
6632 | 302 |
self computeAndShowCompletions. |
6432 | 303 |
]. |
304 |
] ifFalse:[ |
|
6632 | 305 |
self computeAndShowCompletions. |
6432 | 306 |
]. |
6391 | 307 |
]. |
6627 | 308 |
p == completionProcess ifTrue:[ |
309 |
completionProcess := nil |
|
310 |
] |
|
6432 | 311 |
] ifCurtailed:[ |
6433 | 312 |
"/ completionView notNil ifTrue:[ |
313 |
"/ completionView topView destroy |
|
314 |
"/ ]. |
|
6432 | 315 |
]. |
6627 | 316 |
] newProcess. |
317 |
"/ p priority:(Processor activePriority - 1). |
|
318 |
p priorityRange:(Processor activePriority-1 to:Processor activePriority). |
|
319 |
p resume. |
|
4788 | 320 |
|
321 |
"Modified: / 26-09-2013 / 17:36:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
6632 | 322 |
"Modified: / 15-07-2019 / 17:30:55 / Claus Gittinger" |
4788 | 323 |
! |
324 |
||
325 |
stopCompletionProcess |
|
326 |
"kill any background completion process" |
|
327 |
||
328 |
|p| |
|
329 |
||
330 |
(p := completionProcess) notNil ifTrue:[ |
|
331 |
completionProcess := nil. |
|
332 |
p terminate. |
|
333 |
]. |
|
334 |
! |
|
335 |
||
336 |
updateCompletionList |
|
337 |
"called for keypress events" |
|
338 |
||
339 |
self startCompletionProcess. |
|
340 |
! ! |
|
341 |
||
342 |
!EditTextViewCompletionSupport methodsFor:'private-API'! |
|
343 |
||
344 |
closeCompletionView |
|
345 |
|v| |
|
346 |
||
347 |
(v := completionView) notNil ifTrue:[ |
|
348 |
completionView := nil. |
|
6432 | 349 |
|
4788 | 350 |
"/ let it close itself - avoids synchronization problems |
351 |
v sensor |
|
352 |
pushUserEvent:#value |
|
353 |
for:[ v topView destroy ] |
|
354 |
]. |
|
6432 | 355 |
|
356 |
"Modified (format): / 14-09-2018 / 22:08:05 / Claus Gittinger" |
|
4788 | 357 |
! |
358 |
||
359 |
openCompletionView |
|
360 |
"Opens the completion view with an initial list. Called as soon as |
|
361 |
completion is initiated but completion options are not yet computed." |
|
362 |
||
363 |
self openCompletionView: (Array with: 'Busy...') |
|
364 |
||
365 |
"Created: / 26-09-2013 / 17:06:12 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
366 |
! |
|
367 |
||
368 |
openCompletionView: list |
|
369 |
"Makes sure the completion view is opened and with given `list`." |
|
370 |
||
5939 | 371 |
| textCursorPosInTextView textCursorPosOnScreen movePos topView |
372 |
screenBounds screenBoundsCorner |
|
373 |
helpViewsExtent helpViewsWidth helpViewsHeight| |
|
4817
597e3af71218
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4808
diff
changeset
|
374 |
|
5939 | 375 |
"/ move the window away from the text cursor (to not cover what user types in) |
376 |
"/ get the screen-relative position of the text cursor |
|
377 |
textCursorPosInTextView := editView xOfCursor @ editView yOfCursor. |
|
378 |
||
379 |
"/ care for the scroll-offset (xOfCursor/yOFCursor gives me |
|
380 |
textCursorPosInTextView := textCursorPosInTextView - (editView viewOrigin x @ 0). |
|
381 |
||
382 |
textCursorPosOnScreen := editView device |
|
383 |
translatePoint:textCursorPosInTextView |
|
384 |
fromView:editView toView:nil. |
|
385 |
||
4788 | 386 |
"/ currently, we have to stay away a bit, to avoid getting the focus |
5939 | 387 |
"/ this will be somewhat to the down-right of the textCursor |
388 |
movePos := textCursorPosOnScreen + (60 @ (editView font height)). |
|
4788 | 389 |
|
390 |
completionView isNil ifTrue:[ |
|
391 |
completionView := CodeCompletionHelpMenuView new. |
|
392 |
completionView name:'completion'. |
|
393 |
completionView level:0. |
|
394 |
completionView list:list. |
|
395 |
completionView enable:false. |
|
396 |
completionView extent:completionView preferredExtentForContents. |
|
4824
e3806247e940
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4819
diff
changeset
|
397 |
"/ completionView font: editView font. |
4788 | 398 |
topView := CodeCompletionHelpView with:completionView. |
4968
254b5e81199a
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4824
diff
changeset
|
399 |
topView editView:editView. |
4788 | 400 |
] ifFalse:[ |
401 |
completionView list:list. |
|
402 |
topView := completionView topView. |
|
4824
e3806247e940
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4819
diff
changeset
|
403 |
]. |
5939 | 404 |
|
4824
e3806247e940
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4819
diff
changeset
|
405 |
topView ~~ completionView ifTrue:[ |
e3806247e940
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4819
diff
changeset
|
406 |
topView resizeToFit. |
5939 | 407 |
|
5032
395358c11314
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4968
diff
changeset
|
408 |
"/ make sure, the window is visible |
5939 | 409 |
screenBounds := topView device monitorBoundsAt:topView origin. |
410 |
screenBoundsCorner := screenBounds corner. |
|
411 |
||
412 |
helpViewsExtent := topView extent. |
|
413 |
helpViewsWidth := helpViewsExtent x. |
|
414 |
helpViewsHeight := helpViewsExtent y. |
|
415 |
||
416 |
"/ if it does not lie completely inside the screen, move it |
|
417 |
(movePos x + helpViewsWidth) > screenBoundsCorner x ifTrue:[ |
|
418 |
movePos := (textCursorPosOnScreen x - 60 - helpViewsWidth) @ movePos y. |
|
5032
395358c11314
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4968
diff
changeset
|
419 |
]. |
5939 | 420 |
(movePos y + helpViewsHeight) > screenBoundsCorner y ifTrue:[ |
421 |
movePos := movePos x @ (textCursorPosOnScreen y - helpViewsHeight). |
|
5032
395358c11314
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4968
diff
changeset
|
422 |
]. |
5939 | 423 |
movePos y < 0 ifTrue:[ |
424 |
movePos := movePos x @ 0 |
|
425 |
]. |
|
4824
e3806247e940
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4819
diff
changeset
|
426 |
topView origin:movePos. |
4788 | 427 |
]. |
428 |
||
429 |
"Created: / 26-09-2013 / 17:07:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
430 |
! ! |
|
431 |
||
6391 | 432 |
|
4788 | 433 |
!EditTextViewCompletionSupport class methodsFor:'documentation'! |
434 |
||
435 |
version |
|
5410
78eefa911c26
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5064
diff
changeset
|
436 |
^ '$Header$' |
4788 | 437 |
! |
438 |
||
439 |
version_CVS |
|
5410
78eefa911c26
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5064
diff
changeset
|
440 |
^ '$Header$' |
4788 | 441 |
! ! |
442 |