diff options
author | Tor Norbye <tnorbye@google.com> | 2011-05-16 15:14:24 -0700 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2011-05-17 11:46:24 -0700 |
commit | d5d648c12a073375e60ee9dfd8cbd982f51a44a0 (patch) | |
tree | c420ca3fdb9095103290a0268ced5b272f5acfa9 | |
parent | d31d71a8522072c7df73cffb1c672e45c4d29e96 (diff) | |
download | sdk-d5d648c12a073375e60ee9dfd8cbd982f51a44a0.zip sdk-d5d648c12a073375e60ee9dfd8cbd982f51a44a0.tar.gz sdk-d5d648c12a073375e60ee9dfd8cbd982f51a44a0.tar.bz2 |
Fix bug in editor open utility
The code to open a file (called by Go To Declaration, Show Include
etc) handles two scenarios:
(1) The file is in the workspace - open using Eclipse IFile mechanism
(2) The file is outside the workspace - open using the fallback
external storage (which means you get a plain XML editor)
There's a third scenario: the file is not in the workspace, but is
part of a project in the workspace so it does have a valid IFile.
(This can happen if you import a project but choose not to copy the
contents into the workspace). This changeset adjusts the code to open
up an editor such that it handles this third scenario and we get our
own XML editors for these types of files.
Change-Id: I0fc89316e4625fcf66dd61060cd9b00054bc5464
2 files changed, 55 insertions, 47 deletions
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 c87b669..4c5aaf6 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 @@ -38,7 +38,6 @@ import com.android.sdklib.SdkConstants; import org.eclipse.core.filesystem.EFS; import org.eclipse.core.filesystem.IFileStore; import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; @@ -902,53 +901,56 @@ public class LayoutCanvas extends Canvas { page.saveEditor(mLayoutEditor, false); IWorkspaceRoot workspace = ResourcesPlugin.getWorkspace().getRoot(); + IFile xmlFile = null; IPath workspacePath = workspace.getLocation(); if (workspacePath.isPrefixOf(filePath)) { IPath relativePath = filePath.makeRelativeTo(workspacePath); - IResource xmlFile = workspace.findMember(relativePath); - if (xmlFile != null) { - IFile leavingFile = graphicalEditor.getEditedFile(); - Reference next = Reference.create(graphicalEditor.getEditedFile()); - - try { - IEditorPart openAlready = EditorUtility.isOpenInEditor(xmlFile); - - // Show the included file as included within this click source? - if (openAlready != null) { - if (openAlready instanceof LayoutEditor) { - LayoutEditor editor = (LayoutEditor)openAlready; - GraphicalEditorPart gEditor = editor.getGraphicalEditor(); - if (gEditor.renderingSupports(Capability.EMBEDDED_LAYOUT)) { - gEditor.showIn(next); - } + xmlFile = (IFile) workspace.findMember(relativePath); + } else if (filePath.isAbsolute()) { + xmlFile = workspace.getFileForLocation(filePath); + } + if (xmlFile != null) { + IFile leavingFile = graphicalEditor.getEditedFile(); + Reference next = Reference.create(graphicalEditor.getEditedFile()); + + try { + IEditorPart openAlready = EditorUtility.isOpenInEditor(xmlFile); + + // Show the included file as included within this click source? + if (openAlready != null) { + if (openAlready instanceof LayoutEditor) { + LayoutEditor editor = (LayoutEditor)openAlready; + GraphicalEditorPart gEditor = editor.getGraphicalEditor(); + if (gEditor.renderingSupports(Capability.EMBEDDED_LAYOUT)) { + gEditor.showIn(next); } - } else { + } + } else { + try { + // Set initial state of a new file + // TODO: Only set rendering target portion of the state + QualifiedName qname = ConfigurationComposite.NAME_CONFIG_STATE; + String state = AdtPlugin.getFileProperty(leavingFile, qname); + xmlFile.setSessionProperty(GraphicalEditorPart.NAME_INITIAL_STATE, + state); + } catch (CoreException e) { + // pass + } + + if (graphicalEditor.renderingSupports(Capability.EMBEDDED_LAYOUT)) { try { - // Set initial state of a new file - // TODO: Only set rendering target portion of the state - QualifiedName qname = ConfigurationComposite.NAME_CONFIG_STATE; - String state = AdtPlugin.getFileProperty(leavingFile, qname); - xmlFile.setSessionProperty(GraphicalEditorPart.NAME_INITIAL_STATE, - state); + xmlFile.setSessionProperty(GraphicalEditorPart.NAME_INCLUDE, next); } catch (CoreException e) { - // pass - } - - if (graphicalEditor.renderingSupports(Capability.EMBEDDED_LAYOUT)) { - try { - xmlFile.setSessionProperty(GraphicalEditorPart.NAME_INCLUDE, next); - } catch (CoreException e) { - // pass - worst that can happen is that we don't - //start with inclusion - } + // pass - worst that can happen is that we don't + //start with inclusion } } - - EditorUtility.openInEditor(xmlFile, true); - return; - } catch (PartInitException ex) { - AdtPlugin.log(ex, "Can't open %$1s", url); //$NON-NLS-1$ } + + EditorUtility.openInEditor(xmlFile, true); + return; + } catch (PartInitException ex) { + AdtPlugin.log(ex, "Can't open %$1s", url); //$NON-NLS-1$ } } else { // It's not a path in the workspace; look externally diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/xml/Hyperlinks.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/xml/Hyperlinks.java index 069d475..ae84f13 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/xml/Hyperlinks.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/xml/Hyperlinks.java @@ -540,16 +540,22 @@ public class Hyperlinks { IWorkbenchPage page = sourceEditor.getEditorSite().getPage(); IWorkspaceRoot workspace = ResourcesPlugin.getWorkspace().getRoot(); IPath workspacePath = workspace.getLocation(); + IFile file = null; if (workspacePath.isPrefixOf(filePath)) { IPath relativePath = filePath.makeRelativeTo(workspacePath); - IResource file = workspace.findMember(relativePath); - if (file instanceof IFile) { - try { - AdtPlugin.openFile((IFile) file, region); - return; - } catch (PartInitException ex) { - AdtPlugin.log(ex, "Can't open %$1s", filePath); //$NON-NLS-1$ - } + IResource member = workspace.findMember(relativePath); + if (member instanceof IFile) { + file = (IFile) member; + } + } else if (filePath.isAbsolute()) { + file = workspace.getFileForLocation(filePath); + } + if (file != null) { + try { + AdtPlugin.openFile(file, region); + return; + } catch (PartInitException ex) { + AdtPlugin.log(ex, "Can't open %$1s", filePath); //$NON-NLS-1$ } } else { // It's not a path in the workspace; look externally |