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