author | Stefan Vogel <sv@exept.de> |
Fri, 17 May 2019 17:11:44 +0200 | |
changeset 18767 | 0478d93cdb75 |
parent 18187 | 154e5460cf12 |
child 19144 | 5133e7763456 |
permissions | -rw-r--r-- |
18187 | 1 |
"{ Encoding: utf8 }" |
2 |
||
9959 | 3 |
" |
10078 | 4 |
COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague |
5 |
All Rights Reserved |
|
9959 | 6 |
|
10078 | 7 |
Permission is hereby granted, free of charge, to any person |
8 |
obtaining a copy of this software and associated documentation |
|
9 |
files (the 'Software'), to deal in the Software without |
|
10 |
restriction, including without limitation the rights to use, |
|
11 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
12 |
copies of the Software, and to permit persons to whom the |
|
13 |
Software is furnished to do so, subject to the following |
|
14 |
conditions: |
|
15 |
||
16 |
The above copyright notice and this permission notice shall be |
|
17 |
included in all copies or substantial portions of the Software. |
|
18 |
||
19 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
20 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
21 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
22 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
23 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
24 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
25 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
26 |
OTHER DEALINGS IN THE SOFTWARE. |
|
9959 | 27 |
" |
28 |
"{ Package: 'stx:libtool' }" |
|
29 |
||
30 |
"{ NameSpace: Tools }" |
|
31 |
||
32 |
SelectionInListModelView subclass:#CodeCompletionMenu |
|
33 |
instanceVariableNames:'wholeList typedString codeView selectedString cursorCol column |
|
34 |
position' |
|
35 |
classVariableNames:'' |
|
36 |
poolDictionaries:'' |
|
37 |
category:'Interface-CodeView' |
|
38 |
! |
|
39 |
||
40 |
!CodeCompletionMenu class methodsFor:'documentation'! |
|
41 |
||
42 |
copyright |
|
43 |
" |
|
10078 | 44 |
COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague |
45 |
All Rights Reserved |
|
46 |
||
47 |
Permission is hereby granted, free of charge, to any person |
|
48 |
obtaining a copy of this software and associated documentation |
|
49 |
files (the 'Software'), to deal in the Software without |
|
50 |
restriction, including without limitation the rights to use, |
|
51 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
52 |
copies of the Software, and to permit persons to whom the |
|
53 |
Software is furnished to do so, subject to the following |
|
54 |
conditions: |
|
9959 | 55 |
|
10078 | 56 |
The above copyright notice and this permission notice shall be |
57 |
included in all copies or substantial portions of the Software. |
|
58 |
||
59 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
60 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
61 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
62 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
63 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
64 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
65 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
66 |
OTHER DEALINGS IN THE SOFTWARE. |
|
9959 | 67 |
" |
68 |
! ! |
|
69 |
||
70 |
!CodeCompletionMenu class methodsFor:'interface opening'! |
|
71 |
||
72 |
openFor: aCodeView at: anInteger with:aCollection |
|
73 |
|m| |
|
74 |
||
75 |
m := (self new) |
|
76 |
initializeForView:aCodeView at: anInteger with: aCollection. |
|
77 |
||
78 |
^ m openModalXX. |
|
79 |
||
80 |
"Created: / 16-02-2010 / 10:18:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
81 |
"Modified: / 04-09-2010 / 08:41:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
82 |
"Modified: / 01-07-2011 / 00:05:01 / cg" |
|
83 |
! ! |
|
84 |
||
85 |
!CodeCompletionMenu methodsFor:'accessing'! |
|
86 |
||
87 |
contentHeight |
|
88 |
||
89 |
| size | |
|
90 |
||
91 |
size := self list size max: 10. |
|
92 |
^(size * (wholeList anyOne heightOn:self)) + 15 |
|
93 |
||
94 |
"Created: / 22-03-2006 / 22:36:49 / janfrog" |
|
95 |
"Modified: / 26-03-2006 / 19:39:49 / janfrog" |
|
96 |
"Modified: / 16-02-2010 / 10:58:30 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
97 |
! |
|
98 |
||
99 |
contentWidth |
|
100 |
||
101 |
| w | |
|
102 |
||
103 |
w := wholeList |
|
104 |
inject:0 |
|
105 |
into:[:max :each|max max:(each widthOn:self)]. |
|
106 |
||
107 |
^(w + 20) min: 600 |
|
108 |
||
109 |
"Created: / 22-03-2006 / 22:36:49 / janfrog" |
|
110 |
"Modified: / 06-03-2010 / 08:17:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
111 |
! ! |
|
112 |
||
113 |
!CodeCompletionMenu methodsFor:'event handling'! |
|
114 |
||
115 |
backspaceKeyPress |
|
116 |
||
117 |
typedString isEmpty ifTrue:[^self topView close]. |
|
118 |
||
119 |
typedString := typedString allButLast. |
|
120 |
self updateList |
|
121 |
||
122 |
"Created: / 25-05-2005 / 20:03:22 / janfrog" |
|
123 |
"Modified: / 22-03-2006 / 21:04:09 / janfrog" |
|
124 |
! |
|
125 |
||
126 |
characterKeyPress:aCharacter |
|
12107
9aa2298d243a
class: Tools::CodeCompletionMenu
Claus Gittinger <cg@exept.de>
parents:
10078
diff
changeset
|
127 |
| newString | |
9959 | 128 |
|
129 |
newString := typedString , aCharacter. |
|
130 |
(wholeList anySatisfy:[:s|s startsWith:newString]) ifTrue:[ |
|
131 |
typedString := newString. |
|
132 |
self updateList. |
|
133 |
] |
|
134 |
||
135 |
"Created: / 25-05-2005 / 20:02:12 / janfrog" |
|
136 |
"Modified: / 27-05-2005 / 22:29:10 / janfrog" |
|
137 |
! |
|
138 |
||
139 |
doubleClicked |
|
140 |
self returnKeyPress |
|
141 |
||
142 |
"Created: / 30-06-2011 / 20:01:03 / cg" |
|
143 |
! |
|
144 |
||
145 |
keyPress:key x:x y:y |
|
12107
9aa2298d243a
class: Tools::CodeCompletionMenu
Claus Gittinger <cg@exept.de>
parents:
10078
diff
changeset
|
146 |
<resource: #keyboard (#Return #BackSpace #Tab)> |
9959 | 147 |
|
148 |
key isCharacter ifTrue:[ |
|
149 |
self characterKeyPress:key. |
|
150 |
codeView keyPress:key x:x y:y. |
|
151 |
^self |
|
152 |
]. |
|
153 |
key == #Return ifTrue:[ |
|
154 |
self returnKeyPress. |
|
155 |
^self |
|
156 |
]. |
|
157 |
key == #BackSpace ifTrue:[ |
|
158 |
codeView keyPress:key x:x y:y. |
|
159 |
self backspaceKeyPress. |
|
160 |
^self |
|
161 |
]. |
|
162 |
key == #Tab ifTrue:[ |
|
18187 | 163 |
"/self tabKeyPressX:x y:y. |
164 |
Transcript showCR:'Tab-completion broken. Disabled'. |
|
165 |
^self. |
|
9959 | 166 |
]. |
167 |
||
168 |
^super keyPress:key x:x y:y |
|
169 |
||
170 |
"Created: / 25-05-2005 / 19:57:27 / janfrog" |
|
171 |
"Modified: / 22-03-2006 / 21:12:35 / janfrog" |
|
18187 | 172 |
"Modified (format): / 09-06-2018 / 09:30:34 / Claus Gittinger" |
9959 | 173 |
! |
174 |
||
175 |
mapped |
|
176 |
super mapped. |
|
177 |
self forceUngrabPointer. |
|
178 |
self grabPointer. |
|
179 |
||
180 |
"/ self requestFocus. |
|
181 |
"/ self grabPointer. |
|
182 |
"/ self grabKeyboard. |
|
183 |
||
184 |
"Created: / 30-06-2011 / 19:58:59 / cg" |
|
185 |
! |
|
186 |
||
187 |
returnKeyPress |
|
188 |
||
189 |
self list size = 1 ifTrue:[ |
|
190 |
selectedString := self list first. |
|
191 |
codeView setCursorCol:cursorCol. |
|
192 |
self topView close |
|
193 |
] ifFalse:[ |
|
194 |
self selection ifNotNil:[ |
|
195 |
selectedString := self at:self selection. |
|
196 |
codeView setCursorCol:cursorCol. |
|
197 |
self topView close |
|
198 |
] |
|
199 |
] |
|
200 |
||
201 |
"Created: / 25-05-2005 / 20:34:16 / janfrog" |
|
202 |
"Modified: / 29-05-2005 / 09:40:15 / janfrog" |
|
203 |
! |
|
204 |
||
205 |
tabKeyPressX:x y:y |
|
12107
9aa2298d243a
class: Tools::CodeCompletionMenu
Claus Gittinger <cg@exept.de>
parents:
10078
diff
changeset
|
206 |
| currentList idx char completionString| |
9959 | 207 |
|
208 |
currentList := self list. |
|
209 |
idx := typedString size + 1. |
|
210 |
[ |
|
13514
b94a5e518918
class: Tools::CodeCompletionMenu
Claus Gittinger <cg@exept.de>
parents:
12107
diff
changeset
|
211 |
(currentList conform:[:s|s size >= idx]) |
b94a5e518918
class: Tools::CodeCompletionMenu
Claus Gittinger <cg@exept.de>
parents:
12107
diff
changeset
|
212 |
and:[ |
9959 | 213 |
char := currentList anyOne at:idx. |
13514
b94a5e518918
class: Tools::CodeCompletionMenu
Claus Gittinger <cg@exept.de>
parents:
12107
diff
changeset
|
214 |
currentList conform:[:s|(s at:idx) == char] |
9959 | 215 |
] |
216 |
] whileTrue:[ |
|
217 |
idx := idx + 1. |
|
218 |
]. |
|
219 |
completionString := currentList anyOne copyFrom:(typedString size + 1) to:idx - 1. |
|
220 |
completionString do:[:c|codeView keyPress:c x:x y:y]. |
|
221 |
typedString := typedString , completionString. |
|
222 |
Transcript showCR:typedString |
|
223 |
||
224 |
"Created: / 29-05-2005 / 09:50:03 / janfrog" |
|
225 |
! ! |
|
226 |
||
227 |
!CodeCompletionMenu methodsFor:'initialize'! |
|
228 |
||
229 |
initialize |
|
230 |
||
231 |
super initialize. |
|
232 |
||
233 |
typedString := ''. |
|
234 |
highlightMode := #line |
|
235 |
||
236 |
"Created: / 28-05-2005 / 19:49:09 / janfrog" |
|
237 |
! |
|
238 |
||
239 |
initializeForView: aTextView at: anInteger with: aCollection |
|
240 |
||
241 |
self initialize. |
|
242 |
||
243 |
codeView := aTextView. |
|
244 |
wholeList := aCollection. |
|
245 |
"/ self font:codeView font. |
|
246 |
position := anInteger. |
|
247 |
cursorCol := codeView cursorCol. |
|
248 |
||
249 |
"Modified: / 29-05-2005 / 09:39:35 / janfrog" |
|
250 |
"Created: / 16-02-2010 / 10:10:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
251 |
"Modified: / 01-07-2011 / 00:08:31 / cg" |
|
252 |
! ! |
|
253 |
||
254 |
!CodeCompletionMenu methodsFor:'interface opening'! |
|
255 |
||
256 |
openModalXX |
|
257 |
| modalBox p | |
|
258 |
||
259 |
self updateList. |
|
260 |
||
261 |
self list size == 1 ifTrue:[^self list anyOne string copyFrom:(typedString size + 1)]. |
|
262 |
||
263 |
modalBox := PopUpView new. |
|
264 |
||
265 |
ScrollableView |
|
266 |
forView:self |
|
267 |
hasHorizontalScrollBar:false |
|
268 |
hasVerticalScrollBar:true |
|
269 |
miniScrollerH:true |
|
270 |
miniScrollerV:true |
|
271 |
origin:0.0@0.0 |
|
272 |
corner:1.0@1.0 |
|
273 |
in:modalBox. |
|
274 |
||
275 |
modalBox extent:(self contentWidth) @ (self contentHeight). |
|
276 |
||
277 |
p := codeView originRelativeTo: nil. |
|
278 |
p x: (p x + (codeView xOfPosition:position) - textStartLeft - 3). |
|
279 |
p y: (p y + ("(codeView yOfPosition:position) max:" |
|
13961
8139baad1f4e
class: Tools::CodeCompletionMenu
Stefan Vogel <sv@exept.de>
parents:
13514
diff
changeset
|
280 |
(codeView yOfCursor)) + gc font maxHeight). |
9959 | 281 |
"/x := codeView absoluteXOfCursor - (typedString widthOn:codeView) - 10 - 12"/width of icon |
282 |
" 10 - Magic number, but looks good on my computer" |
|
283 |
"/x := (codeView absoluteXOfPosition: position) - textStartLeft - 3. |
|
284 |
"/y := codeView absoluteYOfCursor + font maxHeight. |
|
285 |
"/y := (codeView absoluteYOfCursor max: (codeView absoluteYOfPosition: position)) + font maxHeight. |
|
286 |
||
287 |
modalBox origin:p. |
|
288 |
modalBox makeFullyVisible. |
|
289 |
modalBox exclusivePointer:false. |
|
290 |
modalBox open. |
|
291 |
^ selectedString ifNotNil:[selectedString string copyFrom:(typedString size + 1)] |
|
292 |
||
293 |
"Modified: / 01-07-2011 / 09:30:29 / cg" |
|
294 |
! ! |
|
295 |
||
296 |
!CodeCompletionMenu methodsFor:'updating'! |
|
297 |
||
298 |
updateList |
|
299 |
||
300 |
self list:(wholeList select:[:s| s startsWith:typedString]) |
|
301 |
||
302 |
"Created: / 25-05-2005 / 20:06:07 / janfrog" |
|
303 |
"Modified: / 27-05-2005 / 22:23:37 / janfrog" |
|
304 |
! ! |
|
305 |
||
306 |
!CodeCompletionMenu class methodsFor:'documentation'! |
|
307 |
||
308 |
version_CVS |
|
18187 | 309 |
^ '$Header$' |
9959 | 310 |
! |
311 |
||
312 |
version_SVN |
|
18187 | 313 |
^ '$Id$' |
9959 | 314 |
! ! |
12107
9aa2298d243a
class: Tools::CodeCompletionMenu
Claus Gittinger <cg@exept.de>
parents:
10078
diff
changeset
|
315 |