[squeak-dev] The Inbox: ToolBuilder-Kernel-jr.110.mcz

Jakob Reschke jakob.reschke at student.hpi.de
Tue May 16 17:07:53 UTC 2017


This enables to use the search box to go to behaviors in other environments.

The new method is structurally the same as
#classOrTraitFrom:pattern:label:, but changed in various places to
handle the fact that there is not a single source to collect behaviors
from. Also it does not operate primarily on Strings, for obvious
reasons, but with the behaviors themselves.

2017-05-16 19:02 GMT+02:00 commits at source.squeak.org
<commits at source.squeak.org>:
> A new version of ToolBuilder-Kernel was added to project The Inbox:
> http://source.squeak.org/inbox/ToolBuilder-Kernel-jr.110.mcz
>
> ==================== Summary ====================
>
> Name: ToolBuilder-Kernel-jr.110
> Author: jr
> Time: 13 May 2017, 10:49:04.306891 pm
> UUID: 41b8cbb2-c017-f84b-af5d-a6b52d1365cd
> Ancestors: ToolBuilder-Kernel-jr.109
>
> extend behavior search to all environments
>
> =============== Diff against ToolBuilder-Kernel-jr.109 ===============
>
> Item was added:
> + ----- Method: ClassDescription>>labelForBehaviorsList (in category '*ToolBuilder-Kernel') -----
> + labelForBehaviorsList
> +       ^ self name,
> +               (self environment == Smalltalk globals
> +                       ifTrue: ['']
> +                       ifFalse: [' (', self environment name, ')'])!
>
> Item was changed:
>   ----- Method: UIManager>>classFromPattern:withCaption: (in category 'system introspecting') -----
>   classFromPattern: pattern withCaption: aCaption
> +       ^self classOrTraitFromAny: (Environment allInstances) pattern: pattern label: aCaption
> -       ^self classFromPattern: pattern withCaption: aCaption in: Smalltalk environment
>   "
>         self classFromPattern: 'CharRecog' withCaption: ''
>         self classFromPattern: 'rRecog' withCaption: ''
>         self classFromPattern: 'znak' withCaption: ''
>         self classFromPattern: 'orph' withCaption: ''
>         self classFromPattern: 'TCompil' withCaption: ''
>   "
>   !
>
> Item was added:
> + ----- Method: UIManager>>classOrTraitFromAny:pattern:label: (in category 'system introspecting') -----
> + classOrTraitFromAny: environments pattern: pattern label: label
> +       "If only one class or trait in the given environments has a name that matches pattern, return it.
> +       Otherwise, put up a menu offering the names (and environments) of all matching behaviors, and return the chosen one, else nil if nothing chosen.
> +       This method ignores separator characters in the pattern"
> +
> +       | toMatch allBehaviors matchingBehaviors exactMatches behaviorsWithReducedIdentifiers behaviorLabels |
> +       toMatch := pattern copyWithoutAll: Character separators.
> +       toMatch ifEmpty: [ ^nil ].
> +       "If there are behaviors named exactly as pattern, choose only from them."
> +       Symbol hasInterned: pattern ifTrue: [ :symbol | | declaringEnvironments |
> +               declaringEnvironments := environments select: [:each |
> +                       each at: symbol ifPresent: [:it | it isBehavior] ifAbsent: [false]].
> +               declaringEnvironments size = 1
> +                       ifTrue: [^ declaringEnvironments anyOne at: symbol].
> +               declaringEnvironments ifNotEmpty: [ | behaviors |
> +                       behaviors := (declaringEnvironments collect: [:each | each at: symbol]) asOrderedCollection sort: [:a :b | a name <= b name].
> +                       behaviorLabels := behaviors collect: [:each | each labelForBehaviorsList].
> +                       ^ self chooseFrom: behaviorLabels values: behaviors title: label]].
> +       "No exact match, look for potential matches."
> +       toMatch := pattern asLowercase copyWithout: $..
> +       allBehaviors := environments gather: [:each | each allClassesAndTraits].
> +       matchingBehaviors := (pattern last = $. "This is some old hack, using String>>#match: may be better."
> +               ifTrue: [ allBehaviors select: [ :each | each name asLowercase = toMatch ] ]
> +               ifFalse: [
> +                       allBehaviors select: [ :each |
> +                               each name includesSubstring: toMatch caseSensitive: false ] ])
> +               asOrderedCollection.
> +       exactMatches := matchingBehaviors select: [ :each | each name asLowercase = toMatch ].
> +       "Also try some fuzzy matching."
> +       behaviorsWithReducedIdentifiers := pattern suggestedTypeNames gather: [:each |
> +               allBehaviors select: [:behavior | behavior name = each]].
> +       behaviorsWithReducedIdentifiers ifNotEmpty: [
> +               matchingBehaviors addAll: behaviorsWithReducedIdentifiers].
> +       "Let the user select if there's more than one possible match. This may give surprising results."
> +       matchingBehaviors ifEmpty: [^ nil "nothing matches"].
> +       matchingBehaviors size = 1 ifTrue: [^ matchingBehaviors anyOne].
> +       exactMatches ifNotEmpty: [matchingBehaviors addAllFirst: exactMatches].
> +       behaviorLabels := matchingBehaviors collect: [:each | each labelForBehaviorsList].
> +       ^ self chooseFrom: behaviorLabels values: matchingBehaviors title: label!
>
>


More information about the Squeak-dev mailing list