dolphinsmalltalk / Dolphin

Dolphin Smalltalk Core Image
MIT License
294 stars 58 forks source link

First cut of replacement for the poorly regarded #queryCommand: "switch" #1201

Closed blairmcg closed 7 months ago

blairmcg commented 7 months ago

The #queryCommand: method is one of the least satisfactory elements of the original MVP design, because it results in a large and often complex and difficult to maintain switch statement (albeit a switch on value, and not type). It also doesn't lend itself to extensibility, and consequently various ad-hoc approaches have been used to achieve that, e.g. registering additional handlers in the dev tool presenter hierarchy, and the use of ClosedCommandDescriptions (commands that have their own query block, and which are invoked first, effectively shortcutting the normal chain-of-command route).

This PR adds a prototypical replacement mechanism using method annotations to associate a query function with a command. The annotation is placed in the command method and specifies the selector of the query function for that command. A single query method can be associated with multiple commands.

In order to test out the mechanism in practice, the #queryCommand of ClassSelector has been replaced. This is a relatively complex example, and so should cover many of the variations. A couple of extension cases have also been implemented with the new mechanism. It is, however, expected that other cases will be encountered as more #queryCommand: methods are replaced, and so the design may require refinement.

All uses of the existing extension mechanism that allowed for provision of extra old-style command query methods, e.g. the queryRefactoringCommand: methods added to PackageBrowserShell, etc, have also been replaced.