# HG changeset patch # User Claus Gittinger # Date 1372156923 -7200 # Node ID 8298397571ebd1c0277dcb8127ce3d34f669022d # Parent 4cdf177f597661e994afa3fd6c33566631744b26 class: MethodFinderWindow added: #resultInfoText comment/format in: #searchPatternChanged changed:5 methods better (faster) incremental search diff -r 4cdf177f5976 -r 8298397571eb MethodFinderWindow.st --- a/MethodFinderWindow.st Mon Jun 24 17:51:10 2013 +0200 +++ b/MethodFinderWindow.st Tue Jun 25 12:42:03 2013 +0200 @@ -283,7 +283,7 @@ layout: (LayoutFrame 5 0.5 -25 1 -5 1 0 1) translateLabel: true tabable: true - model: searchPatternMatches + model: searchPatternMatchesInBackground ) ) @@ -752,58 +752,32 @@ ! searchPatternChanged - "/ self searchPatternMatches self searchPatternMatchesInBackground "Created: / 01-06-2012 / 13:18:16 / cg" ! -searchPatternMatches - "Do a search based on the pattern match" - - | pattern list selectors counts| - - pattern := self selectorPattern value. - - self resultHolder value: nil. "reset the result list" - self classOfResultHolder value: nil. "reset the implementorOf list" - self codeHolder value: nil. "reset the source" - - self withCursor:Cursor execute do:[ - pattern includesMatchCharacters ifFalse:[ - pattern := '*',pattern,'*' - ]. - list := SystemBrowser findImplementorsMatching:pattern in:Smalltalk allClasses ignoreCase:true. - ]. +searchPatternMatchesInBackground + "Do a search based on the pattern match as a background task" - counts := IdentityDictionary new. - selectors := IdentitySet new. - - list do:[:eachMethod | - selectors add: eachMethod selector. - (counts at:(eachMethod selector) ifAbsentPut:[0 asValue]) increment - ]. - - resultSelectors := selectors asOrderedCollection sort. - - self resultHolder value: (resultSelectors collect:[:sel | sel,' --> ',(counts at:sel) value printString,' implementor(s)']). - - "Created: / 27-04-2012 / 14:46:35 / cg" -! - -searchPatternMatchesInBackground - "Do a search based on the pattern match" - - | p pattern list| + | p pattern| (p := searchProcess) notNil ifTrue:[ searchProcess := nil. p terminate. ]. + pattern := self selectorPattern value. + pattern isEmptyOrNil ifTrue:[ + self resultHolder value:self resultInfoText. + self classOfResultHolder value:nil. + self codeHolder value:nil. + ^ self + ]. + searchProcess := [ - pattern := self selectorPattern value. + |list counts firsts seconds selectors resultList| self withCursor:Cursor execute do:[ pattern includesMatchCharacters ifFalse:[ @@ -811,7 +785,43 @@ ]. list := SystemBrowser findImplementorsMatching:pattern in:Smalltalk allClasses ignoreCase:true. ]. - self enqueueDelayedAction:[ self updateListAfterPatternSearch: list ] + + counts := IdentityDictionary new. + firsts := IdentityDictionary new. + seconds := IdentityDictionary new. + selectors := IdentitySet new. + list do:[:eachMethod | + |msel| + + msel := eachMethod selector. + selectors add:msel. + (counts at:msel ifAbsentPut:[ 0 asValue ]) increment. + (firsts includesKey:msel) ifTrue:[ + (seconds includesKey:msel) ifFalse:[ + seconds at:msel ifAbsentPut:[ eachMethod mclass ]. + ]. + ] ifFalse:[ + firsts at:msel ifAbsentPut:[ eachMethod mclass ]. + ]. + ]. + resultSelectors := selectors asOrderedCollection sort. + resultList := resultSelectors + collect:[:sel | + |cnt s| + + s := sel allBold , ' --> '. + cnt := (counts at:sel) value. + cnt == 1 ifTrue:[ + s , (firsts at:sel) name + ] ifFalse:[ + cnt == 2 ifTrue:[ + s , (firsts at:sel) name , ' and ' , (seconds at:sel) name + ] ifFalse:[ + s , cnt printString , ' implementor(s)' + ] + ]. + ]. + self enqueueDelayedAction:[ self updateListAfterPatternSearch: resultList ] ] fork. "Created: / 01-06-2012 / 13:16:54 / cg" @@ -872,34 +882,10 @@ "Modified (comment): / 24-06-2012 / 18:41:45 / cg" ! -updateListAfterPatternSearch:list - "Do a search based on the pattern match" - - |selectors counts firsts| - - self resultHolder value:nil. +updateListAfterPatternSearch:resultList self classOfResultHolder value:nil. self codeHolder value:nil. - counts := IdentityDictionary new. - firsts := IdentityDictionary new. - selectors := IdentitySet new. - list do:[:eachMethod | - selectors add:eachMethod selector. - (counts at:(eachMethod selector) ifAbsentPut:[ 0 asValue ]) increment. - firsts at:(eachMethod selector) ifAbsentPut:[ eachMethod mclass ]. - ]. - resultSelectors := selectors asOrderedCollection sort. - self resultHolder value:(resultSelectors - collect:[:sel | - |cnt| - - cnt := (counts at:sel) value. - cnt == 1 ifTrue:[ - sel , ' --> ' , (firsts at:sel) name - ] ifFalse:[ - sel , ' --> ' , cnt printString , ' implementor(s)' - ]. - ]). + self resultHolder value:resultList. "Created: / 01-06-2012 / 13:17:34 / cg" ! ! @@ -990,19 +976,23 @@ (holder := builder bindingAt:#resultHolder) isNil ifTrue:[ holder := ValueHolder new. builder aspectAt:#resultHolder put:holder. - holder value:{ - 'Please enter combination of' . - ' ',('receiver, arg and result' allBold) . - 'or a'. - ' ',('selector search pattern' allBold) . - 'into the above fields, then click on either ',('"search"' allBold),'-button.' - } + holder value:self resultInfoText. ]. ^ holder. "Modified: / 01-06-2012 / 13:06:02 / cg" ! +resultInfoText + ^ { + 'Please enter combination of' . + ' ',('receiver, arg and result' allBold) . + 'or a'. + ' ',('selector search pattern' allBold) . + 'into the above fields, then click on either ',('"search"' allBold),'-button.' + } +! + selectedClassOfResultHolder "valueHolder which contains the index of the selected result class (right list)"