Author: yradtsevich
Date: 2009-06-23 10:13:55 -0400 (Tue, 23 Jun 2009)
New Revision: 16142
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/InsertContributionItem.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/VpeMenuCreator.java
Log:
RESOLVED - issue
https://jira.jboss.org/jira/browse/JBIDE-4397 : Context menu on the
Visual Pane works wrong with Insert, Replace commands.
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/InsertContributionItem.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/InsertContributionItem.java 2009-06-23
14:12:09 UTC (rev 16141)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/InsertContributionItem.java 2009-06-23
14:13:55 UTC (rev 16142)
@@ -11,6 +11,7 @@
import java.util.List;
import org.eclipse.jface.action.ContributionItem;
+import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
@@ -27,7 +28,9 @@
import org.jboss.tools.jst.web.tld.URIConstants;
import org.jboss.tools.vpe.editor.VpeEditorPart;
import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.menu.action.ComplexAction;
import org.jboss.tools.vpe.editor.menu.action.InsertAction2;
+import org.jboss.tools.vpe.editor.menu.action.SelectThisTagAction;
import org.jboss.tools.vpe.editor.util.Constants;
import org.jboss.tools.vpe.editor.util.XmlUtil;
import org.jboss.tools.vpe.messages.VpeUIMessages;
@@ -35,10 +38,11 @@
/**
* @author Sergey Dzmitrovich
- *
+ * @author yradtsevich
*/
public class InsertContributionItem extends ContributionItem {
+ private final Node node;
private final StructuredTextEditor sourceEditor;
private final VpePageContext pageContext;
private final static String NAME_PROPERTY = "name"; //$NON-NLS-1$
@@ -51,10 +55,24 @@
private final static String LEFT_ANGLE_BRACKET = "<"; //$NON-NLS-1$
private final static String RIGHT_ANGLE_BRACKET = ">"; //$NON-NLS-1$
+ /**
+ * Creates an {@code InsertContributionItem}
+ * to make insert actions on the currently selected node.
+ */
public InsertContributionItem() {
- final JSPMultiPageEditor editor = (JSPMultiPageEditor) PlatformUI
- .getWorkbench().getActiveWorkbenchWindow().getActivePage()
- .getActiveEditor();
+ this(null);
+ }
+
+ /**
+ * Creates an {@code InsertContributionItem}
+ * to make insert actions on the given {@code node}.
+ */
+ public InsertContributionItem(final Node node) {
+ this.node = node;
+
+ final JSPMultiPageEditor editor = (JSPMultiPageEditor)
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow()
+ .getActivePage().getActiveEditor();
this.sourceEditor = editor.getSourceEditor();
this.pageContext = ((VpeEditorPart) editor.getVisualEditor())
.getController().getPageContext();
@@ -115,6 +133,9 @@
prefix = getPrefix(modelObject);
}
+ final IAction selectNodeAction =
+ node == null ? null : new SelectThisTagAction(node);
+
for (final XModelObject modelObjectChild : modelObjectChildren) {
if (Constants.YES_STRING.equals(
modelObjectChild.getAttributeValue(HIDDEN_PROPERTY))) {
@@ -138,8 +159,18 @@
.getAttributeValue(NAME_PROPERTY)
+ RIGHT_ANGLE_BRACKET;
- manager.add(new InsertAction2(name, modelObjectChild,
- sourceEditor, insertionType));
+ final InsertAction2 insertAction = new InsertAction2(
+ name, modelObjectChild,
+ sourceEditor, insertionType);
+
+ final IAction action;
+ if (selectNodeAction == null) {
+ action = insertAction;
+ } else {
+ action = new ComplexAction(insertAction.getText(),
+ selectNodeAction, insertAction);
+ }
+ manager.add(action);
}
} else {
final MenuManager subMenu = new InsertSubMenuManager(
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/VpeMenuCreator.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/VpeMenuCreator.java 2009-06-23
14:12:09 UTC (rev 16141)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/menu/VpeMenuCreator.java 2009-06-23
14:13:55 UTC (rev 16142)
@@ -83,7 +83,7 @@
}
addSeparator();
- menuManager.add(new InsertContributionItem());
+ menuManager.add(new InsertContributionItem(node));
addIfEnabled(new StripTagAction(node));
addSeparator();