Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-patch] Open Declarations UI/Responsiveness improvement


OK - I repackaged Thomas' patch as two files. Alain, can you please apply this to the 1.2 and head branches. For 2.0, I'd like to move Open Declarations to the background processing thread but this fix can be a place holder until then.

Thanks,
Bogdan




"Alain Magloire" <alain@xxxxxxx>
Sent by: cdt-patch-admin@xxxxxxxxxxx

02/05/2004 11:37 AM

Please respond to
cdt-patch@xxxxxxxxxxx

To
cdt-patch@xxxxxxxxxxx
cc
Subject
Re: [cdt-patch] Open Declarations UI/Responsiveness improvement





>
>
>
> Alain Magloire <alain@xxxxxxx> said:
>
> > >
> > > Thomas -
> > >
> > > Can you update and resend this? I tried applying this to both 1.2  and
> >
> > > head (after updating both) and got a bunch of "no matches".
> > >
> >
> > - and create an appropriate PR for it.
> >
> > Bogdan/andrew,
> >   I did not follow the in/outs of this part of the code, so you'll have
> > to
> > tell me nay or yay for this patch. For Head && branch.
>
> In a nutshell, it moves the search operation into a runnable which
> can be passed to a progress dialog.
>
> The Bugzilla for this is 51221.
>

Thanks,
 Reassign and retarget for 1.2.1

Bogdan, this is your call.

_______________________________________________
cdt-patch mailing list
cdt-patch@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/cdt-patch

Index: src/org/eclipse/cdt/internal/ui/editor/OpenDeclarationsAction.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OpenDeclarationsAction.java,v
retrieving revision 1.2.2.2
diff -u -r1.2.2.2 OpenDeclarationsAction.java
--- src/org/eclipse/cdt/internal/ui/editor/OpenDeclarationsAction.java	11 Nov 2003 18:28:20 -0000	1.2.2.2
+++ src/org/eclipse/cdt/internal/ui/editor/OpenDeclarationsAction.java	5 Feb 2004 18:41:59 -0000
@@ -23,9 +23,10 @@
 import org.eclipse.cdt.ui.CSearchResultLabelProvider;
 import org.eclipse.cdt.ui.CUIPlugin;
 import org.eclipse.cdt.ui.IWorkingCopyManager;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jface.action.Action;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.jface.text.BadLocationException;
 import org.eclipse.jface.text.IDocument;
@@ -35,6 +36,7 @@
 import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.texteditor.IDocumentProvider;
+import org.eclipse.ui.texteditor.IUpdate;
 
 /**
  * This action opens a java CEditor on the element represented by text selection of
@@ -42,12 +44,11 @@
  * 
  * Use action from package org.eclipse.jdt.ui.actions
  */
