aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2010-10-27 14:33:42 -0700
committerTor Norbye <tnorbye@google.com>2010-10-27 14:34:23 -0700
commit76bbc57fcc07859cd1d7f1c9be102b1dc5218f27 (patch)
tree695b2ce18d66cb8b5e3a48d345a42b2f678a6db0
parente0e9393a1b57107d25a8f9586bd5d7b04905023d (diff)
downloadsdk-76bbc57fcc07859cd1d7f1c9be102b1dc5218f27.zip
sdk-76bbc57fcc07859cd1d7f1c9be102b1dc5218f27.tar.gz
sdk-76bbc57fcc07859cd1d7f1c9be102b1dc5218f27.tar.bz2
Warp to source editor on widget double click
Update mouse handler such that a double click will look up the corresponding XML element, front the XML source editor and select the text range (scrolling if necessary) to reveal the corresponding tag. Change-Id: Iaa3d6f845c3fea190c304a07fab07314baa3f638
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidXmlEditor.java34
-rwxr-xr-xeclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasViewInfo.java16
-rwxr-xr-xeclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java17
3 files changed, 66 insertions, 1 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidXmlEditor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidXmlEditor.java
index 18f1e28..a1b9d13 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidXmlEditor.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidXmlEditor.java
@@ -62,10 +62,12 @@ import org.eclipse.wst.sse.core.StructuredModelManager;
import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
import org.eclipse.wst.sse.core.internal.provisional.IModelStateListener;
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
import org.eclipse.wst.sse.ui.StructuredTextEditor;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
import org.w3c.dom.Document;
+import org.w3c.dom.Node;
import java.net.MalformedURLException;
import java.net.URL;
@@ -870,6 +872,38 @@ public abstract class AndroidXmlEditor extends FormEditor implements IResourceCh
return null;
}
+ /**
+ * Shows the editor range corresponding to the given XML node. This will
+ * front the editor and select the text range.
+ *
+ * @param xmlNode The DOM node to be shown. The DOM node should be an XML
+ * node from the existing XML model used by the structured XML
+ * editor; it will not do attribute matching to find a
+ * "corresponding" element in the document from some foreign DOM
+ * tree.
+ * @return True if the node was shown.
+ */
+ @SuppressWarnings("restriction") // Yes, this method relies a lot on restricted APIs
+ public boolean show(Node xmlNode) {
+ if (xmlNode instanceof IndexedRegion) {
+ IndexedRegion region = (IndexedRegion)xmlNode;
+
+ IEditorPart textPage = getEditor(mTextPageIndex);
+ if (textPage instanceof StructuredTextEditor) {
+ StructuredTextEditor editor = (StructuredTextEditor) textPage;
+
+ setActivePage(AndroidXmlEditor.TEXT_EDITOR_ID);
+
+ // Note - we cannot use region.getLength() because that seems to
+ // always return 0.
+ int regionLength = region.getEndOffset() - region.getStartOffset();
+ editor.selectAndReveal(region.getStartOffset(), regionLength);
+ return true;
+ }
+ }
+
+ return false;
+ }
/**
* Listen to changes in the underlying XML model in the structured editor.
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasViewInfo.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasViewInfo.java
index 2781d1a..f4dce0f 100755
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasViewInfo.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasViewInfo.java
@@ -24,6 +24,7 @@ import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySheetPage;
import org.eclipse.ui.views.properties.IPropertySource;
+import org.w3c.dom.Node;
import java.util.ArrayList;
@@ -242,4 +243,19 @@ public class CanvasViewInfo implements IPropertySource {
((IPropertySource) uiView).setPropertyValue(id, value);
}
}
+
+ /**
+ * Returns the XML node corresponding to this info, or null if there is no
+ * such XML node.
+ *
+ * @return The XML node corresponding to this info object, or null
+ */
+ public Node getXmlNode() {
+ UiViewElementNode uiView = getUiViewKey();
+ if (uiView != null) {
+ return uiView.getXmlNode();
+ }
+
+ return null;
+ }
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java
index 44a2e74..29094b7 100755
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java
@@ -1328,7 +1328,22 @@ class LayoutCanvas extends Canvas implements ISelectionProvider {
}
private void onDoubleClick(MouseEvent e) {
- // pass, not used yet.
+ // Warp to the text editor and show the corresponding XML for the
+ // double-clicked widget
+ int x = mHScale.inverseTranslate(e.x);
+ int y = mVScale.inverseTranslate(e.y);
+ CanvasViewInfo vi = findViewInfoAt(x, y);
+ if (vi == null) {
+ return;
+ }
+
+ Node xmlNode = vi.getXmlNode();
+ if (xmlNode != null) {
+ boolean found = mLayoutEditor.show(xmlNode);
+ if (!found) {
+ getDisplay().beep();
+ }
+ }
}
/**