Commit [c35e8c] jedit-0-4 Maximize Restore History

import of jEdit-0.4

Slava Pestov Slava Pestov 1998-10-01

1 2 > >> (Page 1 of 2)
added plugins/Reverse/Cmd_Reverse.java
added plugins/Reverse/Makefile
added plugins/Reverse/Reverse.props
added plugins/ToLower/Cmd_ToLower.java
added plugins/ToLower/Makefile
added plugins/ToLower/ToLower.props
added plugins/ToUpper/Makefile
added plugins/ToUpper/ToUpper.props
added plugins/WordCount/Cmd_WordCount.java
changed bin/Makefile
changed doc/Makefile
changed doc/index.txt
changed doc/menus.txt
changed doc/props.txt
changed doc/starting.txt
changed plugins/HelloWorld/Cmd_HelloWorld.java
changed plugins/HelloWorld/HelloWorld.props
copied doc/old/menus.txt -> doc/plugins.txt
copied doc/old/plugins.txt -> plugins/ToUpper/Cmd_ToUpper.java
plugins/Reverse/Cmd_Reverse.java Diff Switch to side-by-side view
Loading...
plugins/Reverse/Makefile Diff Switch to side-by-side view
Loading...
plugins/Reverse/Reverse.props Diff Switch to side-by-side view
Loading...
plugins/ToLower/Cmd_ToLower.java Diff Switch to side-by-side view
Loading...
plugins/ToLower/Makefile Diff Switch to side-by-side view
Loading...
plugins/ToLower/ToLower.props Diff Switch to side-by-side view
Loading...
plugins/ToUpper/Makefile Diff Switch to side-by-side view
Loading...
plugins/ToUpper/ToUpper.props Diff Switch to side-by-side view
Loading...
plugins/WordCount/Cmd_WordCount.java Diff Switch to side-by-side view
Loading...
bin/Makefile Diff Switch to side-by-side view
Loading...
doc/Makefile Diff Switch to side-by-side view
Loading...
doc/index.txt Diff Switch to side-by-side view
Loading...
doc/menus.txt Diff Switch to side-by-side view
Loading...
doc/props.txt Diff Switch to side-by-side view
Loading...
doc/starting.txt Diff Switch to side-by-side view
Loading...
plugins/HelloWorld/Cmd_HelloWorld.java Diff Switch to side-by-side view
Loading...
plugins/HelloWorld/HelloWorld.props Diff Switch to side-by-side view
Loading...
doc/old/menus.txt to doc/plugins.txt
--- a/doc/old/menus.txt
+++ b/doc/plugins.txt
@@ -1,107 +1,216 @@
-JEDIT MENU CONFIGURATION
+JEDIT PLUGINS (plugins.txt, last modified 1 Oct 1998)
+
+Contents
+--------
+1. Introduction
+2. Installing Plugins
+3. Using Plugins
+4. Developing Plugins
+5. Creating a Simple Plugin
 
 1. Introduction
 ---------------
-jEdit stores it's menus in property files (see props.txt). This has a number of
-advantages to compiling them into the program:
-- They're easier to modify.
-- One can make JARs that add support for other languages.
-- One can make JARs that add support for other key bindings, eg Emacs.
-
-2. Menubar Definition
+jEdit has a powerful plugin architecture. Plugins can be used to add almost
+any feature to jEdit. They are easy to write and even easier to install.
+
+2. Installing Plugins
 ---------------------
