Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] UI Patch


UI
==

This patch changes the search context menu in the CEditor, CContentPage and CView:

Search > C/C++ Search...
                File Search > Workspace
                             WorkingSets


- C/C++ Search pops up the search dialog with the chosen element filled out.
- File Search does a text based file search on the Workspace or a chosen WorkingSet


Core
=====

Added some error checking to the dependency generator.

- Bogdan

Index: dependency/ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/dependency/ChangeLog,v
retrieving revision 1.2
diff -u -r1.2 ChangeLog
--- dependency/ChangeLog	8 Sep 2003 18:10:49 -0000	1.2
+++ dependency/ChangeLog	11 Sep 2003 15:35:01 -0000
@@ -1,3 +1,7 @@
+2003-09-11 Bogdan Gheorghe
+	- Added null guard to DependencyManager.getDependencyTree(), 
+	  DependencyTree.getFileDependencies()
+	
 2003-09-08 Andrew Niefer
 	- Modified calls to ParserFactory to specify which language to use
 	- Modified IDependencyTree.add to take ParserLanguage as a parameter so that it can
@@ -24,5 +28,5 @@
 	* src/org/eclipse/cdt/internal/core/sourcedependency/impl/InMemoryTree.java
 	* src/org/eclipse/cdt/internal/core/sourcedependency/impl/Node.java
 	
-
+-
 	
Index: dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencyManager.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencyManager.java,v
retrieving revision 1.3
diff -u -r1.3 DependencyManager.java
--- dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencyManager.java	9 Sep 2003 17:53:51 -0000	1.3
+++ dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencyManager.java	11 Sep 2003 15:35:02 -0000
@@ -98,10 +98,12 @@
 		IPath path =project.getFullPath();
 		IDependencyTree dTree= this.getDependencyTree(path,true,false);
 		try{
+			if (dTree != null) { 
 			//dTree.printIncludeEntries();
 			//dTree.printIndexedFiles();
 			String[] files = dTree.getFileDependencies(file.getFullPath());
 			 return files;
+			}
 		}
 		catch(Exception e){}
 		return null;
