Actions and Shortcuts and Action chaining

I hope someone can clear this up for me.

I have created an action class that extends AnAction for my plugin. Now let's say I map this to a common key such as the "Enter" key because I want to do some processing each time a user presses this key. I created a new keymap based on "default", and removed the "Enter" key mapping for the Editor Action "EditorEnter" and make the "Enter" key a shorcut for my custom action.

This works in an editor. My custom action gets called each time the user press the "Enter" key. Now, of course, I need IDEA to process the "Enter" key too. So I call ActionManager.getAction("EditorEnter") and then call the actionPerformed() method and the world is a happy place.

OK - now my problem. If I type Ctrl-N to search for a class, the classname entry field doesn't get my "Enter" key. My custom action is still getting called each time the user presses "Enter". I've determined that in this case the Editor within the DataContext received as part of the AnActionEvent is null so I know the "Enter" key is meant for something other than an editor.

How do I resend the "Enter" key so the entry field in the classname dialog gets it? This isn't specific to this dialog - just an example. I have the same problem is many dialogs and other plugins such as the SQL plugin.

Thanks for any pointers,
Rick

1 comment

It's amazing how one is able to answer their own question minutes after asking someone else the question. I've been struggling with this for a few days and here's the answer:

Don't create a new action. Simply create a new EditorActionHandler and replace the default "Enter" key (or whatever) handler with yours. Make sure yours keeps a reference to the original handler. Then in your handler's execute() method, call the original handler if the editor is null, or do your own code then, optionally, if appropriate, call the original handler.

Here is the code for my custom EditorActionHandler:


To setup the original editor action do the following:

0

Please sign in to leave a comment.