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