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