Molding Spotter searches

A Spotter search is like an inspector view: it's a method implemented in a class of the object in the context of which we want to search. The global Spotter starts from an instance of GtSpotterStart Object subclass: #GtSpotterStart instanceVariableNames: 'spotterModel' classVariableNames: '' package: 'GToolkit-Spotter-Extensions' . For example, GtSpotterStart>>#gtSearchForPragmasFor: gtSearchForPragmasFor: aSearch <gtSearch> ^ aSearch list priority: 40; items: [ GtPragmaType all ]; title: 'Pragmas'; itemName: [ :pragma | pragma keyword ]; filterBySubstring; wantsToDisplayOnEmptyQuery: false defines the search of the pragmas from the image.

The method above defines the search through a fluent API, not unlike the Inspector views. Specifically, it uses the GtSpotterProtoSearch>>#list list ^ GtSpotterListSearch new .

Other methods, like GtSpotterStart>>#gtSearchForClassesFor: gtSearchForClassesFor: aSearch <gtSearch> ^ aSearch explicit priority: 10; title: 'Classes'; search: [ :aContext | GtPharoIndex current asyncClassesForWord: aContext searchQuery ]; "itemIcon: #systemIcon;" "keyBinding: $b meta;" yourself which is responsible for searching for classes and traits in the image, rely on an explicit search. We use an explicit search because we want to delegate to a cache rather than traversing an existing list.

Examples

To learn from similar methods, you can look at Querying Pharo code with GT filters:

#gtSearch gtPragmas
  

Inspecting

Such search methods can be defined in any class and when Spotter is opened on an instance of the class, the custom search will become available. When a class defines a custom search, the inspector over an instance of that class will have a Spotter action button with the custom search.

For example, GtABAddressBook>>#gtGtSpotterForAddressesFor: gtGtSpotterForAddressesFor: aSearch <gtSearch> ^ aSearch list priority: 10; title: 'Addresses' translated; items: [ (self contacts collect: #address as: Set) asOrderedCollection ]; itemName: [ :each | each city , ', ' , each country ]; filterBySubstring; wantsToDisplayOnEmptyQuery: true defines a search over the addresses from an address book. When inspecting an instance of GtABAddressBook Object subclass: #GtABAddressBook instanceVariableNames: 'label contacts categories' classVariableNames: '' package: 'GToolkit-Demo-AddressBook-Models' we get a search button in the inspector.