[ENH] Hooker-nk
Ned Konz
ned at bike-nomad.com
Wed Mar 14 15:14:37 UTC 2001
This moves the hook registry into its own class, and out of
the environment global.
from preamble:
"Change Set: Hooker-nk
Date: 14 March 2001
Author: Ned Konz
This implements a global registry for general-purpose
additions of behavior without having to edit code.
For instance, the method changes in the MenuMorph class
in this change set allow one to intercept calls to the various
menu construction functions and add new menu items without
having to edit menu construction code.
However, this can be used to intercept calls to any method.
Lookup of hooks is by category (typically a Symbol, like
#menuAdditions), tag (an arbitrary object, often a Symbol), calling
class (exact match, no inheritance), and calling selector.
For instance, if we want to catch calls from A>>a to B>>b or C>>c, we
would add the line
self callHooksInCategory: #myCategory.
to both B>>b and C>>c.
Then we would register a global hook using
HookRegistry addHook: [ :cat :tag :mc1 :mc2 | 'actions here' ]
named: #someName
inCategory: #myCategory
fromClass: A
selector: #a.
When callHooksInCategory: call is made from A>>a to either B>>b or C>>c
(or any other method that calls self callHooksInCategory: #myCategory),
the block given in the registry call above will get called with:
cat #myCategory
tag #someName
mc1 A>>a method context (not a copy!!)
mc2 B>>b or C>>c method context (not a copy!!)
Because mc1 and mc2 are real block contexts, you can skip further
execution by using something like:
thisContext terminateTo: mc2 sender
in your block (in this case, the rest of B>>b or C>>c would be skipped).
Look at HookRegistry class>>hookExample1 for an example of adding
an item to the World Menu.
Look at HookRegistry class>>hookExample2 for an example of adding
an item to the World Menu, and skipping another one using the
terminateTo: trick.
"!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Hooker-nk.cs.gz
Type: application/octet-stream
Size: 3852 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20010314/ce8e3128/Hooker-nk.cs.obj
More information about the Squeak-dev
mailing list
|