Author: yradtsevich
Date: 2011-02-16 04:25:03 -0500 (Wed, 16 Feb 2011)
New Revision: 29168
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/editor/IVisualEditorFactory.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageEditor.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeEditorPart.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeEditorPartFactory.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ISelectionManager.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/SelectionManager.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/SelectionUtil.java
Log:
https://issues.jboss.org/browse/JBIDE-8115 : Support for multiple selection in visual
part
- methods of SelectionManager
setSelection(nsISelection selection) and
setSelection(nsIDOMNode visualNode, int rangeOffset)
are merged into
setSelection(nsIDOMNode visualNode, int focusOffset, int anchorOffset)
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/editor/IVisualEditorFactory.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/editor/IVisualEditorFactory.java 2011-02-16
09:13:42 UTC (rev 29167)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/editor/IVisualEditorFactory.java 2011-02-16
09:25:03 UTC (rev 29168)
@@ -17,7 +17,7 @@
public interface IVisualEditorFactory {
public IVisualEditor createVisualEditor(EditorPart multiPageEditor,
- StructuredTextEditor textEditor, boolean visualMode,
+ StructuredTextEditor textEditor, int visualMode,
BundleMap bundleMap);
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageEditor.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageEditor.java 2011-02-16
09:13:42 UTC (rev 29167)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPMultiPageEditor.java 2011-02-16
09:25:03 UTC (rev 29168)
@@ -482,7 +482,7 @@
if (visualEditorFactory != null) {
visualEditor = visualEditorFactory.createVisualEditor(this,
- sourceEditor, false, bundleMap);
+ sourceEditor, IVisualEditor.VISUALSOURCE_MODE, bundleMap);
}
try {
if (visualEditor != null) {
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2011-02-16
09:13:42 UTC (rev 29167)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2011-02-16
09:25:03 UTC (rev 29168)
@@ -1150,7 +1150,8 @@
* <select> node to be selected on the first click.
*/
if (node != null) {
- selectionManager.setSelection(selection);
+ selectionManager.setSelection(SelectionUtil.getSelectedNode(selection),
+ selection.getFocusOffset(), selection.getAnchorOffset());
}
}
// enables cursor on selection event
@@ -1219,9 +1220,12 @@
if (vpeDnD.isDragIconClicked(mouseEvent)) {
vpeDnD.dragStart(mouseEvent);
} else {
+ int rangeOffset = queryInterface(mouseEvent,
nsIDOMNSUIEvent.class).getRangeOffset();
+
+ // set source selection at the point where mouse is clicked
selectionManager.setSelection(
- VisualDomUtil.getTargetNode(mouseEvent),
- queryInterface(mouseEvent, nsIDOMNSUIEvent.class).getRangeOffset());
+ VisualDomUtil.getTargetNode(mouseEvent),
+ rangeOffset, rangeOffset);
}
}
} finally {
@@ -1270,7 +1274,7 @@
VpeNodeMapping toggledMapping
= getDomMapping().getNearNodeMapping(toggledElement);
if (toggledMapping != null && toggledMapping.getVisualNode() != null) {
- selectionManager.setSelection(toggledMapping.getVisualNode(), 0);
+ selectionManager.setSelection(toggledMapping.getVisualNode(), 0, 0);
}
}
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeEditorPart.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeEditorPart.java 2011-02-16
09:13:42 UTC (rev 29167)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeEditorPart.java 2011-02-16
09:25:03 UTC (rev 29168)
@@ -20,7 +20,10 @@
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.TextSelection;
+import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.ControlEvent;
@@ -44,6 +47,7 @@
import org.eclipse.ui.IPartListener;
import org.eclipse.ui.IPropertyListener;
import org.eclipse.ui.IReusableEditor;
+import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IStorageEditorInput;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPart;
@@ -94,7 +98,7 @@
private Composite cmpEdTl;
private CustomSashForm container;
protected EditorSettings editorSettings;
- private StructuredTextEditor sourceEditor = null;
+ private StructuredTextEditor sourceEditor;
private MozillaEditor visualEditor;
private BundleMap bundleMap;
private IEditorPart activeEditor;
@@ -103,7 +107,7 @@
private XModelObject optionsObject;
// private SelectionBar selectionBar = new SelectionBar();
private ActivationListener activationListener = new ActivationListener();
- private int visualMode = 0;
+ private int visualMode;
private EditorPart multiPageEditor;
private int controlCount = 0;
@@ -247,20 +251,21 @@
}
public VpeEditorPart(EditorPart multiPageEditor,
- StructuredTextEditor textEditor, boolean visualMode, BundleMap bundleMap) {
- sourceEditor = textEditor;
- // this.visualMode = visualMode;
+ StructuredTextEditor textEditor, int visualMode, BundleMap bundleMap) {
+ this.sourceEditor = textEditor;
+ this.visualMode = visualMode;
this.bundleMap = bundleMap;
this.multiPageEditor = multiPageEditor;
}
+
+ public VpeEditorPart() {
+ this(null, null, VISUALSOURCE_MODE, null);
+ }
public IAction getAction(String actionID) {
return sourceEditor.getAction(actionID);
}
- public VpeEditorPart() {
- }
-
public void doSave(IProgressMonitor monitor) {
if (sourceEditor != null) {
sourceEditor.doSave(monitor);
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeEditorPartFactory.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeEditorPartFactory.java 2011-02-16
09:13:42 UTC (rev 29167)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeEditorPartFactory.java 2011-02-16
09:25:03 UTC (rev 29168)
@@ -19,7 +19,7 @@
public class VpeEditorPartFactory implements IVisualEditorFactory {
- public IVisualEditor createVisualEditor(final EditorPart multiPageEditor,
StructuredTextEditor textEditor, boolean visualMode, BundleMap bundleMap) {
+ public IVisualEditor createVisualEditor(final EditorPart multiPageEditor,
StructuredTextEditor textEditor, int visualMode, BundleMap bundleMap) {
return new VpeEditorPart(multiPageEditor, textEditor, visualMode, bundleMap) {
public void doSave(IProgressMonitor monitor){
multiPageEditor.doSave(monitor);
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ISelectionManager.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ISelectionManager.java 2011-02-16
09:13:42 UTC (rev 29167)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/ISelectionManager.java 2011-02-16
09:25:03 UTC (rev 29168)
@@ -26,16 +26,9 @@
*
* @param selection
*/
- public void setSelection(nsISelection selection);
+ public void setSelection(nsIDOMNode visualNode, int focusOffset, int anchorOffset);
/**
- * set selection by mouse
- *
- * @param mouseEvent
- */
- public void setSelection(nsIDOMNode visualNode, int rangeOffset);
-
- /**
* to bring in correspondence visual selection and source selection
*/
public void refreshVisualSelection();
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/SelectionManager.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/SelectionManager.java 2011-02-16
09:13:42 UTC (rev 29167)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/SelectionManager.java 2011-02-16
09:25:03 UTC (rev 29168)
@@ -59,9 +59,7 @@
this.selectionController = selectionController;
}
- /* TODO: merge this method with setSelection(nsIDOMNode visualNode, int rangeOffset) */
- public final void setSelection(nsISelection selection) {
- nsIDOMNode visualNode = SelectionUtil.getSelectedNode(selection);
+ public final void setSelection(nsIDOMNode visualNode, int focusOffset, int anchorOffset)
{
if (visualNode == null) {
return;
}
@@ -81,7 +79,7 @@
int selectionLength;
if (selectionData.isNodeEditable()) {
Point sourceSelectionRange = SelectionUtil.getSourceSelectionRange(
- selection, selectionData.getSourceNode());
+ visualNode, focusOffset, anchorOffset, selectionData.getSourceNode());
selectionOffset = sourceSelectionRange.x;
selectionLength = sourceSelectionRange.y;
} else {
@@ -89,28 +87,6 @@
selectionLength = NodesManagingUtil.getNodeLength(selectionData.getSourceNode());
}
/*************** Apply selection to views *****************************/
- SelectionUtil.setSourceSelection(getPageContext(), selectionData.getSourceNode(),
- selectionOffset, selectionLength);
- getPageContext().getVisualBuilder().setSelectionRectangle(
- selectionData.getVisualNode());
- }
-
- final public void setSelection(nsIDOMNode visualNode, int rangeOffset) {
- SelectionData selectionData = getSelectionData(visualNode);
- if (selectionData == null) {
- return;
- }
- /*************** Calculate selection range ****************************/
- int selectionOffset;
- int selectionLength;
- if (selectionData.isNodeEditable()) {
- selectionOffset = rangeOffset;
- selectionLength = 0;
- } else {
- selectionOffset = 0;
- selectionLength = NodesManagingUtil.getNodeLength(selectionData.getSourceNode());
- }
- /*************** Apply selection to views *****************************/
SelectionUtil.setSourceSelection(getPageContext(),
selectionData.getSourceNode(),
selectionOffset, selectionLength);
@@ -164,7 +140,6 @@
* source selection to visual selection
*/
final public void refreshVisualSelection() {
-
// checks for null, for case when we close editor and background
// update job is running
if (getSourceEditor().getTextViewer() == null) {
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/SelectionUtil.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/SelectionUtil.java 2011-02-16
09:13:42 UTC (rev 29167)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/SelectionUtil.java 2011-02-16
09:25:03 UTC (rev 29168)
@@ -208,9 +208,8 @@
* the selection in visual part of editor
* @return source editor selection range
*/
- public static Point getSourceSelectionRange(nsISelection selection,
- Node sourceNode) {
- nsIDOMNode focusedNode = getSelectedNode(selection);
+ public static Point getSourceSelectionRange(nsIDOMNode focusedNode,
+ int focusOffset, int anchorOffset, Node sourceNode) {
// gets visual selection range
Point sourceRange = new Point(0, 0);
// converts to source selection
@@ -218,9 +217,9 @@
//fix for JBIDE-3650
NodeImpl nodeImpl = (NodeImpl) sourceNode;
sourceRange.x = TextUtil.sourcePosition(nodeImpl.getValueSource(),
- focusedNode.getNodeValue(), selection.getFocusOffset());
+ focusedNode.getNodeValue(), focusOffset);
sourceRange.y = TextUtil.sourcePosition(nodeImpl.getValueSource(),
- focusedNode.getNodeValue(), selection.getAnchorOffset())
+ focusedNode.getNodeValue(), anchorOffset)
- sourceRange.x;
}
return sourceRange;