Index: dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencyTree.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencyTree.java,v
retrieving revision 1.3
diff -u -r1.3 DependencyTree.java
--- dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencyTree.java	9 Sep 2003 17:53:51 -0000	1.3
+++ dependency/org/eclipse/cdt/internal/core/sourcedependency/DependencyTree.java	11 Sep 2003 15:35:02 -0000
@@ -145,6 +145,10 @@
 	public String[] getFileDependencies(IPath filePath) throws IOException {
 		List tempFileReturn = new ArrayList();
 		IndexedFile indexFile = addsTree.getIndexedFile(filePath.toString());
+		
+		if (indexFile == null)
+		 return new String[0];
+		 
 		int fileNum = indexFile.getFileNumber();
 		IncludeEntry[] tempEntries = addsTree.getIncludeEntries();
 		for (int i=0; i<tempEntries.length; i++)
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/ChangeLog,v
retrieving revision 1.167
diff -u -r1.167 ChangeLog
--- ChangeLog	11 Sep 2003 14:58:30 -0000	1.167
+++ ChangeLog	11 Sep 2003 15:39:06 -0000
@@ -1,3 +1,11 @@
+2003-09-11 Bogdan Gheorghe
+	- Added Search Menu to CView.java
+	- Added queryWorkingSets to CSearchScopeFactory to bring up the working
+	  set dialog
+	- Modified Search Menu in CEditor.java, CContentOutlinePage.java
+	- Added new action FileSearchActionInWorkingSet
+	- Modified actions FileSearchAction, SearchDialogAction
+	
 2003-09-10 Sean Evoy
 	Work completed to resolve [Bug 41412] Restore Default in Managed Build 
 	project's settings Not Working. Added an event handler to reset the selected 
Index: src/org/eclipse/cdt/internal/ui/CPluginResources.properties
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties,v
retrieving revision 1.20
diff -u -r1.20 CPluginResources.properties
--- src/org/eclipse/cdt/internal/ui/CPluginResources.properties	9 Sep 2003 17:54:02 -0000	1.20
+++ src/org/eclipse/cdt/internal/ui/CPluginResources.properties	11 Sep 2003 15:39:06 -0000
@@ -293,13 +293,19 @@
 OpenIncludeAction.dialog.title=Open Include
 OpenIncludeAction.dialog.message=Select the file to open
 
-# ------- SearchForReferencesAction ---------------
-SearchForReferencesAction.label=File Search
-SearchForReferencesAction.tooltip=Performs a text based file search for element in workspace
-SearchForReferencesAction.description=Performs a text based file search for element in workspace
+# ------- FileSearchAction ---------------
+FileSearchAction.label=Workspace
+FileSearchAction.tooltip=Performs a text based file search for element in workspace
+FileSearchAction.description=Performs a text based file search for element in workspace
+
+# ------- FileSearchActionInWorkingSet ---------------
+FileSearchActionInWorkingSet.label=Working Set...
+FileSearchActionInWorkingSet.tooltip=Performs a text based file search for element in the selected working set
+FileSearchActionInWorkingSet.description=Performs a text based file search for element in the selected working set
+
 
 # ------- SearchDialogAction ---------------
-SearchDialogAction.label=C/C++ Search Dialog
+SearchDialogAction.label=C/C++ Search Dialog...
 SearchDialogAction.tooltip=Opens C/C++ Search Dialog
 SearchDialogAction.description=Opens C/C++ Search Dialog
 
Index: src/org/eclipse/cdt/internal/ui/cview/CView.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CView.java,v
retrieving revision 1.28
diff -u -r1.28 CView.java
--- src/org/eclipse/cdt/internal/ui/cview/CView.java	20 Aug 2003 17:34:33 -0000	1.28
+++ src/org/eclipse/cdt/internal/ui/cview/CView.java	11 Sep 2003 15:39:06 -0000
@@ -21,8 +21,14 @@
 import org.eclipse.cdt.core.model.ISourceReference;
 import org.eclipse.cdt.core.model.ITranslationUnit;
 import org.eclipse.cdt.core.resources.MakeUtil;
+import org.eclipse.cdt.internal.core.model.CProject;
+import org.eclipse.cdt.internal.core.model.TranslationUnit;
+import org.eclipse.cdt.internal.ui.IContextMenuConstants;
 import org.eclipse.cdt.internal.ui.StandardCElementLabelProvider;
+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.makeview.MakeAction;
 import org.eclipse.cdt.internal.ui.makeview.MakeTarget;
 import org.eclipse.cdt.internal.ui.makeview.MakeTargetAction;
@@ -174,6 +180,11 @@
 	// Collapsing
 	CollapseAllAction collapseAllAction;
 
+	//Search
+	FileSearchAction fFileSearchAction;
+	FileSearchActionInWorkingSet fFileSearchActionInWorkingSet;
+	SearchDialogAction fSearchDialogAction;
+	
 	// Persistance tags.
 	static final String TAG_SELECTION= "selection"; //$NON-NLS-1$
 	static final String TAG_EXPANDED= "expanded"; //$NON-NLS-1$
@@ -636,6 +647,10 @@
 		actionBars.setGlobalActionHandler(IWorkbenchActionConstants.CLOSE_PROJECT, closeProjectAction);
 
 		collapseAllAction = new CollapseAllAction(this);
+		
+		fFileSearchAction = new FileSearchAction(viewer);
+		fFileSearchActionInWorkingSet = new	FileSearchActionInWorkingSet(viewer);
+		fSearchDialogAction = new SearchDialogAction(viewer, this.getViewSite().getWorkbenchWindow());
 	}
 
 	/**
@@ -743,6 +758,8 @@
 		addIOMenu(menu, selection);
 		menu.add(new Separator());
 		addBookMarkMenu (menu, selection);
+		menu.add(new Separator());
+		addSearchMenu(menu, selection);
 		//menu.add(new Separator());
 		menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
 		menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS+"-end"));//$NON-NLS-1$
@@ -1303,4 +1320,28 @@
 			}
 		}
 	}
+	
+	void addSearchMenu(IMenuManager menu, IStructuredSelection selection) {	
+		IAdaptable element = (IAdaptable)selection.getFirstElement();
+
+		if (element instanceof TranslationUnit ||
+			element instanceof CProject)
+		 return;
+		 
+		MenuManager search = new MenuManager("Search", IContextMenuConstants.GROUP_SEARCH); //$NON-NLS-1$
+		
+		if (SearchDialogAction.canActionBeAdded(selection)){
+			search.add(fSearchDialogAction);
+		}
+		
+		if (FileSearchAction.canActionBeAdded(selection)) {
+			MenuManager fileSearch = new MenuManager("File Search");
+			fileSearch.add(fFileSearchAction);
+			fileSearch.add(fFileSearchActionInWorkingSet);
+			search.add(fileSearch);
+		}
+		
+		menu.add(search);
+	}
+	
 }
Index: src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java,v
retrieving revision 1.14
diff -u -r1.14 CContentOutlinePage.java
--- src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java	28 Aug 2003 19:46:41 -0000	1.14
+++ src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java	11 Sep 2003 15:39:06 -0000
@@ -58,7 +58,8 @@
 	private String fContextMenuId;
 	
 	private OpenIncludeAction fOpenIncludeAction;
-	private SearchForReferencesAction fSearchForReferencesAction;
+	private FileSearchAction fFileSearchAction;
+	private FileSearchActionInWorkingSet fFileSearchActionInWorkingSet;
 	private SearchDialogAction fSearchDialogAction;
 	
 	private MemberFilterActionGroup fMemberFilterActionGroup;
@@ -77,7 +78,8 @@
 		fTogglePresentation.setEditor(editor);
 		
 		fOpenIncludeAction= new OpenIncludeAction(this);
-		fSearchForReferencesAction= new SearchForReferencesAction(this);
+		fFileSearchAction= new FileSearchAction(this);
+		fFileSearchActionInWorkingSet = new FileSearchActionInWorkingSet(this);
 		fSearchDialogAction = new SearchDialogAction(this, editor);
 	}
 	
@@ -143,8 +145,11 @@
 			menu.add(fSearchDialogAction);
 		}
 		
-		if (SearchForReferencesAction.canActionBeAdded(getSelection())) {
-			menu.add(fSearchForReferencesAction);
+		if (FileSearchAction.canActionBeAdded(getSelection())) {
+			MenuManager fileSearch = new MenuManager("File Search");
+			fileSearch.add(fFileSearchAction);
+			fileSearch.add(fFileSearchActionInWorkingSet);
+			menu.add(fileSearch);
 		}
 		menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
 		menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS+"-end"));//$NON-NLS-1$
Index: src/org/eclipse/cdt/internal/ui/editor/CEditor.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java,v
retrieving revision 1.29
diff -u -r1.29 CEditor.java
--- src/org/eclipse/cdt/internal/ui/editor/CEditor.java	26 Aug 2003 19:15:37 -0000	1.29
+++ src/org/eclipse/cdt/internal/ui/editor/CEditor.java	11 Sep 2003 15:39:07 -0000
@@ -96,8 +96,10 @@
 	/** The outline page */
 	protected CContentOutlinePage fOutlinePage;
 
