PageRenderTime 302ms CodeModel.GetById 296ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 1<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
 2        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
 3        scripting language. These scripts either direct the action themselves,
 4        delegate to a method in one of the plugin's classes that encapsulates
 5        the action, or do a little of both. The scripts are usually short;
 6        elaborate action protocols are usually contained in compiled code,
 7        rather than an interpreted macro script, to speed execution.</p><p>Actions are defined by creating an XML file entitled
 8        <code class="filename">actions.xml</code> and placing it in the plugin JAR
 9        file.</p><p>The <code class="filename">actions.xml</code> file from the
10        <span class="application">QuickNotepad</span> plugin looks as follows:</p><div class="informalexample"><pre class="programlisting">&lt;ACTIONS&gt;
11	&lt;ACTION NAME="quicknotepad.choose-file"&gt;
12		&lt;CODE&gt;
13			wm.addDockableWindow(QuickNotepadPlugin.NAME);
14			wm.getDockableWindow(QuickNotepadPlugin.NAME).chooseFile();
15		&lt;/CODE&gt;
16	&lt;/ACTION&gt;
17
18	&lt;ACTION NAME="quicknotepad.save-file"&gt;
19		&lt;CODE&gt;
20			wm.addDockableWindow(QuickNotepadPlugin.NAME);
21			wm.getDockableWindow(QuickNotepadPlugin.NAME).saveFile();
22		&lt;/CODE&gt;
23	&lt;/ACTION&gt;
24
25	&lt;ACTION NAME="quicknotepad.copy-to-buffer"&gt;
26		&lt;CODE&gt;
27			wm.addDockableWindow(QuickNotepadPlugin.NAME);
28			wm.getDockableWindow(QuickNotepadPlugin.NAME).copyToBuffer();
29		&lt;/CODE&gt;
30	&lt;/ACTION&gt;
31&lt;/ACTIONS&gt;</pre></div><p>This file defines three actions. They each use a built-in variable
32        <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">
33        <code class="classname">DockableWindowManager</code></a>. Whenever you need
34        to obtain a reference to the current dockable, or create a new one, this
35        is the class to use. We use the method <code class="filename">addDockable() followed
36        by getDockable()</code> to create if necessary, and then bring up
37        the QuickNotepad plugin dockable. This will be docked or floating,
38        depending on how it was last used.</p><p>When an action is invoked, the BeanShell scripts address the
39        plugin through static methods, or if instance data is needed, the
40        current <a class="ulink" href="../api/org/gjt/sp/jedit/View.html" target="_top">
41        <code class="classname">View</code></a>, its <a class="ulink" href="../api/org/gjt/sp/jedit/gui/DockableWindowManager.html" target="_top">
42        <code class="classname">DockableWindowManager</code></a>, and the plugin
43        object return by the <code class="filename">getDockable()</code> method.</p><p>If you are unfamiliar with BeanShell code, you may nevertheless
44        notice that the code statements bear a strong resemblance to Java code,
45        with one exception: the variable <code class="varname">view</code> is never
46        assigned any value.</p><p>For complete answers to this and other BeanShell mysteries, see
47        <a class="xref" href="writing-macros-part.html" title="Part III. Writing Macros">Part III, &#8220;Writing Macros&#8221;</a>; two observations will suffice
48        here. First, the variable <code class="varname">view</code> is predefined by
49        jEdit's implementation of BeanShell to refer to the current
50        <code class="classname">View</code> object. Second, the BeanShell scripting
51        language is based upon Java syntax, but allows variables to be typed at
52        run time, so explicit types for variables need not be declared.</p><p>A formal description of each element of the
53        <code class="filename">actions.xml</code> file can be found in the documentation
54        of the <a class="ulink" href="../api/org/gjt/sp/jedit/ActionSet.html" target="_top">
55        <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
56                ProjectViewer, create pure Java EditAction-derived Actions,
57                based which services are available, or which files are found in
58                a certain path. However, this is an advanced topic you can
59                explore further in the source and API docs of those
60                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>