mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-20 07:25:23 +02:00
Enclosing definitions in C/C++ search results. Patch by Andrey Eremchenko. Bug 282668.
This commit is contained in:
parent
608669a12f
commit
90300f0889
15 changed files with 371 additions and 141 deletions
|
@ -6,8 +6,9 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX - Initial API and implementation
|
* QNX - Initial API and implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.ui.indexview;
|
package org.eclipse.cdt.internal.ui.indexview;
|
||||||
|
@ -61,7 +62,7 @@ public class IndexViewSearchQuery extends PDOMSearchQuery {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getLabel() {
|
public String getResultLabel(int numMatches) {
|
||||||
return super.getLabel() + " " + fName; //$NON-NLS-1$
|
return super.getResultLabel(fName, numMatches);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Corp. - Rational Software - initial implementation
|
* IBM Corp. - Rational Software - initial implementation
|
||||||
* Anton Leherbauer (Wind River Systems)
|
* Anton Leherbauer (Wind River Systems)
|
||||||
|
* Andrey Eremchenko (LEDAS)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.search;
|
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_declarations;
|
||||||
public static String group_references;
|
public static String group_references;
|
||||||
public static String CSearchResultCollector_matches;
|
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_label;
|
||||||
public static String CSearchPage_searchFor_namespace;
|
public static String CSearchPage_searchFor_namespace;
|
||||||
public static String CSearchPage_searchFor_method;
|
public static String CSearchPage_searchFor_method;
|
||||||
|
@ -59,9 +62,13 @@ public final class CSearchMessages extends NLS {
|
||||||
public static String WorkingSetScope;
|
public static String WorkingSetScope;
|
||||||
public static String SelectionScope;
|
public static String SelectionScope;
|
||||||
public static String ProjectScope;
|
public static String ProjectScope;
|
||||||
public static String PDOMSearch_query_refs_label;
|
public static String PDOMSearchQuery_refs_label;
|
||||||
public static String PDOMSearch_query_defs_label;
|
public static String PDOMSearchQuery_defs_label;
|
||||||
public static String PDOMSearch_query_decls_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 PDOMSearchPatternQuery_PatternQuery_labelPatternInScope;
|
||||||
public static String PDOMSearch_query_pattern_error;
|
public static String PDOMSearch_query_pattern_error;
|
||||||
public static String SelectionParseAction_FileOpenFailure_format;
|
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_actionLabel;
|
||||||
public static String HidePolymorphicCalls_description;
|
public static String HidePolymorphicCalls_description;
|
||||||
public static String HidePolymorphicCalls_name;
|
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_IndexerNotEnabledWarning;
|
||||||
public static String PDOMSearchTreeContentProvider_ProjectClosedWarning;
|
public static String PDOMSearchTreeContentProvider_ProjectClosedWarning;
|
||||||
public static String PDOMSearchUnresolvedIncludesQuery_title;
|
public static String PDOMSearchUnresolvedIncludesQuery_title;
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
# IBM Corporation - initial API and implementation
|
# IBM Corporation - initial API and implementation
|
||||||
# Ed Swartz (Nokia)
|
# Ed Swartz (Nokia)
|
||||||
# Anton Leherbauer (Wind River Systems)
|
# Anton Leherbauer (Wind River Systems)
|
||||||
|
# Andrey Eremchenko (LEDAS)
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
group_declarations=Dec&larations
|
group_declarations=Dec&larations
|
||||||
|
@ -18,6 +19,8 @@ group_references=Re&ferences
|
||||||
# Examples of the display for the following value are
|
# Examples of the display for the following value are
|
||||||
# "(1 match)", where {0} is 1 and "(5 matches)", where {0} is 2 or more.
|
# "(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_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_label= Search For
|
||||||
CSearchPage_searchFor_namespace= Names&pace
|
CSearchPage_searchFor_namespace= Names&pace
|
||||||
|
@ -64,10 +67,14 @@ WorkingSetScope= Working Set - {0}
|
||||||
SelectionScope= Selection
|
SelectionScope= Selection
|
||||||
ProjectScope = Project
|
ProjectScope = Project
|
||||||
|
|
||||||
PDOMSearch_query_refs_label = Find references to
|
PDOMSearchQuery_refs_label = Search references
|
||||||
PDOMSearch_query_defs_label = Find definitions of
|
PDOMSearchQuery_defs_label = Search definitions
|
||||||
PDOMSearch_query_decls_label = Find declarations of
|
PDOMSearchQuery_decls_label = Search declarations
|
||||||
PDOMSearchPatternQuery_PatternQuery_labelPatternInScope={0} {1} in {2}
|
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_IndexerNotEnabledWarning=(unknown results: indexer is not enabled)
|
||||||
PDOMSearchTreeContentProvider_ProjectClosedWarning=(unknown results: project is closed)
|
PDOMSearchTreeContentProvider_ProjectClosedWarning=(unknown results: project is closed)
|
||||||
PDOMSearchListContentProvider_IndexerNotEnabledMessageFormat=(project ''{0}'' - unknown results: indexer is not enabled)
|
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_actionLabel=Hide Potential Method Calls
|
||||||
HidePolymorphicCalls_description=Hides potential method calls to virtual overriders
|
HidePolymorphicCalls_description=Hides potential method calls to virtual overriders
|
||||||
HidePolymorphicCalls_name=Potential Method Calls
|
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
|
PDOMSearch_query_pattern_error = Illegal Search String
|
||||||
PDOMSearchUnresolvedIncludesQuery_title=Unresolved inclusions in {0}
|
PDOMSearchUnresolvedIncludesQuery_title=Unresolved inclusions in {0}
|
||||||
SelectionParseAction_FileOpenFailure_format=Could not open file ''{0}'', verify index is up-to-date
|
SelectionParseAction_FileOpenFailure_format=Could not open file ''{0}'', verify index is up-to-date
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Andrey Eremchenko, kamre@ngs.ru - 222495 C/C++ search should show line matches and line numbers
|
* Andrey Eremchenko, kamre@ngs.ru - 222495 C/C++ search should show line matches and line numbers
|
||||||
*
|
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.search;
|
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.jface.text.IDocument;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
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.core.parser.CodeReader;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Element representing a line with one ore more matches.
|
* Element representing a line with one ore more matches.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class LineSearchElement extends PDOMSearchElement {
|
public class LineSearchElement extends PDOMSearchElement {
|
||||||
public static final class Match {
|
public static final class Match {
|
||||||
private final int fOffset;
|
private final int fOffset;
|
||||||
private final int fLength;
|
private final int fLength;
|
||||||
private final boolean fIsPolymorphicCall;
|
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;
|
fOffset = offset;
|
||||||
fLength = length;
|
fLength = length;
|
||||||
fIsPolymorphicCall = isPolymorphicCall;
|
fIsPolymorphicCall = isPolymorphicCall;
|
||||||
|
fEnclosingElement = enclosingElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getOffset() {
|
public int getOffset() {
|
||||||
|
@ -52,6 +53,10 @@ public class LineSearchElement extends PDOMSearchElement {
|
||||||
return fIsPolymorphicCall;
|
return fIsPolymorphicCall;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ICElement getEnclosingElement() {
|
||||||
|
return fEnclosingElement;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (!(obj instanceof Match))
|
if (!(obj instanceof Match))
|
||||||
|
@ -87,7 +92,7 @@ public class LineSearchElement extends PDOMSearchElement {
|
||||||
int length = content.length();
|
int length = content.length();
|
||||||
int firstMatchOffset = matches[0].getOffset();
|
int firstMatchOffset = matches[0].getOffset();
|
||||||
while (offset < firstMatchOffset && length > 0) {
|
while (offset < firstMatchOffset && length > 0) {
|
||||||
if (content.charAt(index) != ' ')
|
if (!Character.isWhitespace(content.charAt(index)))
|
||||||
break;
|
break;
|
||||||
index++;
|
index++;
|
||||||
offset++;
|
offset++;
|
||||||
|
|
|
@ -6,8 +6,9 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX - Initial API and implementation
|
* QNX - Initial API and implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.ui.search;
|
package org.eclipse.cdt.internal.ui.search;
|
||||||
|
@ -27,7 +28,6 @@ import org.eclipse.cdt.internal.ui.viewsupport.IndexUI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Doug Schaefer
|
* @author Doug Schaefer
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class PDOMSearchElementQuery extends PDOMSearchQuery {
|
public class PDOMSearchElementQuery extends PDOMSearchQuery {
|
||||||
|
|
||||||
|
@ -54,9 +54,9 @@ public class PDOMSearchElementQuery extends PDOMSearchQuery {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getLabel() {
|
public String getResultLabel(int numMatches) {
|
||||||
if (element instanceof ICElement)
|
String pattern = (element instanceof ICElement) ?
|
||||||
return super.getLabel() + " " + ((ICElement)element).getElementName(); //$NON-NLS-1$
|
((ICElement) element).getElementName() : CSearchMessages.PDOMSearchElementQuery_something;
|
||||||
return super.getLabel() + " something."; //$NON-NLS-1$
|
return getResultLabel(pattern, numMatches);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,9 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Markus Schorn - initial API and implementation
|
* Markus Schorn - initial API and implementation
|
||||||
* Ed Swartz (Nokia)
|
* Ed Swartz (Nokia)
|
||||||
|
* Andrey Eremchenko (LEDAS)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.search;
|
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.StyledString;
|
||||||
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
|
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
|
||||||
import org.eclipse.search.ui.text.AbstractTextSearchResult;
|
import org.eclipse.search.ui.text.AbstractTextSearchResult;
|
||||||
import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
|
|
||||||
import org.eclipse.swt.graphics.Image;
|
import org.eclipse.swt.graphics.Image;
|
||||||
import org.eclipse.ui.ISharedImages;
|
import org.eclipse.ui.ISharedImages;
|
||||||
import org.eclipse.ui.PlatformUI;
|
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.dom.ast.ASTSignatureUtil;
|
||||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||||
import org.eclipse.cdt.core.index.IndexLocationFactory;
|
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.ui.browser.typeinfo.TypeInfoLabelProvider;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.model.TranslationUnit;
|
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 {
|
public class PDOMSearchLabelProvider extends LabelProvider implements IStyledLabelProvider {
|
||||||
|
|
||||||
private final AbstractTextSearchViewPage fPage;
|
protected final PDOMSearchViewPage fPage;
|
||||||
private final TypeInfoLabelProvider fTypeInfoLabelProvider;
|
private final TypeInfoLabelProvider fTypeInfoLabelProvider;
|
||||||
private final CUILabelProvider fCElementLabelProvider;
|
private final CUILabelProvider fCElementLabelProvider;
|
||||||
|
|
||||||
public PDOMSearchLabelProvider(AbstractTextSearchViewPage page) {
|
public PDOMSearchLabelProvider(PDOMSearchViewPage page) {
|
||||||
fTypeInfoLabelProvider= new TypeInfoLabelProvider(TypeInfoLabelProvider.SHOW_FULLY_QUALIFIED | TypeInfoLabelProvider.SHOW_PARAMETERS);
|
fTypeInfoLabelProvider= new TypeInfoLabelProvider(TypeInfoLabelProvider.SHOW_FULLY_QUALIFIED | TypeInfoLabelProvider.SHOW_PARAMETERS);
|
||||||
fCElementLabelProvider= new CUILabelProvider(0, CElementImageProvider.SMALL_ICONS);
|
fCElementLabelProvider= new CUILabelProvider(0, CElementImageProvider.SMALL_ICONS);
|
||||||
fPage= page;
|
fPage= page;
|
||||||
|
@ -64,8 +65,13 @@ public class PDOMSearchLabelProvider extends LabelProvider implements IStyledLab
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Image getImage(Object element) {
|
public Image getImage(Object element) {
|
||||||
if (element instanceof LineSearchElement)
|
if (element instanceof LineSearchElement) {
|
||||||
return CPluginImages.get(CPluginImages.IMG_OBJS_SEARCH_LINE);
|
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)
|
if (element instanceof TypeInfoSearchElement)
|
||||||
return fTypeInfoLabelProvider.getImage(((TypeInfoSearchElement)element).getTypeInfo());
|
return fTypeInfoLabelProvider.getImage(((TypeInfoSearchElement)element).getTypeInfo());
|
||||||
|
@ -161,9 +167,9 @@ public class PDOMSearchLabelProvider extends LabelProvider implements IStyledLab
|
||||||
String lineContent = lineElement.getContent();
|
String lineContent = lineElement.getContent();
|
||||||
StyledString styled = new StyledString(lineContent);
|
StyledString styled = new StyledString(lineContent);
|
||||||
for (Match match : lineElement.getMatches()) {
|
for (Match match : lineElement.getMatches()) {
|
||||||
int offset = match.getOffset();
|
int offset = Math.max(0, match.getOffset() - lineOffset);
|
||||||
int length = Math.min(match.getLength(), lineContent.length() - (offset - lineOffset));
|
int length = Math.min(match.getLength(), lineContent.length() - offset);
|
||||||
styled.setStyle(offset - lineOffset, length, ColoringLabelProvider.HIGHLIGHT_STYLE);
|
styled.setStyle(offset, length, ColoringLabelProvider.HIGHLIGHT_STYLE);
|
||||||
}
|
}
|
||||||
return styled;
|
return styled;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,65 +6,68 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX - Initial API and implementation
|
* QNX - Initial API and implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
* Ed Swartz (Nokia)
|
* Ed Swartz (Nokia)
|
||||||
|
* Andrey Eremchenko (LEDAS)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.search;
|
package org.eclipse.cdt.internal.ui.search;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.jface.viewers.ViewerCell;
|
||||||
import org.eclipse.jface.viewers.StyledString;
|
|
||||||
import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
|
||||||
import org.eclipse.cdt.core.index.IndexLocationFactory;
|
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.util.Messages;
|
||||||
|
import org.eclipse.cdt.internal.ui.viewsupport.ColoringLabelProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Doug Schaefer
|
* @author Doug Schaefer
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class PDOMSearchListLabelProvider extends PDOMSearchLabelProvider {
|
public class PDOMSearchListLabelProvider extends ColoringLabelProvider {
|
||||||
|
private final PDOMSearchViewPage fPage;
|
||||||
public PDOMSearchListLabelProvider(AbstractTextSearchViewPage page) {
|
private final int fColumnIndex;
|
||||||
super(page);
|
|
||||||
|
public PDOMSearchListLabelProvider(PDOMSearchViewPage page, int columnIndex) {
|
||||||
|
super(new PDOMSearchLabelProvider(page));
|
||||||
|
fPage = page;
|
||||||
|
fColumnIndex = columnIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getText(Object element) {
|
public void update(ViewerCell cell) {
|
||||||
final String text= super.getText(element);
|
Object element = cell.getElement();
|
||||||
|
switch (fColumnIndex) {
|
||||||
if (element instanceof PDOMSearchElement) {
|
case PDOMSearchViewPage.LOCATION_COLUMN_INDEX:
|
||||||
PDOMSearchElement searchElement = (PDOMSearchElement)element;
|
if (element instanceof LineSearchElement) {
|
||||||
final int count= getMatchCount(element);
|
LineSearchElement lineElement = (LineSearchElement) element;
|
||||||
final String filename = " - " + IndexLocationFactory.getPath(searchElement.getLocation()); //$NON-NLS-1$
|
String location = IndexLocationFactory.getPath(lineElement.getLocation()).toString();
|
||||||
if (count == 1) {
|
int lineNumber = lineElement.getLineNumber();
|
||||||
return text+filename;
|
cell.setText(Messages.format(CSearchMessages.CSearchResultCollector_location, location, lineNumber));
|
||||||
|
cell.setImage(CPluginImages.get(CPluginImages.IMG_OBJS_SEARCH_LINE));
|
||||||
}
|
}
|
||||||
return text + filename + " " //$NON-NLS-1$
|
break;
|
||||||
+ Messages.format(CSearchMessages.CSearchResultCollector_matches, new Integer(count));
|
case PDOMSearchViewPage.DEFINITION_COLUMN_INDEX:
|
||||||
}
|
if (element instanceof LineSearchElement) {
|
||||||
|
LineSearchElement lineElement = (LineSearchElement) element;
|
||||||
if (element instanceof IIndexFileLocation) {
|
ICElement enclosingElement = lineElement.getMatches()[0].getEnclosingElement();
|
||||||
IPath path= IndexLocationFactory.getPath((IIndexFileLocation)element);
|
if (fPage.isShowEnclosingDefinitions() && enclosingElement != null) {
|
||||||
if(path!=null) {
|
cell.setText(enclosingElement.getElementName());
|
||||||
return path.toString();
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,10 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX - Initial API and implementation
|
* QNX - Initial API and implementation
|
||||||
* IBM Corporation
|
* IBM Corporation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.search;
|
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.core.Util;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.util.Messages;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Doug Schaefer
|
* @author Doug Schaefer
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class PDOMSearchPatternQuery extends PDOMSearchQuery {
|
public class PDOMSearchPatternQuery extends PDOMSearchQuery {
|
||||||
|
|
||||||
|
@ -186,7 +185,9 @@ public class PDOMSearchPatternQuery extends PDOMSearchQuery {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getLabel() {
|
public String getResultLabel(int numMatches) {
|
||||||
return Messages.format(CSearchMessages.PDOMSearchPatternQuery_PatternQuery_labelPatternInScope, super.getLabel(), patternStr, scopeDesc);
|
String patternInScope = CSearchMessages.bind(
|
||||||
|
CSearchMessages.PDOMSearchPatternQuery_PatternQuery_labelPatternInScope, patternStr, scopeDesc);
|
||||||
|
return getResultLabel(patternInScope, numMatches);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX - Initial API and implementation
|
* Doug Schaefer (QNX) - Initial API and implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
* Ed Swartz (Nokia)
|
* Ed Swartz (Nokia)
|
||||||
|
* Andrey Eremchenko (LEDAS)
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.search;
|
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.core.dom.parser.cpp.ClassTypeHelper;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.search.LineSearchElement.Match;
|
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 abstract class PDOMSearchQuery implements ISearchQuery {
|
||||||
public static final int FIND_DECLARATIONS = IIndex.FIND_DECLARATIONS;
|
public static final int FIND_DECLARATIONS = IIndex.FIND_DECLARATIONS;
|
||||||
public static final int FIND_DEFINITIONS = IIndex.FIND_DEFINITIONS;
|
public static final int FIND_DEFINITIONS = IIndex.FIND_DEFINITIONS;
|
||||||
|
@ -114,14 +114,29 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
|
||||||
public String getLabel() {
|
public String getLabel() {
|
||||||
String type;
|
String type;
|
||||||
if ((flags & FIND_REFERENCES) != 0)
|
if ((flags & FIND_REFERENCES) != 0)
|
||||||
type = CSearchMessages.PDOMSearch_query_refs_label;
|
type = CSearchMessages.PDOMSearchQuery_refs_label;
|
||||||
else if ((flags & FIND_DECLARATIONS) != 0)
|
else if ((flags & FIND_DECLARATIONS) != 0)
|
||||||
type = CSearchMessages.PDOMSearch_query_decls_label;
|
type = CSearchMessages.PDOMSearchQuery_decls_label;
|
||||||
else
|
else
|
||||||
type = CSearchMessages.PDOMSearch_query_defs_label;
|
type = CSearchMessages.PDOMSearchQuery_defs_label;
|
||||||
return type;
|
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() {
|
public boolean canRerun() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -143,11 +158,16 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
|
||||||
protected boolean filterName(IIndexName name) {
|
protected boolean filterName(IIndexName name) {
|
||||||
return false; // i.e. keep it
|
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 {
|
throws CoreException {
|
||||||
if (names == null)
|
if (names == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
ICProject preferred= null;
|
||||||
|
if (projects != null && projects.length == 1) {
|
||||||
|
preferred= projects[0];
|
||||||
|
}
|
||||||
for (IIndexName name : names) {
|
for (IIndexName name : names) {
|
||||||
if (!filterName(name)) {
|
if (!filterName(name)) {
|
||||||
if (!isPolymorphicOnly || name.couldBePolymorphicMethodCall()) {
|
if (!isPolymorphicOnly || name.couldBePolymorphicMethodCall()) {
|
||||||
|
@ -158,7 +178,14 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
|
||||||
matches = new HashSet<Match>();
|
matches = new HashSet<Match>();
|
||||||
fileMatches.put(file, matches);
|
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 offset = region.getOffset();
|
||||||
int length = region.getLength();
|
int length = region.getLength();
|
||||||
boolean isPolymorphicCall = match.isPolymorphicCall();
|
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;
|
matches = convertedMatches;
|
||||||
}
|
}
|
||||||
|
@ -187,8 +215,8 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
|
||||||
private void collectNames(IIndex index, IIndexName[] names, IIndexName[] polymorphicNames) throws CoreException {
|
private void collectNames(IIndex index, IIndexName[] names, IIndexName[] polymorphicNames) throws CoreException {
|
||||||
// group all matched names by files
|
// group all matched names by files
|
||||||
Map<IIndexFile, Set<Match>> fileMatches = new HashMap<IIndexFile, Set<Match>>();
|
Map<IIndexFile, Set<Match>> fileMatches = new HashMap<IIndexFile, Set<Match>>();
|
||||||
createMatchesFromNames(fileMatches, names, false);
|
createMatchesFromNames(index, fileMatches, names, false);
|
||||||
createMatchesFromNames(fileMatches, polymorphicNames, true);
|
createMatchesFromNames(index, fileMatches, polymorphicNames, true);
|
||||||
// compute mapping from paths to dirty text editors
|
// compute mapping from paths to dirty text editors
|
||||||
IEditorPart[] dirtyEditors = CUIPlugin.getDirtyEditors();
|
IEditorPart[] dirtyEditors = CUIPlugin.getDirtyEditors();
|
||||||
Map<IPath, ITextEditor> pathsDirtyEditors = new HashMap<IPath, ITextEditor>();
|
Map<IPath, ITextEditor> pathsDirtyEditors = new HashMap<IPath, ITextEditor>();
|
||||||
|
@ -295,7 +323,7 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
|
||||||
if (typeInfo != null) {
|
if (typeInfo != null) {
|
||||||
ITypeReference ref= typeInfo.getResolvedReference();
|
ITypeReference ref= typeInfo.getResolvedReference();
|
||||||
if (ref != null) {
|
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();
|
fileLocation = typeInfo.getIFL();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,10 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX - Initial API and implementation
|
* QNX - Initial API and implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
* Ed Swartz (Nokia)
|
* Ed Swartz (Nokia)
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.search;
|
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.ui.CUIPlugin;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.util.ExternalEditorInput;
|
import org.eclipse.cdt.internal.ui.util.ExternalEditorInput;
|
||||||
import org.eclipse.cdt.internal.ui.util.Messages;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Doug Schaefer
|
* @author Doug Schaefer
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class PDOMSearchResult extends AbstractTextSearchResult implements IEditorMatchAdapter, IFileMatchAdapter {
|
public class PDOMSearchResult extends AbstractTextSearchResult implements IEditorMatchAdapter, IFileMatchAdapter {
|
||||||
private static final String KEY_SHOW_POLYMORPHIC_CALLS = "ShowPolymorphicCalls"; //$NON-NLS-1$
|
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() {
|
public String getLabel() {
|
||||||
// report pattern and number of matches
|
// Report pattern and number of matches
|
||||||
String label = query.getLabel();
|
return query.getResultLabel(getMatchCount());
|
||||||
String countLabel = Messages.format(CSearchMessages.CSearchResultCollector_matches, new Integer(getMatchCount()));
|
|
||||||
return label + " " + countLabel; //$NON-NLS-1$
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTooltip() {
|
public String getTooltip() {
|
||||||
|
|
|
@ -6,8 +6,9 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX - Initial API and implementation
|
* QNX - Initial API and implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.search;
|
package org.eclipse.cdt.internal.ui.search;
|
||||||
|
|
||||||
|
@ -84,7 +85,7 @@ public class PDOMSearchTextSelectionQuery extends PDOMSearchQuery {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getLabel() {
|
public String getResultLabel(int numMatches) {
|
||||||
return super.getLabel() + " " + searchText; //$NON-NLS-1$
|
return getResultLabel(searchText, numMatches);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX - Initial API and implementation
|
* Doug Schaefer (QNX) - Initial API and implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
* Ed Swartz (Nokia)
|
* Ed Swartz (Nokia)
|
||||||
|
* Andrey Eremchenko (LEDAS)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.search;
|
package org.eclipse.cdt.internal.ui.search;
|
||||||
|
|
||||||
import org.eclipse.jface.viewers.StyledString;
|
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.core.model.TranslationUnit;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.util.Messages;
|
import org.eclipse.cdt.internal.ui.util.Messages;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Doug Schaefer
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class PDOMSearchTreeLabelProvider extends PDOMSearchLabelProvider {
|
public class PDOMSearchTreeLabelProvider extends PDOMSearchLabelProvider {
|
||||||
|
|
||||||
public PDOMSearchTreeLabelProvider(AbstractTextSearchViewPage page) {
|
public PDOMSearchTreeLabelProvider(PDOMSearchViewPage page) {
|
||||||
super(page);
|
super(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,13 +50,19 @@ public class PDOMSearchTreeLabelProvider extends PDOMSearchLabelProvider {
|
||||||
return styled;
|
return styled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (element instanceof LineSearchElement) {
|
if (!(element instanceof LineSearchElement))
|
||||||
LineSearchElement lineElement = (LineSearchElement) element;
|
return new StyledString(getText(element));
|
||||||
int lineNumber = lineElement.getLineNumber();
|
LineSearchElement lineElement = (LineSearchElement) element;
|
||||||
String lineNumberString = Messages.format("{0}: ", Integer.valueOf(lineNumber)); //$NON-NLS-1$
|
String enclosingName = ""; //$NON-NLS-1$
|
||||||
StyledString styled = new StyledString(lineNumberString, StyledString.QUALIFIER_STYLER);
|
ICElement enclosingElement = lineElement.getMatches()[0].getEnclosingElement();
|
||||||
return styled.append(super.getStyledText(element));
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,8 @@ import org.eclipse.cdt.core.index.IIndexInclude;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.parser.IProblem;
|
import org.eclipse.cdt.core.parser.IProblem;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.ui.util.Messages;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query for searching unresolved includes in projects.
|
* Query for searching unresolved includes in projects.
|
||||||
* Could be extended to search resources selections.
|
* Could be extended to search resources selections.
|
||||||
|
@ -55,4 +57,10 @@ public class PDOMSearchUnresolvedIncludesQuery extends PDOMSearchQuery {
|
||||||
public String getLabel() {
|
public String getLabel() {
|
||||||
return NLS.bind(CSearchMessages.PDOMSearchUnresolvedIncludesQuery_title, getScopeDescription());
|
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$
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,24 +6,36 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX - Initial API and implementation
|
* QNX - Initial API and implementation
|
||||||
* Ed Swartz (Nokia)
|
* Ed Swartz (Nokia)
|
||||||
|
* Andrey Eremchenko (LEDAS)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.search;
|
package org.eclipse.cdt.internal.ui.search;
|
||||||
|
|
||||||
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.IStatus;
|
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.StructuredViewer;
|
||||||
import org.eclipse.jface.viewers.TableViewer;
|
import org.eclipse.jface.viewers.TableViewer;
|
||||||
|
import org.eclipse.jface.viewers.TableViewerColumn;
|
||||||
import org.eclipse.jface.viewers.TreeViewer;
|
import org.eclipse.jface.viewers.TreeViewer;
|
||||||
import org.eclipse.jface.viewers.Viewer;
|
import org.eclipse.jface.viewers.Viewer;
|
||||||
import org.eclipse.jface.viewers.ViewerComparator;
|
import org.eclipse.jface.viewers.ViewerComparator;
|
||||||
import org.eclipse.jface.viewers.ViewerSorter;
|
import org.eclipse.jface.viewers.ViewerSorter;
|
||||||
import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
|
import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
|
||||||
import org.eclipse.search.ui.text.Match;
|
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.IEditorPart;
|
||||||
|
import org.eclipse.ui.IMemento;
|
||||||
import org.eclipse.ui.PartInitException;
|
import org.eclipse.ui.PartInitException;
|
||||||
|
import org.eclipse.ui.part.IPageSite;
|
||||||
import org.eclipse.ui.texteditor.ITextEditor;
|
import org.eclipse.ui.texteditor.ITextEditor;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
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 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 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) {
|
public PDOMSearchViewPage(int supportedLayouts) {
|
||||||
super(supportedLayouts);
|
super(supportedLayouts);
|
||||||
|
@ -49,6 +91,69 @@ public class PDOMSearchViewPage extends AbstractTextSearchViewPage {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
@Override
|
||||||
protected void elementsChanged(Object[] objects) {
|
protected void elementsChanged(Object[] objects) {
|
||||||
if (contentProvider != null)
|
if (contentProvider != null)
|
||||||
|
@ -156,12 +261,52 @@ public class PDOMSearchViewPage extends AbstractTextSearchViewPage {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configureTableViewer(TableViewer viewer) {
|
protected void configureTableViewer(TableViewer viewer) {
|
||||||
|
createColumns(viewer);
|
||||||
contentProvider = new PDOMSearchListContentProvider(this);
|
contentProvider = new PDOMSearchListContentProvider(this);
|
||||||
viewer.setComparator(new SearchViewerComparator());
|
viewer.setComparator(new SearchViewerComparator());
|
||||||
viewer.setContentProvider((PDOMSearchListContentProvider)contentProvider);
|
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
|
@Override
|
||||||
|
|
|
@ -7,10 +7,14 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Corp. - Rational Software - initial implementation
|
* IBM Corp. - Rational Software - initial implementation
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.search.actions;
|
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.ITextSelection;
|
||||||
|
import org.eclipse.jface.text.TextSelection;
|
||||||
import org.eclipse.jface.viewers.ISelection;
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||||
import org.eclipse.search.ui.ISearchQuery;
|
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.PDOMSearchElementQuery;
|
||||||
import org.eclipse.cdt.internal.ui.search.PDOMSearchQuery;
|
import org.eclipse.cdt.internal.ui.search.PDOMSearchQuery;
|
||||||
import org.eclipse.cdt.internal.ui.search.PDOMSearchTextSelectionQuery;
|
import org.eclipse.cdt.internal.ui.search.PDOMSearchTextSelectionQuery;
|
||||||
|
import org.eclipse.cdt.internal.ui.text.CWordFinder;
|
||||||
|
|
||||||
|
|
||||||
public abstract class FindAction extends SelectionParseAction {
|
public abstract class FindAction extends SelectionParseAction {
|
||||||
public FindAction(CEditor editor){
|
public FindAction(CEditor editor){
|
||||||
super( editor );
|
super(editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FindAction(IWorkbenchSite site){
|
public FindAction(IWorkbenchSite site){
|
||||||
super( site );
|
super(site);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -43,15 +48,20 @@ public abstract class FindAction extends SelectionParseAction {
|
||||||
|
|
||||||
ISelection selection = getSelection();
|
ISelection selection = getSelection();
|
||||||
if (selection instanceof IStructuredSelection) {
|
if (selection instanceof IStructuredSelection) {
|
||||||
Object object = ((IStructuredSelection)selection).getFirstElement();
|
Object object = ((IStructuredSelection) selection).getFirstElement();
|
||||||
if (object instanceof ISourceReference)
|
if (object instanceof ISourceReference)
|
||||||
searchJob = createQuery((ISourceReference) object);
|
searchJob = createQuery((ISourceReference) object);
|
||||||
} else if (selection instanceof ITextSelection) {
|
} else if (selection instanceof ITextSelection) {
|
||||||
ITextSelection selNode = (ITextSelection)selection;
|
ITextSelection selNode = (ITextSelection) selection;
|
||||||
ICElement element = fEditor.getInputCElement();
|
ICElement element = fEditor.getInputCElement();
|
||||||
while (element != null && !(element instanceof ITranslationUnit))
|
while (element != null && !(element instanceof ITranslationUnit))
|
||||||
element = element.getParent();
|
element = element.getParent();
|
||||||
if (element != null) {
|
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);
|
searchJob = createQuery(element, selNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,9 +72,7 @@ public abstract class FindAction extends SelectionParseAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
clearStatusLine();
|
clearStatusLine();
|
||||||
|
|
||||||
NewSearchUI.activateSearchResultView();
|
NewSearchUI.activateSearchResultView();
|
||||||
|
|
||||||
NewSearchUI.runQueryInBackground(searchJob);
|
NewSearchUI.runQueryInBackground(searchJob);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,5 +90,4 @@ public abstract class FindAction extends SelectionParseAction {
|
||||||
abstract protected ICElement[] getScope();
|
abstract protected ICElement[] getScope();
|
||||||
|
|
||||||
abstract protected int getLimitTo();
|
abstract protected int getLimitTo();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue