1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

2004-02-05 Alain Magloire

PR 51221
	Reformat Patch from Bogdan base on Thomas Fletcher original patch
	In a nutshell, it moves the search operation into a runnable which
	can be passed to a progress dialog.

	* src/org/eclipse/cdt/internal/ui/editor/OpenDeclarationsAction.java
This commit is contained in:
Alain Magloire 2004-02-05 19:53:54 +00:00
parent 206694da40
commit 8df8840f36
2 changed files with 88 additions and 52 deletions

View file

@ -1,3 +1,11 @@
2004-02-05 Alain Magloire
PR 51221
Reformat Patch from Bogdan base on Thomas Fletcher original patch
In a nutshell, it moves the search operation into a runnable which
can be passed to a progress dialog.
* src/org/eclipse/cdt/internal/ui/editor/OpenDeclarationsAction.java
2004-02-05 Hoda Amer 2004-02-05 Hoda Amer
Small prefrence page fix Small prefrence page fix

View file

@ -23,9 +23,10 @@ import org.eclipse.cdt.internal.ui.util.EditorUtility;
import org.eclipse.cdt.ui.CSearchResultLabelProvider; import org.eclipse.cdt.ui.CSearchResultLabelProvider;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.IWorkingCopyManager; import org.eclipse.cdt.ui.IWorkingCopyManager;
import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.action.Action; 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.resource.ImageDescriptor;
import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocument;
@ -35,6 +36,7 @@ import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PartInitException; import org.eclipse.ui.PartInitException;
import org.eclipse.ui.texteditor.IDocumentProvider; 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 * This action opens a java CEditor on the element represented by text selection of
@ -42,12 +44,11 @@ import org.eclipse.ui.texteditor.IDocumentProvider;
* *
* Use action from package org.eclipse.jdt.ui.actions * 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 fDialogTitle;
private String fDialogMessage; private String fDialogMessage;
protected CEditor fEditor; protected CEditor fEditor;
BasicSearchResultCollector resultCollector = null;
SearchEngine searchEngine = null; SearchEngine searchEngine = null;
/** /**
@ -63,7 +64,6 @@ public class OpenDeclarationsAction extends Action {
setDialogMessage(CEditorMessages.getString("OpenDeclarations.dialog.message")); //$NON-NLS-1$ setDialogMessage(CEditorMessages.getString("OpenDeclarations.dialog.message")); //$NON-NLS-1$
searchEngine = new SearchEngine(); searchEngine = new SearchEngine();
resultCollector = new BasicSearchResultCollector();
} }
/** /**
@ -95,17 +95,16 @@ public class OpenDeclarationsAction extends Action {
} }
/** /**
* @see IAction#actionPerformed * Return the selected string from the editor
* @return The string currently selected, or null if there is no valid selection
*/ */
public void run() { protected String getSelectedStringFromEditor() {
if (fEditor.getSelectionProvider() == null) {
return null;
}
IWorkingCopyManager fManager = CUIPlugin.getDefault().getWorkingCopyManager();
ITranslationUnit unit = fManager.getWorkingCopy(fEditor.getEditorInput());
if (fEditor.getSelectionProvider() != null) {
ITextSelection selection= (ITextSelection) fEditor.getSelectionProvider().getSelection();
try { try {
ArrayList elementsFound = new ArrayList(); ITextSelection selection= (ITextSelection) fEditor.getSelectionProvider().getSelection();
String sel = selection.getText(); String sel = selection.getText();
if (sel.equals("")) if (sel.equals(""))
{ {
@ -115,46 +114,67 @@ public class OpenDeclarationsAction extends Action {
IDocument doc = prov.getDocument(fEditor.getEditorInput()); IDocument doc = prov.getDocument(fEditor.getEditorInput());
sel = getSelection(doc, selStart); sel = getSelection(doc, selStart);
} }
return sel;
} catch(Exception x) {
return null;
}
}
IFile file = fEditor.getInputFile(); /**
if(file == null) * @see IAction#actionPerformed
return; */
IProject project = file.getProject(); public void run() {
if(project == null) final String selectedText = getSelectedStringFromEditor();
if(selectedText == null) {
return; 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]; ICElement[] projectScopeElement = new ICElement[1];
projectScopeElement[0] = unit.getCProject();//(ICElement)currentScope.getCProject(); projectScopeElement[0] = unit.getCProject();//(ICElement)currentScope.getCProject();
ICSearchScope scope = SearchEngine.createCSearchScope(projectScopeElement, true); ICSearchScope scope = SearchEngine.createCSearchScope(projectScopeElement, true);
OrPattern orPattern = new OrPattern(); OrPattern orPattern = new OrPattern();
// search for global variables, functions, classes, structs, unions, enums and macros // 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( selectedText, ICSearchConstants.VAR, ICSearchConstants.DECLARATIONS, true ));
orPattern.addPattern(SearchEngine.createSearchPattern( sel, ICSearchConstants.FUNCTION, ICSearchConstants.DECLARATIONS, true )); orPattern.addPattern(SearchEngine.createSearchPattern( selectedText, ICSearchConstants.FUNCTION, ICSearchConstants.DECLARATIONS, true ));
orPattern.addPattern(SearchEngine.createSearchPattern( sel, ICSearchConstants.METHOD, ICSearchConstants.DECLARATIONS, true )); orPattern.addPattern(SearchEngine.createSearchPattern( selectedText, ICSearchConstants.METHOD, ICSearchConstants.DECLARATIONS, true ));
orPattern.addPattern(SearchEngine.createSearchPattern( sel, ICSearchConstants.TYPE, ICSearchConstants.DECLARATIONS, true )); orPattern.addPattern(SearchEngine.createSearchPattern( selectedText, ICSearchConstants.TYPE, ICSearchConstants.DECLARATIONS, true ));
orPattern.addPattern(SearchEngine.createSearchPattern( sel, ICSearchConstants.ENUM, ICSearchConstants.DECLARATIONS, true )); orPattern.addPattern(SearchEngine.createSearchPattern( selectedText, ICSearchConstants.ENUM, ICSearchConstants.DECLARATIONS, true ));
orPattern.addPattern(SearchEngine.createSearchPattern( sel, ICSearchConstants.FIELD, ICSearchConstants.DECLARATIONS, true )); orPattern.addPattern(SearchEngine.createSearchPattern( selectedText, ICSearchConstants.FIELD, ICSearchConstants.DECLARATIONS, true ));
orPattern.addPattern(SearchEngine.createSearchPattern( sel, ICSearchConstants.NAMESPACE, ICSearchConstants.DECLARATIONS, true )); orPattern.addPattern(SearchEngine.createSearchPattern( selectedText, ICSearchConstants.NAMESPACE, ICSearchConstants.DECLARATIONS, true ));
orPattern.addPattern(SearchEngine.createSearchPattern( sel, ICSearchConstants.MACRO, ICSearchConstants.DECLARATIONS, true )); orPattern.addPattern(SearchEngine.createSearchPattern( selectedText, ICSearchConstants.MACRO, ICSearchConstants.DECLARATIONS, true ));
orPattern.addPattern(SearchEngine.createSearchPattern( sel, ICSearchConstants.TYPEDEF, ICSearchConstants.DECLARATIONS, true )); orPattern.addPattern(SearchEngine.createSearchPattern( selectedText, ICSearchConstants.TYPEDEF, ICSearchConstants.DECLARATIONS, true ));
searchEngine.search(CUIPlugin.getWorkspace(), orPattern, scope, resultCollector, true); searchEngine.search(CUIPlugin.getWorkspace(), orPattern, scope, resultCollector, true);
elementsFound.addAll(resultCollector.getSearchResults()); elementsFound.addAll(resultCollector.getSearchResults());
}
};
try {
ProgressMonitorDialog progressMonitor = new ProgressMonitorDialog(getShell());
progressMonitor.run(true, true, runnable);
if (elementsFound.isEmpty() == true) {
return;
}
if (elementsFound.isEmpty() == false) {
IMatch selected= selectCElement(elementsFound, getShell(), fDialogTitle, fDialogMessage); IMatch selected= selectCElement(elementsFound, getShell(), fDialogTitle, fDialogMessage);
if (selected != null) { if (selected != null) {
open(selected); open(selected);
return; return;
} }
}
} catch(Exception x) { } catch(Exception x) {
CUIPlugin.getDefault().log(x); CUIPlugin.getDefault().log(x);
} }
} }
getShell().getDisplay().beep();
}
protected Shell getShell() { protected Shell getShell() {
return fEditor.getSite().getShell(); return fEditor.getSite().getShell();
} }
@ -247,5 +267,13 @@ public class OpenDeclarationsAction extends Action {
return selectedWord; return selectedWord;
} }
/* (non-Javadoc)
* @see org.eclipse.ui.texteditor.IUpdate#update()
*/
public void update() {
setEnabled(getSelectedStringFromEditor() != null);
}
} }