SelectCase
Hans-Martin Mosner
hmm at heeg.de
Wed Jan 4 20:08:05 UTC 2006
Chris Muller wrote:
>A key-command handler method.
>
> keyPressed caseOf:
> {[$c]->[self copy].
> [$x]->[self cut].
> [$v]->[self paste]}
>
>What's the best way other than case statement to map
>keyPressed to the desired action?
>
>
The explicit Dictionary approach might be easiest, and if the dictionary
is not built on the fly in te method which interprets key characters but
during initialization, there are opportunities for plug-ins to add their
key->action associations.
An even better option might be something like Command objects which know
their appropriate action, their keyboard shortcut and their label, icon
and position in the menu structure of your application. Then you would
have just one big bag of Commands, and the keyboard handler can just
grab the right one out of it, the menu builder can use it to build the
menu and to interpret menu actions, etc.
Cheers,
Hans-Martin
Recommended reading: "Domain-Driven Design" by Eric Evans. Questions
such as how a case statement should be written become really secondary.
More information about the Squeak-dev
mailing list
|