-	private SearchForReferencesAction fSearchForReferencesAction;
+	private FileSearchAction fFileSearchAction;
 
+	private FileSearchActionInWorkingSet fFileSearchActionInWorkingSet;
+	
 	private SearchDialogAction fSearchDialogAction;
 	
 	protected ISelectionChangedListener fStatusLineClearer;
@@ -427,7 +429,9 @@
 		setAction("AddIncludeOnSelection", new AddIncludeOnSelectionAction(this)); //$NON-NLS-1$
 		setAction("OpenDeclarations", new OpenDeclarationsAction(this));
 
-		fSearchForReferencesAction = new SearchForReferencesAction(getSelectionProvider());
+		fFileSearchAction = new FileSearchAction(getSelectionProvider());
+		
+		fFileSearchActionInWorkingSet = new FileSearchActionInWorkingSet(getSelectionProvider());
 		
 		fSearchDialogAction = new SearchDialogAction(getSelectionProvider(), this);
 	}
@@ -452,8 +456,11 @@
 			search.add(fSearchDialogAction);
 		}
 		
-		if (SearchForReferencesAction.canActionBeAdded(getSelectionProvider().getSelection())) {
-			search.add(fSearchForReferencesAction);
+		if (FileSearchAction.canActionBeAdded(getSelectionProvider().getSelection())) {
+			MenuManager fileSearch = new MenuManager("File Search");
+			fileSearch.add(fFileSearchAction);
+			fileSearch.add(fFileSearchActionInWorkingSet);
+			search.add(fileSearch);
 		}
 
 		addAction(menu, IContextMenuConstants.GROUP_GENERATE, "ContentAssistProposal"); //$NON-NLS-1$
Index: src/org/eclipse/cdt/internal/ui/editor/FileSearchAction.java
===================================================================
RCS file: src/org/eclipse/cdt/internal/ui/editor/FileSearchAction.java
diff -N src/org/eclipse/cdt/internal/ui/editor/FileSearchAction.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/internal/ui/editor/FileSearchAction.java	11 Sep 2003 15:39:07 -0000
@@ -0,0 +1,160 @@
+package org.eclipse.cdt.internal.ui.editor;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.internal.ui.CPluginImages;
+import org.eclipse.cdt.ui.CUIPlugin;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableContext;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+//import org.eclipse.search.internal.core.text.TextSearchEngine;
+import org.eclipse.search.internal.core.text.TextSearchScope;
+import org.eclipse.search.internal.ui.text.TextSearchOperation;
+import org.eclipse.search.internal.ui.text.TextSearchResultCollector;
+import org.eclipse.search.internal.ui.util.ExceptionHandler;
+import org.eclipse.search.ui.SearchUI;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorDescriptor;
+import org.eclipse.ui.IEditorRegistry;
+import org.eclipse.ui.PlatformUI;
+
+
+
+public class FileSearchAction extends Action {
+
+
+	private static final String PREFIX= "FileSearchAction.";
+	
+	private ISelectionProvider fSelectionProvider;
+
+	public FileSearchAction(ISelectionProvider provider) {
+		super(CUIPlugin.getResourceString(PREFIX + "label"));
+		setDescription(CUIPlugin.getResourceString(PREFIX + "description"));
+		setToolTipText(CUIPlugin.getResourceString(PREFIX + "tooltip"));
+		
+		if(provider instanceof CContentOutlinePage) {
+			CPluginImages.setImageDescriptors(this, CPluginImages.T_LCL, CPluginImages.IMG_MENU_OPEN_INCLUDE);
+			//setText("Search for References"); // $NON-NLS
+		}
+		
+		fSelectionProvider= provider;
+	}
+			
+	public void run() {
+		String search_name;
+		
+		ISelection selection= fSelectionProvider.getSelection();
+		if(selection instanceof ITextSelection) {
+			search_name = ((ITextSelection)selection).getText();
+			if(search_name.length() == 0) return;
+		} else {
+			ICElement element= getElement(selection);
+			if (element == null) {
+				return;
+			}
+			search_name = element.getElementName();
+		}
+		
+		// @@@ we rely on the internal functions of the Search plugin, since
+		// none of these are actually exported. This is probably going to change
+		// with 2.0.
+		TextSearchResultCollector col = new TextSearchResultCollector();
+		try {
+			//TextSearchPage
+			//ProgressMonitor monitor = new ProgressMonitor();
+			//col.setProgressMonitor(monitor)
+			SearchUI.activateSearchResultView();
+			//col.aboutToStart();
+		
+			// We now have the element, start a search on the string
+			//TextSearchEngine engine = new TextSearchEngine();
+			TextSearchScope scope= TextSearchScope.newWorkspaceScope();
+			// Add the extensions from the C editor definition for now
+			// FIXME: For C/C++ not all files rely on extension to be C++ for <cstring>
+			String[] cexts = CoreModel.getDefault().getTranslationUnitExtensions();
+			for (int i = 0; i < cexts.length; i++) {
+				scope.addExtension("*." + cexts[i]);
+			}
+//			scope.addExtension("*.c");
+//			scope.addExtension("*.h");
+//			scope.addExtension("*.cc");
+//			scope.addExtension("*.hh");
+			
+			TextSearchOperation op= new TextSearchOperation(
+				CUIPlugin.getWorkspace(),
+				search_name,
+				"",
+				scope,
+				col);
+
+
+			//engine.search(CUIPlugin.getWorkspace(), element.getName(),
+			//	null, scope, col);
+			IRunnableContext context=  null;
+			//context= getContainer().getRunnableContext();
+			
+			Shell shell= new Shell(); // getShell();
+			if (context == null)
+				context= new ProgressMonitorDialog(shell);
+
+
+			try {			
+				context.run(true, true, op);
+			} catch (InvocationTargetException ex) {
+				ExceptionHandler.handle(ex, "Error","Error"); //$NON-NLS-2$ //$NON-NLS-1$
+			} catch (InterruptedException e) {
+			}
+		} catch (Exception e) {}
+		
+	}
+
+
+	private static ICElement getElement(ISelection sel) {
+		if (!sel.isEmpty() && sel instanceof IStructuredSelection) {
+			List list= ((IStructuredSelection)sel).toList();
+			if (list.size() == 1) {
+				Object element= list.get(0);
+				if (element instanceof ICElement) {
+					return (ICElement)element;
+				}
+			}
+		}
+		return null;
+	}
+	
+	public static boolean canActionBeAdded(ISelection selection) {
+		if(selection instanceof ITextSelection) {
+			return (((ITextSelection)selection).getLength() > 0);
+		} else {
+			return getElement(selection) != null;
+		}
+	}	
+
+
+	public static String getEditorID(String name) {
+		IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry();
+		if (registry != null) {
+			IEditorDescriptor descriptor = registry.getDefaultEditor(name);
+			if (descriptor != null) {
+				return descriptor.getId();
+			} else {
+				return registry.getDefaultEditor().getId();
+			}
+		}
+		return null;
+	}
+}
+
+
Index: src/org/eclipse/cdt/internal/ui/editor/FileSearchActionInWorkingSet.java
===================================================================
RCS file: src/org/eclipse/cdt/internal/ui/editor/FileSearchActionInWorkingSet.java
diff -N src/org/eclipse/cdt/internal/ui/editor/FileSearchActionInWorkingSet.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/internal/ui/editor/FileSearchActionInWorkingSet.java	11 Sep 2003 15:39:07 -0000
@@ -0,0 +1,157 @@
+/*
+ * Created on Sep 9, 2003
+ */
+package org.eclipse.cdt.internal.ui.editor;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.internal.ui.CPluginImages;
+import org.eclipse.cdt.internal.ui.search.CSearchScopeFactory;
+import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableContext;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.search.internal.core.SearchScope;
+import org.eclipse.search.internal.ui.text.TextSearchOperation;
+import org.eclipse.search.internal.ui.text.TextSearchResultCollector;
+import org.eclipse.search.internal.ui.util.ExceptionHandler;
+import org.eclipse.search.ui.SearchUI;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorDescriptor;
+import org.eclipse.ui.IEditorRegistry;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * @author bgheorgh
+ */
+public class FileSearchActionInWorkingSet extends Action {
+
+
+	private static final String PREFIX= "FileSearchActionInWorkingSet.";
+	
+	private ISelectionProvider fSelectionProvider;
+
+	public FileSearchActionInWorkingSet(ISelectionProvider provider) {
+		super(CUIPlugin.getResourceString(PREFIX + "label"));
+		setDescription(CUIPlugin.getResourceString(PREFIX + "description"));
+		setToolTipText(CUIPlugin.getResourceString(PREFIX + "tooltip"));
+		
+		if(provider instanceof CContentOutlinePage) {
+			CPluginImages.setImageDescriptors(this, CPluginImages.T_LCL, CPluginImages.IMG_MENU_OPEN_INCLUDE);
+		}
+		
+		fSelectionProvider= provider;
+	}
+			
+	public void run() {
+		String search_name;
+		
+		ISelection selection= fSelectionProvider.getSelection();
+		if(selection instanceof ITextSelection) {
+			search_name = ((ITextSelection)selection).getText();
+			if(search_name.length() == 0) return;
+		} else {
+			ICElement element= getElement(selection);
+			if (element == null) {
+				return;
+			}
+			search_name = element.getElementName();
+		}
+		
+		// @@@ we rely on the internal functions of the Search plugin, since
+		// none of these are actually exported. This is probably going to change
+		// with 2.0.
+		TextSearchResultCollector col = new TextSearchResultCollector();
+		try {
+			SearchUI.activateSearchResultView();
+			
+			IWorkingSet[] workingSets= CSearchScopeFactory.getInstance().queryWorkingSets();
+			ArrayList resourceList = new ArrayList();
+			for (int i=0; i<workingSets.length; i++){
+				IAdaptable[] elements = workingSets[i].getElements();
+				
+				for (int j=0; j< elements.length; j++){
+					IResource resource= (IResource)elements[j].getAdapter(IResource.class);
+					if (resource != null){
+						resourceList.add(resource);
+					}
+				}
+			}
+			IResource[] result = new IResource[resourceList.size()];
+			resourceList.toArray(result);
+			
+			SearchScope scope= new SearchScope("File Search",(IResource []) result);
+	
+			
+			TextSearchOperation op= new TextSearchOperation(
+				CUIPlugin.getWorkspace(),
+				search_name,
+				"",
+				scope,
+				col);
+				
+			IRunnableContext context=  null;
+			
+			Shell shell= new Shell(); // getShell();
+			if (context == null)
+				context= new ProgressMonitorDialog(shell);
+
+
+			try {			
+				context.run(true, true, op);
+			} catch (InvocationTargetException ex) {
+				ExceptionHandler.handle(ex, "Error","Error"); //$NON-NLS-2$ //$NON-NLS-1$
+			} catch (InterruptedException e) {
+			}
+		} catch (Exception e) {}
+		
+
+	}
+
+
+	private static ICElement getElement(ISelection sel) {
+		if (!sel.isEmpty() && sel instanceof IStructuredSelection) {
+			List list= ((IStructuredSelection)sel).toList();
+			if (list.size() == 1) {
+				Object element= list.get(0);
+				if (element instanceof ICElement) {
+					return (ICElement)element;
+				}
+			}
+		}
+		return null;
+	}
+	
+	public static boolean canActionBeAdded(ISelection selection) {
+		if(selection instanceof ITextSelection) {
+			return (((ITextSelection)selection).getLength() > 0);
+		} else {
+			return getElement(selection) != null;
+		}
+	}	
+
+
+	public static String getEditorID(String name) {
+		IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry();
+		if (registry != null) {
+			IEditorDescriptor descriptor = registry.getDefaultEditor(name);
+			if (descriptor != null) {
+				return descriptor.getId();
+			} else {
+				return registry.getDefaultEditor().getId();
+			}
+		}
+		return null;
+	}
+
+}
Index: src/org/eclipse/cdt/internal/ui/editor/SearchDialogAction.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SearchDialogAction.java,v
retrieving revision 1.2
diff -u -r1.2 SearchDialogAction.java
--- src/org/eclipse/cdt/internal/ui/editor/SearchDialogAction.java	5 Sep 2003 18:31:52 -0000	1.2
+++ src/org/eclipse/cdt/internal/ui/editor/SearchDialogAction.java	11 Sep 2003 15:39:07 -0000
@@ -19,6 +19,7 @@
 import org.eclipse.search.ui.SearchUI;
 import org.eclipse.ui.IEditorDescriptor;
 import org.eclipse.ui.IEditorRegistry;
+import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.texteditor.ITextEditor;
 
@@ -29,12 +30,12 @@
  * Window>Preferences>Java>Code Generation>Code and Comments
  */
 public class SearchDialogAction extends Action {
-
 	private static final String PREFIX= "SearchDialogAction.";
 	private static final String C_SEARCH_PAGE_ID= "org.eclipse.cdt.ui.CSearchPage"; 
 
 	private ISelectionProvider fSelectionProvider;
 	private ITextEditor fEditor;
+	private IWorkbenchWindow fWorkbenchWindow;
 	
 	public SearchDialogAction(ISelectionProvider provider, CEditor editor) {
 		super(CUIPlugin.getResourceString(PREFIX + "label"));
@@ -48,6 +49,20 @@
 		fSelectionProvider= provider;
 		fEditor = editor;
 	}
+	
+	public SearchDialogAction(ISelectionProvider provider, IWorkbenchWindow window) {
+		
+		super(CUIPlugin.getResourceString(PREFIX + "label"));
+		setDescription(CUIPlugin.getResourceString(PREFIX + "description"));
+		setToolTipText(CUIPlugin.getResourceString(PREFIX + "tooltip"));
+		
+		if(provider instanceof CContentOutlinePage) {
+			CPluginImages.setImageDescriptors(this, CPluginImages.T_LCL, CPluginImages.IMG_MENU_OPEN_INCLUDE);
+		}
+		
+		fSelectionProvider= provider;
+		fWorkbenchWindow = window;
+	}
 			
 	public void run() {
 		String search_name;
@@ -64,8 +79,12 @@
 			search_name = element.getElementName();
 		}
 		
-		SearchUI.openSearchDialog(fEditor.getEditorSite().getWorkbenchWindow(),C_SEARCH_PAGE_ID);
-		
+		if (fEditor != null){
+			SearchUI.openSearchDialog(fEditor.getEditorSite().getWorkbenchWindow(),C_SEARCH_PAGE_ID);
+		} 
+		else if (fWorkbenchWindow != null){
+			SearchUI.openSearchDialog(fWorkbenchWindow,C_SEARCH_PAGE_ID);
+		}
 //		// @@@ we rely on the internal functions of the Search plugin, since
 //		// none of these are actually exported. This is probably going to change
 //		// with 2.0.
Index: src/org/eclipse/cdt/internal/ui/editor/SearchForReferencesAction.java
===================================================================
RCS file: src/org/eclipse/cdt/internal/ui/editor/SearchForReferencesAction.java
diff -N src/org/eclipse/cdt/internal/ui/editor/SearchForReferencesAction.java
--- src/org/eclipse/cdt/internal/ui/editor/SearchForReferencesAction.java	9 Sep 2003 17:54:02 -0000	1.5
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,160 +0,0 @@
-package org.eclipse.cdt.internal.ui.editor;
-
-/*
- * (c) Copyright QNX Software Systems Ltd. 2002.
- * All Rights Reserved.
- */
-
-import org.eclipse.cdt.core.model.CoreModel;
-import org.eclipse.cdt.core.model.ICElement;
-import org.eclipse.cdt.internal.ui.CPluginImages;
-import org.eclipse.cdt.ui.CUIPlugin;
-
-import java.lang.reflect.InvocationTargetException;
-import java.util.List;
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.dialogs.ProgressMonitorDialog;
-import org.eclipse.jface.operation.IRunnableContext;
-import org.eclipse.jface.text.ITextSelection;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-//import org.eclipse.search.internal.core.text.TextSearchEngine;
-import org.eclipse.search.internal.core.text.TextSearchScope;
-import org.eclipse.search.internal.ui.text.TextSearchOperation;
-import org.eclipse.search.internal.ui.text.TextSearchResultCollector;
-import org.eclipse.search.internal.ui.util.ExceptionHandler;
-import org.eclipse.search.ui.SearchUI;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IEditorDescriptor;
-import org.eclipse.ui.IEditorRegistry;
-import org.eclipse.ui.PlatformUI;
-
-
-
-public class SearchForReferencesAction extends Action {
-
-
-	private static final String PREFIX= "SearchForReferencesAction.";
-	
-	private ISelectionProvider fSelectionProvider;
-
-	public SearchForReferencesAction(ISelectionProvider provider) {
-		super(CUIPlugin.getResourceString(PREFIX + "label"));
-		setDescription(CUIPlugin.getResourceString(PREFIX + "description"));
-		setToolTipText(CUIPlugin.getResourceString(PREFIX + "tooltip"));
-		
-		if(provider instanceof CContentOutlinePage) {
-			CPluginImages.setImageDescriptors(this, CPluginImages.T_LCL, CPluginImages.IMG_MENU_OPEN_INCLUDE);
-			//setText("Search for References"); // $NON-NLS
-		}
-		
-		fSelectionProvider= provider;
-	}
-			
-	public void run() {
-		String search_name;
-		
-		ISelection selection= fSelectionProvider.getSelection();
-		if(selection instanceof ITextSelection) {
-			search_name = ((ITextSelection)selection).getText();
-			if(search_name.length() == 0) return;
-		} else {
-			ICElement element= getElement(selection);
-			if (element == null) {
-				return;
-			}
-			search_name = element.getElementName();
-		}
-		
-		// @@@ we rely on the internal functions of the Search plugin, since
-		// none of these are actually exported. This is probably going to change
-		// with 2.0.
-		TextSearchResultCollector col = new TextSearchResultCollector();
-		try {
-			//TextSearchPage
-			//ProgressMonitor monitor = new ProgressMonitor();
-			//col.setProgressMonitor(monitor)
-			SearchUI.activateSearchResultView();
-			//col.aboutToStart();
-		
-			// We now have the element, start a search on the string
-			//TextSearchEngine engine = new TextSearchEngine();
-			TextSearchScope scope= TextSearchScope.newWorkspaceScope();
-			// Add the extensions from the C editor definition for now
-			// FIXME: For C/C++ not all files rely on extension to be C++ for <cstring>
-			String[] cexts = CoreModel.getDefault().getTranslationUnitExtensions();
-			for (int i = 0; i < cexts.length; i++) {
-				scope.addExtension("*." + cexts[i]);
-			}
-//			scope.addExtension("*.c");
-//			scope.addExtension("*.h");
-//			scope.addExtension("*.cc");
-//			scope.addExtension("*.hh");
-			
-			TextSearchOperation op= new TextSearchOperation(
-				CUIPlugin.getWorkspace(),
-				search_name,
-				"",
-				scope,
-				col);
-
-
-			//engine.search(CUIPlugin.getWorkspace(), element.getName(),
-			//	null, scope, col);
-			IRunnableContext context=  null;
-			//context= getContainer().getRunnableContext();
-			
-			Shell shell= new Shell(); // getShell();
-			if (context == null)
-				context= new ProgressMonitorDialog(shell);
-
-
-			try {			
-				context.run(true, true, op);
-			} catch (InvocationTargetException ex) {
-				ExceptionHandler.handle(ex, "Error","Error"); //$NON-NLS-2$ //$NON-NLS-1$
-			} catch (InterruptedException e) {
-			}
-		} catch (Exception e) {}
-		
-	}
-
-
-	private static ICElement getElement(ISelection sel) {
-		if (!sel.isEmpty() && sel instanceof IStructuredSelection) {
-			List list= ((IStructuredSelection)sel).toList();
-			if (list.size() == 1) {
-				Object element= list.get(0);
-				if (element instanceof ICElement) {
-					return (ICElement)element;
-				}
-			}
-		}
-		return null;
-	}
-	
-	public static boolean canActionBeAdded(ISelection selection) {
-		if(selection instanceof ITextSelection) {
-			return (((ITextSelection)selection).getLength() > 0);
-		} else {
-			return getElement(selection) != null;
-		}
-	}	
-
-
-	public static String getEditorID(String name) {
-		IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry();
-		if (registry != null) {
-			IEditorDescriptor descriptor = registry.getDefaultEditor(name);
-			if (descriptor != null) {
-				return descriptor.getId();
-			} else {
-				return registry.getDefaultEditor().getId();
-			}
-		}
-		return null;
-	}
-}
-
-
Index: src/org/eclipse/cdt/internal/ui/search/CSearchScopeFactory.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchScopeFactory.java,v
retrieving revision 1.3
diff -u -r1.3 CSearchScopeFactory.java
--- src/org/eclipse/cdt/internal/ui/search/CSearchScopeFactory.java	5 Sep 2003 18:31:52 -0000	1.3
+++ src/org/eclipse/cdt/internal/ui/search/CSearchScopeFactory.java	11 Sep 2003 15:39:07 -0000
@@ -20,9 +20,14 @@
 import org.eclipse.cdt.core.model.ICElement;
 import org.eclipse.cdt.core.search.ICSearchScope;
 import org.eclipse.cdt.core.search.SearchEngine;
+import org.eclipse.cdt.ui.CUIPlugin;
 import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.IWorkingSetSelectionDialog;
 
 /**
  * @author aniefer
@@ -114,6 +119,20 @@
 		}
 		
 		return createCSearchScope( cElements );
+	}
+	
+
+	public IWorkingSet[] queryWorkingSets() {
+		Shell shell= CUIPlugin.getDefault().getActiveWorkbenchShell();
+		if (shell == null)
+			return null;
+		IWorkingSetSelectionDialog dialog= PlatformUI.getWorkbench().getWorkingSetManager().createWorkingSetSelectionDialog(shell, true);
+		if (dialog.open() == Window.OK) {
+			IWorkingSet[] workingSets= dialog.getSelection();
+			if (workingSets.length > 0)
+				return workingSets;
+		}
+		return null;
 	}
 	
 }

Back to the top