/www/tags/NOV_07_2009/htdocs/users-guide/plugin-implement-actions.html
HTML | 60 lines | 58 code | 2 blank | 0 comment | 0 complexity | 75045f5ea0b5980aaf8cfd2f9c96b439 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
- <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>The Actions Catalog</title><meta name="generator" content="DocBook XSL Stylesheets V1.73.2"><link rel="start" href="index.html" title="jEdit 4.3 User's Guide"><link rel="up" href="plugin-implement.html" title="Chapter 18. Implementing a Simple Plugin"><link rel="prev" href="plugin-implement-editbus.html" title="The EditBus"><link rel="next" href="plugin-implement-dockables.html" title="The dockables.xml Window Catalog"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">The Actions Catalog</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="plugin-implement-editbus.html">Prev</a> </td><th width="60%" align="center">Chapter 18. Implementing a Simple Plugin</th><td width="20%" align="right"> <a accesskey="n" href="plugin-implement-dockables.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="plugin-implement-actions"></a>The Actions Catalog</h2></div></div></div><p>Actions define procedures that can be bound to a menu item, a
- toolbar button or a keyboard shortcut. Most plugin Actions <sup>[<a name="id2608896" href="#ftn.id2608896" class="footnote">4</a>]</sup> 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.</p><p>Actions are defined by creating an XML file entitled
- <code class="filename">actions.xml</code> and placing it in the plugin JAR
- file.</p><p>The <code class="filename">actions.xml</code> file from the
- <span class="application">QuickNotepad</span> plugin looks as follows:</p><div class="informalexample"><pre class="programlisting"><ACTIONS>
- <ACTION NAME="quicknotepad.choose-file">
- <CODE>
- wm.addDockableWindow(QuickNotepadPlugin.NAME);
- wm.getDockableWindow(QuickNotepadPlugin.NAME).chooseFile();
- </CODE>
- </ACTION>
- <ACTION NAME="quicknotepad.save-file">
- <CODE>
- wm.addDockableWindow(QuickNotepadPlugin.NAME);
- wm.getDockableWindow(QuickNotepadPlugin.NAME).saveFile();
- </CODE>
- </ACTION>
- <ACTION NAME="quicknotepad.copy-to-buffer">
- <CODE>
- wm.addDockableWindow(QuickNotepadPlugin.NAME);
- wm.getDockableWindow(QuickNotepadPlugin.NAME).copyToBuffer();
- </CODE>
- </ACTION>
- </ACTIONS></pre></div><p>This file defines three actions. They each use a built-in variable
- <code class="literal">wm</code>, which refers to the current view's <a class="ulink" href="../api/org/gjt/sp/jedit/gui/DockableWindowManager.html" target="_top">
- <code class="classname">DockableWindowManager</code></a>. Whenever you need
- to obtain a reference to the current dockable, or create a new one, this
- is the class to use. We use the method <code class="filename">addDockable() followed
- by getDockable()</code> to create if necessary, and then bring up
- the QuickNotepad plugin dockable. This will be docked or floating,
- depending on how it was last used.</p><p>When an action is invoked, the BeanShell scripts address the
- plugin through static methods, or if instance data is needed, the
- current <a class="ulink" href="../api/org/gjt/sp/jedit/View.html" target="_top">
- <code class="classname">View</code></a>, its <a class="ulink" href="../api/org/gjt/sp/jedit/gui/DockableWindowManager.html" target="_top">
- <code class="classname">DockableWindowManager</code></a>, and the plugin
- object return by the <code class="filename">getDockable()</code> method.</p><p>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 <code class="varname">view</code> is never
- assigned any value.</p><p>For complete answers to this and other BeanShell mysteries, see
- <a class="xref" href="writing-macros-part.html" title="Part III. Writing Macros">Part III, “Writing Macros”</a>; two observations will suffice
- here. First, the variable <code class="varname">view</code> is predefined by
- jEdit's implementation of BeanShell to refer to the current
- <code class="classname">View</code> 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.</p><p>A formal description of each element of the
- <code class="filename">actions.xml</code> file can be found in the documentation
- of the <a class="ulink" href="../api/org/gjt/sp/jedit/ActionSet.html" target="_top">
- <code class="classname">ActionSet</code></a> class.</p><div class="footnotes"><br><hr width="100" align="left"><div class="footnote"><p><sup>[<a name="ftn.id2608896" href="#id2608896" class="para">4</a>] </sup>Some plugins, such as Sidekick, Console, and
- ProjectViewer, create pure Java EditAction-derived Actions,
- based which services are available, or which files are found in
- a certain path. However, this is an advanced topic you can
- explore further in the source and API docs of those
- plugins.</p></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="plugin-implement-editbus.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="plugin-implement.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="plugin-implement-dockables.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">The EditBus </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> The dockables.xml Window Catalog</td></tr></table></div></body></html>