-When a module wants to load a property-based menubar, it calls the
-jEdit.loadMenubar(View view, String name) method. The method does the
-following:
-- It loads the property `name'. This is assumed to be a while space separated
-  list of menu names.
-- It creates an empty menubar.
-- It calls loadMenu() for each of the menus specified and adds them to the
-  menubar.
-- It returns the menubar.
-
-3. Menu Definition
-------------------
-The loadMenu(View view, String name) method is usually called by loadMenubar(),
-but it can be called manually to load popup menus, etc. It does the following:
-- It loads the property `name'. This is assumed to be a while space separated
-  list of menu item names.
-- It creates an empty menu whose label is the value of the property
-  `name'.label.
-- It adds a separator to the menu if a menu item is '-', otherwise it calls
-  loadMenuItem(). It then adds the separator/menu/menu item to the menu.
-- It returns the menu.
-
-4. Menu Item Definition
------------------------
-The loadMenuItem(View view, String name) method is usually called by
-loadMenu(), but it can be called manually for on-the-fly menu creation, etc. If
-`name' starts with '%', it loads the menu whose name is `name', *NOT* including
-the '%'. Otherwise, it creates a menu item whose label is the value of the
-property `name'.label and whose shortcut is the value of the property
-`name'.shortcut. Shortcuts are parsed as follows:
-- An 'A' character adds ALT to the shortcut's modifier mask.
-- An 'C' character adds CONTROL to the shortcut's modifier mask.
-- An 'M' character adds META to the shortcut's modifier mask. This is probably
-  the right alt key.
-- An 'S' character adds SHIFT to the shortcut's modifier mask.
-- The last character that is not an uppercase A, C, M or S is the key.
-
-5. Commands
------------
-When a menu item is selected, the command with the menu item's name (NOT the
-label) is executed. For more information on commands, see commands.txt.
-
-6. Dynamic Menus
+Plugins are distributed as JAR files. They have a .jar extension.
+
+Plugins can be installed in one of two directories - the system plugin
+directory and the user plugin directory. Plugins in the system directory
+can be used by all users on the system. Plugins in a user's plugin directory
+can only be used by that user.
+
+On Unix, the system plugin directory (assuming that you didn't change any
+installation variables) is /opt/slava/share/jedit-1.00/jars. Each user has
+a plugin directory in $HOME/.jedit-jars.
+
+On Windows 95 and 98, the system plugin directory is
+C:\Program Files\jEdit\jars. The user plugin directory is
+$JAVAHOME\.jedit-jars.
+
+On Windows NT, the system plugin directory is the same as that on
+Windows 95/98, but each user has a plugin directory in $HOME\.jedit-jars.
+
+Additional directories can be added to the search path with the -plugindir=
+command line option, see starting.txt for details.
+
+3. Using Plugins
 ----------------
-jEdit automatically generates some menus that you can insert in your menubar.
-jEdit currently supports the following dynamic menus:
-- `plugins': a list of installed plugins
-- `buffers': a list of opened buffers
-- `open_recent': a list of recently opened files
-- `goto_marker': a list of markers, with each menuitem bound to goto_marker
-- `clear_marker': a list of markers, with each menuitem bound to clear_marker
+Once a plugin is installed, jEdit will say so during startup.
+
+	Loading plugin /opt/slava/share/jedit-1.00/jars/HelloWorld.jar
+	Loading plugin /opt/slava/share/jedit-1.00/jars/ToLowercase.jar
+	Loading plugin /opt/slava/share/jedit-1.00/jars/ToUppercase.jar
+
+If a newly installed plugin doesn't appear to be loaded, check that it's in
+the correct directory and that it's a JAR file. Also, a message such as this
+indicates that the plugin is probably corrupted:
+
+	Loading plugin /opt/slava/share/jedit-1.00/jars/WordCount.jar
+	java.util.zip.ZipException: not a ZIP file (END header not found)
+		at java.util.zip.ZipFile.findEND(ZipFile.java)
+		at java.util.zip.ZipFile.readCEN(ZipFile.java)
+		at java.util.zip.ZipFile.<init>(ZipFile.java)
+		at CommandMgr.loadJar(CommandMgr.java:63)
+		at CommandMgr.loadPlugins(CommandMgr.java:52)
+		at jEdit.main(jEdit.java:95)
+
+If all goes well during startup, the plugins should also appear in the 
+`Plugins' menu. If a plugin doesn't appear in the plugins menu but a
+`Loading...' is printed, check that the plugin is valid and compatible with
+the current version of jEdit.
+
+4. Developing Plugins
+---------------------
+Plugins are stored in JAR files. The JAR file can contain two types of
+entries - properties and classes. Other types of entries are ignored.
+
+Property entries have a .props extension and should be in standard Java
+property file format. Any property files in a plugin are loaded by the
+jEdit property manager automatically.
+
+Class entries have a .class extension. They are standard Java classes. The
+jEdit command manager loads any classes in a plugin automatically. Also,
+classes which implement the `Command' interface and have a name prefixed with
+`Cmd_' are added to the plugins menu. To find out how to give the plugin's
+menu item a shortcut and label, see menus.txt.
+
+The Command interface defines the following methods:
+
+- public Object init(Hashtable args);
+  This method is called when the plugin is loaded. `args' is a Hashtable
+  which may be used to pass parameters in the future. At the moment, it's
+  always empty. The return value is also unused - it should be null.
   
