From 2e497d6a545ef2eed3f90a1d09e9bcb8fe924709 Mon Sep 17 00:00:00 2001 From: Bogdan Gheorghe Date: Wed, 25 Feb 2004 23:24:04 +0000 Subject: [PATCH] - First go at adding selection search to CDT. You can now search for Declarations, References in Workspace, WorkingSets triggered from the CEditor, CView or COutline. - Added Dependency NPE check + test - Selection Parser change from John - Cleaned up search properties file --- core/org.eclipse.cdt.core.tests/ChangeLog | 3 + .../core/indexer/tests/DependencyTests.java | 15 +- .../org.eclipse.cdt.core/dependency/ChangeLog | 4 + .../sourcedependency/UpdateDependency.java | 5 +- .../parser/ChangeLog-parser | 4 + .../internal/core/parser/SelectionParser.java | 9 +- core/org.eclipse.cdt.ui/ChangeLog | 20 ++ .../internal/ui/cview/MainActionGroup.java | 18 +- .../ui/editor/CContentOutlinePage.java | 8 + .../cdt/internal/ui/editor/CEditor.java | 18 +- .../ui/search/CSearchMessages.properties | 104 +------ .../actions/DeclarationsSearchGroup.java | 54 ++++ .../ui/search/actions/FindAction.java | 270 ++++++++++++++++++ .../actions/FindDeclarationsAction.java | 73 +++++ .../FindDeclarationsInWorkingSetAction.java | 90 ++++++ .../ui/search/actions/FindRefsAction.java | 78 +++++ .../actions/FindRefsInWorkingSetAction.java | 87 ++++++ .../search/actions/ReferencesSearchGroup.java | 55 ++++ .../search/actions/SelectionSearchGroup.java | 67 +++++ 19 files changed, 886 insertions(+), 96 deletions(-) create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/DeclarationsSearchGroup.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindAction.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindDeclarationsAction.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindDeclarationsInWorkingSetAction.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindRefsAction.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindRefsInWorkingSetAction.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/ReferencesSearchGroup.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/SelectionSearchGroup.java diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog index 08c49f12831..d0ddc8d86f4 100644 --- a/core/org.eclipse.cdt.core.tests/ChangeLog +++ b/core/org.eclipse.cdt.core.tests/ChangeLog @@ -1,3 +1,6 @@ +2004-02-25 Bogdan Gheorghe + Added DependencyTests::testUpdateDependencyNPE + 2004-02-25 John Camelon Updates for new ISourceElementRequestor interface updates. diff --git a/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/DependencyTests.java b/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/DependencyTests.java index 8c6c8ec5c77..e8a23ae0847 100644 --- a/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/DependencyTests.java +++ b/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/DependencyTests.java @@ -33,7 +33,9 @@ import org.eclipse.cdt.internal.core.search.PathCollector; import org.eclipse.cdt.internal.core.search.PatternSearchJob; import org.eclipse.cdt.internal.core.search.indexing.IndexManager; import org.eclipse.cdt.internal.core.search.matching.CSearchPattern; +import org.eclipse.cdt.internal.core.search.processing.IJob; import org.eclipse.cdt.internal.core.sourcedependency.DependencyQueryJob; +import org.eclipse.cdt.internal.core.sourcedependency.UpdateDependency; import org.eclipse.cdt.testplugin.CProjectHelper; import org.eclipse.cdt.testplugin.CTestPlugin; import org.eclipse.core.resources.IFile; @@ -72,6 +74,7 @@ import org.eclipse.core.runtime.Platform; suite.addTest(new DependencyTests("testDepHeaderChangeReindex")); suite.addTest(new DependencyTests("testDepSourceChangeTable")); suite.addTest(new DependencyTests("testDepHeaderChangeTable")); + suite.addTest(new DependencyTests("testUpdateDependancyNPE")); return suite; } /** @@ -535,6 +538,16 @@ import org.eclipse.core.runtime.Platform; compareArrays(iPath,beforeModel); } + + public void testUpdateDependancyNPE() { + IResource nonExistantResource = ResourcesPlugin.getWorkspace().getRoot().getProject("non-existant-project-aha"); + + assertFalse(nonExistantResource.exists()); + assertNull(nonExistantResource.getLocation()); + + IJob job = new UpdateDependency(nonExistantResource); + assertFalse(job.execute(new NullProgressMonitor())); + } public void testDepHeaderChangeReindex() throws Exception{ @@ -570,7 +583,7 @@ import org.eclipse.core.runtime.Platform; private String[] convertToLocalPath(String[] model) { - IPath defaultPath = Platform.getLocation(); + IPath defaultPath = Platform.getInstanceLocation(); String[] tempLocalArray = new String[model.length]; for (int i=0;i= offsetRange.getCeilingOffset() ) + if( scanner.isOnTopContext() && lastTokenOfDuple != null && lastTokenOfDuple.getEndOffset() >= offsetRange.getCeilingOffset() ) throw new EndOfFileException(); } diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog index 7b13bbed4d9..a9a61be68f4 100644 --- a/core/org.eclipse.cdt.ui/ChangeLog +++ b/core/org.eclipse.cdt.ui/ChangeLog @@ -1,3 +1,23 @@ +2004-02-25 Bogdan Gheorghe + First go at Selection Search facility. Added Selection Search menus to + the CView, the CEditor and the COutlineView. + + New: + * src/org/eclipse/cdt/internal/ui/search/actions/DeclarationsSearchGroup.java + * src/org/eclipse/cdt/internal/ui/search/actions/FindAction.java + * src/org/eclipse/cdt/internal/ui/search/actions/FindDeclarationsAction.java + * src/org/eclipse/cdt/internal/ui/search/actions/FindRefsAction.java + * src/org/eclipse/cdt/internal/ui/search/actions/FindRefsInWorkingSetAction.java + * src/org/eclipse/cdt/internal/ui/search/actions/ReferencesSearchGroup.java + * src/org/eclipse/cdt/internal/ui/search/actions/SelctionSearchGroup.java + * src/org/eclipse/cdt/internal/ui/search/actions/FindDeclarationsInWorkingSetAction.java + + Modified: + * src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java + * src/org/eclipse/cdt/internal/ui/editor/CContentOutline.java + * src/org/eclipse/cdt/internal/ui/editor/CEditor.java + + 2004-02-25 John Camelon Updates for new ISourceElementRequestor interface updates. diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java index c32860ef2b9..afd6b887735 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java @@ -17,6 +17,7 @@ import org.eclipse.cdt.internal.ui.editor.FileSearchAction; import org.eclipse.cdt.internal.ui.editor.FileSearchActionInWorkingSet; import org.eclipse.cdt.internal.ui.editor.OpenIncludeAction; import org.eclipse.cdt.internal.ui.editor.SearchDialogAction; +import org.eclipse.cdt.internal.ui.search.actions.SelectionSearchGroup; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; @@ -79,6 +80,8 @@ public class MainActionGroup extends CViewActionGroup { OpenProjectGroup openProjectGroup; WorkingSetFilterActionGroup workingSetGroup; + SelectionSearchGroup selectionSearchGroup; + public MainActionGroup(CView cview) { super(cview); } @@ -153,6 +156,10 @@ public class MainActionGroup extends CViewActionGroup { fFileSearchAction = new FileSearchAction(viewer); fFileSearchActionInWorkingSet = new FileSearchActionInWorkingSet(viewer); fSearchDialogAction = new SearchDialogAction(viewer, getCView().getViewSite().getWorkbenchWindow()); + + selectionSearchGroup = new SelectionSearchGroup(getCView().getSite()); + + } /** @@ -167,6 +174,8 @@ public class MainActionGroup extends CViewActionGroup { new NewWizardMenu(menu, getCView().getSite().getWorkbenchWindow(), false); menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS + "-end")); //$NON-NLS-1$ + menu.add(new Separator()); + addSelectionSearchMenu(menu, resources); return; } @@ -193,7 +202,6 @@ public class MainActionGroup extends CViewActionGroup { menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS + "-end")); //$NON-NLS-1$ addPropertyMenu(menu, resources); } - /** * Extends the superclass implementation to set the context in the * subgroups. @@ -256,6 +264,14 @@ public class MainActionGroup extends CViewActionGroup { menu.add(search); } + + /** + * @param menu + */ + void addSelectionSearchMenu(IMenuManager menu, IStructuredSelection selection) { + selectionSearchGroup.fillContextMenu(menu); + } + public void runDefaultAction(IStructuredSelection selection) { openFileGroup.runDefaultAction(selection); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java index a94f63951a6..bbe4fa83ede 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java @@ -47,6 +47,8 @@ import org.eclipse.ui.part.IPageSite; import org.eclipse.ui.part.Page; import org.eclipse.ui.texteditor.IDocumentProvider; import org.eclipse.ui.views.contentoutline.IContentOutlinePage; +import org.eclipse.ui.actions.ActionGroup; +import org.eclipse.cdt.internal.ui.search.actions.SelectionSearchGroup; public class CContentOutlinePage extends Page implements IContentOutlinePage, ISelectionChangedListener { private CEditor fEditor; @@ -64,6 +66,8 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS private MemberFilterActionGroup fMemberFilterActionGroup; + private ActionGroup fSelectionSearchGroup; + public CContentOutlinePage(CEditor editor) { this("#TranslationUnitOutlinerContext", editor); } @@ -153,6 +157,8 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS } menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS+"-end"));//$NON-NLS-1$ + + fSelectionSearchGroup.fillContextMenu(menu); } /** @@ -181,6 +187,8 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS Menu menu= manager.createContextMenu(control); control.setMenu(menu); + fSelectionSearchGroup = new SelectionSearchGroup(this); + // register global actions IPageSite site= getSite(); site.registerContextMenu(fContextMenuId, manager, treeViewer); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java index 780fb0a3144..70a7199388f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java @@ -20,6 +20,7 @@ import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.internal.ui.IContextMenuConstants; import org.eclipse.cdt.internal.ui.editor.asm.AsmTextTools; +import org.eclipse.cdt.internal.ui.search.actions.SelectionSearchGroup; import org.eclipse.cdt.internal.ui.text.CPairMatcher; import org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration; import org.eclipse.cdt.internal.ui.text.CTextTools; @@ -75,12 +76,14 @@ import org.eclipse.ui.IStorageEditorInput; import org.eclipse.ui.IViewPart; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.actions.ActionGroup; import org.eclipse.ui.editors.text.TextEditor; import org.eclipse.ui.editors.text.TextEditorPreferenceConstants; import org.eclipse.ui.editors.text.TextFileDocumentProvider; import org.eclipse.ui.part.EditorActionBarContributor; import org.eclipse.ui.part.IShowInSource; import org.eclipse.ui.part.ShowInContext; +import org.eclipse.ui.texteditor.AbstractTextEditor; import org.eclipse.ui.texteditor.AnnotationPreference; import org.eclipse.ui.texteditor.ContentAssistAction; import org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess; @@ -104,6 +107,8 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS /** The outline page */ protected CContentOutlinePage fOutlinePage; + + /** Search actions **/ private FileSearchAction fFileSearchAction; @@ -111,6 +116,8 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS private SearchDialogAction fSearchDialogAction; + private ActionGroup fSelectionSearchGroup; + protected ISelectionChangedListener fStatusLineClearer; /** The property change listener */ @@ -465,7 +472,11 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS action = new ShowInCViewAction(this); action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_CVIEW); setAction("ShowInCView", action); //$NON-NLS-1$ - + + //Selection Search group + fSelectionSearchGroup = new SelectionSearchGroup(this); + + //Search items fFileSearchAction = new FileSearchAction(getSelectionProvider()); fFileSearchActionInWorkingSet = new FileSearchActionInWorkingSet(getSelectionProvider()); @@ -504,7 +515,10 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS addAction(menu, IContextMenuConstants.GROUP_GENERATE, "ContentAssistProposal"); //$NON-NLS-1$ addAction(menu, IContextMenuConstants.GROUP_GENERATE, "AddIncludeOnSelection"); //$NON-NLS-1$ addAction(menu, IContextMenuConstants.GROUP_GENERATE, "OpenDeclarations"); //$NON-NLS-1$ - addAction(menu, IContextMenuConstants.GROUP_GENERATE, "ShowInCView"); //$NON-NLS-1$ + addAction(menu, IContextMenuConstants.GROUP_GENERATE, "ShowInCView"); //$NON-NLS-1$ + + fSelectionSearchGroup.fillContextMenu(menu); + } public void setOutlinePageInput(CContentOutlinePage page, IEditorInput input) { 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 55a28c8b7d6..be8e3b42cdc 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,36 +9,14 @@ # IBM Corporation - initial API and implementation ############################################################################### -group.search=S&earch +group.search=Selection S&earch group.declarations= Dec&larations group.references= Re&ferences -group.readReferences= &Read Access -group.writeReferences= &Write Access -group.implementors= &Implementors + Search.Error.search.title=Search Error Search.Error.search.message=An error occurred during the search operation -Search.Error.javaElementAccess.title=Search Error -Search.Error.javaElementAccess.message=An error occurred while accessing a Java element - -Search.Error.markerAttributeAccess.title=Search Error -Search.Error.markerAttributeAccess.message=An error occurred while accessing a marker attribute - -Search.Error.createJavaElement.title=Search Error -Search.Error.createJavaElement.message=An error occurred while creating a Java element - -Search.Error.openEditor.title=Search Error -Search.Error.openEditor.message=Could not open the editor - -Search.Error.codeResolve= Code resolve error - -Search.Error.setDescription.title=Search Error -Search.Error.setDescription.message=Cannot save workspace description - -SearchElementSelectionDialog.title=Search -SearchElementSelectionDialog.message=Select the element to search for. - CSearchResultCollector.match= 1 match CSearchResultCollector.matches= {0} matches CSearchResultCollector.done= Search done: {0}. @@ -74,60 +52,17 @@ CSearchPage.expression.caseSensitive= Case sens&itive # Concatenate two working set names e.g. "Source, Lib" SearchUtil.workingSetConcatenation= {0}, {1} -Search.FindDeclarationAction.label= &Workspace -Search.FindDeclarationAction.tooltip= Search for Declarations of the Selected Element in the Workspace +CSearch.FindDeclarationAction.label= &Workspace +CSearch.FindDeclarationAction.tooltip= Search for Declarations of the Selected Element in the Workspace -Search.FindDeclarationsInWorkingSetAction.label= Working &Set... -Search.FindDeclarationsInWorkingSetAction.tooltip= Search for Declarations of the Selected Element in a Working Set +CSearch.FindDeclarationsInWorkingSetAction.label= Working &Set... +CSearch.FindDeclarationsInWorkingSetAction.tooltip= Search for Declarations of the Selected Element in a Working Set -Search.FindHierarchyDeclarationsAction.label= &Hierarchy -Search.FindHierarchyDeclarationsAction.tooltip= Search for Declarations of the Selected Element in its Hierarchy +CSearch.FindReferencesAction.label= &Workspace +CSearch.FindReferencesAction.tooltip= Search for References to the Selected Element in the Workspace -Search.FindImplementorsAction.label= &Workspace -Search.FindImplementorsAction.tooltip= Search for Implementors of the Selected Interface - -Search.FindImplementorsInWorkingSetAction.label= Working &Set... -Search.FindImplementorsInWorkingSetAction.tooltip= Search for Implementors of the Selected Interface in a Working Set - -Search.FindReferencesAction.label= &Workspace -Search.FindReferencesAction.tooltip= Search for References to the Selected Element in the Workspace - -Search.FindReferencesAction.BinPrimConstWarnDialog.title= Search for References to a Binary Constant -Search.FindReferencesAction.BinPrimConstWarnDialog.message= Matches to this constant will only be discovered in source files and binary files where the constant value is not inlined. - -Search.FindReferencesInWorkingSetAction.label= Working &Set... -Search.FindReferencesInWorkingSetAction.tooltip= Search for References to the Selected Element in a Working Set - -Search.FindHierarchyReferencesAction.label= &Hierarchy -Search.FindHierarchyReferencesAction.tooltip= Search for References of the Selected Element in its Hierarchy - -Search.FindReadReferencesAction.label= &Workspace -Search.FindReadReferencesAction.tooltip= Search for Read References to the Selected Element in the Workspace - -Search.FindReadReferencesInWorkingSetAction.label= Working &Set... -Search.FindReadReferencesInWorkingSetAction.tooltip= Search for Read References to the Selected Element in a Working Set - -Search.FindReadReferencesInHierarchyAction.label= &Hierarchy -Search.FindReadReferencesInHierarchyAction.tooltip= Search for Read References of the Selected Element in its Hierarchy - -Search.FindWriteReferencesAction.label= &Workspace -Search.FindWriteReferencesAction.tooltip= Search for Write References to the Selected Element in the Workspace - -Search.FindWriteReferencesInWorkingSetAction.label= Working &Set... -Search.FindWriteReferencesInWorkingSetAction.tooltip= Search for Write References to the Selected Element in a Working Set - -Search.FindWriteReferencesInHierarchyAction.label= &Hierarchy -Search.FindWriteReferencesInHierarchyAction.tooltip= Search for Write References of the Selected Element in its Hierarchy - -Search.FindOccurrencesInFile.label= Occurre&nces in File -Search.FindOccurrencesInFile.tooltip= Find occurrences of selected element in the editor - -FindOccurrencesEngine.noSource.text= No source available. To perform this operation you need to attach source. -FindOccurrencesEngine.noJavaElement.text= Cannot search for the current selection. Please select a valid Java element name. -FindOccurrencesEngine.cannotParse.text= Cannot analyze the compilation unit or class file. - - -JavaSearchOperation.default_package=(default package) +CSearch.FindReferencesInWorkingSetAction.label= Working &Set... +CSearch.FindReferencesInWorkingSetAction.tooltip= Search for References to the Selected Element in a Working Set # The first argument will be replaced by the pattern and the second by the scope CSearchOperation.singularDeclarationsPostfix={0} - 1 Declaration in {1} @@ -145,23 +80,12 @@ CSearchOperation.pluralWriteReferencesPostfix={0} - {1} Write References in {2} CSearchOperation.pluralImplementorsPostfix={0} - {1} Implementors in {2} CSearchOperation.pluralOccurrencesPostfix={0} - {1} Occurrences in {2} - -# The first argument will be replaced by the element name and the second one by the file name -JavaSearchInFile.singularPostfix={0} - 1 Occurrence in {1} -# The first argument will be replaced by the element name, the second by the count and the last by the file name -JavaSearchInFile.pluralPostfix={0} - {1} Occurrences in {2} - -JavaElementAction.typeSelectionDialog.title=Search -JavaElementAction.typeSelectionDialog.message=&Select the type to search: -JavaElementAction.error.open.message=An exception occurred while opening the type. - -JavaElementAction.operationUnavailable.title= Operation Unavailable -JavaElementAction.operationUnavailable.generic= The operation is unavailable on the current selection. Please select a valid Java element name. -JavaElementAction.operationUnavailable.field= The operation is unavailable on the current selection. Please select the name of a field. -JavaElementAction.operationUnavailable.interface= The operation is unavailable on the current selection. Please select the name of an interface. - CSearchResultLabelProvider.potentialMatch= \ (inexact) +CSearchOperation.operationUnavailable.title= Operation Unavailable +CSearchOperation.operationUnavailable.message= The operation is unavailable on the current selection. + + WorkspaceScope= Workspace WorkingSetScope= Working Set - {0} SelectionScope= Selection diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/DeclarationsSearchGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/DeclarationsSearchGroup.java new file mode 100644 index 00000000000..a574ef22a83 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/DeclarationsSearchGroup.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Corp. - Rational Software - initial implementation + ******************************************************************************/ + +package org.eclipse.cdt.internal.ui.search.actions; + +import org.eclipse.cdt.internal.ui.editor.CEditor; +import org.eclipse.cdt.internal.ui.search.CSearchMessages; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.search.ui.IContextMenuConstants; +import org.eclipse.ui.IWorkbenchSite; +import org.eclipse.ui.actions.ActionGroup; + + +public class DeclarationsSearchGroup extends ActionGroup { + + private FindDeclarationsAction fFindDeclarationsAction; + private FindDeclarationsInWorkingSetAction fFindDeclarationsInWorkingSetAction; + + public DeclarationsSearchGroup(IWorkbenchSite site) { + fFindDeclarationsAction= new FindDeclarationsAction(site); + fFindDeclarationsInWorkingSetAction = new FindDeclarationsInWorkingSetAction(site); + } + /** + * @param editor + */ + public DeclarationsSearchGroup(CEditor editor) { + fFindDeclarationsAction= new FindDeclarationsAction(editor); + fFindDeclarationsInWorkingSetAction = new FindDeclarationsInWorkingSetAction(editor); + } + /* + * Method declared on ActionGroup. + */ + public void fillContextMenu(IMenuManager menu) { + super.fillContextMenu(menu); + + IMenuManager incomingMenu = menu; + + IMenuManager declarationsMenu = new MenuManager(CSearchMessages.getString("group.declarations"), IContextMenuConstants.GROUP_SEARCH); //$NON-NLS-1$ + incomingMenu.add(declarationsMenu); + incomingMenu = declarationsMenu; + + incomingMenu.add(fFindDeclarationsAction); + incomingMenu.add(fFindDeclarationsInWorkingSetAction); + } +} 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 new file mode 100644 index 00000000000..ece217d9512 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindAction.java @@ -0,0 +1,270 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Corp. - Rational Software - initial implementation + ******************************************************************************/ + +package org.eclipse.cdt.internal.ui.search.actions; + +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.util.LinkedList; +import java.util.List; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.parser.IParser; +import org.eclipse.cdt.core.parser.IScannerInfo; +import org.eclipse.cdt.core.parser.IScannerInfoProvider; +import org.eclipse.cdt.core.parser.NullSourceElementRequestor; +import org.eclipse.cdt.core.parser.ParseError; +import org.eclipse.cdt.core.parser.ParserFactory; +import org.eclipse.cdt.core.parser.ParserFactoryError; +import org.eclipse.cdt.core.parser.ParserLanguage; +import org.eclipse.cdt.core.parser.ParserMode; +import org.eclipse.cdt.core.parser.ParserUtil; +import org.eclipse.cdt.core.parser.ScannerInfo; +import org.eclipse.cdt.core.parser.ParseError.ParseErrorKind; +import org.eclipse.cdt.core.parser.ast.ASTClassKind; +import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; +import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier; +import org.eclipse.cdt.core.parser.ast.IASTEnumerator; +import org.eclipse.cdt.core.parser.ast.IASTField; +import org.eclipse.cdt.core.parser.ast.IASTFunction; +import org.eclipse.cdt.core.parser.ast.IASTMethod; +import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; +import org.eclipse.cdt.core.parser.ast.IASTNode; +import org.eclipse.cdt.core.parser.ast.IASTVariable; +import org.eclipse.cdt.core.search.ICSearchConstants; +import org.eclipse.cdt.core.search.ICSearchScope; +import org.eclipse.cdt.core.search.ICSearchConstants.LimitTo; +import org.eclipse.cdt.core.search.ICSearchConstants.SearchFor; +import org.eclipse.cdt.internal.ui.editor.CEditor; +import org.eclipse.cdt.internal.ui.search.CSearchMessages; +import org.eclipse.cdt.internal.ui.search.CSearchOperation; +import org.eclipse.cdt.internal.ui.search.CSearchResultCollector; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.dialogs.ProgressMonitorDialog; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.search.ui.SearchUI; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchSite; + + +public abstract class FindAction extends Action { + + protected IWorkbenchSite fSite; + protected CEditor fEditor; + + public FindAction(CEditor editor){ + fEditor=editor; + fSite=editor.getSite(); + } + + public FindAction(IWorkbenchSite site){ + fSite=site; + } + + protected IParser setupParser(IFile resourceFile){ + //Get the scanner info + IProject currentProject = resourceFile.getProject(); + IScannerInfo scanInfo = new ScannerInfo(); + IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(currentProject); + if (provider != null){ + IScannerInfo buildScanInfo = provider.getScannerInformation(currentProject); + if (buildScanInfo != null){ + scanInfo = new ScannerInfo(buildScanInfo.getDefinedSymbols(), buildScanInfo.getIncludePaths()); + } + } + + //C or CPP? + ParserLanguage language = CoreModel.getDefault().hasCCNature(currentProject) ? ParserLanguage.CPP : ParserLanguage.C; + + IParser parser = null; + FileReader reader = null; + try { + reader = new FileReader(resourceFile.getLocation().toFile()); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + + try + { + parser = ParserFactory.createParser( + ParserFactory.createScanner( reader, resourceFile.getLocation().toOSString(), scanInfo, ParserMode.SELECTION_PARSE, language, new NullSourceElementRequestor(), ParserUtil.getScannerLogService() ), + new NullSourceElementRequestor(), ParserMode.SELECTION_PARSE, language, ParserUtil.getParserLogService() ); + + } catch( ParserFactoryError pfe ){} + + return parser; + } + /** + * @param node + */ + protected CSearchOperation createSearchOperation(String pattern, SearchFor searchFor) { + CSearchOperation op = null; + ICSearchScope scope = getScope(); + String scopeDescription = getScopeDescription(); + + //Create a case sensitive search operation - limited by the node + List search = new LinkedList(); + search.add(searchFor); + + CSearchResultCollector collector= new CSearchResultCollector(); + + LimitTo limitTo = getLimitTo(); + + op = new CSearchOperation(CCorePlugin.getWorkspace(), pattern,true,search,limitTo,scope,scopeDescription,collector); + return op; + + } + + protected ISelection getSelection(){ + ISelection sel = null; + if (fSite != null){ + sel = fSite.getSelectionProvider().getSelection(); + } + + return sel; + } + + public void run() { + ISelection sel = getSelection(); + + if (sel instanceof IStructuredSelection) { + run((IStructuredSelection) sel); + } else if (sel instanceof ITextSelection) { + run((ITextSelection) sel); + } + } + + public void run(IStructuredSelection sel){ + ICElement tempElement = null; + + IEditorPart temp = fSite.getPage().getActiveEditor(); + CEditor cTemp = null; + if (temp instanceof CEditor){ + cTemp = (CEditor) temp; + } + + if (cTemp == null || + cTemp.getSelectionProvider() == null){ + operationNotAvailableDialog(); + return; + } + + fEditor=cTemp; + ITextSelection selection= (ITextSelection) fEditor.getSelectionProvider().getSelection(); + + run(selection); + } + + public void run(ITextSelection sel){ + if(sel == null) { + return; + } + + final ITextSelection selectedText = sel; + int selectionStart = selectedText.getOffset(); + int selectionEnd = selectionStart + selectedText.getLength(); + + IFile resourceFile = fEditor.getInputFile(); + IParser parser = setupParser(resourceFile); + IASTNode node = null; + + try{ + node = parser.parse(selectionStart,selectionEnd); + } + catch (ParseError er){ + ParseErrorKind per = er.getErrorKind(); + int val = per.getEnumValue(); + er.printStackTrace(); + } + catch (Exception ex){ + ex.printStackTrace();} + + if (node == null){ + operationNotAvailableDialog(); + return; + } + + CSearchOperation op = createSearchOperation(selectedText.getText(),getSearchForFromNode(node)); + + performSearch(op); + } + + private SearchFor getSearchForFromNode(IASTNode node){ + SearchFor searchFor = null; + + if (node instanceof IASTClassSpecifier){ + //Find out if class, struct, union + IASTClassSpecifier tempNode = (IASTClassSpecifier) node; + if(tempNode.getClassKind().equals(ASTClassKind.CLASS)){ + searchFor = ICSearchConstants.CLASS; + } + else if (tempNode.getClassKind().equals(ASTClassKind.STRUCT)){ + searchFor = ICSearchConstants.STRUCT; + } + else if (tempNode.getClassKind().equals(ASTClassKind.UNION)){ + searchFor = ICSearchConstants.UNION; + } + } + else if (node instanceof IASTMethod){ + searchFor = ICSearchConstants.METHOD; + } + else if (node instanceof IASTFunction){ + searchFor = ICSearchConstants.FUNCTION; + } + else if (node instanceof IASTField){ + searchFor = ICSearchConstants.FIELD; + } + else if (node instanceof IASTVariable){ + searchFor = ICSearchConstants.VAR; + } + else if (node instanceof IASTEnumerationSpecifier){ + searchFor = ICSearchConstants.ENUM; + } + else if (node instanceof IASTEnumerator){ + searchFor = ICSearchConstants.FIELD; + } + else if (node instanceof IASTNamespaceDefinition){ + searchFor = ICSearchConstants.NAMESPACE; + } + + return searchFor; + } + + protected void performSearch(CSearchOperation op){ + try { + SearchUI.activateSearchResultView(); + + ProgressMonitorDialog progressMonitor = new ProgressMonitorDialog(fSite.getShell()); + progressMonitor.run(true, true, op); + + } catch(Exception x) { + CUIPlugin.getDefault().log(x); + } + } + + private void operationNotAvailableDialog(){ + MessageDialog.openInformation(fEditor.getSite().getShell(),CSearchMessages.getString("CSearchOperation.operationUnavailable.title"), CSearchMessages.getString("CSearchOperation.operationUnavailable.message")); + } + + abstract protected String getScopeDescription(); + + abstract protected ICSearchScope getScope(); + + abstract protected LimitTo getLimitTo(); +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindDeclarationsAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindDeclarationsAction.java new file mode 100644 index 00000000000..300d75085d8 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindDeclarationsAction.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Corp. - Rational Software - initial implementation + ******************************************************************************/ + +package org.eclipse.cdt.internal.ui.search.actions; + +import org.eclipse.cdt.core.search.ICSearchConstants; +import org.eclipse.cdt.core.search.ICSearchScope; +import org.eclipse.cdt.core.search.SearchEngine; +import org.eclipse.cdt.core.search.ICSearchConstants.LimitTo; +import org.eclipse.cdt.internal.ui.editor.CEditor; +import org.eclipse.cdt.internal.ui.search.CSearchMessages; +import org.eclipse.ui.IWorkbenchSite; + + +public class FindDeclarationsAction extends FindAction { + + public FindDeclarationsAction(CEditor editor, String label, String tooltip){ + super(editor); + setText(label); //$NON-NLS-1$ + setToolTipText(tooltip); //$NON-NLS-1$ + } + + public FindDeclarationsAction(CEditor editor){ + this(editor, + CSearchMessages.getString("CSearch.FindDeclarationAction.label"), + CSearchMessages.getString("CSearch.FindDeclarationAction.tooltip")); + } + + public FindDeclarationsAction(IWorkbenchSite site){ + this(site, + CSearchMessages.getString("CSearch.FindDeclarationAction.label"), + CSearchMessages.getString("CSearch.FindDeclarationAction.tooltip")); + } + /** + * @param site + * @param string + * @param string2 + * @param string3 + */ + public FindDeclarationsAction(IWorkbenchSite site, String label, String tooltip) { + super(site); + setText(label); + setToolTipText(tooltip); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.ui.editor.selsearch.FindAction#getScope() + */ + protected ICSearchScope getScope() { + return SearchEngine.createWorkspaceScope(); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.ui.editor.selsearch.FindAction#getScopeDescription() + */ + protected String getScopeDescription() { + // TODO Auto-generated method stub + return CSearchMessages.getString("WorkspaceScope"); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.ui.editor.selsearch.FindAction#getLimitTo() + */ + protected LimitTo getLimitTo() { + // TODO Auto-generated method stub + return ICSearchConstants.DECLARATIONS; + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindDeclarationsInWorkingSetAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindDeclarationsInWorkingSetAction.java new file mode 100644 index 00000000000..cb30657c4a5 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindDeclarationsInWorkingSetAction.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Corp. - Rational Software - initial implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.search.actions; + +import org.eclipse.cdt.core.search.ICSearchConstants; +import org.eclipse.cdt.core.search.ICSearchScope; +import org.eclipse.cdt.core.search.ICSearchConstants.LimitTo; +import org.eclipse.cdt.internal.ui.editor.CEditor; +import org.eclipse.cdt.internal.ui.search.CSearchMessages; +import org.eclipse.cdt.internal.ui.search.CSearchScopeFactory; +import org.eclipse.cdt.internal.ui.search.CSearchUtil; +import org.eclipse.ui.IWorkbenchSite; +import org.eclipse.ui.IWorkingSet; + +public class FindDeclarationsInWorkingSetAction extends FindAction { + + private IWorkingSet[] fWorkingSet; + + /** + * @param site + */ + public FindDeclarationsInWorkingSetAction(IWorkbenchSite site) { + this(site, + CSearchMessages.getString("CSearch.FindDeclarationsInWorkingSetAction.label"), + CSearchMessages.getString("CSearch.FindDeclarationsInWorkingSetAction.tooltip")); + } + + /** + * @param editor + */ + public FindDeclarationsInWorkingSetAction(CEditor editor) { + this(editor, + CSearchMessages.getString("CSearch.FindDeclarationsInWorkingSetAction.label"), + CSearchMessages.getString("CSearch.FindDeclarationsInWorkingSetAction.tooltip")); + } + + public FindDeclarationsInWorkingSetAction(CEditor editor, String label, String tooltip){ + super(editor); + setText(label); //$NON-NLS-1$ + setToolTipText(tooltip); //$NON-NLS-1$ + } + /** + * @param site + * @param string + * @param string2 + * @param string3 + */ + public FindDeclarationsInWorkingSetAction(IWorkbenchSite site,String label, String tooltip){ + super(site); + setText(label); //$NON-NLS-1$ + setToolTipText(tooltip); //$NON-NLS-1$ + } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.ui.editor.selsearch.FindAction#getScopeDescription() + */ + protected String getScopeDescription() { + return CSearchMessages.getString("WorkingSetScope"); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.ui.editor.selsearch.FindAction#getScope() + */ + protected ICSearchScope getScope() { + // + IWorkingSet[] workingSets= fWorkingSet; + if (fWorkingSet == null) { + workingSets= CSearchScopeFactory.getInstance().queryWorkingSets(); + if (workingSets == null) + return null; + } + ICSearchScope scope= CSearchScopeFactory.getInstance().createCSearchScope(workingSets); + CSearchUtil.updateLRUWorkingSets(workingSets); + + return scope; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.ui.editor.selsearch.FindAction#getLimitTo() + */ + protected LimitTo getLimitTo() { + return ICSearchConstants.DECLARATIONS; + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindRefsAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindRefsAction.java new file mode 100644 index 00000000000..0ddfdcdd4de --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindRefsAction.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Corp. - Rational Software - initial implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.search.actions; + +import org.eclipse.cdt.core.search.ICSearchConstants; +import org.eclipse.cdt.core.search.ICSearchScope; +import org.eclipse.cdt.core.search.SearchEngine; +import org.eclipse.cdt.core.search.ICSearchConstants.LimitTo; +import org.eclipse.cdt.internal.ui.editor.CEditor; +import org.eclipse.cdt.internal.ui.search.CSearchMessages; +import org.eclipse.ui.IWorkbenchSite; + + +public class FindRefsAction extends FindAction { + /** + * @param editor + */ + public FindRefsAction(CEditor editor) { + this(editor, + CSearchMessages.getString("CSearch.FindReferencesAction.label"), + CSearchMessages.getString("CSearch.FindReferencesAction.tooltip")); + } + + public FindRefsAction(IWorkbenchSite site){ + this(site, + CSearchMessages.getString("CSearch.FindReferencesAction.label"), + CSearchMessages.getString("CSearch.FindReferencesAction.tooltip")); + } + /** + * @param editor + * @param string + * @param string2 + * @param string3 + */ + public FindRefsAction(CEditor editor, String label, String tooltip) { + super(editor); + setText(label); //$NON-NLS-1$ + setToolTipText(tooltip); //$NON-NLS-1$ + } + /** + * @param site + * @param string + * @param string2 + * @param string3 + */ + public FindRefsAction(IWorkbenchSite site, String label, String tooltip) { + super(site); + setText(label); + setToolTipText(tooltip); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.ui.editor.selsearch.FindAction#getScopeDescription() + */ + protected String getScopeDescription() { + return CSearchMessages.getString("WorkspaceScope"); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.ui.editor.selsearch.FindAction#getScope() + */ + protected ICSearchScope getScope() { + return SearchEngine.createWorkspaceScope(); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.ui.editor.selsearch.FindAction#getLimitTo() + */ + protected LimitTo getLimitTo() { + return ICSearchConstants.REFERENCES; + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindRefsInWorkingSetAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindRefsInWorkingSetAction.java new file mode 100644 index 00000000000..f800023112f --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindRefsInWorkingSetAction.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Corp. - Rational Software - initial implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.search.actions; + +import org.eclipse.cdt.core.search.ICSearchConstants; +import org.eclipse.cdt.core.search.ICSearchScope; +import org.eclipse.cdt.core.search.ICSearchConstants.LimitTo; +import org.eclipse.cdt.internal.ui.editor.CEditor; +import org.eclipse.cdt.internal.ui.search.CSearchMessages; +import org.eclipse.cdt.internal.ui.search.CSearchScopeFactory; +import org.eclipse.cdt.internal.ui.search.CSearchUtil; +import org.eclipse.ui.IWorkbenchSite; +import org.eclipse.ui.IWorkingSet; + +public class FindRefsInWorkingSetAction extends FindAction { + + public FindRefsInWorkingSetAction(CEditor editor) { + this(editor, + CSearchMessages.getString("CSearch.FindReferencesInWorkingSetAction.label"), + CSearchMessages.getString("CSearch.FindReferencesInWorkingSetAction.tooltip")); + } + + public FindRefsInWorkingSetAction(IWorkbenchSite site){ + this(site, + CSearchMessages.getString("CSearch.FindReferencesInWorkingSetAction.label"), + CSearchMessages.getString("CSearch.FindReferencesInWorkingSetAction.tooltip")); + } + /** + * @param editor + * @param string + * @param string2 + * @param string3 + */ + public FindRefsInWorkingSetAction(CEditor editor, String label, String tooltip) { + super(editor); + setText(label); //$NON-NLS-1$ + setToolTipText(tooltip); //$NON-NLS-1$ + } + /** + * @param site + * @param string + * @param string2 + * @param string3 + */ + public FindRefsInWorkingSetAction(IWorkbenchSite site, String label, String tooltip) { + super(site); + setText(label); //$NON-NLS-1$ + setToolTipText(tooltip); //$NON-NLS-1 + } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.ui.editor.selsearch.FindAction#getLimitTo() + */ + protected LimitTo getLimitTo() { + return ICSearchConstants.REFERENCES; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.ui.editor.selsearch.FindAction#getScopeDescription() + */ + protected String getScopeDescription() { + return CSearchMessages.getString("WorkingSetScope"); + } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.ui.editor.selsearch.FindAction#getScope() + */ + protected ICSearchScope getScope() { + IWorkingSet[] workingSets= fWorkingSet; + if (fWorkingSet == null) { + workingSets= CSearchScopeFactory.getInstance().queryWorkingSets(); + if (workingSets == null) + return null; + } + ICSearchScope scope= CSearchScopeFactory.getInstance().createCSearchScope(workingSets); + CSearchUtil.updateLRUWorkingSets(workingSets); + + return scope; + } + + private IWorkingSet[] fWorkingSet; +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/ReferencesSearchGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/ReferencesSearchGroup.java new file mode 100644 index 00000000000..9c5d0182db8 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/ReferencesSearchGroup.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Corp. - Rational Software - initial implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.search.actions; + +import org.eclipse.cdt.internal.ui.editor.CEditor; +import org.eclipse.cdt.internal.ui.search.CSearchMessages; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.search.ui.IContextMenuConstants; +import org.eclipse.ui.IWorkbenchSite; +import org.eclipse.ui.actions.ActionGroup; + +public class ReferencesSearchGroup extends ActionGroup { + + private FindRefsAction fFindRefsAction; + private FindRefsInWorkingSetAction fFindRefsInWorkingSetAction; + + public ReferencesSearchGroup(IWorkbenchSite site) { + fFindRefsAction= new FindRefsAction(site); + fFindRefsInWorkingSetAction = new FindRefsInWorkingSetAction(site); + } + /** + * @param editor + */ + public ReferencesSearchGroup(CEditor editor) { + fFindRefsAction= new FindRefsAction(editor); + fFindRefsInWorkingSetAction = new FindRefsInWorkingSetAction(editor); + } + + /* + * Method declared on ActionGroup. + */ + public void fillContextMenu(IMenuManager menu) { + + super.fillContextMenu(menu); + + IMenuManager incomingMenu = menu; + + IMenuManager refsMenu = new MenuManager(CSearchMessages.getString("group.references"), IContextMenuConstants.GROUP_SEARCH); //$NON-NLS-1$ + incomingMenu.add(refsMenu); + incomingMenu = refsMenu; + + incomingMenu.add(fFindRefsAction); + incomingMenu.add(fFindRefsInWorkingSetAction); + + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/SelectionSearchGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/SelectionSearchGroup.java new file mode 100644 index 00000000000..2f39124d054 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/SelectionSearchGroup.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Corp. - Rational Software - initial implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.search.actions; + +import org.eclipse.cdt.internal.ui.editor.CEditor; +import org.eclipse.cdt.internal.ui.search.CSearchMessages; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.search.ui.IContextMenuConstants; +import org.eclipse.ui.IWorkbenchSite; +import org.eclipse.ui.actions.ActionGroup; +import org.eclipse.ui.part.Page; +import org.eclipse.ui.texteditor.ITextEditorActionConstants; + +public class SelectionSearchGroup extends ActionGroup { + + private CEditor fEditor; + + private DeclarationsSearchGroup fDeclarationsSearchGroup; + private ReferencesSearchGroup fRefSearchGroup; + + public SelectionSearchGroup(CEditor editor){ + //TODO: Assert editor not null + fEditor= editor; + + fDeclarationsSearchGroup= new DeclarationsSearchGroup(fEditor); + fRefSearchGroup = new ReferencesSearchGroup(fEditor); + } + /** + * @param page + */ + public SelectionSearchGroup(Page page) { + this(page.getSite()); + } + /** + * @param site + */ + public SelectionSearchGroup(IWorkbenchSite site) { + fDeclarationsSearchGroup= new DeclarationsSearchGroup(site); + fRefSearchGroup = new ReferencesSearchGroup(site); + } + /* + * Method declared on ActionGroup. + */ + public void fillContextMenu(IMenuManager menu) { + super.fillContextMenu(menu); + + IMenuManager incomingMenu = menu; + + if (fEditor != null){ + IMenuManager selSearchMenu = new MenuManager(CSearchMessages.getString("group.search"), IContextMenuConstants.GROUP_SEARCH); //$NON-NLS-1$ + menu.appendToGroup(ITextEditorActionConstants.GROUP_FIND, selSearchMenu); + incomingMenu = selSearchMenu; + } + + fDeclarationsSearchGroup.fillContextMenu(incomingMenu); + fRefSearchGroup.fillContextMenu(incomingMenu); + } +}