XHandler
XHandler is an AppleScript library to execute a handler with specifying its name with a text. This libary allows to change a handler to execute at run-time.
Fhutermore, followings can be made possible.
- Check whther the script object has the handler or not.
- If the script object don't have called handler, it is made possible that the script object can hand calling the handler over another script object.
XHandler can be used for chain of responder pattern and method forwarding.
use XHandler : script "XHandler"
script BScript
on say_msg(a_msg)
return "hey " & a_msg
end say_msg
end script
script AScript
on show_msg(a_msg)
return "hello " & a_msg
end show_msg
-- successor object to foward calling handlers which are not implemented.
on successor()
return BScript
end successor
end script
(*== Simply calling handler ==*)
set xhandler1 to XHandler's make_with("show_msg", 1)
log xhandler1's do(AScript, "good morning") -- hello good morning
(*== Test whether AScript can respont to the handler "show_msg" ==*)
log xhandler1's responded_by(AScript) -- true
(*== If target object can't resond to the handler, try to call handler in a successr object . ==*)
set xhandler2 to XHandler's make_with("say_msg", 1)
log xhandler2's call_to(AScript, "good evening") -- "hey good evening"
History
- 1.4 -- 2020-02-05
- OpenHelpBook.scptd is used to display a help book instead of HelpBook.osax.
- OS X 10.9 or later.
- 1.3 -- 2010-04-01
- Added "responded_by".
- Removed depencency on "ShowHelpBook".
- 1.2 -- 2008-02-28
- Remove call_handler to support all of handlers which have positional parameters.
- Add Japanese manual.
- 1.1.1 -- 2007-12-17
- Fix a problem that the Help Book is not shown in the Help Viewer.
- 1.1 -- 2007.08.22
- Split DynamicAccess into two moules of XAccessor and XHandler
- 1.0 -- 2007-06-06
- First Release