Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2009-08-23 16:02:53 -0400
committerSergey Prigogin2009-08-23 16:02:53 -0400
commit727bcb6654d7619830a47d1bbebdab747ac6e4e5 (patch)
tree270cc427db458b3a89e798b739a465ee66f4fe56
parenta23a43efce58264a79b5ce1d23da20e546d22298 (diff)
downloadorg.eclipse.cdt-727bcb6654d7619830a47d1bbebdab747ac6e4e5.tar.gz
org.eclipse.cdt-727bcb6654d7619830a47d1bbebdab747ac6e4e5.tar.xz
org.eclipse.cdt-727bcb6654d7619830a47d1bbebdab747ac6e4e5.zip
Enclosing definitions in C/C++ search results. Patch by Andrey Eremchenko. Bug 282668.
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/indexview/IndexViewSearchQuery.java9
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.java18
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties20
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/LineSearchElement.java13
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchElementQuery.java14
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchLabelProvider.java26
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchListLabelProvider.java88
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchPatternQuery.java15
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchQuery.java64
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchResult.java15
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTextSelectionQuery.java9
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTreeLabelProvider.java38
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchUnresolvedIncludesQuery.java8
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchViewPage.java155
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindAction.java21
15 files changed, 371 insertions, 142 deletions
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/indexview/IndexViewSearchQuery.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/indexview/IndexViewSearchQuery.java
index f18e9492ea..18f2f6f1d5 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/indexview/IndexViewSearchQuery.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/indexview/IndexViewSearchQuery.java
@@ -6,8 +6,9 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * QNX - Initial API and implementation
- * Markus Schorn (Wind River Systems)
+ * QNX - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.indexview;
@@ -61,7 +62,7 @@ public class IndexViewSearchQuery extends PDOMSearchQuery {
}
@Override
- public String getLabel() {
- return super.getLabel() + " " + fName; //$NON-NLS-1$
+ public String getResultLabel(int numMatches) {
+ return super.getResultLabel(fName, numMatches);
}
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.java
index a226a2c14f..c281fbcfbe 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.java
@@ -8,6 +8,7 @@
* Contributors:
* IBM Corp. - Rational Software - initial implementation
* Anton Leherbauer (Wind River Systems)
+ * Andrey Eremchenko (LEDAS)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
@@ -24,6 +25,8 @@ public final class CSearchMessages extends NLS {
public static String group_declarations;
public static String group_references;
public static String CSearchResultCollector_matches;
+ public static String CSearchResultCollector_line;
+ public static String CSearchResultCollector_location;
public static String CSearchPage_searchFor_label;
public static String CSearchPage_searchFor_namespace;
public static String CSearchPage_searchFor_method;
@@ -59,9 +62,13 @@ public final class CSearchMessages extends NLS {
public static String WorkingSetScope;
public static String SelectionScope;
public static String ProjectScope;
- public static String PDOMSearch_query_refs_label;
- public static String PDOMSearch_query_defs_label;
- public static String PDOMSearch_query_decls_label;
+ public static String PDOMSearchQuery_refs_label;
+ public static String PDOMSearchQuery_defs_label;
+ public static String PDOMSearchQuery_decls_label;
+ public static String PDOMSearchQuery_refs_result_label;
+ public static String PDOMSearchQuery_defs_result_label;
+ public static String PDOMSearchQuery_decls_result_label;
+ public static String PDOMSearchElementQuery_something;
public static String PDOMSearchPatternQuery_PatternQuery_labelPatternInScope;
public static String PDOMSearch_query_pattern_error;
public static String SelectionParseAction_FileOpenFailure_format;
@@ -82,6 +89,11 @@ public final class CSearchMessages extends NLS {
public static String HidePolymorphicCalls_actionLabel;
public static String HidePolymorphicCalls_description;
public static String HidePolymorphicCalls_name;
+ public static String PDOMSearchViewPage_ShowEnclosingDefinitions_actionLabel;
+ public static String PDOMSearchViewPage_ShowEnclosingDefinitions_description;
+ public static String PDOMSearchViewPageLocationColumn_label;
+ public static String PDOMSearchViewPageDefinitionColumn_label;
+ public static String PDOMSearchViewPageMatchColumn_label;
public static String PDOMSearchTreeContentProvider_IndexerNotEnabledWarning;
public static String PDOMSearchTreeContentProvider_ProjectClosedWarning;
public static String PDOMSearchUnresolvedIncludesQuery_title;
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 3ac516362d..418f5662d7 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
@@ -9,6 +9,7 @@
# IBM Corporation - initial API and implementation
# Ed Swartz (Nokia)
# Anton Leherbauer (Wind River Systems)
+# Andrey Eremchenko (LEDAS)
###############################################################################
group_declarations=Dec&larations
@@ -18,6 +19,8 @@ group_references=Re&ferences
# Examples of the display for the following value are
# "(1 match)", where {0} is 1 and "(5 matches)", where {0} is 2 or more.
CSearchResultCollector_matches= ({0} {0, choice, 0\#matches|1\#match|2\#matches})
+CSearchResultCollector_line= {0}line {1,number,######}
+CSearchResultCollector_location= {0}, line {1,number,######}
CSearchPage_searchFor_label= Search For
CSearchPage_searchFor_namespace= Names&pace
@@ -64,10 +67,14 @@ WorkingSetScope= Working Set - {0}
SelectionScope= Selection
ProjectScope = Project
-PDOMSearch_query_refs_label = Find references to
-PDOMSearch_query_defs_label = Find definitions of
-PDOMSearch_query_decls_label = Find declarations of
-PDOMSearchPatternQuery_PatternQuery_labelPatternInScope={0} {1} in {2}
+PDOMSearchQuery_refs_label = Search references
+PDOMSearchQuery_defs_label = Search definitions
+PDOMSearchQuery_decls_label = Search declarations
+PDOMSearchQuery_refs_result_label = References to {0}
+PDOMSearchQuery_defs_result_label = Definitions of {0}
+PDOMSearchQuery_decls_result_label = Declarations of {0}
+PDOMSearchElementQuery_something = something
+PDOMSearchPatternQuery_PatternQuery_labelPatternInScope={0} in {1}
PDOMSearchTreeContentProvider_IndexerNotEnabledWarning=(unknown results: indexer is not enabled)
PDOMSearchTreeContentProvider_ProjectClosedWarning=(unknown results: project is closed)
PDOMSearchListContentProvider_IndexerNotEnabledMessageFormat=(project ''{0}'' - unknown results: indexer is not enabled)
@@ -76,6 +83,11 @@ CSearchMessages_IndexRunningIncompleteWarning=(incomplete or inaccurate results:
HidePolymorphicCalls_actionLabel=Hide Potential Method Calls
HidePolymorphicCalls_description=Hides potential method calls to virtual overriders
HidePolymorphicCalls_name=Potential Method Calls
+PDOMSearchViewPage_ShowEnclosingDefinitions_actionLabel=Show Enclosing Definitions
+PDOMSearchViewPage_ShowEnclosingDefinitions_description=Shows enclosing definitions for matches
+PDOMSearchViewPageLocationColumn_label=Location
+PDOMSearchViewPageDefinitionColumn_label=Enclosing Definition
+PDOMSearchViewPageMatchColumn_label=Match
PDOMSearch_query_pattern_error = Illegal Search String
PDOMSearchUnresolvedIncludesQuery_title=Unresolved inclusions in {0}
SelectionParseAction_FileOpenFailure_format=Could not open file ''{0}'', verify index is up-to-date
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/LineSearchElement.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/LineSearchElement.java
index 0b843e4823..c3e2a9bf98 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/LineSearchElement.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/LineSearchElement.java
@@ -7,7 +7,6 @@
*
* Contributors:
* Andrey Eremchenko, kamre@ngs.ru - 222495 C/C++ search should show line matches and line numbers
- *
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
@@ -21,23 +20,25 @@ import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.cdt.core.index.IIndexFileLocation;
+import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.ui.CUIPlugin;
/**
* Element representing a line with one ore more matches.
- *
*/
public class LineSearchElement extends PDOMSearchElement {
public static final class Match {
private final int fOffset;
private final int fLength;
private final boolean fIsPolymorphicCall;
+ private final ICElement fEnclosingElement;
- public Match(int offset, int length, boolean isPolymorphicCall) {
+ public Match(int offset, int length, boolean isPolymorphicCall, ICElement enclosingElement) {
fOffset = offset;
fLength = length;
fIsPolymorphicCall = isPolymorphicCall;
+ fEnclosingElement = enclosingElement;
}
public int getOffset() {
@@ -52,6 +53,10 @@ public class LineSearchElement extends PDOMSearchElement {
return fIsPolymorphicCall;
}
+ public ICElement getEnclosingElement() {
+ return fEnclosingElement;
+ }
+
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Match))
@@ -87,7 +92,7 @@ public class LineSearchElement extends PDOMSearchElement {
int length = content.length();
int firstMatchOffset = matches[0].getOffset();
while (offset < firstMatchOffset && length > 0) {
- if (content.charAt(index) != ' ')
+ if (!Character.isWhitespace(content.charAt(index)))
break;
index++;
offset++;
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchElementQuery.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchElementQuery.java
index 4a5ae2d001..4a9254b111 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchElementQuery.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchElementQuery.java
@@ -6,8 +6,9 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * QNX - Initial API and implementation
- * Markus Schorn (Wind River Systems)
+ * QNX - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
@@ -27,7 +28,6 @@ import org.eclipse.cdt.internal.ui.viewsupport.IndexUI;
/**
* @author Doug Schaefer
- *
*/
public class PDOMSearchElementQuery extends PDOMSearchQuery {
@@ -54,9 +54,9 @@ public class PDOMSearchElementQuery extends PDOMSearchQuery {
}
@Override
- public String getLabel() {
- if (element instanceof ICElement)
- return super.getLabel() + " " + ((ICElement)element).getElementName(); //$NON-NLS-1$
- return super.getLabel() + " something."; //$NON-NLS-1$
+ public String getResultLabel(int numMatches) {
+ String pattern = (element instanceof ICElement) ?
+ ((ICElement) element).getElementName() : CSearchMessages.PDOMSearchElementQuery_something;
+ return getResultLabel(pattern, numMatches);
}
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchLabelProvider.java
index 94e76c3ccd..8d71240c72 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchLabelProvider.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchLabelProvider.java
@@ -6,8 +6,9 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Markus Schorn - initial API and implementation
- * Ed Swartz (Nokia)
+ * Markus Schorn - initial API and implementation
+ * Ed Swartz (Nokia)
+ * Andrey Eremchenko (LEDAS)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
@@ -19,7 +20,6 @@ import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
import org.eclipse.search.ui.text.AbstractTextSearchResult;
-import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
@@ -27,6 +27,7 @@ import org.eclipse.ui.PlatformUI;
import org.eclipse.cdt.core.dom.ast.ASTSignatureUtil;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IndexLocationFactory;
+import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.ui.browser.typeinfo.TypeInfoLabelProvider;
import org.eclipse.cdt.internal.core.model.TranslationUnit;
@@ -52,11 +53,11 @@ import org.eclipse.cdt.internal.ui.viewsupport.ColoringLabelProvider;
*/
public class PDOMSearchLabelProvider extends LabelProvider implements IStyledLabelProvider {
- private final AbstractTextSearchViewPage fPage;
+ protected final PDOMSearchViewPage fPage;
private final TypeInfoLabelProvider fTypeInfoLabelProvider;
private final CUILabelProvider fCElementLabelProvider;
- public PDOMSearchLabelProvider(AbstractTextSearchViewPage page) {
+ public PDOMSearchLabelProvider(PDOMSearchViewPage page) {
fTypeInfoLabelProvider= new TypeInfoLabelProvider(TypeInfoLabelProvider.SHOW_FULLY_QUALIFIED | TypeInfoLabelProvider.SHOW_PARAMETERS);
fCElementLabelProvider= new CUILabelProvider(0, CElementImageProvider.SMALL_ICONS);
fPage= page;
@@ -64,8 +65,13 @@ public class PDOMSearchLabelProvider extends LabelProvider implements IStyledLab
@Override
public Image getImage(Object element) {
- if (element instanceof LineSearchElement)
- return CPluginImages.get(CPluginImages.IMG_OBJS_SEARCH_LINE);
+ if (element instanceof LineSearchElement) {
+ LineSearchElement lineSearchElement = (LineSearchElement) element;
+ ICElement enclosingElement = lineSearchElement.getMatches()[0].getEnclosingElement();
+ if (!fPage.isShowEnclosingDefinitions() || enclosingElement == null)
+ return CPluginImages.get(CPluginImages.IMG_OBJS_SEARCH_LINE);
+ element = enclosingElement;
+ }
if (element instanceof TypeInfoSearchElement)
return fTypeInfoLabelProvider.getImage(((TypeInfoSearchElement)element).getTypeInfo());
@@ -161,9 +167,9 @@ public class PDOMSearchLabelProvider extends LabelProvider implements IStyledLab
String lineContent = lineElement.getContent();
StyledString styled = new StyledString(lineContent);
for (Match match : lineElement.getMatches()) {
- int offset = match.getOffset();
- int length = Math.min(match.getLength(), lineContent.length() - (offset - lineOffset));
- styled.setStyle(offset - lineOffset, length, ColoringLabelProvider.HIGHLIGHT_STYLE);
+ int offset = Math.max(0, match.getOffset() - lineOffset);
+ int length = Math.min(match.getLength(), lineContent.length() - offset);
+ styled.setStyle(offset, length, ColoringLabelProvider.HIGHLIGHT_STYLE);
}
return styled;
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchListLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchListLabelProvider.java
index f4e6714918..65ada19c26 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchListLabelProvider.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchListLabelProvider.java
@@ -6,65 +6,67 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * QNX - Initial API and implementation
- * Markus Schorn (Wind River Systems)
- * Ed Swartz (Nokia)
+ * QNX - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
+ * Ed Swartz (Nokia)
+ * Andrey Eremchenko (LEDAS)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.jface.viewers.StyledString;
-import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
+import org.eclipse.jface.viewers.ViewerCell;
-import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IndexLocationFactory;
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.internal.ui.CPluginImages;
import org.eclipse.cdt.internal.ui.util.Messages;
+import org.eclipse.cdt.internal.ui.viewsupport.ColoringLabelProvider;
/**
* @author Doug Schaefer
- *
*/
-public class PDOMSearchListLabelProvider extends PDOMSearchLabelProvider {
-
- public PDOMSearchListLabelProvider(AbstractTextSearchViewPage page) {
- super(page);
+public class PDOMSearchListLabelProvider extends ColoringLabelProvider {
+ private final PDOMSearchViewPage fPage;
+ private final int fColumnIndex;
+
+ public PDOMSearchListLabelProvider(PDOMSearchViewPage page, int columnIndex) {
+ super(new PDOMSearchLabelProvider(page));
+ fPage = page;
+ fColumnIndex = columnIndex;
}
@Override
- public String getText(Object element) {
- final String text= super.getText(element);
-
- if (element instanceof PDOMSearchElement) {
- PDOMSearchElement searchElement = (PDOMSearchElement)element;
- final int count= getMatchCount(element);
- final String filename = " - " + IndexLocationFactory.getPath(searchElement.getLocation()); //$NON-NLS-1$
- if (count == 1) {
- return text+filename;
+ public void update(ViewerCell cell) {
+ Object element = cell.getElement();
+ switch (fColumnIndex) {
+ case PDOMSearchViewPage.LOCATION_COLUMN_INDEX:
+ if (element instanceof LineSearchElement) {
+ LineSearchElement lineElement = (LineSearchElement) element;
+ String location = IndexLocationFactory.getPath(lineElement.getLocation()).toString();
+ int lineNumber = lineElement.getLineNumber();
+ cell.setText(Messages.format(CSearchMessages.CSearchResultCollector_location, location, lineNumber));
+ cell.setImage(CPluginImages.get(CPluginImages.IMG_OBJS_SEARCH_LINE));
}
- return text + filename + " " //$NON-NLS-1$
- + Messages.format(CSearchMessages.CSearchResultCollector_matches, new Integer(count));
- }
-
- if (element instanceof IIndexFileLocation) {
- IPath path= IndexLocationFactory.getPath((IIndexFileLocation)element);
- if(path!=null) {
- return path.toString();
+ break;
+ case PDOMSearchViewPage.DEFINITION_COLUMN_INDEX:
+ if (element instanceof LineSearchElement) {
+ LineSearchElement lineElement = (LineSearchElement) element;
+ ICElement enclosingElement = lineElement.getMatches()[0].getEnclosingElement();
+ if (fPage.isShowEnclosingDefinitions() && enclosingElement != null) {
+ cell.setText(enclosingElement.getElementName());
+ cell.setImage(getImage(element));
+ } else {
+ cell.setText(""); //$NON-NLS-1$
+ }
}
+ break;
+ case PDOMSearchViewPage.MATCH_COLUMN_INDEX:
+ super.update(cell);
+ cell.setImage(null);
+ break;
+ default:
+ cell.setText(""); //$NON-NLS-1$
+ break;
}
-
- return text;
- }
-
- @Override
- public StyledString getStyledText(Object element) {
- if (!(element instanceof LineSearchElement))
- return new StyledString(getText(element));
- LineSearchElement lineElement = (LineSearchElement) element;
- int lineNumber = lineElement.getLineNumber();
- final String filename = " - " + IndexLocationFactory.getPath(lineElement.getLocation()); //$NON-NLS-1$
- final String lineNumberString = " (" + lineNumber + ")"; //$NON-NLS-1$ //$NON-NLS-2$
- StyledString styled = super.getStyledText(element);
- return styled.append(filename + lineNumberString, StyledString.QUALIFIER_STYLER);
}
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchPatternQuery.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchPatternQuery.java
index cd438a3170..310782a434 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchPatternQuery.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchPatternQuery.java
@@ -6,9 +6,10 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * QNX - Initial API and implementation
- * IBM Corporation
- * Markus Schorn (Wind River Systems)
+ * QNX - Initial API and implementation
+ * IBM Corporation
+ * Markus Schorn (Wind River Systems)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
@@ -42,11 +43,9 @@ import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.internal.core.Util;
-import org.eclipse.cdt.internal.ui.util.Messages;
/**
* @author Doug Schaefer
- *
*/
public class PDOMSearchPatternQuery extends PDOMSearchQuery {
@@ -196,7 +195,9 @@ public class PDOMSearchPatternQuery extends PDOMSearchQuery {
}
@Override
- public String getLabel() {
- return Messages.format(CSearchMessages.PDOMSearchPatternQuery_PatternQuery_labelPatternInScope, super.getLabel(), patternStr, scopeDesc);
+ public String getResultLabel(int numMatches) {
+ String patternInScope = CSearchMessages.bind(
+ CSearchMessages.PDOMSearchPatternQuery_PatternQuery_labelPatternInScope, patternStr, scopeDesc);
+ return getResultLabel(patternInScope, numMatches);
}
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchQuery.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchQuery.java
index 2a169d1829..5b01d9dbaf 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchQuery.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchQuery.java
@@ -1,14 +1,16 @@
/*******************************************************************************
- * Copyright (c) 2006, 2008 QNX Software Systems and others.
+ * Copyright (c) 2006, 2009 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * QNX - Initial API and implementation
- * Markus Schorn (Wind River Systems)
- * Ed Swartz (Nokia)
+ * Doug Schaefer (QNX) - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
+ * Ed Swartz (Nokia)
+ * Andrey Eremchenko (LEDAS)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
@@ -59,12 +61,10 @@ import org.eclipse.cdt.internal.core.browser.ASTTypeInfo;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
import org.eclipse.cdt.internal.ui.search.LineSearchElement.Match;
+import org.eclipse.cdt.internal.ui.util.Messages;
+import org.eclipse.cdt.internal.ui.viewsupport.IndexUI;
-/**
- * @author Doug Schaefer
- *
- */
public abstract class PDOMSearchQuery implements ISearchQuery {
public static final int FIND_DECLARATIONS = IIndex.FIND_DECLARATIONS;
public static final int FIND_DEFINITIONS = IIndex.FIND_DEFINITIONS;
@@ -114,14 +114,29 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
public String getLabel() {
String type;
if ((flags & FIND_REFERENCES) != 0)
- type = CSearchMessages.PDOMSearch_query_refs_label;
+ type = CSearchMessages.PDOMSearchQuery_refs_label;
else if ((flags & FIND_DECLARATIONS) != 0)
- type = CSearchMessages.PDOMSearch_query_decls_label;
+ type = CSearchMessages.PDOMSearchQuery_decls_label;
else
- type = CSearchMessages.PDOMSearch_query_defs_label;
+ type = CSearchMessages.PDOMSearchQuery_defs_label;
return type;
}
+ public abstract String getResultLabel(int matchCount);
+
+ public String getResultLabel(String pattern, int matchCount) {
+ // Report pattern and number of matches
+ String label;
+ if ((flags & FIND_REFERENCES) != 0)
+ label = CSearchMessages.bind(CSearchMessages.PDOMSearchQuery_refs_result_label, pattern);
+ else if ((flags & FIND_DECLARATIONS) != 0)
+ label =CSearchMessages.bind(CSearchMessages.PDOMSearchQuery_decls_result_label, pattern);
+ else
+ label = CSearchMessages.bind(CSearchMessages.PDOMSearchQuery_defs_result_label, pattern);
+ String countLabel = Messages.format(CSearchMessages.CSearchResultCollector_matches, new Integer(matchCount));
+ return label + " " + countLabel; //$NON-NLS-1$
+ }
+
public boolean canRerun() {
return true;
}
@@ -143,11 +158,16 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
protected boolean filterName(IIndexName name) {
return false; // i.e. keep it
}
-
- private void createMatchesFromNames(Map<IIndexFile, Set<Match>> fileMatches, IIndexName[] names, boolean isPolymorphicOnly)
+
+ private void createMatchesFromNames(IIndex index, Map<IIndexFile, Set<Match>> fileMatches, IIndexName[] names, boolean isPolymorphicOnly)
throws CoreException {
if (names == null)
return;
+
+ ICProject preferred= null;
+ if (projects != null && projects.length == 1) {
+ preferred= projects[0];
+ }
for (IIndexName name : names) {
if (!filterName(name)) {
if (!isPolymorphicOnly || name.couldBePolymorphicMethodCall()) {
@@ -158,7 +178,14 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
matches = new HashSet<Match>();
fileMatches.put(file, matches);
}
- matches.add(new Match(loc.getNodeOffset(), loc.getNodeLength(), isPolymorphicOnly));
+ int nodeOffset = loc.getNodeOffset();
+ int nodeLength = loc.getNodeLength();
+ ICElement enclosingElement = null;
+ IIndexName enclosingDefinition = name.getEnclosingDefinition();
+ if (enclosingDefinition != null) {
+ enclosingElement = IndexUI.getCElementForName(preferred, index, enclosingDefinition);
+ }
+ matches.add(new Match(nodeOffset, nodeLength, isPolymorphicOnly, enclosingElement));
}
}
@@ -177,7 +204,8 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
int offset = region.getOffset();
int length = region.getLength();
boolean isPolymorphicCall = match.isPolymorphicCall();
- convertedMatches.add(new Match(offset, length, isPolymorphicCall));
+ ICElement enclosingElement = match.getEnclosingElement();
+ convertedMatches.add(new Match(offset, length, isPolymorphicCall, enclosingElement));
}
matches = convertedMatches;
}
@@ -187,8 +215,8 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
private void collectNames(IIndex index, IIndexName[] names, IIndexName[] polymorphicNames) throws CoreException {
// group all matched names by files
Map<IIndexFile, Set<Match>> fileMatches = new HashMap<IIndexFile, Set<Match>>();
- createMatchesFromNames(fileMatches, names, false);
- createMatchesFromNames(fileMatches, polymorphicNames, true);
+ createMatchesFromNames(index, fileMatches, names, false);
+ createMatchesFromNames(index, fileMatches, polymorphicNames, true);
// compute mapping from paths to dirty text editors
IEditorPart[] dirtyEditors = CUIPlugin.getDirtyEditors();
Map<IPath, ITextEditor> pathsDirtyEditors = new HashMap<IPath, ITextEditor>();
@@ -295,7 +323,7 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
if (typeInfo != null) {
ITypeReference ref= typeInfo.getResolvedReference();
if (ref != null) {
- localMatches.add(new Match(ref.getOffset(), ref.getLength(), false));
+ localMatches.add(new Match(ref.getOffset(), ref.getLength(), false, null));
fileLocation = typeInfo.getIFL();
}
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchResult.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchResult.java
index 90f18033f7..a9e76dc277 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchResult.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchResult.java
@@ -6,9 +6,10 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * QNX - Initial API and implementation
- * Markus Schorn (Wind River Systems)
- * Ed Swartz (Nokia)
+ * QNX - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
+ * Ed Swartz (Nokia)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
@@ -41,11 +42,9 @@ import org.eclipse.cdt.core.index.IndexLocationFactory;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.util.ExternalEditorInput;
-import org.eclipse.cdt.internal.ui.util.Messages;
/**
* @author Doug Schaefer
- *
*/
public class PDOMSearchResult extends AbstractTextSearchResult implements IEditorMatchAdapter, IFileMatchAdapter {
private static final String KEY_SHOW_POLYMORPHIC_CALLS = "ShowPolymorphicCalls"; //$NON-NLS-1$
@@ -167,10 +166,8 @@ public class PDOMSearchResult extends AbstractTextSearchResult implements IEdito
}
public String getLabel() {
- // report pattern and number of matches
- String label = query.getLabel();
- String countLabel = Messages.format(CSearchMessages.CSearchResultCollector_matches, new Integer(getMatchCount()));
- return label + " " + countLabel; //$NON-NLS-1$
+ // Report pattern and number of matches
+ return query.getResultLabel(getMatchCount());
}
public String getTooltip() {
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTextSelectionQuery.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTextSelectionQuery.java
index 9faba43552..d4271762e6 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTextSelectionQuery.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTextSelectionQuery.java
@@ -6,8 +6,9 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * QNX - Initial API and implementation
- * Markus Schorn (Wind River Systems)
+ * QNX - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
@@ -84,7 +85,7 @@ public class PDOMSearchTextSelectionQuery extends PDOMSearchQuery {
}
@Override
- public String getLabel() {
- return super.getLabel() + " " + searchText; //$NON-NLS-1$
+ public String getResultLabel(int numMatches) {
+ return getResultLabel(searchText, numMatches);
}
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTreeLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTreeLabelProvider.java
index d9ee7c8f9e..2fcc5309ac 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTreeLabelProvider.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTreeLabelProvider.java
@@ -1,31 +1,29 @@
/*******************************************************************************
- * Copyright (c) 2006, 2008 QNX Software Systems and others.
+ * Copyright (c) 2006, 2009 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * QNX - Initial API and implementation
- * Markus Schorn (Wind River Systems)
- * Ed Swartz (Nokia)
+ * Doug Schaefer (QNX) - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
+ * Ed Swartz (Nokia)
+ * Andrey Eremchenko (LEDAS)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
import org.eclipse.jface.viewers.StyledString;
-import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
+
+import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.internal.core.model.TranslationUnit;
import org.eclipse.cdt.internal.ui.util.Messages;
-/**
- * @author Doug Schaefer
- *
- */
public class PDOMSearchTreeLabelProvider extends PDOMSearchLabelProvider {
- public PDOMSearchTreeLabelProvider(AbstractTextSearchViewPage page) {
+ public PDOMSearchTreeLabelProvider(PDOMSearchViewPage page) {
super(page);
}
@@ -52,13 +50,19 @@ public class PDOMSearchTreeLabelProvider extends PDOMSearchLabelProvider {
return styled;
}
}
- if (element instanceof LineSearchElement) {
- LineSearchElement lineElement = (LineSearchElement) element;
- int lineNumber = lineElement.getLineNumber();
- String lineNumberString = Messages.format("{0}: ", Integer.valueOf(lineNumber)); //$NON-NLS-1$
- StyledString styled = new StyledString(lineNumberString, StyledString.QUALIFIER_STYLER);
- return styled.append(super.getStyledText(element));
+ if (!(element instanceof LineSearchElement))
+ return new StyledString(getText(element));
+ LineSearchElement lineElement = (LineSearchElement) element;
+ String enclosingName = ""; //$NON-NLS-1$
+ ICElement enclosingElement = lineElement.getMatches()[0].getEnclosingElement();
+ if (fPage.isShowEnclosingDefinitions() && enclosingElement != null) {
+ enclosingName = enclosingElement.getElementName() + ", "; //$NON-NLS-1$
}
- return new StyledString(getText(element));
+ Integer lineNumber = lineElement.getLineNumber();
+ String prefix = Messages.format(CSearchMessages.CSearchResultCollector_line, enclosingName, lineNumber);
+ prefix += ": "; //$NON-NLS-1$
+ StyledString location = new StyledString(prefix, StyledString.QUALIFIER_STYLER);
+ return location.append(super.getStyledText(element));
}
+
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchUnresolvedIncludesQuery.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchUnresolvedIncludesQuery.java
index 70c8d1e8ba..b519f3237e 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchUnresolvedIncludesQuery.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchUnresolvedIncludesQuery.java
@@ -22,6 +22,8 @@ import org.eclipse.cdt.core.index.IIndexInclude;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.parser.IProblem;
+import org.eclipse.cdt.internal.ui.util.Messages;
+
/**
* Query for searching unresolved includes in projects.
* Could be extended to search resources selections.
@@ -55,4 +57,10 @@ public class PDOMSearchUnresolvedIncludesQuery extends PDOMSearchQuery {
public String getLabel() {
return NLS.bind(CSearchMessages.PDOMSearchUnresolvedIncludesQuery_title, getScopeDescription());
}
+
+ @Override
+ public String getResultLabel(int matchCount) {
+ String countLabel = Messages.format(CSearchMessages.CSearchResultCollector_matches, new Integer(matchCount));
+ return getLabel() + " " + countLabel; //$NON-NLS-1$
+ }
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchViewPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchViewPage.java
index 2e40fdd5c4..77d2b5e6a7 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchViewPage.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchViewPage.java
@@ -6,24 +6,36 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * QNX - Initial API and implementation
- * Ed Swartz (Nokia)
+ * QNX - Initial API and implementation
+ * Ed Swartz (Nokia)
+ * Andrey Eremchenko (LEDAS)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
import org.eclipse.search.ui.text.Match;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IMemento;
import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.part.IPageSite;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.cdt.core.index.IIndexFileLocation;
@@ -39,7 +51,37 @@ import org.eclipse.cdt.internal.ui.viewsupport.ColoringLabelProvider;
*/
public class PDOMSearchViewPage extends AbstractTextSearchViewPage {
+ public static final int LOCATION_COLUMN_INDEX = 0;
+ public static final int DEFINITION_COLUMN_INDEX = 1;
+ public static final int MATCH_COLUMN_INDEX = 2;
+
+ private static final String[] fColumnLabels = new String[] {
+ CSearchMessages.PDOMSearchViewPageLocationColumn_label,
+ CSearchMessages.PDOMSearchViewPageDefinitionColumn_label,
+ CSearchMessages.PDOMSearchViewPageMatchColumn_label
+ };
+
+ private static final String KEY_LOCATION_COLUMN_WIDTH = "locationColumnWidth"; //$NON-NLS-1$
+ private static final String KEY_DEFINITION_COLUMN_WIDTH = "definitionColumnWidth"; //$NON-NLS-1$
+ private static final String KEY_MATCH_COLUMN_WIDTH = "matchColumnWidth"; //$NON-NLS-1$
+ private static final String KEY_SHOW_ENCLOSING_DEFINITIONS = "showEnclosingDefinitions"; //$NON-NLS-1$
+
private IPDOMSearchContentProvider contentProvider;
+ private boolean fShowEnclosingDefinitions;
+ private ShowEnclosingDefinitionsAction fShowEnclosingDefinitionsAction;
+ private int[] fColumnWidths = { 300, 300, 300 };
+
+ private class ShowEnclosingDefinitionsAction extends Action {
+ public ShowEnclosingDefinitionsAction() {
+ super(CSearchMessages.PDOMSearchViewPage_ShowEnclosingDefinitions_actionLabel, SWT.CHECK);
+ setChecked(fShowEnclosingDefinitions);
+ }
+
+ @Override
+ public void run() {
+ setShowEnclosingDefinitions(isChecked());
+ }
+ }
public PDOMSearchViewPage(int supportedLayouts) {
super(supportedLayouts);
@@ -50,6 +92,69 @@ public class PDOMSearchViewPage extends AbstractTextSearchViewPage {
}
@Override
+ public void init(IPageSite pageSite) {
+ super.init(pageSite);
+ fShowEnclosingDefinitionsAction = new ShowEnclosingDefinitionsAction();
+ IMenuManager menuManager= pageSite.getActionBars().getMenuManager();
+ menuManager.add(fShowEnclosingDefinitionsAction);
+ menuManager.updateAll(true);
+ pageSite.getActionBars().updateActionBars();
+ }
+
+ @Override
+ public void restoreState(IMemento memento) {
+ super.restoreState(memento);
+ if (memento != null) {
+ Boolean showEnclosingDefinitions = memento.getBoolean(KEY_SHOW_ENCLOSING_DEFINITIONS);
+ if (showEnclosingDefinitions != null)
+ setShowEnclosingDefinitions(showEnclosingDefinitions);
+ String[] keys = { KEY_LOCATION_COLUMN_WIDTH, KEY_DEFINITION_COLUMN_WIDTH, KEY_MATCH_COLUMN_WIDTH };
+ for (int i = 0; i < keys.length; i++) {
+ Integer width = memento.getInteger(keys[i]);
+ if (width == null)
+ continue;
+ if (width > 0)
+ fColumnWidths[i] = width;
+ }
+ }
+ }
+
+ @Override
+ public void saveState(IMemento memento) {
+ super.saveState(memento);
+ saveColumnWidths();
+ memento.putInteger(KEY_DEFINITION_COLUMN_WIDTH, fColumnWidths[DEFINITION_COLUMN_INDEX]);
+ memento.putInteger(KEY_LOCATION_COLUMN_WIDTH, fColumnWidths[LOCATION_COLUMN_INDEX]);
+ memento.putInteger(KEY_MATCH_COLUMN_WIDTH, fColumnWidths[MATCH_COLUMN_INDEX]);
+ memento.putBoolean(KEY_SHOW_ENCLOSING_DEFINITIONS, fShowEnclosingDefinitions);
+ }
+
+ public void setShowEnclosingDefinitions(boolean showEnclosingDefinitions) {
+ fShowEnclosingDefinitions = showEnclosingDefinitions;
+ if (fShowEnclosingDefinitionsAction.isChecked() != showEnclosingDefinitions)
+ fShowEnclosingDefinitionsAction.setChecked(showEnclosingDefinitions);
+ StructuredViewer viewer = getViewer();
+ if (viewer instanceof TableViewer) {
+ TableViewer tableViewer = (TableViewer) viewer;
+ TableColumn tableColumn = tableViewer.getTable().getColumn(DEFINITION_COLUMN_INDEX);
+ if (fShowEnclosingDefinitions) {
+ tableColumn.setWidth(fColumnWidths[DEFINITION_COLUMN_INDEX]);
+ tableColumn.setResizable(true);
+ } else {
+ fColumnWidths[DEFINITION_COLUMN_INDEX] = tableColumn.getWidth();
+ tableColumn.setWidth(0);
+ tableColumn.setResizable(false);
+ }
+ }
+ if (viewer != null)
+ viewer.refresh();
+ }
+
+ public boolean isShowEnclosingDefinitions() {
+ return fShowEnclosingDefinitions;
+ }
+
+ @Override
protected void elementsChanged(Object[] objects) {
if (contentProvider != null)
contentProvider.elementsChanged(objects);
@@ -156,12 +261,52 @@ public class PDOMSearchViewPage extends AbstractTextSearchViewPage {
@Override
protected void configureTableViewer(TableViewer viewer) {
+ createColumns(viewer);
contentProvider = new PDOMSearchListContentProvider(this);
viewer.setComparator(new SearchViewerComparator());
viewer.setContentProvider((PDOMSearchListContentProvider)contentProvider);
- PDOMSearchListLabelProvider innerLabelProvider = new PDOMSearchListLabelProvider(this);
- ColoringLabelProvider labelProvider = new ColoringLabelProvider(innerLabelProvider);
- viewer.setLabelProvider(labelProvider);
+ }
+
+ @Override
+ protected TableViewer createTableViewer(Composite parent) {
+ TableViewer tableViewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
+ tableViewer.getControl().addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ saveColumnWidths();
+ }
+ });
+ return tableViewer;
+ }
+
+ private void saveColumnWidths() {
+ StructuredViewer viewer = getViewer();
+ if (viewer instanceof TableViewer) {
+ TableViewer tableViewer = (TableViewer) viewer;
+ for (int i = 0; i < fColumnLabels.length; i++) {
+ if (i == DEFINITION_COLUMN_INDEX && !fShowEnclosingDefinitions)
+ continue;
+ fColumnWidths[i] = tableViewer.getTable().getColumn(i).getWidth();
+ }
+ }
+ }
+
+ private void createColumns(TableViewer viewer) {
+ for (int i = 0; i < fColumnLabels.length; i++) {
+ TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE);
+ viewerColumn.setLabelProvider(new PDOMSearchListLabelProvider(this, i));
+ TableColumn tableColumn = viewerColumn.getColumn();
+ tableColumn.setText(fColumnLabels[i]);
+ tableColumn.setWidth(fColumnWidths[i]);
+ tableColumn.setResizable(true);
+ tableColumn.setMoveable(false);
+ if (i == DEFINITION_COLUMN_INDEX && !fShowEnclosingDefinitions) {
+ tableColumn.setWidth(0);
+ tableColumn.setResizable(false);
+ }
+ }
+ Table table = viewer.getTable();
+ table.setHeaderVisible(true);
+ table.setLinesVisible(true);
}
@Override
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 586fec7629..0683370b08 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
@@ -7,10 +7,14 @@
*
* Contributors:
* IBM Corp. - Rational Software - initial implementation
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search.actions;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
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.ISearchQuery;
@@ -26,15 +30,16 @@ import org.eclipse.cdt.internal.ui.search.CSearchMessages;
import org.eclipse.cdt.internal.ui.search.PDOMSearchElementQuery;
import org.eclipse.cdt.internal.ui.search.PDOMSearchQuery;
import org.eclipse.cdt.internal.ui.search.PDOMSearchTextSelectionQuery;
+import org.eclipse.cdt.internal.ui.text.CWordFinder;
public abstract class FindAction extends SelectionParseAction {
public FindAction(CEditor editor){
- super( editor );
+ super(editor);
}
public FindAction(IWorkbenchSite site){
- super( site );
+ super(site);
}
@Override
@@ -43,15 +48,20 @@ public abstract class FindAction extends SelectionParseAction {
ISelection selection = getSelection();
if (selection instanceof IStructuredSelection) {
- Object object = ((IStructuredSelection)selection).getFirstElement();
+ Object object = ((IStructuredSelection) selection).getFirstElement();
if (object instanceof ISourceReference)
searchJob = createQuery((ISourceReference) object);
} else if (selection instanceof ITextSelection) {
- ITextSelection selNode = (ITextSelection)selection;
+ ITextSelection selNode = (ITextSelection) selection;
ICElement element = fEditor.getInputCElement();
while (element != null && !(element instanceof ITranslationUnit))
element = element.getParent();
if (element != null) {
+ if (selNode.getLength() == 0) {
+ IDocument document= fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput());
+ IRegion reg= CWordFinder.findWord(document, selNode.getOffset());
+ selNode = new TextSelection(document, reg.getOffset(), reg.getLength());
+ }
searchJob = createQuery(element, selNode);
}
}
@@ -62,9 +72,7 @@ public abstract class FindAction extends SelectionParseAction {
}
clearStatusLine();
-
NewSearchUI.activateSearchResultView();
-
NewSearchUI.runQueryInBackground(searchJob);
}
@@ -82,5 +90,4 @@ public abstract class FindAction extends SelectionParseAction {
abstract protected ICElement[] getScope();
abstract protected int getLimitTo();
-
}

Back to the top