-Note: A dynamic menu can only be included once in each menubar.
-
-7. Example Menubar Definition
------------------------------
-This is a simple menu bar definition. So if you didn't understand the above
-description, this will help. If you want a more complex one, take a look at the
-jEdit properties file.
-###
-app_mbar=file edit window help
-file=new open close - save save_as - exit
-file.label=File
-new.label=New
-new.shortcut=An ### Alt-N
-open.label=Open
-open.shortcut=Ao
-close.label=Close
-close.shortcut=Aw
-save.label=Save
-save.shortcut=As
-save_as.label=Save As...
-save_as.shortcut=ASs ### Alt-Shift-S
-exit.label=Exit
-exit.shortcut=Aq
-edit=undo redo - cut copy paste clear select_all
-edit.label=Edit
-undo.label=Undo
-undo.shortcut=Cz ### Control-z
-redo.label=Redo
-redo.shortcut=CSz ### Control-Shift-z
-cut.label=Cut
-cut.shortcut=Cx
-copy.label=Copy
-copy.shortcut=Cc
-paste.label=Paste
-paste.shortcut=Cv
-clear.label=Clear
-clear.shortcut=CSx
-select_all.label=Select All
-select_all.shortcut=Ca
-###
+- public Object exec(Hashtable args)
+  This method is called when the plugin is selected from the menu. `args'
+  is a Hashtable used to pass parameters. At the moment, the only parameter
+  applicable to plugins is stored at the `Command.VIEW' key. It's the view
+  that was active when the plugin was invoked. As with init(), the return
+  value is unused. For forward compatibility, it should be null.
+
+- Also, all commands must have a public constructor which accepts no
+  arguments.
+
+5. Creating a Simple Plugin
+---------------------------
+The previous section probably doesn't make any sense at all. That's okay :).
+This section contains step by step instructions for creating a simple
+plugin. Hopefully, you'll be able to get the hang of this after reading this
+section.
+
+You will need a java compiler and the jar tool to do this example.
+
+Step 1 - Create the source file
+
+Create a file, Cmd_SimplePlugin.java, with the following in it:
+
+// Simple jEdit plugin
+import java.util.Hashtable;
+
+public class Cmd_SimplePlugin implements Command
+{
+	public Object init(Hashtable args)
+	{
+	/** this method is called when the plugin is loaded */
+		System.out.println("Hello from SimplePlugin.init()!");
+	/** the return value is ignored at the moment, so return null */
+		return null;
+	}
+	
+	public Object exec(Hashtable args)
+	{
+	/** this method is called when the plugin is invoked */
+	/** args contains one key - VIEW, which is the current view */
+		System.out.println("Hello from SimplePlugin.exec()!");
+	/** replace the selection in the current view with `hello!!!' */
+		View view = (View)args.get(VIEW);
+		view.getTextArea().replaceSelection("hello!!!");
+	}
+	
+	public SimplePlugin()
+	{
+	/** Constructor, required for command to work */
+	}
+}
+
+// End of Cmd_SimplePlugin.java
+
+Step 2 - Compile the source file
+
+Use the javac compiler to compile the source file. On Unix, do:
+
+	javac -classpath $CLASSPATH:/opt/slava/share/jedit-1.00/jedit.jar \
+		Cmd_SimplePlugin.java
+
+On Windows 95 98 and NT, do:
+
+	javac -classpath "%CLASSPATH%;C:\Program Files\jEdit\jedit.jar" \
+		Cmd_SimplePlugin.java
+
+The `-classpath' option tells javac where to look for jEdit's classes.
+An error such as this during compilation means that the classpath is wrong:
+
+	Cmd_SimplePlugin.java:4: Interface Command of class SimplePlugin
+		not found.
+	public class Cmd_SimplePlugin implements Command
+	                                     ^
+	1 error
+
+If all goes well, go onto the next step.
+
+Step 3 - Create the properties file
+
+Create a file, SimplePlugin.props, with the following in it:
+
+# SimplePlugin.props: properties for simple plugin
+# The menu item label that will appear in the Plugins menu
+SimplePlugin.label=Simple Plugin
+# The menu item's shortcut (Control-Shift-H)
+# It is discouraged to give your plugins shortcuts, because
+# collisions are very likely
+SimplePlugin.shortcut=CS-h
+# End of SimplePlugin.props
+
+Step 4 - Create the JAR file
+
+Use the jar tool to create the JAR file:
+
+	jar cf0 SimplePlugin.jar Cmd_SimplePlugin.class SimplePlugin.props
+
+There should now be a file called SimplePlugin.jar. It is the finished
+plugin.
 Note that the first parameter is c-f-zero, not c-f-capital-o.
+
+Step 4 - Install the test plugin
+
+Install the plugin in your personal plugins directory. On Unix:
+
+	mkdir $HOME/.jedit-jars
+	cp SimplePlugin.jar $HOME/.jedit-jars
+
+On Windows 95 or 98:
+
+	md %JAVAHOME%\.jedit-jars
+	copy SimplePlugin.jar %JAVAHOME%\.jedit-jars
+
+On Windows NT:
+
+	md %HOME%\.jedit-jars
+	copy SimplePlugin.jar %HOME%\.jedit-jars
+
+Step 5 - Test it!
+
+Fire up jEdit. A message such as this should be printed:
+
+	Loading plugin /home/slava/.jedit-jars/SimplePlugin.jar
+	Hello from SimplePlugin.init()!
+
+The plugin should also appear in the Plugins menu. Test it. It should output
+`Hello from SimplePlugin.exec()!' and replace the current selection with
+`hello!!!'.
 
 -- Slava Pestov
 <slava_pestov@geocities.com>
+
doc/old/plugins.txt to plugins/ToUpper/Cmd_ToUpper.java
--- a/doc/old/plugins.txt
+++ b/plugins/ToUpper/Cmd_ToUpper.java
@@ -1,23 +1,45 @@
-JEDIT PLUGIN INTERFACE VERSION 1
+/*
+ * Cmd_ToUpper.java - Simple plugin
+ * Copyright (C) 1998 Slava Pestov
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
 
-1. Using Plugins
-----------------
-jEdit is extensible using plugins. A plugin is a JAR file with class and/or
-property files. Plugins are searched for in the plugin path. The default path
-is:
-- The system plugin directory, (/opt/slava/share/jedit/1.00 on Unix,
-  \Program Files\jEdit\share on Windows 95/NT).
-- The user plugin directory (~/.jedit-jars on Unix, some JVM-dependent
-  directory on Windows 95/NT).
-Directories can be added to the plugin path with the -plugindir= parameter.
+import com.sun.java.swing.JTextArea;
+import java.util.Hashtable;
 
-2. Developing Plugins
----------------------
-To be useful, the JAR files must contain at least one .class or .props file.
-The .props files are in standard Java property format. See props.txt for more
-info. Each .class file is loaded into the runtime, and if it implements the
-Command interface, a new instance of it is created and added to the command
-list. See commands.txt for details.
+public class Cmd_ToUpper implements Command
+{
+	public Object init(Hashtable args)
+	{
+		return null;
+	}
 
--- Slava Pestov
-<slava_pestov@geocities.com>
+	public Object exec(Hashtable args)
+	{
+		View view = (View)args.get(VIEW);
+		if(view != null)
+		{
+			JTextArea textArea = view.getTextArea();
+			String selection = textArea.getSelectedText();
+			if(selection != null)
+				textArea.replaceSelection(selection
+					.toUpperCase());
+			else
+				view.getToolkit().beep();
+		}
+		return null;
+	}
+}
1 2 > >> (Page 1 of 2)