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