/www/tags/NOV_07_2009/htdocs/42docs/users-guide/plugin-implement-actions.html
HTML | 76 lines | 72 code | 4 blank | 0 comment | 0 complexity | c24d265eb7c2f6f2b858f9dff6dbfdd5 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
1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>The Action Catalog</title><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><link rel="home" href="index.html" title="jEdit 4.2 User's Guide"><link rel="up" href="plugin-implement.html" title="Chapter 18. Implementing a Simple Plugin"><link rel="previous" href="plugin-implement-properties.html" title="The Property File"><link rel="next" href="plugin-implement-dockables.html" title="The Dockable 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 Action Catalog</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="plugin-implement-properties.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 Action Catalog</h2></div></div><div></div></div><p>
2 Actions define procedures that can be bound to a menu
3 item, a toolbar button or a keyboard shortcut. Actions are short
4 scripts written in BeanShell, jEdit's macro scripting
5 language. These scripts either direct the action themselves,
6 delegate to a method in one of the plugin's classes that
7 encapsulates the action, or do a little of both. The scripts are
8 usually short; elaborate action protocols are usually contained in
9 compiled code, rather than an interpreted macro script, to speed
10 execution.
11</p><p>
12 Actions are defined by creating an XML file entitled
13 <tt class="filename">actions.xml</tt> and placing it in the plugin JAR
14 file.
15</p><p>
16 The <tt class="filename">actions.xml</tt>
17 file from the <span class="application">QuickNotepad</span> plugin looks
18 as follows:
19</p><div class="informalexample"><table border="0" bgcolor="#E0E0E0"><tr><td><pre class="programlisting"><?xml version="1.0"?>
20
21<!DOCTYPE ACTIONS SYSTEM "actions.dtd">
22
23<ACTIONS>
24 <ACTION NAME="quicknotepad.choose-file">
25 <CODE>
26 wm.getDockable(QuickNotepadPlugin.NAME).chooseFile();
27 </CODE>
28 </ACTION>
29
30 <ACTION NAME="quicknotepad.save-file">
31 <CODE>
32 wm.getDockable(QuickNotepadPlugin.NAME).saveFile();
33 </CODE>
34 </ACTION>
35
36 <ACTION NAME="quicknotepad.copy-to-buffer">
37 <CODE>
38 wm.getDockable(QuickNotepadPlugin.NAME).copyToBuffer();
39 </CODE>
40 </ACTION>
41</ACTIONS></pre></td></tr></table></div><p>
42 This file defines three actions. They use the current view's
43 <a href="../api/org/gjt/sp/jedit/gui/DockableWindowManager.html" target="_top">
44 <tt class="classname">DockableWindowManager</tt></a> object and the method
45 <tt class="filename">getDockable()</tt> to find the QuickNotepad plugin
46 window and call the desired method.
47</p><p>
48 When an action is invoked, the BeanShell scripts address
49 the plugin through static methods, or if instance data is needed, the
50 current <a href="../api/org/gjt/sp/jedit/View.html" target="_top">
51 <tt class="classname">View</tt></a>, its
52 <a href="../api/org/gjt/sp/jedit/gui/DockableWindowManager.html" target="_top">
53 <tt class="classname">DockableWindowManager</tt></a>, and the plugin
54 object return by the <tt class="filename">getDockable()</tt> method.
55</p><p>
56 If you are unfamiliar with BeanShell code, you may nevertheless notice
57 that the code statements bear a strong resemblance to Java code, with
58 one exception: the
59 variable <tt class="varname">view</tt> is never assigned any value.
60</p><p>
61 For complete answers to this and other BeanShell
62 mysteries, see <a href="writing-macros-part.html" title="Part III. Writing Macros">Part III, “Writing Macros”</a>; two
63 observations will suffice here. First, the variable
64 <tt class="varname">view</tt> is predefined by jEdit's implementation of
65 BeanShell to refer to the current <tt class="classname">View</tt> object.
66 Second, the
67 BeanShell scripting language is based upon Java syntax, but allows
68 variables to be typed at run time, so explicit types for variables
69 need not be declared.
70</p><p>
71 A formal description of each element of the
72 <tt class="filename">actions.xml</tt> file can be found in the
73 documentation of the
74 <a href="../api/org/gjt/sp/jedit/ActionSet.html" target="_top">
75 <tt class="classname">ActionSet</tt></a> class.
76</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="plugin-implement-properties.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 Property File </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> The Dockable Window Catalog</td></tr></table></div></body></html>