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