-public class OpenDeclarationsAction extends Action {
+public class OpenDeclarationsAction extends Action implements IUpdate {
 		
 	private String fDialogTitle;
 	private String fDialogMessage;
 	protected CEditor fEditor;
-	BasicSearchResultCollector  resultCollector = null;
 	SearchEngine searchEngine = null;
 	
 	/**
@@ -63,7 +64,6 @@
 		setDialogMessage(CEditorMessages.getString("OpenDeclarations.dialog.message")); //$NON-NLS-1$
 
 		searchEngine = new SearchEngine();
-		resultCollector = new BasicSearchResultCollector();
 	}
 	
 	/**
@@ -93,66 +93,86 @@
 	public void setContentEditor(CEditor editor) {	
 		fEditor= editor;
 	}
+
+		 /**
+		  * Return the selected string from the editor
+		  * @return The string currently selected, or null if there is no valid selection
+		  */
+		 protected String getSelectedStringFromEditor() {
+		 		 if (fEditor.getSelectionProvider() == null) {
+		 		 		 return null;
+		 		 }
+
+		 		 try {
+		 		 		 ITextSelection selection= (ITextSelection) fEditor.getSelectionProvider().getSelection();
+		 		 		 String sel = selection.getText();
+		 		 		 if (sel.equals(""))
+		 		 		 {
+		 		 		 		 int selStart =  selection.getOffset();
+		 		 		 
+		 		 		 		 IDocumentProvider prov = fEditor.getDocumentProvider();
+		 		 		 		 IDocument doc = prov.getDocument(fEditor.getEditorInput());
+		 		 		 		 sel = getSelection(doc, selStart);
+		 		 		 }
+		 		 		 return sel;
+		 		 } catch(Exception x) {
+		 		 		 return null;
+		 		 }
+		 }
 	
 	/**
 	 * @see IAction#actionPerformed
 	 */
 	public void run() {
-		
-		IWorkingCopyManager fManager = CUIPlugin.getDefault().getWorkingCopyManager();
-		ITranslationUnit unit = fManager.getWorkingCopy(fEditor.getEditorInput());
-		 
-		if (fEditor.getSelectionProvider() != null) {
-			ITextSelection selection= (ITextSelection) fEditor.getSelectionProvider().getSelection();
-			try {
-				ArrayList elementsFound = new ArrayList();
-				String sel = selection.getText();
-				if (sel.equals(""))
-				{
-					int selStart =  selection.getOffset();
-					
-					IDocumentProvider prov = fEditor.getDocumentProvider();
-					IDocument doc = prov.getDocument(fEditor.getEditorInput());
-					sel = getSelection(doc, selStart);
-				}
-				
-				IFile file = fEditor.getInputFile();
-				if(file == null)
-					return;
-				IProject project = file.getProject();
-				if(project == null)
-					return;
-				
+		 		 final String selectedText = getSelectedStringFromEditor();
+
+		 		 if(selectedText == null) {
+		 		 		 return;
+		 		 }
+
+		 		 final ArrayList elementsFound = new ArrayList();
+
+		 		 IRunnableWithProgress runnable = new IRunnableWithProgress() {
+		 		 		 public void run(IProgressMonitor monitor) {
+		 		 		 		 BasicSearchResultCollector  resultCollector =  new BasicSearchResultCollector(monitor);
+		 		 		 		 IWorkingCopyManager fManager = CUIPlugin.getDefault().getWorkingCopyManager();
+		 		 		 		 ITranslationUnit unit = fManager.getWorkingCopy(fEditor.getEditorInput());
+
 				ICElement[] projectScopeElement = new ICElement[1];
 				projectScopeElement[0] = unit.getCProject();//(ICElement)currentScope.getCProject();
 				ICSearchScope scope = SearchEngine.createCSearchScope(projectScopeElement, true);
 				OrPattern orPattern = new OrPattern();
 				// search for global variables, functions, classes, structs, unions, enums and macros
-				orPattern.addPattern(SearchEngine.createSearchPattern( sel, ICSearchConstants.VAR, ICSearchConstants.DECLARATIONS, true ));
-				orPattern.addPattern(SearchEngine.createSearchPattern( sel, ICSearchConstants.FUNCTION, ICSearchConstants.DECLARATIONS, true ));
-				orPattern.addPattern(SearchEngine.createSearchPattern( sel, ICSearchConstants.METHOD, ICSearchConstants.DECLARATIONS, true ));
-				orPattern.addPattern(SearchEngine.createSearchPattern( sel, ICSearchConstants.TYPE, ICSearchConstants.DECLARATIONS, true ));
-				orPattern.addPattern(SearchEngine.createSearchPattern( sel, ICSearchConstants.ENUM, ICSearchConstants.DECLARATIONS, true ));
-				orPattern.addPattern(SearchEngine.createSearchPattern( sel, ICSearchConstants.FIELD, ICSearchConstants.DECLARATIONS, true ));
-				orPattern.addPattern(SearchEngine.createSearchPattern( sel, ICSearchConstants.NAMESPACE, ICSearchConstants.DECLARATIONS, true ));
-				orPattern.addPattern(SearchEngine.createSearchPattern( sel, ICSearchConstants.MACRO, ICSearchConstants.DECLARATIONS, true ));
-				orPattern.addPattern(SearchEngine.createSearchPattern( sel, ICSearchConstants.TYPEDEF, ICSearchConstants.DECLARATIONS, true ));
+		 		 		 		 orPattern.addPattern(SearchEngine.createSearchPattern( selectedText, ICSearchConstants.VAR, ICSearchConstants.DECLARATIONS, true ));
+		 		 		 		 orPattern.addPattern(SearchEngine.createSearchPattern( selectedText, ICSearchConstants.FUNCTION, ICSearchConstants.DECLARATIONS, true ));
+		 		 		 		 orPattern.addPattern(SearchEngine.createSearchPattern( selectedText, ICSearchConstants.METHOD, ICSearchConstants.DECLARATIONS, true ));
+		 		 		 		 orPattern.addPattern(SearchEngine.createSearchPattern( selectedText, ICSearchConstants.TYPE, ICSearchConstants.DECLARATIONS, true ));
+		 		 		 		 orPattern.addPattern(SearchEngine.createSearchPattern( selectedText, ICSearchConstants.ENUM, ICSearchConstants.DECLARATIONS, true ));
+		 		 		 		 orPattern.addPattern(SearchEngine.createSearchPattern( selectedText, ICSearchConstants.FIELD, ICSearchConstants.DECLARATIONS, true ));
+		 		 		 		 orPattern.addPattern(SearchEngine.createSearchPattern( selectedText, ICSearchConstants.NAMESPACE, ICSearchConstants.DECLARATIONS, true ));
+		 		 		 		 orPattern.addPattern(SearchEngine.createSearchPattern( selectedText, ICSearchConstants.MACRO, ICSearchConstants.DECLARATIONS, true ));
+		 		 		 		 orPattern.addPattern(SearchEngine.createSearchPattern( selectedText, ICSearchConstants.TYPEDEF, ICSearchConstants.DECLARATIONS, true ));
 				searchEngine.search(CUIPlugin.getWorkspace(), orPattern, scope, resultCollector, true);
-				elementsFound.addAll(resultCollector.getSearchResults());
-				
-				if (elementsFound.isEmpty() == false) {
-					IMatch selected= selectCElement(elementsFound, getShell(), fDialogTitle, fDialogMessage);
-					if (selected != null) {
-						open(selected);
-						return;
-					}
-				}
-			} catch	 (Exception x) {
-				CUIPlugin.getDefault().log(x);
+		 		 		 		 elementsFound.addAll(resultCollector.getSearchResults());		 
 			}
-		}
+		 		 };
 
-		getShell().getDisplay().beep();		
+		 		 try {
+		 		 		 ProgressMonitorDialog progressMonitor = new ProgressMonitorDialog(getShell());
+		 		 		 progressMonitor.run(true, true, runnable);
+
+		 		 		 if (elementsFound.isEmpty() == true) {
+		 		 		 		 return;
+		 		 		 }
+
+		 		 		 IMatch selected= selectCElement(elementsFound, getShell(), fDialogTitle, fDialogMessage);
+		 		 		 if (selected != null) {
+		 		 		 		 open(selected);
+		 		 		 		 return;
+		 		 		 }
+		 		 } catch(Exception x) {
+		 		 		 CUIPlugin.getDefault().log(x);
+		 		 }
 	}
 
 	protected Shell getShell() {
@@ -247,5 +267,13 @@
 	
 		return selectedWord;		
 	}
+		 		 
+		 /* (non-Javadoc)
+		  * @see org.eclipse.ui.texteditor.IUpdate#update()
+		  */
+		 public void update() {
+		 		 setEnabled(getSelectedStringFromEditor() != null);
+		 }
+
 }
 
Index: search/org/eclipse/cdt/core/search/BasicSearchResultCollector.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/BasicSearchResultCollector.java,v
retrieving revision 1.8
diff -u -r1.8 BasicSearchResultCollector.java
--- search/org/eclipse/cdt/core/search/BasicSearchResultCollector.java	23 Sep 2003 13:54:21 -0000	1.8
+++ search/org/eclipse/cdt/core/search/BasicSearchResultCollector.java	5 Feb 2004 18:38:35 -0000
@@ -53,6 +53,14 @@
  * Window>Preferences>Java>Code Generation>Code and Comments
  */
 public class BasicSearchResultCollector implements ICSearchResultCollector {
+		 IProgressMonitor fProgressMonitor = null;
+
+		 public BasicSearchResultCollector() {
+		 }
+		 
+		 public BasicSearchResultCollector(IProgressMonitor monitor) {
+		 		 fProgressMonitor = monitor;
+		 }
 
 	public void aboutToStart() {
 		results = new HashSet();
@@ -62,7 +70,7 @@
 	}
 	
 	public IProgressMonitor getProgressMonitor() {
-		return null;
+		 		 return fProgressMonitor;
 	}
 
 	public IMatch createMatch(Object fileResource, int start, int end, ISourceElementCallbackDelegate node ) throws CoreException 

Back to the top