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
|
|
125 |
|
|
126 |
| newString |
|
|
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
|
|
144 |
|
|
145 |
key isCharacter ifTrue:[
|
|
146 |
self characterKeyPress:key.
|
|
147 |
codeView keyPress:key x:x y:y.
|
|
148 |
^self
|
|
149 |
].
|
|
150 |
key == #Return ifTrue:[
|
|
151 |
self returnKeyPress.
|
|
152 |
^self
|
|
153 |
].
|
|
154 |
key == #BackSpace ifTrue:[
|
|
155 |
codeView keyPress:key x:x y:y.
|
|
156 |
self backspaceKeyPress.
|
|
157 |
^self
|
|
158 |
].
|
|
159 |
key == #Tab ifTrue:[
|
|
160 |
"/self tabKeyPressX:x y:y.
|
|
161 |
Transcript showCR:'Tab-completion broken. Disabled'.
|
|
162 |
^self.
|
|
163 |
].
|
|
164 |
|
|
165 |
^super keyPress:key x:x y:y
|
|
166 |
|
|
167 |
"Created: / 25-05-2005 / 19:57:27 / janfrog"
|
|
168 |
"Modified: / 22-03-2006 / 21:12:35 / janfrog"
|
|
169 |
!
|
|
170 |
|
|
171 |
mapped
|
|
172 |
super mapped.
|
|
173 |
self forceUngrabPointer.
|
|
174 |
self grabPointer.
|
|
175 |
|
|
176 |
"/ self requestFocus.
|
|
177 |
"/ self grabPointer.
|
|
178 |
"/ self grabKeyboard.
|
|
179 |
|
|
180 |
"Created: / 30-06-2011 / 19:58:59 / cg"
|
|
181 |
!
|
|
182 |
|
|
183 |
returnKeyPress
|
|
184 |
|
|
185 |
self list size = 1 ifTrue:[
|
|
186 |
selectedString := self list first.
|
|
187 |
codeView setCursorCol:cursorCol.
|
|
188 |
self topView close
|
|
189 |
] ifFalse:[
|
|
190 |
self selection ifNotNil:[
|
|
191 |
selectedString := self at:self selection.
|
|
192 |
codeView setCursorCol:cursorCol.
|
|
193 |
self topView close
|
|
194 |
]
|
|
195 |
]
|
|
196 |
|
|
197 |
"Created: / 25-05-2005 / 20:34:16 / janfrog"
|
|
198 |
"Modified: / 29-05-2005 / 09:40:15 / janfrog"
|
|
199 |
!
|
|
200 |
|
|
201 |
tabKeyPressX:x y:y
|
|
202 |
|
|
203 |
| currentList idx char completionString|
|
|
204 |
currentList := self list.
|
|
205 |
idx := typedString size + 1.
|
|
206 |
[
|
|
207 |
(currentList allSatisfy:[:s|s size >= idx]) and:[
|
|
208 |
char := currentList anyOne at:idx.
|
|
209 |
currentList allSatisfy:[:s|(s at:idx) == char]
|
|
210 |
]
|
|
211 |
] whileTrue:[
|
|
212 |
idx := idx + 1.
|
|
213 |
].
|
|
214 |
completionString := currentList anyOne copyFrom:(typedString size + 1) to:idx - 1.
|
|
215 |
completionString do:[:c|codeView keyPress:c x:x y:y].
|
|
216 |
typedString := typedString , completionString.
|
|
217 |
Transcript showCR:typedString
|
|
218 |
|
|
219 |
"Created: / 29-05-2005 / 09:50:03 / janfrog"
|
|
220 |
! !
|
|
221 |
|
|
222 |
!CodeCompletionMenu methodsFor:'initialize'!
|
|
223 |
|
|
224 |
initialize
|
|
225 |
|
|
226 |
super initialize.
|
|
227 |
|
|
228 |
typedString := ''.
|
|
229 |
highlightMode := #line
|
|
230 |
|
|
231 |
"Created: / 28-05-2005 / 19:49:09 / janfrog"
|
|
232 |
!
|
|
233 |
|
|
234 |
initializeForView: aTextView at: anInteger with: aCollection
|
|
235 |
|
|
236 |
self initialize.
|
|
237 |
|
|
238 |
codeView := aTextView.
|
|
239 |
wholeList := aCollection.
|
|
240 |
"/ self font:codeView font.
|
|
241 |
position := anInteger.
|
|
242 |
cursorCol := codeView cursorCol.
|
|
243 |
|
|
244 |
"Modified: / 29-05-2005 / 09:39:35 / janfrog"
|
|
245 |
"Created: / 16-02-2010 / 10:10:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
246 |
"Modified: / 01-07-2011 / 00:08:31 / cg"
|
|
247 |
! !
|
|
248 |
|
|
249 |
!CodeCompletionMenu methodsFor:'interface opening'!
|
|
250 |
|
|
251 |
openModalXX
|
|
252 |
| modalBox p |
|
|
253 |
|
|
254 |
self updateList.
|
|
255 |
|
|
256 |
self list size == 1 ifTrue:[^self list anyOne string copyFrom:(typedString size + 1)].
|
|
257 |
|
|
258 |
modalBox := PopUpView new.
|
|
259 |
|
|
260 |
ScrollableView
|
|
261 |
forView:self
|
|
262 |
hasHorizontalScrollBar:false
|
|
263 |
hasVerticalScrollBar:true
|
|
264 |
miniScrollerH:true
|
|
265 |
miniScrollerV:true
|
|
266 |
origin:0.0@0.0
|
|
267 |
corner:1.0@1.0
|
|
268 |
in:modalBox.
|
|
269 |
|
|
270 |
modalBox extent:(self contentWidth) @ (self contentHeight).
|
|
271 |
|
|
272 |
p := codeView originRelativeTo: nil.
|
|
273 |
p x: (p x + (codeView xOfPosition:position) - textStartLeft - 3).
|
|
274 |
p y: (p y + ("(codeView yOfPosition:position) max:"
|
|
275 |
(codeView yOfCursor)) + font maxHeight).
|
|
276 |
"/x := codeView absoluteXOfCursor - (typedString widthOn:codeView) - 10 - 12"/width of icon
|
|
277 |
" 10 - Magic number, but looks good on my computer"
|
|
278 |
"/x := (codeView absoluteXOfPosition: position) - textStartLeft - 3.
|
|
279 |
"/y := codeView absoluteYOfCursor + font maxHeight.
|
|
280 |
"/y := (codeView absoluteYOfCursor max: (codeView absoluteYOfPosition: position)) + font maxHeight.
|
|
281 |
|
|
282 |
modalBox origin:p.
|
|
283 |
modalBox makeFullyVisible.
|
|
284 |
modalBox exclusivePointer:false.
|
|
285 |
modalBox open.
|
|
286 |
^ selectedString ifNotNil:[selectedString string copyFrom:(typedString size + 1)]
|
|
287 |
|
|
288 |
"Modified: / 01-07-2011 / 09:30:29 / cg"
|
|
289 |
! !
|
|
290 |
|
|
291 |
!CodeCompletionMenu methodsFor:'updating'!
|
|
292 |
|
|
293 |
updateList
|
|
294 |
|
|
295 |
self list:(wholeList select:[:s| s startsWith:typedString])
|
|
296 |
|
|
297 |
"Created: / 25-05-2005 / 20:06:07 / janfrog"
|
|
298 |
"Modified: / 27-05-2005 / 22:23:37 / janfrog"
|
|
299 |
! !
|
|
300 |
|
|
301 |
!CodeCompletionMenu class methodsFor:'documentation'!
|
|
302 |
|
|
303 |
version_CVS
|
10078
|
304 |
^ '$Header: /cvs/stx/stx/libtool/Tools__CodeCompletionMenu.st,v 1.3 2011-07-03 17:50:23 cg Exp $'
|
9959
|
305 |
!
|
|
306 |
|
|
307 |
version_SVN
|
|
308 |
^ '§Id: Tools__CodeCompletionMenu.st 7690 2011-03-19 02:23:25Z vranyj1 §'
|
|
309 |
! !
|