//----------------------------------------------------------------------------
// COMPONENT NAME: LPEX Editor
//
// © Copyright IBM Corporation 2003, 2006
// All Rights Reserved.
//
// DESCRIPTION:
// TestAction - sample user-defined action (deleteBlockDelete)
//----------------------------------------------------------------------------
package com.ibm.lpex.samples;
import com.ibm.lpex.core.LpexAction;
import com.ibm.lpex.core.LpexView;
/**
* Sample action <b>deleteBlockDelete</b> - delete any selection.
* This action is similar to the <b>delete</b> default editor action, but
* it will delete any current selection in the current view (even though
* the cursor is not anchored to it), not just a stream selection.
*
* <p>Here is the TestAction
* <a href="doc-files/TestAction.java.html">source code</a>.</p>
*
* <p>To run this sample:
* <ul>
* <li>Define this user action via an editor preference page, where available,
* or from the editor command line:
* <pre>set actionClass.deleteBlockDelete com.ibm.lpex.samples.TestAction</pre></li>
* <li>Run it from the editor command line:
* <pre>action deleteBlockDelete</pre>
* or associate it with a key (here, <b>Delete</b>):
* <pre>set keyAction.delete deleteBlockDelete</pre></li>
* </ul></p>
*
* <p>A user action is a Java class that implements the
* com.ibm.lpex.core.LpexAction interface. Several actions are also defined in
* {@link com.ibm.lpex.samples.TestUserProfile TestUserProfile}.</p>
*
* @see com.ibm.lpex.samples All the samples
*/
public class TestAction implements LpexAction
{
public void doAction(LpexView lpexView)
{
// if there is a selection in this view, delete it
if (lpexView.queryOn("block.inView"))
{
lpexView.doCommand("block delete");
}
// otherwise run the editor "delete" action to delete character(s)
else
{
lpexView.doAction(lpexView.actionId("delete"));
}
}
public boolean available(LpexView lpexView)
{
// this action can be run whenever the editor action "delete" can
return lpexView.actionAvailable(lpexView.actionId("delete"));
}
}