author | Stefan Vogel <sv@exept.de> |
Thu, 24 Oct 2019 18:45:44 +0200 | |
changeset 6721 | 1cd09d31cb4a |
parent 6712 | 293d6dde8845 |
child 6722 | e302ad05e8c1 |
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]. |
|
6721 | 231 |
"/ Pro: This saves some warnings about timeout for dead process. |
232 |
"/ Con: Can add more than a single exit action |
|
233 |
"/ Processor activeProcess |
|
234 |
"/ addExitAction:[Processor removeTimedBlock:editViewLostFocusBlock]. |
|
5772 | 235 |
]. |
236 |
Processor addTimedBlock:editViewLostFocusBlock afterMilliseconds:200. |
|
6721 | 237 |
|
238 |
"Modified: / 24-10-2019 / 18:44:41 / Stefan Vogel" |
|
4788 | 239 |
! ! |
240 |
||
241 |
!EditTextViewCompletionSupport methodsFor:'private'! |
|
242 |
||
6632 | 243 |
computeAndShowCompletions |
6704 | 244 |
"compute completions, then push an event to show them. |
245 |
Notice: this is interrupted and terminated if the user presses another key |
|
246 |
within delayTime" |
|
6657 | 247 |
|
6704 | 248 |
|delayTime completions startTime restTime| |
6632 | 249 |
|
6704 | 250 |
delayTime := 0.4 seconds. |
251 |
||
252 |
startTime := Timestamp now. |
|
6657 | 253 |
completions := self computeCompletions. |
254 |
completions notEmptyOrNil ifTrue:[ |
|
6704 | 255 |
restTime := (startTime + delayTime) - Timestamp now. |
256 |
restTime positive ifTrue:[ |
|
257 |
Delay waitFor:restTime |
|
258 |
]. |
|
6657 | 259 |
self assert:completions isArray. |
260 |
self assert:completions size == 4. |
|
261 |
editView sensor |
|
262 |
pushUserEvent:#'suggestionsArrived:implementations:actions:autoSelect:' |
|
263 |
for:self |
|
264 |
withArguments:completions |
|
265 |
]. |
|
6632 | 266 |
|
6657 | 267 |
"Created: / 15-07-2019 / 17:29:54 / Claus Gittinger" |
268 |
"Modified: / 24-07-2019 / 07:53:35 / Claus Gittinger" |
|
6632 | 269 |
! |
270 |
||
4824
e3806247e940
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4819
diff
changeset
|
271 |
computeCompletions |
6659 | 272 |
"compute the completions. |
273 |
Don't know how to do this here." |
|
4824
e3806247e940
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4819
diff
changeset
|
274 |
|
6659 | 275 |
^ nil |
4824
e3806247e940
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4819
diff
changeset
|
276 |
|
e3806247e940
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4819
diff
changeset
|
277 |
"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
|
278 |
! |
e3806247e940
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4819
diff
changeset
|
279 |
|
4788 | 280 |
release |
281 |
self stopCompletionProcess. |
|
282 |
self closeCompletionView. |
|
283 |
super release |
|
284 |
! |
|
285 |
||
286 |
startCompletionProcess |
|
287 |
"start the code completion process in the background" |
|
288 |
||
6627 | 289 |
|initialList cursorX cursorY p| |
4788 | 290 |
|
291 |
"/ terminate any previous process |
|
6632 | 292 |
self synchronized:[ |
293 |
self stopCompletionProcess. |
|
294 |
]. |
|
295 |
||
4788 | 296 |
(editView sensor hasKeyPressEventFor:nil) ifTrue:[ |
4817
597e3af71218
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4808
diff
changeset
|
297 |
"/ 'cl' printCR. |
4788 | 298 |
self closeCompletionView. |
299 |
^ self |
|
300 |
]. |
|
301 |
((cursorX := editView xOfCursor) isNil |
|
302 |
or:[ (cursorY := editView yOfCursor) isNil ]) ifTrue:[ |
|
303 |
"/ 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
|
304 |
"/ 'cl2' printCR. |
4788 | 305 |
self closeCompletionView. |
306 |
^ self |
|
307 |
]. |
|
308 |
||
6704 | 309 |
initialList := #( 'Busy...' ). |
310 |
completionView notNil ifTrue:[ |
|
311 |
"/ initialList := completionView list. |
|
4817
597e3af71218
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4808
diff
changeset
|
312 |
]. |
6704 | 313 |
"/ self openCompletionView:initialList. |
4788 | 314 |
|
6627 | 315 |
completionProcess := p := |
4788 | 316 |
[ |
6432 | 317 |
[ |
318 |
"/ protect end-user applications from errors |
|
319 |
Error handle:[:ex | |
|
320 |
(ParseError accepts:ex creator) ifFalse:[ |
|
321 |
Smalltalk isSmalltalkDevelopmentSystem ifTrue:[ ex reject ] |
|
322 |
]. |
|
323 |
] do:[ |
|
6632 | 324 |
|startTime| |
6704 | 325 |
|
326 |
false ifTrue:[ |
|
6632 | 327 |
startTime := Timestamp now. |
328 |
"/ Wait a while to give user chance finish typing. |
|
329 |
"/ This also reduces CPU consumption by avoiding |
|
330 |
"/ useless computation |
|
331 |
Delay waitForMilliseconds: 200. |
|
6704 | 332 |
]. |
6432 | 333 |
(editView topView isDebugView) ifTrue:[ |
334 |
ControlInterrupt ignoreIn:[ |
|
6632 | 335 |
self computeAndShowCompletions. |
6432 | 336 |
]. |
337 |
] ifFalse:[ |
|
6632 | 338 |
self computeAndShowCompletions. |
6432 | 339 |
]. |
6391 | 340 |
]. |
6627 | 341 |
p == completionProcess ifTrue:[ |
342 |
completionProcess := nil |
|
343 |
] |
|
6432 | 344 |
] ifCurtailed:[ |
6433 | 345 |
"/ completionView notNil ifTrue:[ |
346 |
"/ completionView topView destroy |
|
347 |
"/ ]. |
|
6432 | 348 |
]. |
6627 | 349 |
] newProcess. |
350 |
"/ p priority:(Processor activePriority - 1). |
|
351 |
p priorityRange:(Processor activePriority-1 to:Processor activePriority). |
|
352 |
p resume. |
|
4788 | 353 |
|
354 |
"Modified: / 26-09-2013 / 17:36:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
6632 | 355 |
"Modified: / 15-07-2019 / 17:30:55 / Claus Gittinger" |
4788 | 356 |
! |
357 |
||
358 |
stopCompletionProcess |
|
359 |
"kill any background completion process" |
|
360 |
||
361 |
|p| |
|
362 |
||
363 |
(p := completionProcess) notNil ifTrue:[ |
|
364 |
completionProcess := nil. |
|
365 |
p terminate. |
|
366 |
]. |
|
367 |
! |
|
368 |
||
369 |
updateCompletionList |
|
370 |
"called for keypress events" |
|
371 |
||
372 |
self startCompletionProcess. |
|
373 |
! ! |
|
374 |
||
375 |
!EditTextViewCompletionSupport methodsFor:'private-API'! |
|
376 |
||
6704 | 377 |
adjustSizeOfCompletionView:topView |
378 |
|screenBounds screenBoundsCorner |
|
379 |
helpViewsExtent helpViewsWidth helpViewsHeight |
|
380 |
textCursorPosInTextView textCursorPosOnScreen |
|
6721 | 381 |
newX newY cursorX cursorY distanceFromCursorIfBelow distanceFromCursorIfAbove| |
6704 | 382 |
|
383 |
textCursorPosInTextView := editView xOfCursor @ editView yOfCursor. |
|
384 |
textCursorPosOnScreen := editView device |
|
385 |
translatePoint:textCursorPosInTextView |
|
386 |
fromView:editView toView:nil. |
|
387 |
||
388 |
cursorX := textCursorPosOnScreen x. |
|
389 |
cursorY := textCursorPosOnScreen y. |
|
390 |
distanceFromCursorIfAbove := editView font height. |
|
391 |
distanceFromCursorIfBelow := distanceFromCursorIfAbove * 2. |
|
392 |
||
393 |
topView resizeToFit. |
|
394 |
||
395 |
"/ make sure, the window is visible |
|
6721 | 396 |
screenBounds := topView device monitorBoundsAt:editView topView origin. |
6704 | 397 |
screenBoundsCorner := screenBounds corner. |
398 |
||
399 |
helpViewsExtent := topView extent. |
|
400 |
helpViewsWidth := helpViewsExtent x. |
|
401 |
helpViewsHeight := helpViewsExtent y. |
|
402 |
||
403 |
||
404 |
newX := cursorX + 20. |
|
405 |
newY := cursorY + distanceFromCursorIfBelow. |
|
406 |
||
407 |
"/ if it does not lie completely inside the screen, move it |
|
408 |
(newX + helpViewsWidth) > screenBoundsCorner x ifTrue:[ |
|
409 |
newX := screenBoundsCorner x - helpViewsWidth. |
|
410 |
]. |
|
411 |
(newY + helpViewsHeight) > screenBoundsCorner y ifTrue:[ |
|
412 |
newY := screenBoundsCorner y - helpViewsHeight. |
|
413 |
]. |
|
414 |
newX < 0 ifTrue:[ |
|
415 |
newX := 0 |
|
416 |
]. |
|
417 |
newY < 0 ifTrue:[ |
|
418 |
newY := 0 |
|
419 |
]. |
|
420 |
||
421 |
"/ topView origin:(newX @ newY). |
|
422 |
(cursorY between:newY and:(newY + helpViewsHeight)) ifTrue:[ |
|
423 |
"/ lift it towards the top |
|
424 |
newY := cursorY - distanceFromCursorIfAbove - helpViewsHeight. |
|
425 |
] ifFalse:[ |
|
426 |
"/ (cursorX between:newX and:(newX + helpViewsWidth)) ifTrue:[ |
|
427 |
"/ self halt. |
|
428 |
"/ ]. |
|
429 |
]. |
|
430 |
topView origin:(newX @ newY). |
|
6721 | 431 |
|
432 |
"Modified: / 24-10-2019 / 18:41:07 / Stefan Vogel" |
|
6704 | 433 |
! |
434 |
||
4788 | 435 |
closeCompletionView |
436 |
|v| |
|
437 |
||
438 |
(v := completionView) notNil ifTrue:[ |
|
439 |
completionView := nil. |
|
6432 | 440 |
|
4788 | 441 |
"/ let it close itself - avoids synchronization problems |
6704 | 442 |
v sensor pushAction:[ v topView destroy ] |
4788 | 443 |
]. |
6432 | 444 |
|
445 |
"Modified (format): / 14-09-2018 / 22:08:05 / Claus Gittinger" |
|
4788 | 446 |
! |
447 |
||
448 |
openCompletionView |
|
449 |
"Opens the completion view with an initial list. Called as soon as |
|
450 |
completion is initiated but completion options are not yet computed." |
|
451 |
||
452 |
self openCompletionView: (Array with: 'Busy...') |
|
453 |
||
454 |
"Created: / 26-09-2013 / 17:06:12 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
455 |
! |
|
456 |
||
457 |
openCompletionView: list |
|
458 |
"Makes sure the completion view is opened and with given `list`." |
|
459 |
||
6711 | 460 |
|cursorX cursorY textCursorPosInTextView textCursorPosOnScreen movePos topView| |
461 |
||
6712 | 462 |
"/ race here - openCompletionView may arrive late, when the user started to do something else |
463 |
"/ (scroll or select). Then it could happen the no cursor is currently visible. |
|
6721 | 464 |
"/ Disable dead code: |
465 |
"/ cursorX := editView xOfCursor. |
|
466 |
"/ cursorY := editView yOfCursor. |
|
467 |
"/ (cursorX isNil or:[cursorY isNil]) ifTrue:[^ self]. |
|
468 |
"/ |
|
469 |
"/ "/ move the window away from the text cursor (to not cover what user types in) |
|
470 |
"/ "/ get the screen-relative position of the text cursor |
|
471 |
"/ textCursorPosInTextView := cursorX @ cursorY. |
|
472 |
"/ |
|
473 |
"/ "/ care for the scroll-offset (xOfCursor/yOFCursor gives me |
|
474 |
"/ textCursorPosInTextView := textCursorPosInTextView - (editView viewOrigin x @ 0). |
|
475 |
"/ |
|
476 |
"/ textCursorPosOnScreen := editView device |
|
477 |
"/ translatePoint:textCursorPosInTextView |
|
478 |
"/ fromView:editView toView:nil. |
|
479 |
"/ |
|
480 |
"/ "/ currently, we have to stay away a bit, to avoid getting the focus |
|
481 |
"/ "/ this will be somewhat to the down-right of the textCursor |
|
482 |
"/ movePos := textCursorPosOnScreen + (60 @ (editView font height)). |
|
4788 | 483 |
|
484 |
completionView isNil ifTrue:[ |
|
485 |
completionView := CodeCompletionHelpMenuView new. |
|
486 |
completionView name:'completion'. |
|
487 |
completionView level:0. |
|
488 |
completionView list:list. |
|
489 |
completionView enable:false. |
|
490 |
completionView extent:completionView preferredExtentForContents. |
|
4824
e3806247e940
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4819
diff
changeset
|
491 |
"/ completionView font: editView font. |
6704 | 492 |
topView := CodeCompletionHelpView with:(HVScrollableView forView:completionView). |
493 |
"/ topView := CodeCompletionHelpView with:completionView. |
|
4968
254b5e81199a
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4824
diff
changeset
|
494 |
topView editView:editView. |
4788 | 495 |
] ifFalse:[ |
496 |
completionView list:list. |
|
497 |
topView := completionView topView. |
|
4824
e3806247e940
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4819
diff
changeset
|
498 |
]. |
5939 | 499 |
|
4824
e3806247e940
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
4819
diff
changeset
|
500 |
topView ~~ completionView ifTrue:[ |
6704 | 501 |
self adjustSizeOfCompletionView:topView. |
4788 | 502 |
]. |
503 |
||
504 |
"Created: / 26-09-2013 / 17:07:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
6721 | 505 |
"Modified: / 24-10-2019 / 17:57:57 / Stefan Vogel" |
4788 | 506 |
! ! |
507 |
||
6391 | 508 |
|
4788 | 509 |
!EditTextViewCompletionSupport class methodsFor:'documentation'! |
510 |
||
511 |
version |
|
5410
78eefa911c26
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5064
diff
changeset
|
512 |
^ '$Header$' |
4788 | 513 |
! |
514 |
||
515 |
version_CVS |
|
5410
78eefa911c26
class: EditTextViewCompletionSupport
Claus Gittinger <cg@exept.de>
parents:
5064
diff
changeset
|
516 |
^ '$Header$' |
4788 | 517 |
! ! |
518 |