Author: dmaliarevich
Date: 2012-02-02 07:01:18 -0500 (Thu, 02 Feb 2012)
New Revision: 38393
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/scrolling/
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/scrolling/IScrollCoordinator.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/scrolling/ScrollCoordinator.java
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/util/XulRunnerVpeUtils.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/VpeVisualDomBuilder.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeDomMapping.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/SourceDomUtil.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java
Log:
https://issues.jboss.org/browse/JBIDE-8701 - Simple scroll functions to correlate between
source and visual nodes were added, +code adjustments.
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 2012-02-02
05:58:57 UTC (rev 38392)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2012-02-02
12:01:18 UTC (rev 38393)
@@ -12,9 +12,7 @@
import static org.jboss.tools.vpe.xulrunner.util.XPCOM.queryInterface;
-import java.text.MessageFormat;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -33,6 +31,7 @@
import org.eclipse.jface.bindings.keys.KeyStroke;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;
@@ -42,8 +41,6 @@
import org.eclipse.swt.custom.LineStyleListener;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.MenuEvent;
import org.eclipse.swt.events.MenuListener;
import org.eclipse.swt.events.SelectionEvent;
@@ -60,13 +57,11 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IFileEditorInput;
-import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.internal.keys.WorkbenchKeyboard;
import org.eclipse.ui.keys.IBindingService;
import org.eclipse.ui.progress.UIJob;
-import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
import org.eclipse.wst.sse.core.internal.model.ModelLifecycleEvent;
import org.eclipse.wst.sse.core.internal.provisional.IModelLifecycleListener;
import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
@@ -78,6 +73,7 @@
import org.eclipse.wst.sse.ui.internal.view.events.ITextSelectionListener;
import org.eclipse.wst.sse.ui.internal.view.events.NodeSelectionChangedEvent;
import org.eclipse.wst.sse.ui.internal.view.events.TextSelectionChangedEvent;
+import org.eclipse.wst.xml.core.internal.document.ElementImpl;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
import org.jboss.tools.common.el.core.ELReferenceList;
@@ -86,7 +82,6 @@
import org.jboss.tools.common.model.event.XModelTreeEvent;
import org.jboss.tools.common.model.event.XModelTreeListener;
import org.jboss.tools.common.model.project.IModelNature;
-import org.jboss.tools.common.model.ui.dnd.ModelTransfer;
import org.jboss.tools.common.model.ui.util.ModelUtilities;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.common.model.util.XModelTreeListenerSWTSync;
@@ -108,7 +103,6 @@
import org.jboss.tools.vpe.dnd.VpeDnD;
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.editor.mapping.VpeDomMapping;
-import org.jboss.tools.vpe.editor.mapping.VpeElementMapping;
import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
import org.jboss.tools.vpe.editor.menu.VpeMenuCreator;
import org.jboss.tools.vpe.editor.mozilla.MozillaEditor;
@@ -121,6 +115,7 @@
import org.jboss.tools.vpe.editor.mozilla.listener.MozillaScrollListener;
import org.jboss.tools.vpe.editor.mozilla.listener.MozillaSelectionListener;
import org.jboss.tools.vpe.editor.mozilla.listener.MozillaTooltipListener;
+import org.jboss.tools.vpe.editor.scrolling.ScrollCoordinator;
import org.jboss.tools.vpe.editor.selection.VpeSelectionController;
import org.jboss.tools.vpe.editor.template.IKeyEventHandler;
import org.jboss.tools.vpe.editor.template.ISelectionManager;
@@ -132,20 +127,10 @@
import org.jboss.tools.vpe.editor.template.VpeTemplateManager;
import org.jboss.tools.vpe.editor.template.ZoomEventManager;
import org.jboss.tools.vpe.editor.toolbar.format.FormatControllerManager;
-import org.jboss.tools.vpe.editor.util.Constants;
import org.jboss.tools.vpe.editor.util.DocTypeUtil;
import org.jboss.tools.vpe.editor.util.SelectionUtil;
import org.jboss.tools.vpe.editor.util.VisualDomUtil;
import org.jboss.tools.vpe.editor.util.VpeDebugUtil;
-import org.jboss.tools.vpe.editor.util.VpeNodesManagingUtil;
-import org.jboss.tools.vpe.handlers.PageDesignOptionsHandler;
-import org.jboss.tools.vpe.handlers.PreferencesHandler;
-import org.jboss.tools.vpe.handlers.RefreshHandler;
-import org.jboss.tools.vpe.handlers.RotateEditorsHandler;
-import org.jboss.tools.vpe.handlers.ShowBorderHandler;
-import org.jboss.tools.vpe.handlers.ShowBundleAsELHandler;
-import org.jboss.tools.vpe.handlers.ShowNonVisualTagsHandler;
-import org.jboss.tools.vpe.handlers.ShowTextFormattingHandler;
import org.jboss.tools.vpe.handlers.VisualPartAbstractHandler;
import org.jboss.tools.vpe.messages.VpeUIMessages;
import org.jboss.tools.vpe.resref.core.AbsoluteFolderReferenceList;
@@ -185,6 +170,7 @@
*
https://issues.jboss.org/browse/JBIDE-8701
* Scroll listeners staff.
*/
+ private ScrollCoordinator scrollCoordinator;
private SelectionListener sourceScrollSelectionListener;
private ScrollBar sourceEditorVerticalScrollBar;
private boolean sourceScrollEventFlag = false;
@@ -358,6 +344,7 @@
*
https://issues.jboss.org/browse/JBIDE-8701
* Add Source ScrollBar Listener
*/
+ scrollCoordinator = new ScrollCoordinator(sourceEditor, visualEditor, domMapping);
if ((visualEditor != null) && (sourceEditor != null)) {
sourceEditorVerticalScrollBar = textWidget.getVerticalBar();
if (sourceEditorVerticalScrollBar != null) {
@@ -378,21 +365,16 @@
public void widgetSelected(SelectionEvent e) {
if (JspEditorPlugin.getDefault().getPreferenceStore().getBoolean(
IVpePreferencesPage.SYNCHRONIZE_SCROLLING_BETWEEN_SOURCE_VISUAL_PANES)
- && !visualScrollEventFlag &&
!selectionManager.isUpdateSelectionEventPerformed()) { // ignore internal visual scroll
event
+ && !visualScrollEventFlag &&
!selectionManager.isUpdateSelectionEventPerformed()
+ && editPart.getVisualMode() == VpeEditorPart.VISUALSOURCE_MODE) { //
ignore internal visual scroll event
sourceScrollEventFlag = true;
- ScrollBar sb = (ScrollBar)e.widget;
- int pageYOffsetSrc = sb.getSelection();
- int scrollMaxYSrc = sb.getMaximum() - sb.getThumb();
- float percentsSrc = ((float)pageYOffsetSrc/scrollMaxYSrc);
- if (windowInternal.getScrollbars().getVisible()) {
- int scrollMaxYVisual = -1;
- scrollMaxYVisual = windowInternal.getScrollMaxY();
- if (scrollMaxYVisual != 0 && scrollMaxYVisual != -1) {
- // there is a visual scroll bar
- int posY = ((int) (scrollMaxYVisual*percentsSrc));
- domWindow.scrollTo(windowInternal.getPageXOffset(),posY);
- }
+ int posY = scrollCoordinator.computeVisualPositionFromSource();
+ int scrollMaxYVisual = -1;
+ scrollMaxYVisual = windowInternal.getScrollMaxY();
+ if (posY > scrollMaxYVisual) {
+ posY = scrollMaxYVisual;
}
+ domWindow.scrollTo(windowInternal.getPageXOffset(),posY);
} else {
visualScrollEventFlag = false;
selectionManager.setUpdateSelectionEventFlag(false);
@@ -1101,29 +1083,15 @@
*/
if (JspEditorPlugin.getDefault().getPreferenceStore().getBoolean(
IVpePreferencesPage.SYNCHRONIZE_SCROLLING_BETWEEN_SOURCE_VISUAL_PANES)
- && !sourceScrollEventFlag &&
!selectionManager.isUpdateSelectionEventPerformed()) { // ignore internal event from
source
- if (visualEditor.getXulRunnerEditor() != null) {
- visualScrollEventFlag = true;
- final nsIWebBrowser webBrowser = visualEditor.getXulRunnerEditor().getWebBrowser();
- removeSourceScrollListener();
- final StyledText textWidget = SelectionHelper.getSourceTextWidget(sourceEditor);
- final nsIDOMWindow domWindow = webBrowser.getContentDOMWindow();
- nsIDOMWindowInternal windowInternal = org.jboss.tools.vpe.xulrunner.util.XPCOM
- .queryInterface(domWindow, nsIDOMWindowInternal.class);
- int pageYOffsetVisual = windowInternal.getPageYOffset();
- int scrollMaxYVisual = windowInternal.getScrollMaxY();
- float percentsVisual = ((float)pageYOffsetVisual/scrollMaxYVisual);
- ScrollBar sb = getSourceEditorVerticalScrollBar();
- if ((sb != null) && (sb.getMaximum() != 1)) {
- int srcLinesCount = textWidget.getLineCount();
- // there is a source scroll bar
- if (srcLinesCount != 1) {
- int posLines = ((int) (srcLinesCount*percentsVisual));
- textWidget.setTopIndex(posLines);
- }
- }
- addSourceScrollListener();
+ && !sourceScrollEventFlag &&
!selectionManager.isUpdateSelectionEventPerformed()
+ && editPart.getVisualMode() == VpeEditorPart.VISUALSOURCE_MODE) { // ignore
internal event from source
+ removeSourceScrollListener();
+ visualScrollEventFlag = true;
+ int line = scrollCoordinator.computeSourcePositionFromVisual();
+ if ((line != -1) && (sourceEditor.getTextViewer() != null)){
+ sourceEditor.getTextViewer().setTopIndex(line);
}
+ addSourceScrollListener();
} else {
sourceScrollEventFlag = false;
selectionManager.setUpdateSelectionEventFlag(false);
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2012-02-02
05:58:57 UTC (rev 38392)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2012-02-02
12:01:18 UTC (rev 38393)
@@ -25,7 +25,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.regex.Matcher;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IStorage;
@@ -35,6 +34,7 @@
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
+import org.eclipse.wst.xml.core.internal.document.ElementImpl;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
import org.jboss.tools.common.resref.core.ResourceReference;
import org.jboss.tools.jst.jsp.JspEditorPlugin;
@@ -58,7 +58,6 @@
import org.jboss.tools.vpe.editor.template.VpeTemplateSafeWrapper;
import org.jboss.tools.vpe.editor.template.VpeToggableTemplate;
import org.jboss.tools.vpe.editor.template.expression.VpeExpressionException;
-import org.jboss.tools.vpe.editor.util.Constants;
import org.jboss.tools.vpe.editor.util.Docbook;
import org.jboss.tools.vpe.editor.util.FaceletUtil;
import org.jboss.tools.vpe.editor.util.HTML;
@@ -529,20 +528,16 @@
}
protected void correctVisualAttribute(nsIDOMElement element) {
- String styleValue = element.getAttribute(HTML.TAG_STYLE);
- String backgroundValue = element
- .getAttribute(VpeStyleUtil.PARAMETR_BACKGROND);
+ String styleValue = element.getAttribute(HTML.ATTR_STYLE);
+ String backgroundValue = element.getAttribute(HTML.ATTR_BACKGROUND);
if (styleValue != null) {
- styleValue = VpeStyleUtil.addFullPathIntoURLValue(styleValue,
- pageContext);
- element.setAttribute(HTML.TAG_STYLE, styleValue);
+ styleValue = VpeStyleUtil.addFullPathIntoURLValue(styleValue, pageContext);
+ element.setAttribute(HTML.ATTR_STYLE, styleValue);
}
if (backgroundValue != null) {
- backgroundValue = VpeStyleUtil
- .addFullPathIntoBackgroundValue(backgroundValue,
- pageContext.getEditPart().getEditorInput());
- element.setAttribute(VpeStyleUtil.PARAMETR_BACKGROND,
- backgroundValue);
+ backgroundValue = VpeStyleUtil.addFullPathIntoBackgroundValue(
+ backgroundValue, pageContext.getEditPart().getEditorInput());
+ element.setAttribute(HTML.ATTR_BACKGROUND, backgroundValue);
}
//fix for jbide-3209
if(element.hasAttribute(HTML.ATTR_DIR)) {
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeDomMapping.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeDomMapping.java 2012-02-02
05:58:57 UTC (rev 38392)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mapping/VpeDomMapping.java 2012-02-02
12:01:18 UTC (rev 38393)
@@ -17,6 +17,7 @@
import java.util.Map;
import java.util.Set;
+import org.eclipse.wst.xml.core.internal.document.ElementImpl;
import org.jboss.tools.vpe.VpePlugin;
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.xulrunner.editor.XulRunnerEditor;
@@ -24,7 +25,6 @@
import org.mozilla.interfaces.nsIDOMNode;
import org.mozilla.xpcom.XPCOMException;
import org.w3c.dom.Attr;
-import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -258,21 +258,72 @@
return null;
}
+ public nsIDOMElement getNearVisualElement(Node sourceNode) {
+ nsIDOMElement element = null;
+ VpeNodeMapping nodeMapping = getNearNodeMappingAtSourceNode(sourceNode);
+ if (sourceNode != null) {
+ if (nodeMapping != null) {
+ nsIDOMNode visualNode = nodeMapping.getVisualNode();
+ if (visualNode != null) {
+ try {
+ element = queryInterface(visualNode, nsIDOMElement.class);
+ } catch (XPCOMException xpcomException) {
+ if (sourceNode.getPreviousSibling() != null) {
+ element = getNearVisualElement(sourceNode.getPreviousSibling());
+ } else {
+ element = getNearVisualElement(sourceNode.getParentNode());
+ }
+ }
+ }
+ } else {
+ if (sourceNode.getPreviousSibling() != null) {
+ element = getNearVisualElement(sourceNode.getPreviousSibling());
+ } else {
+ element = getNearVisualElement(sourceNode.getParentNode());
+ }
+ }
+ }
+ return element;
+ }
+
public nsIDOMNode getNearVisualNode(Node sourceNode) {
if (sourceNode == null) return null;
VpeNodeMapping nodeMapping = getNearNodeMappingAtSourceNode(sourceNode);
if (nodeMapping != null) {
if (nodeMapping.getVisualNode() == null) {
-
return getNearVisualNode(sourceNode.getParentNode());
} else {
-
return nodeMapping.getVisualNode();
}
}
return null;
}
+ public ElementImpl getNearSourceElementImpl(nsIDOMNode visualNode) {
+ ElementImpl element = null;
+ VpeNodeMapping nodeMapping = getNearNodeMappingAtVisualNode(visualNode);
+ if (visualNode != null) {
+ if ((nodeMapping != null) && (nodeMapping.getSourceNode() != null)
+ && (nodeMapping.getSourceNode() instanceof ElementImpl)) {
+ /*
+ * This visual node is OK and src node is Element
+ */
+ element = (ElementImpl) nodeMapping.getSourceNode();
+ } else {
+ /*
+ * Else continue searching
+ */
+ if (visualNode.getNextSibling() != null) {
+ element = getNearSourceElementImpl(visualNode.getNextSibling());
+ } else {
+ element = getNearSourceElementImpl(visualNode.getParentNode());
+ }
+ }
+ }
+// System.out.println("--near src element = " + element);
+ return element;
+ }
+
public Node getNearSourceNode(nsIDOMNode visualNode) {
VpeNodeMapping nodeMapping = getNearNodeMapping(visualNode);
if (nodeMapping != null) {
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/scrolling/IScrollCoordinator.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/scrolling/IScrollCoordinator.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/scrolling/IScrollCoordinator.java 2012-02-02
12:01:18 UTC (rev 38393)
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.vpe.editor.scrolling;
+
+/**
+ * Interface that coordinates scroll position in source and visual editors
+ * @author dmaliarevich
+ */
+public interface IScrollCoordinator {
+ /**
+ * Computes visual editor scroll position
+ * based on the source editor text position
+ *
+ * @return visual editor scroll position
+ */
+ int computeVisualPositionFromSource();
+
+ /**
+ * Computes source editor text position
+ * based on the visual editor scroll position
+ *
+ * @return source editor scroll position
+ */
+ int computeSourcePositionFromVisual();
+}
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/scrolling/ScrollCoordinator.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/scrolling/ScrollCoordinator.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/scrolling/ScrollCoordinator.java 2012-02-02
12:01:18 UTC (rev 38393)
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.vpe.editor.scrolling;
+
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.wst.sse.ui.StructuredTextEditor;
+import org.eclipse.wst.xml.core.internal.document.ElementImpl;
+import org.jboss.tools.vpe.editor.mapping.VpeDomMapping;
+import org.jboss.tools.vpe.editor.mozilla.MozillaEditor;
+import org.jboss.tools.vpe.editor.util.SourceDomUtil;
+import org.jboss.tools.vpe.xulrunner.util.XulRunnerVpeUtils;
+import org.mozilla.interfaces.nsIDOMElement;
+import org.mozilla.interfaces.nsIDOMWindow;
+import org.mozilla.interfaces.nsIDOMWindowUtils;
+import org.mozilla.interfaces.nsIInterfaceRequestor;
+import org.w3c.dom.Node;
+
+/**
+ * Base implementation of IScrollCoordinator
+ * @author dmaliarevich
+ */
+public class ScrollCoordinator implements IScrollCoordinator {
+
+ StructuredTextEditor sourceEditor = null;
+ MozillaEditor visualEditor = null;
+ VpeDomMapping domMapping = null;
+
+ public ScrollCoordinator(StructuredTextEditor sourceEditor,
+ MozillaEditor visualEditor, VpeDomMapping domMapping) {
+ super();
+ this.sourceEditor = sourceEditor;
+ this.visualEditor = visualEditor;
+ this.domMapping = domMapping;
+ }
+
+ /**
+ * Compute an absolute pixel offset to scroll the xulrunner window to.
+ */
+ @Override
+ public int computeVisualPositionFromSource() {
+ int posY = -1;
+ if (sourceEditor != null) {
+ ITextViewer textViewer = sourceEditor.getTextViewer();
+ if (textViewer != null) {
+ int topLine = textViewer.getTopIndex();
+ Node n = SourceDomUtil.getSourceNodeByEditorPosition(textViewer, topLine, 1);
+ if (n != null) {
+ nsIDOMElement visualElement = domMapping.getNearVisualElement(n);
+ if (visualElement != null) {
+ Point r = XulRunnerVpeUtils.getVisualNodeOffset(visualElement);
+ posY = r.y;
+ }
+ }
+ }
+ }
+ return posY;
+ }
+
+ /**
+ * Compute top line index to scroll the source editor to.
+ */
+ @Override
+ public int computeSourcePositionFromVisual() {
+ int line = -1;
+ if ((sourceEditor != null) && (visualEditor != null)) {
+ if (visualEditor.getXulRunnerEditor() != null) {
+ nsIDOMWindow domWindow =
visualEditor.getXulRunnerEditor().getWebBrowser().getContentDOMWindow();
+ nsIInterfaceRequestor iInterfaceRequestor = (nsIInterfaceRequestor)
+ domWindow.queryInterface(nsIInterfaceRequestor.NS_IINTERFACEREQUESTOR_IID);
+ nsIDOMWindowUtils windowUtils = (nsIDOMWindowUtils)
+ iInterfaceRequestor.getInterface(nsIDOMWindowUtils.NS_IDOMWINDOWUTILS_IID);
+ int x = 40;//windowInternal.getInnerWidth()/5;
+ int y = 30;//windowInternal.getInnerHeight()/5;
+ nsIDOMElement elementFromPoint = windowUtils.elementFromPoint(x, y, true, false);
+ if (elementFromPoint != null) {
+ ElementImpl sourceElement = domMapping.getNearSourceElementImpl(elementFromPoint);
+ /*
+ * Transform offset to line number
+ */
+ line =
sourceEditor.getTextViewer().getTextWidget().getLineAtOffset(sourceElement.getStartEndOffset());
+ }
+ }
+ }
+ return line;
+ }
+}
\ No newline at end of file
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/SourceDomUtil.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/SourceDomUtil.java 2012-02-02
05:58:57 UTC (rev 38392)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/SourceDomUtil.java 2012-02-02
12:01:18 UTC (rev 38393)
@@ -13,6 +13,9 @@
import java.util.HashSet;
import java.util.Set;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils;
import org.eclipse.wst.xml.xpath.core.util.XSLTXPathHelper;
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.editor.mapping.VpeDomMapping;
@@ -189,4 +192,66 @@
return currentNode;
}
+
+ /**
+ * Utility function which is used to calculate offset in document by line number and
character position.
+ *
+ * @param linePosition the line position
+ * @param textWidget the text viewer
+ * @param lineIndex the line index
+ *
+ * @return offset in document, -1 for wrong offset
+ *
+ */
+ public static final int getLinePositionOffset(ITextViewer itextViewer, int lineIndex,
int linePosition) {
+ int resultOffset = -1;
+ StyledText textWidget = itextViewer.getTextWidget();
+ if (textWidget != null) {
+ // lineIndex-1 because calculating of line begins in eclipse from
+ // one, but should be form zero
+ resultOffset = textWidget.getOffsetAtLine(lineIndex - 1);
+ // here we get's tabs length
+ // for more example you can see code
+ // org.eclipse.ui.texteditor.AbstractTextEditor@getCursorPosition()
+ // and class $PositionLabelValue
+ int tabWidth = textWidget.getTabs();
+ int characterOffset = 0;
+ String currentString = textWidget.getLine(lineIndex - 1);
+ int pos = 1;
+ for (int i = 0; (i < currentString.length())
+ && (pos < linePosition); i++) {
+ if ('\t' == currentString.charAt(i)) {
+ characterOffset += (tabWidth == 0 ? 0 : 1);
+ pos += tabWidth;
+ } else {
+ pos++;
+ characterOffset++;
+ }
+ }
+ resultOffset += characterOffset;
+ if (textWidget.getLineAtOffset(resultOffset) != (lineIndex - 1)) {
+ resultOffset = -1;
+ }
+ }
+ return resultOffset;
+ }
+
+ /**
+ * Returns source node by source editor position(line and position in line).
+ *
+ * @param linePosition the line position
+ * @param lineIndex the line index
+ * @param itextViewer the itext viewer
+ *
+ * @return node for specified src position
+ */
+ @SuppressWarnings("restriction")
+ public static Node getSourceNodeByEditorPosition(ITextViewer itextViewer, int
lineIndex, int linePosition) {
+ int offset = getLinePositionOffset(itextViewer, lineIndex, linePosition);
+ if (offset != -1) {
+ return (Node) ContentAssistUtils.getNodeAt(itextViewer, offset);
+ } else {
+ return null;
+ }
+ }
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java 2012-02-02
05:58:57 UTC (rev 38392)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java 2012-02-02
12:01:18 UTC (rev 38393)
@@ -435,17 +435,16 @@
}
/**
+ * Adds full path for URL value
*
- * @param value
- * Css string
- * @param input
- * The editor input
- * @return format style string
+ * @param url the url
+ * @param pageContext VPE page context
+ * @return the full path string
*/
- public static String addFullPathIntoURLValue(String value, VpePageContext pageContext)
{
- String urls[] = value.split(ATTR_URL);
+ public static String addFullPathIntoURLValue(String url, VpePageContext pageContext) {
+ String urls[] = url.split(ATTR_URL);
if (urls.length == 1) {
- return value;
+ return url;
}
IFile file = getSourceFileFromPageContext(pageContext);
for (int i = 1; i < urls.length; i++) {
@@ -463,17 +462,16 @@
}
/**
+ * Adds full path for URL value
*
- * @param value
- * Css string
- * @param href_val
- * Path of css file
- * @return Format style string
+ * @param url css url string
+ * @param href_val path to css file
+ * @return the full path string
*/
- public static String addFullPathIntoURLValue(String value, String href_val) {
- String urls[] = value.split(ATTR_URL);
+ public static String addFullPathIntoURLValue(String url, String href_val) {
+ String urls[] = url.split(ATTR_URL);
if (urls.length == 1) {
- return value;
+ return url;
}
for (int i = 1; i < urls.length; i++) {
urls[i] = removeQuotesUpdate(urls[i]);
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/util/XulRunnerVpeUtils.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/util/XulRunnerVpeUtils.java 2012-02-02
05:58:57 UTC (rev 38392)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/util/XulRunnerVpeUtils.java 2012-02-02
12:01:18 UTC (rev 38393)
@@ -142,6 +142,15 @@
return element;
}
+ public static Point getVisualNodeOffset(nsIDOMNode node) {
+ Point p = new Point(-1, -1);
+ try {
+ p = getDocumentPos(queryInterface(node, nsIDOMNSHTMLElement.class));
+ } catch (XPCOMException xpcomException) {
+ // do nothing
+ }
+ return p;
+ }
private static Point getDocumentPos(nsIDOMNSHTMLElement boxElement) {
int x = 0;
@@ -152,7 +161,6 @@
y += curBoxElement.getOffsetTop();
curBoxElement = getOffsetParent(curBoxElement);
}
-
return new Point(x, y);
}