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