9959
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2006 by eXept Software AG
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
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 |
"
|
|
12 |
"{ Package: 'stx:libtool' }"
|
|
13 |
|
|
14 |
"{ NameSpace: Tools }"
|
|
15 |
|
|
16 |
SelectionInListModelView subclass:#CodeCompletionMenu
|
|
17 |
instanceVariableNames:'wholeList typedString codeView selectedString cursorCol column
|
|
18 |
position'
|
|
19 |
classVariableNames:''
|
|
20 |
poolDictionaries:''
|
|
21 |
category:'Interface-CodeView'
|
|
22 |
!
|
|
23 |
|
|
24 |
!CodeCompletionMenu class methodsFor:'documentation'!
|
|
25 |
|
|
26 |
copyright
|
|
27 |
"
|
|
28 |
COPYRIGHT (c) 2006 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 |
!CodeCompletionMenu class methodsFor:'interface opening'!
|
|
41 |
|
|
42 |
openFor: aCodeView at: anInteger with:aCollection
|
|
43 |
|m|
|
|
44 |
|
|
45 |
m := (self new)
|
|
46 |
initializeForView:aCodeView at: anInteger with: aCollection.
|
|
47 |
|
|
48 |
^ m openModalXX.
|
|
49 |
|
|
50 |
"Created: / 16-02-2010 / 10:18:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
51 |
"Modified: / 04-09-2010 / 08:41:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
52 |
"Modified: / 01-07-2011 / 00:05:01 / cg"
|
|
53 |
! !
|
|
54 |
|
|
55 |
!CodeCompletionMenu methodsFor:'accessing'!
|
|
56 |
|
|
57 |
contentHeight
|
|
58 |
|
|
59 |
| size |
|
|
60 |
|
|
61 |
size := self list size max: 10.
|
|
62 |
^(size * (wholeList anyOne heightOn:self)) + 15
|
|
63 |
|
|
64 |
"Created: / 22-03-2006 / 22:36:49 / janfrog"
|
|
65 |
"Modified: / 26-03-2006 / 19:39:49 / janfrog"
|
|
66 |
"Modified: / 16-02-2010 / 10:58:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
67 |
!
|
|
68 |
|
|
69 |
contentWidth
|
|
70 |
|
|
71 |
| w |
|
|
72 |
|
|
73 |
w := wholeList
|
|
74 |
inject:0
|
|
75 |
into:[:max :each|max max:(each widthOn:self)].
|
|
76 |
|
|
77 |
^(w + 20) min: 600
|
|
78 |
|
|
79 |
"Created: / 22-03-2006 / 22:36:49 / janfrog"
|
|
80 |
"Modified: / 06-03-2010 / 08:17:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
81 |
! !
|
|
82 |
|
|
83 |
!CodeCompletionMenu methodsFor:'event handling'!
|
|
84 |
|
|
85 |
backspaceKeyPress
|
|
86 |
|
|
87 |
typedString isEmpty ifTrue:[^self topView close].
|
|
88 |
|
|
89 |
typedString := typedString allButLast.
|
|
90 |
self updateList
|
|
91 |
|
|
92 |
"Created: / 25-05-2005 / 20:03:22 / janfrog"
|
|
93 |
"Modified: / 22-03-2006 / 21:04:09 / janfrog"
|
|
94 |
!
|
|
95 |
|
|
96 |
characterKeyPress:aCharacter
|
|
97 |
|
|
98 |
| newString |
|
|
99 |
newString := typedString , aCharacter.
|
|
100 |
(wholeList anySatisfy:[:s|s startsWith:newString]) ifTrue:[
|
|
101 |
typedString := newString.
|
|
102 |
self updateList.
|
|
103 |
]
|
|
104 |
|
|
105 |
"Created: / 25-05-2005 / 20:02:12 / janfrog"
|
|
106 |
"Modified: / 27-05-2005 / 22:29:10 / janfrog"
|
|
107 |
!
|
|
108 |
|
|
109 |
doubleClicked
|
|
110 |
self returnKeyPress
|
|
111 |
|
|
112 |
"Created: / 30-06-2011 / 20:01:03 / cg"
|
|
113 |
!
|
|
114 |
|
|
115 |
keyPress:key x:x y:y
|
|
116 |
|
|
117 |
key isCharacter ifTrue:[
|
|
118 |
self characterKeyPress:key.
|
|
119 |
codeView keyPress:key x:x y:y.
|
|
120 |
^self
|
|
121 |
].
|
|
122 |
key == #Return ifTrue:[
|
|
123 |
self returnKeyPress.
|
|
124 |
^self
|
|
125 |
].
|
|
126 |
key == #BackSpace ifTrue:[
|
|
127 |
codeView keyPress:key x:x y:y.
|
|
128 |
self backspaceKeyPress.
|
|
129 |
^self
|
|
130 |
].
|
|
131 |
key == #Tab ifTrue:[
|
|
132 |
"/self tabKeyPressX:x y:y.
|
|
133 |
Transcript showCR:'Tab-completion broken. Disabled'.
|
|
134 |
^self.
|
|
135 |
].
|
|
136 |
|
|
137 |
^super keyPress:key x:x y:y
|
|
138 |
|
|
139 |
"Created: / 25-05-2005 / 19:57:27 / janfrog"
|
|
140 |
"Modified: / 22-03-2006 / 21:12:35 / janfrog"
|
|
141 |
!
|
|
142 |
|
|
143 |
mapped
|
|
144 |
super mapped.
|
|
145 |
self forceUngrabPointer.
|
|
146 |
self grabPointer.
|
|
147 |
|
|
148 |
"/ self requestFocus.
|
|
149 |
"/ self grabPointer.
|
|
150 |
"/ self grabKeyboard.
|
|
151 |
|
|
152 |
"Created: / 30-06-2011 / 19:58:59 / cg"
|
|
153 |
!
|
|
154 |
|
|
155 |
returnKeyPress
|
|
156 |
|
|
157 |
self list size = 1 ifTrue:[
|
|
158 |
selectedString := self list first.
|
|
159 |
codeView setCursorCol:cursorCol.
|
|
160 |
self topView close
|
|
161 |
] ifFalse:[
|
|
162 |
self selection ifNotNil:[
|
|
163 |
selectedString := self at:self selection.
|
|
164 |
codeView setCursorCol:cursorCol.
|
|
165 |
self topView close
|
|
166 |
]
|
|
167 |
]
|
|
168 |
|
|
169 |
"Created: / 25-05-2005 / 20:34:16 / janfrog"
|
|
170 |
"Modified: / 29-05-2005 / 09:40:15 / janfrog"
|
|
171 |
!
|
|
172 |
|
|
173 |
tabKeyPressX:x y:y
|
|
174 |
|
|
175 |
| currentList idx char completionString|
|
|
176 |
currentList := self list.
|
|
177 |
idx := typedString size + 1.
|
|
178 |
[
|
|
179 |
(currentList allSatisfy:[:s|s size >= idx]) and:[
|
|
180 |
char := currentList anyOne at:idx.
|
|
181 |
currentList allSatisfy:[:s|(s at:idx) == char]
|
|
182 |
]
|
|
183 |
] whileTrue:[
|
|
184 |
idx := idx + 1.
|
|
185 |
].
|
|
186 |
completionString := currentList anyOne copyFrom:(typedString size + 1) to:idx - 1.
|
|
187 |
completionString do:[:c|codeView keyPress:c x:x y:y].
|
|
188 |
typedString := typedString , completionString.
|
|
189 |
Transcript showCR:typedString
|
|
190 |
|
|
191 |
"Created: / 29-05-2005 / 09:50:03 / janfrog"
|
|
192 |
! !
|
|
193 |
|
|
194 |
!CodeCompletionMenu methodsFor:'initialize'!
|
|
195 |
|
|
196 |
initialize
|
|
197 |
|
|
198 |
super initialize.
|
|
199 |
|
|
200 |
typedString := ''.
|
|
201 |
highlightMode := #line
|
|
202 |
|
|
203 |
"Created: / 28-05-2005 / 19:49:09 / janfrog"
|
|
204 |
!
|
|
205 |
|
|
206 |
initializeForView: aTextView at: anInteger with: aCollection
|
|
207 |
|
|
208 |
self initialize.
|
|
209 |
|
|
210 |
codeView := aTextView.
|
|
211 |
wholeList := aCollection.
|
|
212 |
"/ self font:codeView font.
|
|
213 |
position := anInteger.
|
|
214 |
cursorCol := codeView cursorCol.
|
|
215 |
|
|
216 |
"Modified: / 29-05-2005 / 09:39:35 / janfrog"
|
|
217 |
"Created: / 16-02-2010 / 10:10:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
218 |
"Modified: / 01-07-2011 / 00:08:31 / cg"
|
|
219 |
! !
|
|
220 |
|
|
221 |
!CodeCompletionMenu methodsFor:'interface opening'!
|
|
222 |
|
|
223 |
openModalXX
|
|
224 |
| modalBox p |
|
|
225 |
|
|
226 |
self updateList.
|
|
227 |
|
|
228 |
self list size == 1 ifTrue:[^self list anyOne string copyFrom:(typedString size + 1)].
|
|
229 |
|
|
230 |
modalBox := PopUpView new.
|
|
231 |
|
|
232 |
ScrollableView
|
|
233 |
forView:self
|
|
234 |
hasHorizontalScrollBar:false
|
|
235 |
hasVerticalScrollBar:true
|
|
236 |
miniScrollerH:true
|
|
237 |
miniScrollerV:true
|
|
238 |
origin:0.0@0.0
|
|
239 |
corner:1.0@1.0
|
|
240 |
in:modalBox.
|
|
241 |
|
|
242 |
modalBox extent:(self contentWidth) @ (self contentHeight).
|
|
243 |
|
|
244 |
p := codeView originRelativeTo: nil.
|
|
245 |
p x: (p x + (codeView xOfPosition:position) - textStartLeft - 3).
|
|
246 |
p y: (p y + ("(codeView yOfPosition:position) max:"
|
|
247 |
(codeView yOfCursor)) + font maxHeight).
|
|
248 |
"/x := codeView absoluteXOfCursor - (typedString widthOn:codeView) - 10 - 12"/width of icon
|
|
249 |
" 10 - Magic number, but looks good on my computer"
|
|
250 |
"/x := (codeView absoluteXOfPosition: position) - textStartLeft - 3.
|
|
251 |
"/y := codeView absoluteYOfCursor + font maxHeight.
|
|
252 |
"/y := (codeView absoluteYOfCursor max: (codeView absoluteYOfPosition: position)) + font maxHeight.
|
|
253 |
|
|
254 |
modalBox origin:p.
|
|
255 |
modalBox makeFullyVisible.
|
|
256 |
modalBox exclusivePointer:false.
|
|
257 |
modalBox open.
|
|
258 |
^ selectedString ifNotNil:[selectedString string copyFrom:(typedString size + 1)]
|
|
259 |
|
|
260 |
"Modified: / 01-07-2011 / 09:30:29 / cg"
|
|
261 |
! !
|
|
262 |
|
|
263 |
!CodeCompletionMenu methodsFor:'updating'!
|
|
264 |
|
|
265 |
updateList
|
|
266 |
|
|
267 |
self list:(wholeList select:[:s| s startsWith:typedString])
|
|
268 |
|
|
269 |
"Created: / 25-05-2005 / 20:06:07 / janfrog"
|
|
270 |
"Modified: / 27-05-2005 / 22:23:37 / janfrog"
|
|
271 |
! !
|
|
272 |
|
|
273 |
!CodeCompletionMenu class methodsFor:'documentation'!
|
|
274 |
|
|
275 |
version_CVS
|
9986
|
276 |
^ '$Header: /cvs/stx/stx/libtool/Tools__CodeCompletionMenu.st,v 1.2 2011-07-01 13:21:34 cg Exp $'
|
9959
|
277 |
!
|
|
278 |
|
|
279 |
version_SVN
|
|
280 |
^ '§Id: Tools__CodeCompletionMenu.st 7690 2011-03-19 02:23:25Z vranyj1 §'
|
|
281 |
! !
|