## The Action Catalog

Actions define procedures that can be bound to a menu item, a toolbar button or a keyboard shortcut. Actions are short scripts written in BeanShell, jEdit's macro scripting language. These scripts either direct the action themselves, delegate to a method in one of the plugin's classes that encapsulates the action, or do a little of both. The scripts are usually short; elaborate action protocols are usually contained in compiled code, rather than an interpreted macro script, to speed execution.

Actions are defined by creating an XML file entitled `actions.xml` and placing it in the plugin JAR file.

The `actions.xml` file from the QuickNotepad plugin looks as follows:

    <?xml version="1.0"?>

    <!DOCTYPE ACTIONS SYSTEM "actions.dtd">

    <ACTIONS>
        <ACTION NAME="quicknotepad.choose-file">
            <CODE>
                wm.getDockable(QuickNotepadPlugin.NAME).chooseFile();
            </CODE>
        </ACTION>

        <ACTION NAME="quicknotepad.save-file">
            <CODE>
                wm.getDockable(QuickNotepadPlugin.NAME).saveFile();
            </CODE>
        </ACTION>

        <ACTION NAME="quicknotepad.copy-to-buffer">
            <CODE>
                wm.getDockable(QuickNotepadPlugin.NAME).copyToBuffer();
            </CODE>
        </ACTION>
    </ACTIONS>

This file defines three actions. They use the current view's `DockableWindowManager` object and the method `getDockable()` to find the QuickNotepad plugin window and call the desired method.

When an action is invoked, the BeanShell scripts address the plugin through static methods, or if instance data is needed, the current `View`, its `DockableWindowManager`, and the plugin object return by the `getDockable()` method.

If you are unfamiliar with BeanShell code, you may nevertheless notice that the code statements bear a strong resemblance to Java code, with one exception: the variable `view` is never assigned any value.

For complete answers to this and other BeanShell mysteries, see Part III, “Writing Macros”; two observations will suffice here. First, the variable `view` is predefined by jEdit's implementation of BeanShell to refer to the current `View` object. Second, the BeanShell scripting language is based upon Java syntax, but allows variables to be typed at run time, so explicit types for variables need not be declared.

A formal description of each element of the `actions.xml` file can be found in the documentation of the `ActionSet` class.