17612
|
1 |
"{ Package: 'stx:libtool' }"
|
|
2 |
|
|
3 |
"{ NameSpace: Tools }"
|
|
4 |
|
|
5 |
Object subclass:#ClassSearchDialog
|
|
6 |
instanceVariableNames:'browser resources classFilter classNamesInChangeSet
|
|
7 |
visitedShortNames visitedFullNames reallyAllClasses allClasses
|
|
8 |
classNameHolder onlyShowJavaClassesHolder showFullNameHolder
|
|
9 |
doFuzzyMatchHolder allNames allFullNames allClassesByFullName
|
|
10 |
setOfClassNamesInChangeSet showingWhatLabel okText box'
|
|
11 |
classVariableNames:'LastClassSearchBoxShowedFullName LastClassSearchBoxShowedJavaOnly
|
|
12 |
LastClassSearchUsedFuzzyCompare'
|
|
13 |
poolDictionaries:''
|
|
14 |
category:'Interface-Browsers-Support'
|
|
15 |
!
|
|
16 |
|
|
17 |
!ClassSearchDialog class methodsFor:'documentation'!
|
|
18 |
|
|
19 |
documentation
|
|
20 |
"
|
|
21 |
code extracted from SystemBrowser class,
|
|
22 |
to make it easier to refactor and to reuse.
|
|
23 |
"
|
|
24 |
! !
|
|
25 |
|
|
26 |
!ClassSearchDialog methodsFor:'asking'!
|
|
27 |
|
|
28 |
askForClassToSearch:doWhatByDefault single:singleClass msgTail:msgTail resources:resourcesOrNil filter:filterOrNil forBrowser:aBrowserOrNil thenDo:aBlock
|
|
29 |
"utility common code for both opening a new browser on a class and
|
|
30 |
to search for a class in an existing browser.
|
|
31 |
If singleClass is true, a single class will be asked for and browsed,
|
|
32 |
otherwise, a match pattern is allowed and a multi-class browser is opened.
|
|
33 |
Moved from instance protocol for better reusability."
|
|
34 |
|
|
35 |
|boxLabel title okText2 okText3 okText4 className canFind
|
|
36 |
button2 button3 button4 doWhat doWhat2 doWhat3 doWhat4 check
|
|
37 |
navigationState enableFuzzyHolder|
|
|
38 |
|
|
39 |
classFilter := filterOrNil.
|
|
40 |
self getResourcesFrom:resourcesOrNil orBrowser:aBrowserOrNil.
|
|
41 |
|
|
42 |
showFullNameHolder := (LastClassSearchBoxShowedFullName ? false) asValue.
|
|
43 |
onlyShowJavaClassesHolder := (LastClassSearchBoxShowedJavaOnly ? false) asValue.
|
|
44 |
doFuzzyMatchHolder := (LastClassSearchUsedFuzzyCompare ? false) asValue.
|
|
45 |
enableFuzzyHolder := true asValue.
|
|
46 |
|
|
47 |
aBrowserOrNil notNil ifTrue:[ navigationState := aBrowserOrNil navigationState].
|
|
48 |
|
|
49 |
doWhat := doWhatByDefault.
|
|
50 |
canFind := navigationState notNil and:[ navigationState isFullBrowser ].
|
|
51 |
|
|
52 |
(doWhat isNil or:[aBrowserOrNil isNil]) ifTrue:[
|
|
53 |
title := 'Select a class'.
|
|
54 |
boxLabel := 'Select a class'.
|
|
55 |
okText := 'OK'.
|
|
56 |
okText2 := nil. doWhat2 := nil.
|
|
57 |
okText3 := nil. doWhat3 := nil.
|
|
58 |
okText4 := nil. doWhat4 := nil.
|
|
59 |
] ifFalse:[
|
|
60 |
title := (singleClass ifTrue:[ 'Class to browse' ] ifFalse:[ 'Class(es) to browse' ]).
|
|
61 |
boxLabel := 'Browse or Search'.
|
|
62 |
|
|
63 |
(doWhat isNil and:[canFind not]) ifTrue:[
|
|
64 |
doWhat := #newBuffer.
|
|
65 |
].
|
|
66 |
|
|
67 |
doWhat == #newBrowser ifTrue:[
|
|
68 |
okText := 'Open'.
|
|
69 |
okText2 := 'Add Buffer'. doWhat2 := #newBuffer.
|
|
70 |
okText3 := 'Open All'. doWhat3 := #newBrowserForAll.
|
|
71 |
okText4 := 'Find'. doWhat4 := nil.
|
|
72 |
] ifFalse:[ doWhat == #newBuffer ifTrue:[
|
|
73 |
okText := 'Add Buffer'.
|
|
74 |
okText2 := 'Open New'. doWhat2 := #newBrowser.
|
|
75 |
okText3 := 'Open All'. doWhat3 := #newBrowserForAll.
|
|
76 |
okText4 := 'Find'. doWhat4 := nil.
|
|
77 |
] ifFalse:[
|
|
78 |
title := (singleClass ifTrue:[ 'Class to find' ] ifFalse:[ 'Class(es) to find' ]).
|
|
79 |
okText := 'Find'.
|
|
80 |
okText2 := 'Open New'. doWhat2 := #newBrowser.
|
|
81 |
okText3 := 'Open All'. doWhat3 := #newBrowserForAll.
|
|
82 |
okText4 := 'Add Buffer'. doWhat4 := #newBuffer.
|
|
83 |
]].
|
|
84 |
].
|
|
85 |
|
|
86 |
self getClassNamesInChangeSet.
|
|
87 |
self getVisitedNames.
|
|
88 |
self getAllClasses.
|
|
89 |
|
|
90 |
self createDialogBox:msgTail title:title label:boxLabel.
|
|
91 |
|
|
92 |
doWhat notNil ifTrue:[
|
|
93 |
button2 := Button label:(resources string:okText2).
|
|
94 |
(navigationState notNil and:[navigationState isFullBrowser]) "singleClass" ifTrue:[
|
|
95 |
button3 := Button label:(resources string:okText3).
|
|
96 |
button4 := Button label:(resources string:okText4).
|
|
97 |
].
|
|
98 |
box addButton:button2 after:(box okButton).
|
|
99 |
button3 notNil ifTrue:[box addButton:button3 after:button2].
|
|
100 |
button4 notNil ifTrue:[box addButton:button4 after:button3].
|
|
101 |
|
|
102 |
button2
|
|
103 |
action:[
|
|
104 |
doWhat := doWhat2.
|
|
105 |
box doAccept; okPressed.
|
|
106 |
].
|
|
107 |
button3 notNil ifTrue:[
|
|
108 |
button3
|
|
109 |
action:[
|
|
110 |
doWhat := doWhat3.
|
|
111 |
box doAccept; okPressed.
|
|
112 |
].
|
|
113 |
].
|
|
114 |
button4 notNil ifTrue:[
|
|
115 |
button4
|
|
116 |
action:[
|
|
117 |
doWhat := doWhat4.
|
|
118 |
box doAccept; okPressed.
|
|
119 |
].
|
|
120 |
].
|
|
121 |
].
|
|
122 |
|
|
123 |
classNameHolder := '' asValue.
|
|
124 |
box enterField model:classNameHolder; immediateAccept:true.
|
|
125 |
classNameHolder onChangeEvaluate:[
|
|
126 |
enableFuzzyHolder value:(classNameHolder value includesMatchCharacters not).
|
|
127 |
self updateList
|
|
128 |
].
|
|
129 |
|
|
130 |
box entryCompletionBlock:(DoWhatIMeanSupport classNameEntryCompletionBlock).
|
|
131 |
box action:[:aString | className := aString ].
|
|
132 |
|
|
133 |
box panelView
|
|
134 |
addSubView:(showingWhatLabel := (Label label:(resources string:'Recently Visited:')) adjust:#left) before:nil.
|
|
135 |
|
|
136 |
(JavaVM notNil and:[JavaVM isLoaded]) ifTrue:[
|
|
137 |
box panelView
|
|
138 |
addSubView:(check := CheckBox label:(resources string:'Only show Java Classes') model:onlyShowJavaClassesHolder) before:nil.
|
|
139 |
].
|
|
140 |
box panelView
|
|
141 |
addSubView:(check := CheckBox label:(resources string:'Show Full Name (do not Strip off Namespace)') model:showFullNameHolder) before:nil.
|
|
142 |
box panelView
|
|
143 |
addSubView:(check := CheckBox label:(resources string:'Fuzzy Match (Instead of Substring Search)') model:doFuzzyMatchHolder) before:nil.
|
|
144 |
check enableChannel:enableFuzzyHolder.
|
|
145 |
|
|
146 |
doFuzzyMatchHolder onChangeEvaluate:[self updateList].
|
|
147 |
showFullNameHolder onChangeEvaluate:[self updateList].
|
|
148 |
onlyShowJavaClassesHolder onChangeEvaluate:[ self getAllClasses. self updateList].
|
|
149 |
|
|
150 |
"/ box enterField
|
|
151 |
"/ onKey:#CursorDown leaveWith:[
|
|
152 |
"/ |listView|
|
|
153 |
"/
|
|
154 |
"/ listView := box listView.
|
|
155 |
"/ listView windowGroup focusView:listView byTab:true.
|
|
156 |
"/ listView hasSelection ifFalse:[
|
|
157 |
"/ listView selectFirst
|
|
158 |
"/ ] ifTrue:[
|
|
159 |
"/ listView selectNext
|
|
160 |
"/ ].
|
|
161 |
"/ ].
|
|
162 |
box enterField
|
|
163 |
origin:(0 @ check corner y).
|
|
164 |
box listView origin:(0 @ check corner y).
|
|
165 |
|
|
166 |
box extent:(400 @ 550).
|
|
167 |
box open.
|
|
168 |
|
|
169 |
className isEmptyOrNil ifTrue:[^ nil "cancel"].
|
|
170 |
|
|
171 |
LastClassSearchBoxShowedFullName := showFullNameHolder value.
|
|
172 |
LastClassSearchBoxShowedJavaOnly := onlyShowJavaClassesHolder value.
|
|
173 |
LastClassSearchUsedFuzzyCompare := doFuzzyMatchHolder value.
|
|
174 |
|
|
175 |
(className endsWith:$) ) ifTrue:[
|
|
176 |
(className indexOfSubCollection:'(in ') == 0 ifTrue:[
|
|
177 |
"/ a namespace
|
|
178 |
className := (className copyTo:(className indexOfSubCollection:'(Name')-1) withoutSeparators
|
|
179 |
] ifFalse:[
|
|
180 |
className := ((className copyFrom:(className indexOfSubCollection:'(in ')+4)
|
|
181 |
copyButLast)
|
|
182 |
, '::' , className asCollectionOfWords first
|
|
183 |
].
|
|
184 |
((className startsWith:'JAVA::') and:[className includes:$.]) ifTrue:[
|
|
185 |
className := className copyReplaceString:'.' withString:'::'
|
|
186 |
].
|
|
187 |
].
|
|
188 |
|
|
189 |
(doWhat isNil or:[aBrowserOrNil isNil]) ifTrue:[
|
|
190 |
aBlock notNil ifTrue:[aBlock value:className optionalArgument:singleClass and:doWhat].
|
|
191 |
^ className
|
|
192 |
].
|
|
193 |
|
|
194 |
aBrowserOrNil withSearchCursorDo:[
|
|
195 |
aBlock value:className value:singleClass value:doWhat.
|
|
196 |
].
|
|
197 |
^ className
|
|
198 |
|
|
199 |
"Created: / 03-08-2017 / 12:25:45 / cg"
|
|
200 |
"Modified: / 04-08-2017 / 13:02:36 / cg"
|
|
201 |
!
|
|
202 |
|
|
203 |
old_askForClassToSearch:doWhatByDefault single:singleClass msgTail:msgTail resources:resourcesOrNil filter:filterOrNil forBrowser:aBrowserOrNil thenDo:aBlock
|
|
204 |
"utility common code for both opening a new browser on a class and
|
|
205 |
to search for a class in an existing browser.
|
|
206 |
If singleClass is true, a single class will be asked for and browsed,
|
|
207 |
otherwise, a match pattern is allowed and a multi-class browser is opened.
|
|
208 |
Moved from instance protocol for better reusability."
|
|
209 |
|
|
210 |
"
|
|
211 |
self new
|
|
212 |
old_askForClassToSearch:doWhatByDefault
|
|
213 |
single:singleClass
|
|
214 |
msgTail:msgTail
|
|
215 |
resources:resourcesOrNil
|
|
216 |
filter:filterOrNil
|
|
217 |
forBrowser:aBrowserOrNil
|
|
218 |
thenDo:aBlock
|
|
219 |
"
|
|
220 |
|
|
221 |
|className doWhat updateList check |
|
|
222 |
|
|
223 |
classFilter := filterOrNil.
|
|
224 |
self getResourcesFrom:resourcesOrNil orBrowser:aBrowserOrNil.
|
|
225 |
|
|
226 |
showFullNameHolder := (LastClassSearchBoxShowedFullName ? false) asValue.
|
|
227 |
|
|
228 |
doWhat := doWhatByDefault.
|
|
229 |
|
|
230 |
okText := 'OK'.
|
|
231 |
|
|
232 |
self getClassNamesInChangeSet.
|
|
233 |
self getVisitedNames.
|
|
234 |
self getAllClasses.
|
|
235 |
|
|
236 |
self createDialogBox:msgTail title:'Select a class' label:'Select a class'.
|
|
237 |
|
|
238 |
updateList := [ self halt. self updateList ].
|
|
239 |
"/ updateList := [
|
|
240 |
"/ |nameToSearch list namesStarting namesIncluding lcName nameList|
|
|
241 |
"/
|
|
242 |
"/ (nameToSearch := classNameHolder value withoutSeparators) isEmpty ifTrue:[
|
|
243 |
"/ showingWhatLabel label:(resources string:'Recently visited:').
|
|
244 |
"/ list := (showFullNameHolder value ifTrue:[visitedFullNames] ifFalse:[visitedShortNames]).
|
|
245 |
"/ ] ifFalse:[
|
|
246 |
"/ showingWhatLabel label:(resources string:'Matching classes:').
|
|
247 |
"/ nameList := showFullNameHolder value
|
|
248 |
"/ ifTrue:[ allFullNames ]
|
|
249 |
"/ ifFalse:[ allNames ].
|
|
250 |
"/
|
|
251 |
"/ lcName := nameToSearch asLowercase.
|
|
252 |
"/ (lcName includesString:'::') ifTrue:[
|
|
253 |
"/ list := OrderedCollection new.
|
|
254 |
"/ allClasses doWithIndex:[:cls :idx |
|
|
255 |
"/ |isIncluded|
|
|
256 |
"/
|
|
257 |
"/ (nameToSearch includesMatchCharacters) ifTrue:[
|
|
258 |
"/ isIncluded := (lcName match:cls name asLowercase)
|
|
259 |
"/ ] ifFalse:[
|
|
260 |
"/ isIncluded := (cls name includesString:lcName caseSensitive:false)
|
|
261 |
"/ ].
|
|
262 |
"/ isIncluded ifTrue:[
|
|
263 |
"/ list add:(nameList at:idx)
|
|
264 |
"/ ].
|
|
265 |
"/ ].
|
|
266 |
"/ ] ifFalse:[
|
|
267 |
"/ (nameToSearch includesMatchCharacters) ifTrue:[
|
|
268 |
"/ list := nameList select:[:nm | lcName match:nm asLowercase]
|
|
269 |
"/ ] ifFalse:[
|
|
270 |
"/ namesIncluding := nameList
|
|
271 |
"/ select:[:nm |
|
|
272 |
"/ "/ nm asLowercase startsWith:lcName
|
|
273 |
"/ nm asLowercase includesString:lcName caseSensitive:false
|
|
274 |
"/ ].
|
|
275 |
"/ namesStarting := namesIncluding select:[:nm | nm asLowercase startsWith:lcName].
|
|
276 |
"/ list := namesStarting , {nil} , (namesIncluding \ namesStarting).
|
|
277 |
"/ ]
|
|
278 |
"/ ]
|
|
279 |
"/ ].
|
|
280 |
"/ box listView
|
|
281 |
"/ list:list;
|
|
282 |
"/ scrollToLine:((list findFirst:[:line | (line ? '') startsWith:lcName]) max:1)
|
|
283 |
"/ ].
|
|
284 |
|
|
285 |
classNameHolder := '' asValue.
|
|
286 |
box enterField model:classNameHolder; immediateAccept:true.
|
|
287 |
classNameHolder onChangeEvaluate:updateList.
|
|
288 |
|
|
289 |
box entryCompletionBlock:(DoWhatIMeanSupport classNameEntryCompletionBlock).
|
|
290 |
box action:[:aString | className := aString].
|
|
291 |
|
|
292 |
box panelView
|
|
293 |
addSubView:(showingWhatLabel := (Label label:(resources string:'Recently visited:')) adjust:#left) before:nil;
|
|
294 |
addSubView:(check := CheckBox label:(resources string:'Show Full Name (do not strip off Namespace)') model:showFullNameHolder) before:nil.
|
|
295 |
showFullNameHolder onChangeEvaluate:updateList.
|
|
296 |
box enterField origin:(0 @ check corner y).
|
|
297 |
box listView origin:(0 @ check corner y).
|
|
298 |
|
|
299 |
box extent:(400 @ 350).
|
|
300 |
box open.
|
|
301 |
|
|
302 |
className isEmptyOrNil ifTrue:[^ nil "cancel"].
|
|
303 |
|
|
304 |
LastClassSearchBoxShowedFullName := showFullNameHolder value.
|
|
305 |
|
|
306 |
(className endsWith:$) ) ifTrue:[
|
|
307 |
(className indexOfSubCollection:'(in ') == 0 ifTrue:[
|
|
308 |
"/ a namespace
|
|
309 |
className := (className copyTo:(className indexOfSubCollection:'(Name')-1) withoutSeparators
|
|
310 |
] ifFalse:[
|
|
311 |
className := ((className copyFrom:(className indexOfSubCollection:'(in ')+4)
|
|
312 |
copyButLast:1)
|
|
313 |
, '::' , className asCollectionOfWords first
|
|
314 |
].
|
|
315 |
].
|
|
316 |
|
|
317 |
aBlock notNil ifTrue:[aBlock value:className optionalArgument:singleClass and:doWhat].
|
|
318 |
^ className
|
|
319 |
|
|
320 |
"Created: / 03-08-2017 / 12:31:08 / cg"
|
|
321 |
"Modified: / 03-08-2017 / 14:14:39 / cg"
|
|
322 |
! !
|
|
323 |
|
|
324 |
!ClassSearchDialog methodsFor:'private helpers'!
|
|
325 |
|
|
326 |
createDialogBox:msg title:boxTitle label:boxLabel
|
|
327 |
|title|
|
|
328 |
|
|
329 |
title := (resources string:boxTitle) , msg , '.\' , (resources string:'(TAB to complete; matchPattern allowed - "*" for all):').
|
|
330 |
|
|
331 |
box := SystemBrowser
|
|
332 |
enterBoxForClassWithCodeSelectionTitle:title withCRs
|
|
333 |
withList:(showFullNameHolder value ifTrue:[visitedFullNames] ifFalse:[visitedShortNames])
|
|
334 |
okText:(okText ? 'OK')
|
|
335 |
forBrowser:browser.
|
|
336 |
|
|
337 |
box label:(resources string:boxLabel).
|
|
338 |
^ box
|
|
339 |
|
|
340 |
"Created: / 03-08-2017 / 14:02:33 / cg"
|
|
341 |
!
|
|
342 |
|
|
343 |
genShortNameListEntry:cls
|
|
344 |
|ns|
|
|
345 |
|
|
346 |
cls isNil ifTrue:[
|
|
347 |
^ nil
|
|
348 |
].
|
|
349 |
|
|
350 |
ns := cls topNameSpace name.
|
|
351 |
ns = 'Smalltalk'
|
|
352 |
ifTrue:[ ns := '' ]
|
|
353 |
ifFalse:[ns := ' (in ',ns,')'].
|
|
354 |
|
|
355 |
^ cls nameWithoutNameSpacePrefix,ns
|
|
356 |
|
|
357 |
"Created: / 03-08-2017 / 12:41:04 / cg"
|
|
358 |
!
|
|
359 |
|
|
360 |
getAllClasses
|
|
361 |
"
|
|
362 |
self new getAllClasses
|
|
363 |
|
|
364 |
Time millisecondsToRun:[
|
|
365 |
self new getAllClasses
|
|
366 |
]
|
|
367 |
"
|
|
368 |
|
|
369 |
|prefs emphasisForChanged |
|
|
370 |
|
|
371 |
prefs := UserPreferences current.
|
|
372 |
emphasisForChanged := prefs emphasisForChangedCode.
|
|
373 |
|
|
374 |
setOfClassNamesInChangeSet isNil ifTrue:[
|
|
375 |
self getClassNamesInChangeSet
|
|
376 |
].
|
|
377 |
|
|
378 |
reallyAllClasses isNil ifTrue:[
|
|
379 |
reallyAllClasses := Smalltalk allClasses copyAsOrderedCollection
|
|
380 |
].
|
|
381 |
allClasses := reallyAllClasses.
|
|
382 |
(onlyShowJavaClassesHolder value ? false) ifTrue:[
|
|
383 |
allClasses := allClasses select:[:cls | cls isJavaClass].
|
|
384 |
].
|
|
385 |
classFilter notNil ifTrue:[
|
|
386 |
allClasses := allClasses select:classFilter
|
|
387 |
].
|
|
388 |
allClassesByFullName := allClasses copy.
|
|
389 |
|
|
390 |
allNames := (allClasses
|
|
391 |
collect:[:cls |
|
|
392 |
|ns nm|
|
|
393 |
|
|
394 |
cls isJavaClass ifTrue:[
|
|
395 |
nm := cls javaName,' (in JAVA)'
|
|
396 |
] ifFalse:[
|
|
397 |
ns := cls topNameSpace name.
|
|
398 |
ns = 'Smalltalk'
|
|
399 |
ifTrue:[ ns := '' ]
|
|
400 |
ifFalse:[ns := ' (in ',ns,')'].
|
|
401 |
cls isNameSpace ifTrue:[
|
|
402 |
nm := cls nameWithoutNameSpacePrefix,ns,' (Namespace)'
|
|
403 |
] ifFalse:[
|
|
404 |
nm := cls nameWithoutNameSpacePrefix,ns
|
|
405 |
].
|
|
406 |
].
|
|
407 |
(setOfClassNamesInChangeSet includes:cls name) ifTrue:[
|
|
408 |
nm asText emphasisAllAdd:emphasisForChanged
|
|
409 |
] ifFalse:[
|
|
410 |
nm
|
|
411 |
].
|
|
412 |
]) sortWith:allClasses; yourself.
|
|
413 |
|
|
414 |
allFullNames := (allClasses
|
|
415 |
collect:[:cls |
|
|
416 |
|nm|
|
|
417 |
|
|
418 |
nm := cls name.
|
|
419 |
(setOfClassNamesInChangeSet includes:nm) ifTrue:[
|
|
420 |
nm asText emphasisAllAdd:emphasisForChanged
|
|
421 |
] ifFalse:[
|
|
422 |
nm
|
|
423 |
].
|
|
424 |
]) sortWith:allClassesByFullName; yourself.
|
|
425 |
|
|
426 |
"Created: / 03-08-2017 / 12:59:51 / cg"
|
|
427 |
!
|
|
428 |
|
|
429 |
getClassNamesInChangeSet
|
|
430 |
|classesInChangeSet|
|
|
431 |
|
|
432 |
classesInChangeSet := ChangeSet current changedClasses.
|
|
433 |
classFilter notNil ifTrue:[
|
|
434 |
classesInChangeSet := classesInChangeSet select:classFilter
|
|
435 |
].
|
|
436 |
|
|
437 |
classNamesInChangeSet := classesInChangeSet collect:[:each | each theNonMetaclass name].
|
|
438 |
setOfClassNamesInChangeSet := classNamesInChangeSet asSet.
|
|
439 |
|
|
440 |
"Created: / 03-08-2017 / 12:47:00 / cg"
|
|
441 |
!
|
|
442 |
|
|
443 |
getResourcesFrom:resourcesOrNil orBrowser:aBrowserOrNil
|
|
444 |
resources := resourcesOrNil.
|
|
445 |
resources isNil ifTrue:[
|
|
446 |
aBrowserOrNil notNil ifTrue:[
|
|
447 |
resources := aBrowserOrNil resources.
|
|
448 |
].
|
|
449 |
resources isNil ifTrue:[
|
|
450 |
resources := SystemBrowser classResources.
|
|
451 |
].
|
|
452 |
].
|
|
453 |
|
|
454 |
"Created: / 03-08-2017 / 12:31:58 / cg"
|
|
455 |
!
|
|
456 |
|
|
457 |
getVisitedNames
|
|
458 |
|initialFullNames initialShortNames prefs
|
|
459 |
emphasisForChanged setOfClassNamesInChangeSet|
|
|
460 |
|
|
461 |
initialFullNames := SystemBrowser visitedClassNamesHistory.
|
|
462 |
(classFilter notNil) ifTrue:[
|
|
463 |
initialFullNames := initialFullNames
|
|
464 |
select:[:nm |
|
|
465 |
|cls|
|
|
466 |
|
|
467 |
(cls := Smalltalk at:nm) notNil
|
|
468 |
and:[classFilter value:cls]
|
|
469 |
].
|
|
470 |
].
|
|
471 |
|
|
472 |
initialFullNames := initialFullNames select:[:nm | nm notNil].
|
|
473 |
initialShortNames := initialFullNames collect:[:nm |
|
|
474 |
|cls|
|
|
475 |
|
|
476 |
cls := Smalltalk classNamed:nm.
|
|
477 |
cls isNil ifTrue:[
|
|
478 |
"/ class no longer exists (removed?)
|
|
479 |
nm withColor:(Color gray)
|
|
480 |
] ifFalse:[
|
|
481 |
cls isJavaClass ifTrue:[
|
|
482 |
cls javaName
|
|
483 |
] ifFalse:[
|
|
484 |
self genShortNameListEntry:(Smalltalk classNamed:nm)
|
|
485 |
].
|
|
486 |
].
|
|
487 |
].
|
|
488 |
|
|
489 |
prefs := UserPreferences current.
|
|
490 |
emphasisForChanged := prefs emphasisForChangedCode.
|
|
491 |
|
|
492 |
setOfClassNamesInChangeSet := classNamesInChangeSet asSet.
|
|
493 |
|
|
494 |
visitedFullNames := initialFullNames collect:[:clsName |
|
|
495 |
(setOfClassNamesInChangeSet includes:clsName) ifTrue:[
|
|
496 |
clsName asText emphasisAllAdd:emphasisForChanged
|
|
497 |
] ifFalse:[
|
|
498 |
clsName
|
|
499 |
].
|
|
500 |
].
|
|
501 |
|
|
502 |
visitedShortNames := initialShortNames with:initialFullNames collect:[:shortName :clsName |
|
|
503 |
(setOfClassNamesInChangeSet includes:clsName) ifTrue:[
|
|
504 |
shortName asText emphasisAllAdd:emphasisForChanged
|
|
505 |
] ifFalse:[
|
|
506 |
shortName
|
|
507 |
].
|
|
508 |
].
|
|
509 |
|
|
510 |
"Created: / 03-08-2017 / 12:54:10 / cg"
|
|
511 |
!
|
|
512 |
|
|
513 |
updateList
|
|
514 |
|nameToSearch list namesStarting namesNotStarting lcName nameList classList
|
|
515 |
isGlobOrRegexMatch isFuzzySearch labelText sort|
|
|
516 |
|
|
517 |
(nameToSearch := classNameHolder value withoutSeparators) isEmpty ifTrue:[
|
|
518 |
labelText := 'Recently visited:'.
|
|
519 |
list := (showFullNameHolder value ifTrue:[visitedFullNames] ifFalse:[visitedShortNames]).
|
|
520 |
] ifFalse:[
|
|
521 |
(nameToSearch includesString:'>>') ifTrue:[
|
|
522 |
nameToSearch := (nameToSearch copyTo:(nameToSearch indexOfString:'>>')-1) withoutSeparators.
|
|
523 |
].
|
|
524 |
isGlobOrRegexMatch := nameToSearch includesMatchCharacters.
|
|
525 |
isFuzzySearch := isGlobOrRegexMatch not and:[doFuzzyMatchHolder value].
|
|
526 |
|
|
527 |
labelText := 'Matching classes:'.
|
|
528 |
labelText := isGlobOrRegexMatch
|
|
529 |
ifTrue:['Matching classes (pattern):']
|
|
530 |
ifFalse:[
|
|
531 |
isFuzzySearch ifTrue:[
|
|
532 |
'Matching classes (fuzzy match):'
|
|
533 |
] ifFalse:[
|
|
534 |
'Matching classes (substring):'
|
|
535 |
].
|
|
536 |
].
|
|
537 |
|
|
538 |
nameList := showFullNameHolder value ifTrue:[ allFullNames ] ifFalse:[ allNames ].
|
|
539 |
classList := showFullNameHolder value ifTrue:[ allClassesByFullName ] ifFalse:[ allClasses ].
|
|
540 |
lcName := nameToSearch asLowercase.
|
|
541 |
false "(lcName includesString:'::')" ifTrue:[
|
|
542 |
list := OrderedCollection new.
|
|
543 |
allClasses doWithIndex:[:cls :idx |
|
|
544 |
|isIncluded|
|
|
545 |
|
|
546 |
isGlobOrRegexMatch ifTrue:[
|
|
547 |
isIncluded := (lcName match:cls name asLowercase)
|
|
548 |
] ifFalse:[
|
|
549 |
isIncluded := (cls name includesString:lcName caseSensitive:false)
|
|
550 |
].
|
|
551 |
isIncluded ifTrue:[
|
|
552 |
list add:(nameList at:idx)
|
|
553 |
].
|
|
554 |
].
|
|
555 |
] ifFalse:[
|
|
556 |
isGlobOrRegexMatch ifTrue:[
|
|
557 |
list := (1 to:allFullNames size)
|
|
558 |
select:
|
|
559 |
[:idx |
|
|
560 |
|nm1 nm2|
|
|
561 |
nm1 := (allFullNames at:idx) asLowercase.
|
|
562 |
nm2 := (classList at:idx) name asLowercase.
|
|
563 |
(lcName match:nm1)
|
|
564 |
or:[ (nm1~=nm2) and:[ lcName match:nm2]]
|
|
565 |
]
|
|
566 |
thenCollect:[:idx | "nameList "allFullNames"" at:idx].
|
|
567 |
|
|
568 |
] ifFalse:[
|
|
569 |
(doFuzzyMatchHolder value and:[FuzzyMatcher notNil]) ifTrue:[
|
|
570 |
|matcher matches|
|
|
571 |
|
|
572 |
matches := OrderedCollection new.
|
|
573 |
matcher := FuzzyMatcher pattern:lcName.
|
|
574 |
allFullNames "nameList" do:[:eachClassName |
|
|
575 |
matcher
|
|
576 |
match:eachClassName
|
|
577 |
ifScored: [:score |
|
|
578 |
matches add: { eachClassName . score . (matcher indexes copy) }
|
|
579 |
]
|
|
580 |
].
|
|
581 |
matches
|
|
582 |
sort:[:a :b |
|
|
583 |
|score_a score_b|
|
|
584 |
|
|
585 |
score_a := a at:2.
|
|
586 |
score_b := b at:2.
|
|
587 |
score_a < score_b
|
|
588 |
or:[ score_a = score_b and:[ (a at:1) > (b at:1)]
|
|
589 |
]
|
|
590 |
].
|
|
591 |
matches reverse.
|
|
592 |
list := (matches copyTo:(matches size min:150))
|
|
593 |
collect:[:triple |
|
|
594 |
|name score indexes|
|
|
595 |
name := triple first.
|
|
596 |
indexes := triple third.
|
|
597 |
name := name asText withColor:Color gray slightlyDarkened.
|
|
598 |
indexes do:[:each |
|
|
599 |
"/ name emphasiseFrom:each to:each with:{ #bold . #color->Color black }
|
|
600 |
name emphasiseFrom:each to:each with:{ #color->Color black }
|
|
601 |
].
|
|
602 |
name
|
|
603 |
].
|
|
604 |
] ifFalse:[
|
|
605 |
list := (1 to:nameList size)
|
|
606 |
select:[:idx |
|
|
607 |
|nm|
|
|
608 |
nm := nameList at:idx.
|
|
609 |
(nm includesString:lcName caseSensitive:false)
|
|
610 |
or:[ (classList at:idx) name includesString:lcName caseSensitive:false]
|
|
611 |
] thenCollect:[:idx |
|
|
612 |
|name matchPos|
|
|
613 |
|
|
614 |
name := nameList at:idx.
|
|
615 |
matchPos := name indexOfSubCollection:lcName caseSensitive:false.
|
|
616 |
name := name asText withColor:Color gray slightlyDarkened.
|
|
617 |
matchPos ~~ 0 ifTrue:[
|
|
618 |
name := name emphasiseFrom:matchPos to:matchPos+lcName size-1 with:{ #color->Color black }
|
|
619 |
].
|
|
620 |
name
|
|
621 |
].
|
|
622 |
].
|
|
623 |
]
|
|
624 |
].
|
|
625 |
|
|
626 |
sort :=
|
|
627 |
[:list |
|
|
628 |
|list2 nameForDistance|
|
|
629 |
|
|
630 |
nameForDistance := nameToSearch copyWithoutAll:'*#'.
|
|
631 |
|
|
632 |
list2 := list collect:[:nm | nm -> (nm levenshteinTo:nameForDistance)].
|
|
633 |
list2 sortBySelector:#value.
|
|
634 |
list2 collect:#key
|
|
635 |
].
|
|
636 |
|
|
637 |
namesStarting := list select:[:nm | nm asLowercase startsWith:lcName].
|
|
638 |
namesNotStarting := (list \ namesStarting).
|
|
639 |
list := (sort value:namesStarting) , {nil} , (sort value:namesNotStarting).
|
|
640 |
].
|
|
641 |
|
|
642 |
showingWhatLabel label:(resources string:labelText).
|
|
643 |
box listView
|
|
644 |
list:list;
|
|
645 |
scrollToLine:((list findFirst:[:line | (line ? '') startsWith:lcName]) max:1)
|
|
646 |
|
|
647 |
"Created: / 03-08-2017 / 14:10:37 / cg"
|
|
648 |
"Modified: / 04-08-2017 / 12:59:06 / cg"
|
|
649 |
! !
|
|
650 |
|
|
651 |
!ClassSearchDialog class methodsFor:'documentation'!
|
|
652 |
|
|
653 |
version
|
|
654 |
^ '$Header$'
|
|
655 |
!
|
|
656 |
|
|
657 |
version_CVS
|
|
658 |
^ '$Header$'
|
|
659 |
! !
|
|
660 |
|