At the heart of every plugin is an implementation of the org.gjt.sp.jedit.EditPlugin class. It registers the plugin's actions with jEdit, takes care of setting up the plugin's menus and menu items, and so on. When a plugin JAR is loaded, jEdit scans for any class files whose names end with Plugin (for example, FooPlugin). Those classes are instantiated and added to jEdit's plugin list.
public abstract class EditPlugin { public void start(); public void stop(); public void createMenuItems(Vector menuItems, Vector menus); public void createOptionPanes(OptionsDialog optionsDialog); } |
void start
(void);
This method is responsible for adding actions and edit modes to jEdit, and doing other initialization tasks. It is called at the end of the jEdit startup sequence, after all plugins are loaded (so by the time this method is called, classes from other plugins are available, and so on). Most plugins will want to override this method and do some initialization.
void stop
(void);
This method is called just before jEdit exits. Overriding it is rarely necessary.
Here is the source file (which should be named HelloWorldPlugin.java) for a simple plugin:
import org.gjt.sp.jedit.*; import java.util.Vector; public class HelloWorldPlugin extends EditPlugin { public void start() { jEdit.addAction(new hello_world()); } public void createMenuItems(View view, Vector menus, Vector menuItems) { menuItems.addElement(GUIUtilities.loadMenuItem(view,"hello-world")); } } |