public interface ActionHookInvoker
ActionHookInvoker
is an interface to a class that
is responsible for performing some set of actions. Although this
interface is almost identical to ActionInvoker, it is intended to
be used to allow editor clients or plugins to register themselves
as actions hooks in order to take over responsibility for
handling a certain subset of editor actions for some specific
task (preferably for a temporary period of time. Let's take code insight as an example, when you pop up a completion window, the insight functionality needs to be able to trap the cursor navigation keys, escape (cancel), and enter (complete) from the editor. This is how it would be done. When the dialog is first brought up, it would register itself as an ActionHookDialog, and when it is dismissed, it will deregister itself.
Note, as a hint, in invokeAction
don't do a series of
if comparisons as it can get expensive (if there are a lot of actions
or a lot of ActionHookInvokers
.) For example, don't
do this:
Bad code:
public boolean invokeAction( String actionKey ) { if ( actionKey.equals( "some-action-1" ) ) { // call action 1 here } else if ( actionKey.equals( "some-action-2" ) ) { // call action 2 here } else if ( actionKey.equals( "some-action-3" ) ) { // call action 3 here } }
The better thing to do would be to build up a hash table of actions using the action names as keys and invoke the actions that way.
Note the difference in invokeAction()
between this interface
and ActionInvoker
. invokeAction()
returns
a boolean here based on whether the action was performed by the
ActionHookInvoker
. Otherwise, the caller will continue
on to the next invoker and so on.
A current limitation is that the DefaultKeyTypedAction is not accessible through this interface (or through any interface currently) as it its execution path is different.
BasicEditorPane
,
ActionInvoker
Modifier and Type | Method and Description |
---|---|
boolean |
invokeAction(java.lang.String actionKey)
Invokes the Action corresponding to the given actionKey.
|