mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-13 03:05:39 +02:00
Patch for Devin Steffler.
Fixed Bug 103697 - Open Definition/Declaration on files in linked folders open a new editor
This commit is contained in:
parent
1897a34ffb
commit
08278a1193
11 changed files with 316 additions and 87 deletions
|
@ -128,6 +128,13 @@ public class ParserUtil
|
||||||
resultingResource = root.getFileForLocation( path );
|
resultingResource = root.getFileForLocation( path );
|
||||||
if( resultingResource != null && resultingResource.exists() )
|
if( resultingResource != null && resultingResource.exists() )
|
||||||
return resultingResource;
|
return resultingResource;
|
||||||
|
|
||||||
|
// check for linked resources
|
||||||
|
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path);
|
||||||
|
if( files != null && files.length > 0 && files[0] != null) {
|
||||||
|
return files[0];
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
catch( IllegalArgumentException iae ) //thrown on invalid paths
|
catch( IllegalArgumentException iae ) //thrown on invalid paths
|
||||||
|
|
|
@ -11,8 +11,11 @@
|
||||||
package org.eclipse.cdt.ui.tests.text.selectiontests;
|
package org.eclipse.cdt.ui.tests.text.selectiontests;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.ICDescriptor;
|
import org.eclipse.cdt.core.ICDescriptor;
|
||||||
import org.eclipse.cdt.core.ICDescriptorOperation;
|
import org.eclipse.cdt.core.ICDescriptorOperation;
|
||||||
|
@ -27,28 +30,24 @@ import org.eclipse.cdt.internal.ui.editor.ICEditorActionDefinitionIds;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IFolder;
|
import org.eclipse.core.resources.IFolder;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.Path;
|
||||||
import org.eclipse.jface.action.IAction;
|
import org.eclipse.jface.action.IAction;
|
||||||
import org.eclipse.jface.text.TextSelection;
|
import org.eclipse.jface.text.TextSelection;
|
||||||
import org.eclipse.jface.util.IPropertyChangeListener;
|
|
||||||
import org.eclipse.jface.util.PropertyChangeEvent;
|
|
||||||
import org.eclipse.jface.viewers.ISelection;
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
import org.eclipse.search2.internal.ui.SearchView;
|
|
||||||
import org.eclipse.ui.IEditorInput;
|
import org.eclipse.ui.IEditorInput;
|
||||||
import org.eclipse.ui.IEditorPart;
|
import org.eclipse.ui.IEditorPart;
|
||||||
import org.eclipse.ui.IViewPart;
|
|
||||||
import org.eclipse.ui.IViewReference;
|
|
||||||
import org.eclipse.ui.IWorkbenchPage;
|
import org.eclipse.ui.IWorkbenchPage;
|
||||||
import org.eclipse.ui.PartInitException;
|
import org.eclipse.ui.PartInitException;
|
||||||
import org.eclipse.ui.PlatformUI;
|
import org.eclipse.ui.PlatformUI;
|
||||||
import org.eclipse.ui.part.FileEditorInput;
|
import org.eclipse.ui.part.FileEditorInput;
|
||||||
import org.eclipse.ui.texteditor.AbstractTextEditor;
|
import org.eclipse.ui.texteditor.AbstractTextEditor;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base test class for testing Ctrl_F3/F3 with the indexers.
|
* Base test class for testing Ctrl_F3/F3 with the indexers.
|
||||||
*
|
*
|
||||||
|
@ -114,6 +113,31 @@ public class BaseSelectionTestsIndexer extends TestCase {
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected IFile importFileWithLink(String fileName, String contents) throws Exception{
|
||||||
|
//Obtain file handle
|
||||||
|
IFile file = project.getProject().getFile(fileName);
|
||||||
|
|
||||||
|
IPath location = new Path(project.getLocation().removeLastSegments(1).toOSString() + File.separator + fileName); //$NON-NLS-1$
|
||||||
|
|
||||||
|
File linkFile = new File(location.toOSString());
|
||||||
|
if (!linkFile.exists()) {
|
||||||
|
linkFile.createNewFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
file.createLink(location, IResource.ALLOW_MISSING_LOCAL, null);
|
||||||
|
|
||||||
|
InputStream stream = new ByteArrayInputStream( contents.getBytes() );
|
||||||
|
//Create file input stream
|
||||||
|
if( file.exists() )
|
||||||
|
file.setContents( stream, false, false, monitor );
|
||||||
|
else
|
||||||
|
file.create( stream, false, monitor );
|
||||||
|
|
||||||
|
fileManager.addFile(file);
|
||||||
|
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
protected IFolder importFolder(String folderName) throws Exception {
|
protected IFolder importFolder(String folderName) throws Exception {
|
||||||
IFolder folder = project.getProject().getFolder(folderName);
|
IFolder folder = project.getProject().getFolder(folderName);
|
||||||
|
|
||||||
|
|
|
@ -127,6 +127,7 @@ public class CPPSelectionTestsCTagsIndexer extends BaseSelectionTestsIndexer
|
||||||
suite.addTest(new CPPSelectionTestsCTagsIndexer("testNoDefinitions")); //$NON-NLS-1$
|
suite.addTest(new CPPSelectionTestsCTagsIndexer("testNoDefinitions")); //$NON-NLS-1$
|
||||||
suite.addTest(new CPPSelectionTestsCTagsIndexer("testOpenFileDiffDir")); //$NON-NLS-1$
|
suite.addTest(new CPPSelectionTestsCTagsIndexer("testOpenFileDiffDir")); //$NON-NLS-1$
|
||||||
suite.addTest(new CPPSelectionTestsCTagsIndexer("testBug101287")); //$NON-NLS-1$
|
suite.addTest(new CPPSelectionTestsCTagsIndexer("testBug101287")); //$NON-NLS-1$
|
||||||
|
suite.addTest(new CPPSelectionTestsCTagsIndexer("testBug103697")); //$NON-NLS-1$
|
||||||
|
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
@ -662,6 +663,29 @@ public class CPPSelectionTestsCTagsIndexer extends BaseSelectionTestsIndexer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBug103697() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append("int x;\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("int foo() {\n"); //$NON-NLS-1$
|
||||||
|
buffer.append(" return x;\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("}\n"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
String code = buffer.toString();
|
||||||
|
IFile file = importFileWithLink("testBug103697.cpp", code); //$NON-NLS-1$
|
||||||
|
|
||||||
|
int offset = code.indexOf("return x;\n") + "return ".length(); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
IASTNode def = testCtrl_F3(file, offset);
|
||||||
|
IASTNode decl = testF3(file, offset);
|
||||||
|
assertTrue(def instanceof IASTName);
|
||||||
|
assertEquals(((IASTName)def).toString(), "x"); //$NON-NLS-1$
|
||||||
|
assertEquals(((ASTNode)def).getOffset(), 4);
|
||||||
|
assertEquals(((ASTNode)def).getLength(), 1);
|
||||||
|
assertTrue(decl instanceof IASTName);
|
||||||
|
assertEquals(((IASTName)decl).toString(), "x"); //$NON-NLS-1$
|
||||||
|
assertEquals(((ASTNode)decl).getOffset(), 4);
|
||||||
|
assertEquals(((ASTNode)decl).getLength(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
// REMINDER: see CSelectionTestsCTagsIndexer#suite() when appending new tests to this suite
|
// REMINDER: see CSelectionTestsCTagsIndexer#suite() when appending new tests to this suite
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,6 +127,7 @@ public class CPPSelectionTestsDOMIndexer extends BaseSelectionTestsIndexer imple
|
||||||
suite.addTest(new CPPSelectionTestsDOMIndexer("testBug101287")); //$NON-NLS-1$
|
suite.addTest(new CPPSelectionTestsDOMIndexer("testBug101287")); //$NON-NLS-1$
|
||||||
suite.addTest(new CPPSelectionTestsDOMIndexer("testBug102258")); //$NON-NLS-1$
|
suite.addTest(new CPPSelectionTestsDOMIndexer("testBug102258")); //$NON-NLS-1$
|
||||||
suite.addTest(new CPPSelectionTestsDOMIndexer("testBug103323")); //$NON-NLS-1$
|
suite.addTest(new CPPSelectionTestsDOMIndexer("testBug103323")); //$NON-NLS-1$
|
||||||
|
suite.addTest(new CPPSelectionTestsDOMIndexer("testBug103697")); //$NON-NLS-1$
|
||||||
|
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
@ -1069,5 +1070,28 @@ public class CPPSelectionTestsDOMIndexer extends BaseSelectionTestsIndexer imple
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBug103697() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append("int x;\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("int foo() {\n"); //$NON-NLS-1$
|
||||||
|
buffer.append(" return x;\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("}\n"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
String code = buffer.toString();
|
||||||
|
IFile file = importFileWithLink("testBug103697.cpp", code); //$NON-NLS-1$
|
||||||
|
|
||||||
|
int offset = code.indexOf("return x;\n") + "return ".length(); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
IASTNode def = testCtrl_F3(file, offset);
|
||||||
|
IASTNode decl = testF3(file, offset);
|
||||||
|
assertTrue(def instanceof IASTName);
|
||||||
|
assertEquals(((IASTName)def).toString(), "x"); //$NON-NLS-1$
|
||||||
|
assertEquals(((ASTNode)def).getOffset(), 4);
|
||||||
|
assertEquals(((ASTNode)def).getLength(), 1);
|
||||||
|
assertTrue(decl instanceof IASTName);
|
||||||
|
assertEquals(((IASTName)decl).toString(), "x"); //$NON-NLS-1$
|
||||||
|
assertEquals(((ASTNode)decl).getOffset(), 4);
|
||||||
|
assertEquals(((ASTNode)decl).getLength(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
// REMINDER: see CPPSelectionTestsDomIndexer#suite() when appending new tests to this suite
|
// REMINDER: see CPPSelectionTestsDomIndexer#suite() when appending new tests to this suite
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.Path;
|
||||||
import org.eclipse.jface.action.IAction;
|
import org.eclipse.jface.action.IAction;
|
||||||
import org.eclipse.jface.text.TextSelection;
|
import org.eclipse.jface.text.TextSelection;
|
||||||
import org.eclipse.jface.viewers.ISelection;
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
|
@ -146,6 +147,31 @@ public class CPPSelectionTestsNoIndexer extends TestCase {
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected IFile importFileWithLink(String fileName, String contents) throws Exception{
|
||||||
|
//Obtain file handle
|
||||||
|
IFile file = project.getProject().getFile(fileName);
|
||||||
|
|
||||||
|
IPath location = new Path(project.getLocation().removeLastSegments(1).toOSString() + File.separator + fileName); //$NON-NLS-1$
|
||||||
|
|
||||||
|
File linkFile = new File(location.toOSString());
|
||||||
|
if (!linkFile.exists()) {
|
||||||
|
linkFile.createNewFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
file.createLink(location, IResource.ALLOW_MISSING_LOCAL, null);
|
||||||
|
|
||||||
|
InputStream stream = new ByteArrayInputStream( contents.getBytes() );
|
||||||
|
//Create file input stream
|
||||||
|
if( file.exists() )
|
||||||
|
file.setContents( stream, false, false, monitor );
|
||||||
|
else
|
||||||
|
file.create( stream, false, monitor );
|
||||||
|
|
||||||
|
fileManager.addFile(file);
|
||||||
|
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
protected IASTNode testF3(IFile file, int offset) throws ParserException {
|
protected IASTNode testF3(IFile file, int offset) throws ParserException {
|
||||||
return testF3(file, offset, 0);
|
return testF3(file, offset, 0);
|
||||||
}
|
}
|
||||||
|
@ -1078,4 +1104,27 @@ public class CPPSelectionTestsNoIndexer extends TestCase {
|
||||||
assertEquals(((ASTNode)decl).getOffset(), 11);
|
assertEquals(((ASTNode)decl).getOffset(), 11);
|
||||||
assertEquals(((ASTNode)decl).getLength(), 14);
|
assertEquals(((ASTNode)decl).getLength(), 14);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBug103697() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append("int x;\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("int foo() {\n"); //$NON-NLS-1$
|
||||||
|
buffer.append(" return x;\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("}\n"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
String code = buffer.toString();
|
||||||
|
IFile file = importFileWithLink("testBug103697.cpp", code); //$NON-NLS-1$
|
||||||
|
|
||||||
|
int offset = code.indexOf("return x;\n") + "return ".length(); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
IASTNode def = testCtrl_F3(file, offset);
|
||||||
|
IASTNode decl = testF3(file, offset);
|
||||||
|
assertTrue(def instanceof IASTName);
|
||||||
|
assertEquals(((IASTName)def).toString(), "x"); //$NON-NLS-1$
|
||||||
|
assertEquals(((ASTNode)def).getOffset(), 4);
|
||||||
|
assertEquals(((ASTNode)def).getLength(), 1);
|
||||||
|
assertTrue(decl instanceof IASTName);
|
||||||
|
assertEquals(((IASTName)decl).toString(), "x"); //$NON-NLS-1$
|
||||||
|
assertEquals(((ASTNode)decl).getOffset(), 4);
|
||||||
|
assertEquals(((ASTNode)decl).getLength(), 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,6 +120,7 @@ public class CSelectionTestsCTagsIndexer extends BaseSelectionTestsIndexer
|
||||||
suite.addTest(new CSelectionTestsCTagsIndexer("testNoDefinitions")); //$NON-NLS-1$
|
suite.addTest(new CSelectionTestsCTagsIndexer("testNoDefinitions")); //$NON-NLS-1$
|
||||||
suite.addTest(new CSelectionTestsCTagsIndexer("testOpenFileDiffDir")); //$NON-NLS-1$
|
suite.addTest(new CSelectionTestsCTagsIndexer("testOpenFileDiffDir")); //$NON-NLS-1$
|
||||||
suite.addTest(new CSelectionTestsCTagsIndexer("testBug101287")); //$NON-NLS-1$
|
suite.addTest(new CSelectionTestsCTagsIndexer("testBug101287")); //$NON-NLS-1$
|
||||||
|
suite.addTest(new CSelectionTestsCTagsIndexer("testBug103697")); //$NON-NLS-1$
|
||||||
|
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
@ -648,6 +649,29 @@ public class CSelectionTestsCTagsIndexer extends BaseSelectionTestsIndexer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBug103697() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append("int x;\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("int foo() {\n"); //$NON-NLS-1$
|
||||||
|
buffer.append(" return x;\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("}\n"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
String code = buffer.toString();
|
||||||
|
IFile file = importFileWithLink("testBug103697.cpp", code); //$NON-NLS-1$
|
||||||
|
|
||||||
|
int offset = code.indexOf("return x;\n") + "return ".length(); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
IASTNode def = testCtrl_F3(file, offset);
|
||||||
|
IASTNode decl = testF3(file, offset);
|
||||||
|
assertTrue(def instanceof IASTName);
|
||||||
|
assertEquals(((IASTName)def).toString(), "x"); //$NON-NLS-1$
|
||||||
|
assertEquals(((ASTNode)def).getOffset(), 4);
|
||||||
|
assertEquals(((ASTNode)def).getLength(), 1);
|
||||||
|
assertTrue(decl instanceof IASTName);
|
||||||
|
assertEquals(((IASTName)decl).toString(), "x"); //$NON-NLS-1$
|
||||||
|
assertEquals(((ASTNode)decl).getOffset(), 4);
|
||||||
|
assertEquals(((ASTNode)decl).getLength(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
// REMINDER: see CSelectionTestsCTagsIndexer#suite() when appending new tests to this suite
|
// REMINDER: see CSelectionTestsCTagsIndexer#suite() when appending new tests to this suite
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,6 +115,7 @@ public class CSelectionTestsDOMIndexer extends BaseSelectionTestsIndexer impleme
|
||||||
suite.addTest(new CSelectionTestsDOMIndexer("testNoDefinitions")); //$NON-NLS-1$
|
suite.addTest(new CSelectionTestsDOMIndexer("testNoDefinitions")); //$NON-NLS-1$
|
||||||
suite.addTest(new CSelectionTestsDOMIndexer("testOpenFileDiffDir")); //$NON-NLS-1$
|
suite.addTest(new CSelectionTestsDOMIndexer("testOpenFileDiffDir")); //$NON-NLS-1$
|
||||||
suite.addTest(new CSelectionTestsDOMIndexer("testBug101287")); //$NON-NLS-1$
|
suite.addTest(new CSelectionTestsDOMIndexer("testBug101287")); //$NON-NLS-1$
|
||||||
|
suite.addTest(new CSelectionTestsDOMIndexer("testBug103697")); //$NON-NLS-1$
|
||||||
|
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
@ -644,5 +645,28 @@ public class CSelectionTestsDOMIndexer extends BaseSelectionTestsIndexer impleme
|
||||||
assertEquals(((ASTNode)decl).getLength(), 3);
|
assertEquals(((ASTNode)decl).getLength(), 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBug103697() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append("int x;\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("int foo() {\n"); //$NON-NLS-1$
|
||||||
|
buffer.append(" return x;\n"); //$NON-NLS-1$
|
||||||
|
buffer.append("}\n"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
String code = buffer.toString();
|
||||||
|
IFile file = importFileWithLink("testBug103697.cpp", code); //$NON-NLS-1$
|
||||||
|
|
||||||
|
int offset = code.indexOf("return x;\n") + "return ".length(); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
IASTNode def = testCtrl_F3(file, offset);
|
||||||
|
IASTNode decl = testF3(file, offset);
|
||||||
|
assertTrue(def instanceof IASTName);
|
||||||
|
assertEquals(((IASTName)def).toString(), "x"); //$NON-NLS-1$
|
||||||
|
assertEquals(((ASTNode)def).getOffset(), 4);
|
||||||
|
assertEquals(((ASTNode)def).getLength(), 1);
|
||||||
|
assertTrue(decl instanceof IASTName);
|
||||||
|
assertEquals(((IASTName)decl).toString(), "x"); //$NON-NLS-1$
|
||||||
|
assertEquals(((ASTNode)decl).getOffset(), 4);
|
||||||
|
assertEquals(((ASTNode)decl).getLength(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
// REMINDER: see CSelectionTestsDomIndexer#suite() when appending new tests to this suite
|
// REMINDER: see CSelectionTestsDomIndexer#suite() when appending new tests to this suite
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ import org.eclipse.cdt.ui.CSearchResultLabelProvider;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IMarker;
|
import org.eclipse.core.resources.IMarker;
|
||||||
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
|
@ -119,8 +120,25 @@ public class CSearchResultPage extends AbstractTextSearchViewPage {
|
||||||
editor = IDE.openEditor(CUIPlugin.getActivePage(), getCanonicalFile((IFile) searchMatch.getResource()), false);
|
editor = IDE.openEditor(CUIPlugin.getActivePage(), getCanonicalFile((IFile) searchMatch.getResource()), false);
|
||||||
IMatchLocatable searchLocatable = searchMatch.getLocatable();
|
IMatchLocatable searchLocatable = searchMatch.getLocatable();
|
||||||
showWithMarker(editor, getCanonicalFile((IFile) searchMatch.getResource()), searchLocatable, currentOffset, currentLength);
|
showWithMarker(editor, getCanonicalFile((IFile) searchMatch.getResource()), searchLocatable, currentOffset, currentLength);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
|
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(searchMatch.getPath());
|
||||||
|
if (files != null && files.length > 0){
|
||||||
|
for (int i=0; i<files.length; i++) {
|
||||||
|
if (EditorUtility.isLinked(files[i])) {
|
||||||
|
try {
|
||||||
|
editor = EditorUtility.openInEditor(files[i]);
|
||||||
|
} catch (PartInitException e) {
|
||||||
|
} catch (CModelException e) {
|
||||||
|
}
|
||||||
|
IMatchLocatable searchLocatable = searchMatch.getLocatable();
|
||||||
|
showWithMarker(editor, getCanonicalFile(files[i]), searchLocatable, currentOffset, currentLength);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Match is outside of the workspace
|
//Match is outside of the workspace
|
||||||
try {
|
try {
|
||||||
IEditorInput input =EditorUtility.getEditorInput(new ExternalSearchFile(searchMatch.getPath(), searchMatch));
|
IEditorInput input =EditorUtility.getEditorInput(new ExternalSearchFile(searchMatch.getPath(), searchMatch));
|
||||||
|
@ -194,7 +212,7 @@ public class CSearchResultPage extends AbstractTextSearchViewPage {
|
||||||
}*/
|
}*/
|
||||||
} catch (CModelException e) {}
|
} catch (CModelException e) {}
|
||||||
catch (CoreException e) {}
|
catch (CoreException e) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|
|
@ -133,7 +133,7 @@ public class OpenDefinitionAction extends SelectionParseAction implements
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
lang = DOMSearchUtil.getLanguageFromFile(resourceFile);
|
lang = DOMSearchUtil.getLanguageFromFile(resourceFile);
|
||||||
project = new CProject(null, resourceFile.getProject());
|
projectName = resourceFile.getProject().getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
// step 1 starts here
|
// step 1 starts here
|
||||||
|
|
|
@ -59,6 +59,7 @@ import org.eclipse.ui.IFileEditorInput;
|
||||||
import org.eclipse.ui.IViewSite;
|
import org.eclipse.ui.IViewSite;
|
||||||
import org.eclipse.ui.IWorkbenchSite;
|
import org.eclipse.ui.IWorkbenchSite;
|
||||||
import org.eclipse.ui.PartInitException;
|
import org.eclipse.ui.PartInitException;
|
||||||
|
import org.eclipse.ui.PlatformUI;
|
||||||
import org.eclipse.ui.texteditor.AbstractTextEditor;
|
import org.eclipse.ui.texteditor.AbstractTextEditor;
|
||||||
import org.eclipse.ui.texteditor.IDocumentProvider;
|
import org.eclipse.ui.texteditor.IDocumentProvider;
|
||||||
|
|
||||||
|
@ -600,6 +601,15 @@ public class SelectionParseAction extends Action {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check the IWorkspaceRoot to see if it knows of any IFiles that are open for the corresponding filename (i.e. linked resources)
|
||||||
|
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path);
|
||||||
|
for(int i=0; i<files.length; i++) {
|
||||||
|
if (files[i] != null) {
|
||||||
|
open( files[i], locatable );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
FileStorage storage = new FileStorage(null, path);
|
FileStorage storage = new FileStorage(null, path);
|
||||||
IEditorPart part = EditorUtility.openInEditor(storage);
|
IEditorPart part = EditorUtility.openInEditor(storage);
|
||||||
setSelectionAtOffset(part, locatable);
|
setSelectionAtOffset(part, locatable);
|
||||||
|
|
|
@ -28,10 +28,13 @@ import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||||
import org.eclipse.cdt.internal.ui.editor.CEditorMessages;
|
import org.eclipse.cdt.internal.ui.editor.CEditorMessages;
|
||||||
import org.eclipse.cdt.internal.ui.editor.ITranslationUnitEditorInput;
|
import org.eclipse.cdt.internal.ui.editor.ITranslationUnitEditorInput;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
import org.eclipse.core.resources.IContainer;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
|
import org.eclipse.core.resources.IFolder;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.resources.IStorage;
|
import org.eclipse.core.resources.IStorage;
|
||||||
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
import org.eclipse.jface.action.Action;
|
import org.eclipse.jface.action.Action;
|
||||||
|
@ -131,6 +134,7 @@ public class EditorUtility {
|
||||||
|
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
try {
|
try {
|
||||||
|
if (!isLinked(file)) {
|
||||||
File tempFile = file.getRawLocation().toFile();
|
File tempFile = file.getRawLocation().toFile();
|
||||||
|
|
||||||
if (tempFile != null){
|
if (tempFile != null){
|
||||||
|
@ -144,6 +148,7 @@ public class EditorUtility {
|
||||||
file = CUIPlugin.getWorkspace().getRoot().getFileForLocation(path);
|
file = CUIPlugin.getWorkspace().getRoot().getFileForLocation(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
IEditorInput input = getEditorInput(file);
|
IEditorInput input = getEditorInput(file);
|
||||||
if (input != null) {
|
if (input != null) {
|
||||||
|
@ -154,6 +159,26 @@ public class EditorUtility {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isLinked(IFile file) {
|
||||||
|
if (file.isLinked())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
IPath path = file.getLocation();
|
||||||
|
|
||||||
|
while (path.segmentCount() > 0) {
|
||||||
|
path = path.removeLastSegments(1);
|
||||||
|
IContainer[] containers = ResourcesPlugin.getWorkspace().getRoot().findContainersForLocation(path);
|
||||||
|
|
||||||
|
for(int i=0; i<containers.length; i++) {
|
||||||
|
if (containers[i] instanceof IFolder && ((IFolder)containers[i]).isLinked()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param project
|
* @param project
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue