PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/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">&lt;?xml version="1.0"?&gt;
  20. &lt;!DOCTYPE ACTIONS SYSTEM "actions.dtd"&gt;
  21. &lt;ACTIONS&gt;
  22. &lt;ACTION NAME="quicknotepad.choose-file"&gt;
  23. &lt;CODE&gt;
  24. wm.getDockable(QuickNotepadPlugin.NAME).chooseFile();
  25. &lt;/CODE&gt;
  26. &lt;/ACTION&gt;
  27. &lt;ACTION NAME="quicknotepad.save-file"&gt;
  28. &lt;CODE&gt;
  29. wm.getDockable(QuickNotepadPlugin.NAME).saveFile();
  30. &lt;/CODE&gt;
  31. &lt;/ACTION&gt;
  32. &lt;ACTION NAME="quicknotepad.copy-to-buffer"&gt;
  33. &lt;CODE&gt;
  34. wm.getDockable(QuickNotepadPlugin.NAME).copyToBuffer();
  35. &lt;/CODE&gt;
  36. &lt;/ACTION&gt;
  37. &lt;/ACTIONS&gt;</pre></td></tr></table></div><p>
  38. This file defines three actions. They use the current view's
  39. <a href="../api/org/gjt/sp/jedit/gui/DockableWindowManager.html" target="_top">
  40. <tt class="classname">DockableWindowManager</tt></a> object and the method
  41. <tt class="filename">getDockable()</tt> to find the QuickNotepad plugin
  42. window and call the desired method.
  43. </p><p>
  44. When an action is invoked, the BeanShell scripts address
  45. the plugin through static methods, or if instance data is needed, the
  46. current <a href="../api/org/gjt/sp/jedit/View.html" target="_top">
  47. <tt class="classname">View</tt></a>, its
  48. <a href="../api/org/gjt/sp/jedit/gui/DockableWindowManager.html" target="_top">
  49. <tt class="classname">DockableWindowManager</tt></a>, and the plugin
  50. object return by the <tt class="filename">getDockable()</tt> method.
  51. </p><p>
  52. If you are unfamiliar with BeanShell code, you may nevertheless notice
  53. that the code statements bear a strong resemblance to Java code, with
  54. one exception: the
  55. variable <tt class="varname">view</tt> is never assigned any value.
  56. </p><p>
  57. For complete answers to this and other BeanShell
  58. mysteries, see <a href="writing-macros-part.html" title="Part III. Writing Macros">Part III, &#8220;Writing Macros&#8221;</a>; two
  59. observations will suffice here. First, the variable
  60. <tt class="varname">view</tt> is predefined by jEdit's implementation of
  61. BeanShell to refer to the current <tt class="classname">View</tt> object.
  62. Second, the
  63. BeanShell scripting language is based upon Java syntax, but allows
  64. variables to be typed at run time, so explicit types for variables
  65. need not be declared.
  66. </p><p>
  67. A formal description of each element of the
  68. <tt class="filename">actions.xml</tt> file can be found in the
  69. documentation of the
  70. <a href="../api/org/gjt/sp/jedit/ActionSet.html" target="_top">
  71. <tt class="classname">ActionSet</tt></a> class.
  72. </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>