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