Package org.gjt.sp.jedit
Class JEditActionSet<E extends JEditAbstractEditAction>
- java.lang.Object
-
- org.gjt.sp.jedit.JEditActionSet<E>
-
- All Implemented Interfaces:
InputHandlerProvider
- Direct Known Subclasses:
ActionSet,StandaloneTextArea.StandaloneActionSet
public abstract class JEditActionSet<E extends JEditAbstractEditAction> extends java.lang.Object implements InputHandlerProvider
A set of actions, either loaded from an XML file, or constructed at runtime by a plugin.Action sets loaded from XML files
Action sets are read from these files inside the plugin JAR:actions.xml- actions made available for use in jEdit views, including the view's Plugins menu, the tool bar, etc.browser.actions.xml- actions for the file system browser's Plugins menu.
<?xml version="1.0"?> <!DOCTYPE ACTIONS SYSTEM "actions.dtd"> <ACTIONS> <ACTION NAME="some-action"> <CODE> // BeanShell code evaluated when the action is invoked </CODE> </ACTION> <ACTION NAME="some-toggle-action"> <CODE> // BeanShell code evaluated when the action is invoked </CODE> <IS_SELECTED> // BeanShell code that should evaluate to true or false </IS_SELECTED> </ACTION> </ACTIONS>The following elements are valid:-
ACTIONSis the top-level element and refers to the set of actions used by the plugin. -
An
ACTIONcontains the data for a particular action. It has three attributes: a requiredNAME; an optionalNO_REPEAT, which is a flag indicating whether the action should not be repeated with the C+ENTER command; and an optionalNO_RECORDwhich is a a flag indicating whether the action should be recorded if it is invoked while the user is recording a macro. The two flag attributes can have two possible values, "TRUE" or "FALSE". In both cases, "FALSE" is the default if the attribute is not specified. -
An
ACTIONcan have two child elements within it: a requiredCODEelement which specifies the BeanShell code that will be executed when the action is invoked, and an optionalIS_SELECTEDelement, used for checkbox menu items. TheIS_SELECTEDelement contains BeanShell code that returns a boolean flag that will determine the state of the checkbox.
name.labelcontaining the action's menu item label.View actions
Actions defined inactions.xmlcan be added to the view's Plugins menu; seeEditPlugin. The action code may use any standard predefined BeanShell variable; seeBeanShell.File system browser actions
Actions defined inactions.xmlcan be added to the file system browser's Plugins menu; seeEditPlugin. The action code may use any standard predefined BeanShell variable, in addition to a variablebrowserwhich contains a reference to the currentVFSBrowserinstance.File system browser actions should not define
<IS_SELECTED>blocks.Custom action sets
CalljEdit.addActionSet(ActionSet)to add a custom action set to jEdit's action context. You must also callinitKeyBindings()for new action sets. Don't forget to calljEdit.removeActionSet(ActionSet)before your plugin is unloaded, too.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.HashMap<java.lang.String,JEditAbstractEditAction>actionsprotected booleanloadedprotected static JEditAbstractEditActionplaceholderprotected java.net.URLuri
-
Constructor Summary
Constructors Modifier Constructor Description protectedJEditActionSet()Creates a new action set.protectedJEditActionSet(java.lang.String[] cachedActionNames, java.net.URL uri)Creates a new action set.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddAction(E action)Adds an action to the action set.booleancontains(java.lang.String action)protected abstract JEditAbstractEditActioncreateBeanShellAction(java.lang.String actionName, java.lang.String code, java.lang.String selected, boolean noRepeat, boolean noRecord, boolean noRememberLast)This method should be implemented to return an action that will execute the given codeEgetAction(java.lang.String name)intgetActionCount()java.lang.String[]getActionNames()E[]getActions()protected abstract E[]getArray(int size)Returns an empty array E[].java.lang.String[]getCacheableActionNames()protected abstract java.lang.StringgetProperty(java.lang.String name)Returns a property for the given name.voidinitKeyBindings()Initializes the action set's key bindings.voidload()Forces the action set to be loaded.voidremoveAction(java.lang.String name)Removes an action from the action set.voidremoveAllActions()Removes all actions from the action set.intsize()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.gjt.sp.jedit.input.InputHandlerProvider
getInputHandler
-
-
-
-
Field Detail
-
actions
protected java.util.HashMap<java.lang.String,JEditAbstractEditAction> actions
-
uri
protected java.net.URL uri
-
loaded
protected boolean loaded
-
placeholder
protected static final JEditAbstractEditAction placeholder
-
-
Constructor Detail
-
JEditActionSet
protected JEditActionSet()
Creates a new action set.- Since:
- jEdit 4.3pre13
-
JEditActionSet
protected JEditActionSet(java.lang.String[] cachedActionNames, java.net.URL uri)Creates a new action set.- Parameters:
cachedActionNames- The list of cached action namesuri- The actions.xml URI- Since:
- jEdit 4.3pre13
-
-
Method Detail
-
addAction
public void addAction(E action)
Adds an action to the action set.- Parameters:
action- The action- Since:
- jEdit 4.0pre1
-
removeAction
public void removeAction(java.lang.String name)
Removes an action from the action set.- Parameters:
name- The action name- Since:
- jEdit 4.0pre1
-
removeAllActions
public void removeAllActions()
Removes all actions from the action set.- Since:
- jEdit 4.0pre1
-
getAction
public E getAction(java.lang.String name)
- Parameters:
name- The action name- Returns:
- an action with the specified name.
Deferred loading: this will load the action set if necessary.
- Since:
- jEdit 4.0pre1
-
getActionCount
public int getActionCount()
- Returns:
- the number of actions in the set.
- Since:
- jEdit 4.0pre1
-
getActionNames
public java.lang.String[] getActionNames()
- Returns:
- an array of all action names in this action set.
- Since:
- jEdit 4.2pre1
-
getCacheableActionNames
public java.lang.String[] getCacheableActionNames()
- Returns:
- an array of all action names in this action set that should
be cached; namely,
BeanShellActions. - Since:
- jEdit 4.2pre1
-
getArray
protected abstract E[] getArray(int size)
Returns an empty array E[]. I know it is bad, if you find a method to instantiate a generic Array, tell me- Parameters:
size- the size of the array- Returns:
- the empty array
-
getActions
public E[] getActions()
- Returns:
- an array of all actions in this action set.
Deferred loading: this will load the action set if necessary.
- Since:
- jEdit 4.0pre1
-
contains
public boolean contains(java.lang.String action)
- Parameters:
action- The action- Returns:
- if this action set contains the specified action.
- Since:
- jEdit 4.2pre1
-
size
public int size()
- Returns:
- the number of actions in this action set.
- Since:
- jEdit 4.2pre2
-
load
public void load()
Forces the action set to be loaded. Plugins and macros should not call this method.- Since:
- jEdit 4.2pre1
-
createBeanShellAction
protected abstract JEditAbstractEditAction createBeanShellAction(java.lang.String actionName, java.lang.String code, java.lang.String selected, boolean noRepeat, boolean noRecord, boolean noRememberLast)
This method should be implemented to return an action that will execute the given code- Parameters:
actionName- the action namecode- the codeselected- selectednoRepeat- noRepeatnoRecord- noRecordnoRememberLast- noRememberLast- Returns:
- an action
- Since:
- 4.3pre13
-
initKeyBindings
public void initKeyBindings()
Initializes the action set's key bindings. jEdit calls this method for all registered action sets when the user changes key bindings in the Global Options dialog box.Note if your plugin adds a custom action set to jEdit's collection, it must also call this method on the action set after adding it.
- Since:
- jEdit 4.2pre1
-
getProperty
protected abstract java.lang.String getProperty(java.lang.String name)
Returns a property for the given name. In jEdit it will returns a jEdit.getProperty(name), but it can return something else for a standalone textarea.- Parameters:
name- the property name- Returns:
- the property value
- Since:
- 4.3pre13
-
-