diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties index 2aea9ddeb7a..b7aaa4cde94 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties @@ -147,3 +147,7 @@ PDOMSearch.query.defs.label = Find definitions of PDOMSearch.query.decls.label = Find declarations of PDOMSearchPatternQuery.PatternQuery_labelPatternInScope={0} {1} in {2} PDOMSearch.query.pattern.error = Illegal Search String +SelectionParseAction.FileOpenFailure.format=Could not open file ''{0}'', verify index is up-to-date +SelectionParseAction.SelectedTextNotSymbol.message=Selected text cannot be mapped to a symbol name +SelectionParseAction.SymbolNotFoundInIndex.format=Could not find symbol ''{0}'' in index +SelectionParseAction.IncludeNotFound.format=Could not find include file ''{0}'' on include paths diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindAction.java index 1a2c8aa5c49..0d55ec9648a 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindAction.java @@ -15,6 +15,7 @@ import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ISourceReference; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.internal.ui.editor.CEditor; +import org.eclipse.cdt.internal.ui.search.CSearchMessages; import org.eclipse.cdt.internal.ui.search.PDOMSearchElementQuery; import org.eclipse.cdt.internal.ui.search.PDOMSearchTextSelectionQuery; import org.eclipse.jface.text.ITextSelection; @@ -57,7 +58,7 @@ public abstract class FindAction extends SelectionParseAction { } if (searchJob == null) { - operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE); + showStatusLineMessage(CSearchMessages.getString(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE)); return; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java index 16a4cf99a3a..36ed13075b5 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java @@ -64,6 +64,8 @@ public class OpenDeclarationsAction extends SelectionParseAction { protected IStatus run(IProgressMonitor monitor) { try { + clearStatusLine(); + int selectionStart = selNode.getOffset(); int selectionLength = selNode.getLength(); @@ -79,14 +81,16 @@ public class OpenDeclarationsAction extends SelectionParseAction { } catch (InterruptedException e) { return Status.CANCEL_STATUS; } - + + try { IASTTranslationUnit ast= ASTProvider.getASTProvider().getAST( workingCopy, index, ASTProvider.WAIT_YES, monitor); IASTName[] selectedNames = workingCopy.getLanguage().getSelectedNames(ast, selectionStart, selectionLength); - + if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected + boolean found = false; IASTName searchName = selectedNames[0]; boolean isDefinition= searchName.isDefinition(); IBinding binding = searchName.resolveBinding(); @@ -105,6 +109,8 @@ public class OpenDeclarationsAction extends SelectionParseAction { for (int i = 0; i < declNames.length; i++) { IASTFileLocation fileloc = declNames[i].getFileLocation(); if (fileloc != null) { + found = true; + final IPath path = new Path(fileloc.getFileName()); final int offset = fileloc.getNodeOffset(); final int length = fileloc.getNodeLength(); @@ -122,22 +128,29 @@ public class OpenDeclarationsAction extends SelectionParseAction { } } } + if (!found) { + reportSymbolLookupFailure(new String(searchName.toCharArray())); + } + } else { // Check if we're in an include statement IASTPreprocessorStatement[] preprocs = ast.getAllPreprocessorStatements(); + boolean foundInInclude = false; for (int i = 0; i < preprocs.length; ++i) { if (!(preprocs[i] instanceof IASTPreprocessorIncludeStatement)) continue; IASTPreprocessorIncludeStatement incStmt = (IASTPreprocessorIncludeStatement)preprocs[i]; - if (!incStmt.isResolved()) - continue; IASTFileLocation loc = preprocs[i].getFileLocation(); if (loc != null && loc.getFileName().equals(ast.getFilePath()) && loc.getNodeOffset() < selectionStart && loc.getNodeOffset() + loc.getNodeLength() > selectionStart) { // Got it - String name = incStmt.getPath(); + foundInInclude = true; + String name = null; + if (incStmt.isResolved()) + name = incStmt.getPath(); + if (name != null) { final IPath path = new Path(name); runInUIThread(new Runnable() { @@ -149,9 +162,15 @@ public class OpenDeclarationsAction extends SelectionParseAction { } } }); + } else { + reportIncludeLookupFailure(new String(incStmt.getName().toCharArray())); } + break; } + if (!foundInInclude) { + reportSelectionMatchFailure(); + } } } } finally { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java index 145828f393b..204f59bc99c 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java @@ -65,6 +65,8 @@ public class OpenDefinitionAction extends SelectionParseAction { protected IStatus run(IProgressMonitor monitor) { try { + clearStatusLine(); + int selectionStart = selNode.getOffset(); int selectionLength = selNode.getLength(); @@ -83,6 +85,7 @@ public class OpenDefinitionAction extends SelectionParseAction { IASTTranslationUnit ast = workingCopy.getAST(index, ITranslationUnit.AST_SKIP_ALL_HEADERS); IASTName[] selectedNames = workingCopy.getLanguage().getSelectedNames(ast, selectionStart, selectionLength); + boolean found = false; if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected IASTName searchName = selectedNames[0]; @@ -91,8 +94,9 @@ public class OpenDefinitionAction extends SelectionParseAction { final IName[] declNames = ast.getDefinitions(binding); for (int i = 0; i < declNames.length; i++) { IASTFileLocation fileloc = declNames[i].getFileLocation(); - // no source location - TODO spit out an error in the status bar if (fileloc != null) { + found = true; + final IPath path = new Path(fileloc.getFileName()); final int offset = fileloc.getNodeOffset(); final int length = fileloc.getNodeLength(); @@ -110,12 +114,18 @@ public class OpenDefinitionAction extends SelectionParseAction { } } } + if (!found) { + reportSymbolLookupFailure(new String(searchName.toCharArray())); + } + } else { + reportSelectionMatchFailure(); } } finally { index.releaseReadLock(); } - + + return Status.OK_STATUS; } catch (CoreException e) { return e.getStatus(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/SelectionParseAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/SelectionParseAction.java index a95ef4bc624..2acc0a5b46a 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/SelectionParseAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/SelectionParseAction.java @@ -8,10 +8,13 @@ * Contributors: * IBM Corp. - Rational Software - initial implementation * Markus Schorn (Wind River Systems) + * Ed Swartz (Nokia) *******************************************************************************/ package org.eclipse.cdt.internal.ui.search.actions; +import java.text.MessageFormat; + import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; @@ -70,7 +73,7 @@ public class SelectionParseAction extends Action { return fSite; } - protected void operationNotAvailable(final String message) { + protected void showStatusLineMessage(final String message) { // run the code to update the status line on the Display thread // this way any other thread can invoke operationNotAvailable(String) CUIPlugin.getStandardDisplay().asyncExec(new Runnable(){ @@ -86,7 +89,7 @@ public class SelectionParseAction extends Action { statusManager = ((IEditorSite) fSite).getActionBars().getStatusLineManager(); } if( statusManager != null ) - statusManager.setErrorMessage(CSearchMessages.getString(message)); + statusManager.setErrorMessage(message); } }); } @@ -226,10 +229,13 @@ public class SelectionParseAction extends Action { * @param name */ protected void open(IName name) throws CoreException { + clearStatusLine(); + IASTFileLocation fileloc = name.getFileLocation(); - if (fileloc == null) - // no source location - TODO spit out an error in the status bar + if (fileloc == null) { + reportSymbolLookupFailure(new String(name.toCharArray())); return; + } IPath path = new Path(fileloc.getFileName()); int currentOffset = fileloc.getNodeOffset(); @@ -239,12 +245,14 @@ public class SelectionParseAction extends Action { } protected void open(IPath path, int currentOffset, int currentLength) throws CoreException { + clearStatusLine(); + IEditorPart editor = EditorUtility.openInEditor(path, fEditor.getInputCElement()); if (editor instanceof ITextEditor) { ITextEditor textEditor = (ITextEditor)editor; textEditor.selectAndReveal(currentOffset, currentLength); } else { - // TODO: report error + reportSourceFileOpenFailure(path); } } @@ -252,4 +260,26 @@ public class SelectionParseAction extends Action { setEnabled(getSelectedStringFromEditor() != null); } + protected void reportSourceFileOpenFailure(IPath path) { + showStatusLineMessage(MessageFormat.format( + CSearchMessages.getString("SelectionParseAction.FileOpenFailure.format"), //$NON-NLS-1$ + new String[] { path.toOSString() })); + } + + protected void reportSelectionMatchFailure() { + showStatusLineMessage(CSearchMessages.getString("SelectionParseAction.SelectedTextNotSymbol.message")); //$NON-NLS-1$ + } + + protected void reportSymbolLookupFailure(String symbol) { + showStatusLineMessage(MessageFormat.format( + CSearchMessages.getString("SelectionParseAction.SymbolNotFoundInIndex.format"), //$NON-NLS-1$ + new String[] { symbol })); + } + + protected void reportIncludeLookupFailure(String filename) { + showStatusLineMessage(MessageFormat.format( + CSearchMessages.getString("SelectionParseAction.IncludeNotFound.format"), //$NON-NLS-1$ + new String[] { filename })); + } + }