The major issues encountered when writing a plugin core class arise from the developer's decisions on what features the plugin will make available. These issues have implications for other plugin elements as well.
Will the plugin provide for actions that the user can trigger using jEdit's menu items, toolbar buttons and keyboard shortcuts?
Will the plugin have its own visible interface?
Will the plugin have settings that the user can configure?
Will the plugin respond to any messages reflecting changes in the host application's state?
Should the plugin do something special when it gets focus?
Recall that the plugin core class must extend
EditPlugin
. In QuickNotepad's plugin core
class, there are no special initialization or shutdown chores to
perform, so we will not need a start()
or
stop()
method.
The resulting plugin core class is lightweight and straightforward to implement:
public class QuickNotepadPlugin extends EditPlugin { public static final String NAME = "quicknotepad"; public static final String OPTION_PREFIX = "options.quicknotepad."; }
The class has been simplified since 4.1, and all we
defined here were a couple of String
data
members to enforce consistent syntax for the name of properties
we will use throughout the plugin.
These names are used in actions.xml
for each of the menu choices. This file is discussed in more
detail in the section called “The Actions Catalog”. Each
action is a beanshell script.
<!DOCTYPE ACTIONS SYSTEM "actions.dtd"> <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>
The names also come up in the properties file,
QuickNotePad.props
file. The properties
define option panes and strings used by the plugin. It is
explained in more detail in the section called “The Property File” and the
EditPlugin
API docs.
# jEdit only needs to load the plugin the first time the user accesses it # the presence of this property also tells jEdit the plugin is using the new API plugin.QuickNotepadPlugin.activate=defer # These two properties are required for all plugins plugin.QuickNotepadPlugin.name=QuickNotepad plugin.QuickNotepadPlugin.author=John Gellene # version number == jEdit version number plugin.QuickNotepadPlugin.version=4.3 # online help plugin.QuickNotepadPlugin.docs=index.html # we only have one dependency, jEdit 4.2final, since we use the new plugin API plugin.QuickNotepadPlugin.depend.0=jedit 04.02.99.00 # plugin menu plugin.QuickNotepadPlugin.menu=quicknotepad \ - \ quicknotepad.choose-file \ quicknotepad.save-file \ quicknotepad.copy-to-buffer # action labels for actions supplied by dockables.xml quicknotepad.label=QuickNotepad # action labels for actions supplied by actions.xml quicknotepad.choose-file.label=Choose notepad file quicknotepad.save-file.label=Save notepad file quicknotepad.copy-to-buffer.label=Copy notepad to buffer # plugin option pane plugin.QuickNotepadPlugin.option-pane=quicknotepad # Option pane activation BeanShell snippet options.quicknotepad.code=new QuickNotepadOptionPane(); # Option pane labels options.quicknotepad.label=QuickNotepad options.quicknotepad.file=File: options.quicknotepad.choose-file=Choose options.quicknotepad.choose-file.title=Choose a notepad file options.quicknotepad.choose-font=Font: options.quicknotepad.show-filepath.title=Display notepad file path # window title quicknotepad.title=QuickNotepad # window toolbar buttons quicknotepad.choose-file.icon=Open.png quicknotepad.save-file.icon=Save.png quicknotepad.copy-to-buffer.icon=CopyToBuffer.png # default settings options.quicknotepad.show-filepath=true options.quicknotepad.font=Monospaced options.quicknotepad.fontstyle=0 options.quicknotepad.fontsize=14 # Setting not defined but supplied for completeness options.quicknotepad.filepath=