From 2f5b010e80c2bf6217ea41bf38379eff35bec802 Mon Sep 17 00:00:00 2001 From: Bogdan Gheorghe Date: Wed, 13 Jul 2005 20:12:35 +0000 Subject: [PATCH] Fix for 70137: Cannot use context-search at template member definition --- .../ui/editor/CContentOutlinePage.java | 8 +++++++ .../ui/search/actions/FindAction.java | 22 ++++++++++++++++++- .../internal/ui/util/ProblemTreeViewer.java | 22 +++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java index 287d134308a..00708ab59f0 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java @@ -171,6 +171,14 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS return fInput; } + /** + * Returns the CEditor corresponding to this CContentOutlinePage. + * @param return + */ + public CEditor getEditor() { + return fEditor; + } + /** * Called by the editor to signal that the content has updated. */ 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 bf7dc5ec91c..1a5b7d4e410 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 @@ -27,6 +27,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.ILabel; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.ISourceReference; import org.eclipse.cdt.core.parser.ParseError; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.search.DOMSearchUtil; @@ -38,11 +39,14 @@ import org.eclipse.cdt.internal.ui.search.CSearchQuery; import org.eclipse.cdt.internal.ui.search.CSearchUtil; import org.eclipse.cdt.internal.ui.search.DOMQuery; import org.eclipse.cdt.internal.ui.util.ExternalEditorInput; +import org.eclipse.cdt.internal.ui.util.ProblemTreeViewer; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.dialogs.ProgressMonitorDialog; import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.text.TextSelection; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.search.ui.NewSearchUI; @@ -95,7 +99,23 @@ public abstract class FindAction extends SelectionParseAction { ISelection sel = getSelection(); if (sel instanceof IStructuredSelection) { - run((IStructuredSelection) sel); + Object obj = ((IStructuredSelection)sel).getFirstElement(); + + // if possible, try to perform a full blown DOM query before the Index query, if this fails, then perform an Index query + if (obj instanceof ISourceReference && fSite.getSelectionProvider() instanceof ProblemTreeViewer) { + try { + fEditor = ((ProblemTreeViewer)fSite.getSelectionProvider()).getEditor(); + IDocument doc = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput()); + ISourceReference ref = (ISourceReference)obj; + + TextSelection selection = new TextSelection(doc, ref.getSourceRange().getIdStartPos(), ref.getSourceRange().getIdLength()); + run(selection); + return; + } catch (Exception e) { + } + } + + run((IStructuredSelection) sel); } else if (sel instanceof ITextSelection) { run((ITextSelection) sel); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/ProblemTreeViewer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/ProblemTreeViewer.java index 69236bf80fd..92a539b373f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/ProblemTreeViewer.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/ProblemTreeViewer.java @@ -7,8 +7,11 @@ package org.eclipse.cdt.internal.ui.util; import java.util.ArrayList; +import org.eclipse.cdt.internal.ui.editor.CContentOutlinePage; +import org.eclipse.cdt.internal.ui.editor.CEditor; import org.eclipse.core.resources.IResource; import org.eclipse.jface.viewers.IBaseLabelProvider; +import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.LabelProviderChangedEvent; import org.eclipse.jface.viewers.TreeViewer; @@ -26,6 +29,7 @@ import org.eclipse.swt.widgets.Widget; public class ProblemTreeViewer extends TreeViewer { protected ResourceToItemsMapper fResourceToItemsMapper; + private CEditor editor = null; /* * @see TreeViewer#TreeViewer(Composite) @@ -141,5 +145,23 @@ public class ProblemTreeViewer extends TreeViewer { // or lots of TUs exist in one folder so lets skip it.... return cp.hasChildren(element); } + + /* (non-Javadoc) + * Method declared on ISelectionProvider. + */ + public void addSelectionChangedListener(ISelectionChangedListener listener) { + super.addSelectionChangedListener(listener); + if (listener instanceof CContentOutlinePage) { + editor =((CContentOutlinePage)listener).getEditor(); + } + } + + /** + * This returns the editor corresponding to the opened CEditor that is listening to the selection changes on the Outline View. + * @return + */ + public CEditor getEditor() { + return editor; + } }