From 090476da2dec6e339aa45e73008cbb87da2b34d4 Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Sun, 28 May 2006 00:05:41 +0000 Subject: [PATCH] Bug 143488 - Hooked up the FindAction to the Selection Parse methods for getting full name text selections. Also upgraded these methods to reuse TextSelection from JFace instead of rolling our own. --- .../ui/search/actions/FindAction.java | 3 +- .../actions/OpenDeclarationsAction.java | 7 +-- .../search/actions/OpenDefinitionAction.java | 7 +-- .../search/actions/SelectionParseAction.java | 54 ++++--------------- 4 files changed, 21 insertions(+), 50 deletions(-) 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 index 083a4415b56..d4e1fd1a867 100644 --- 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 @@ -43,6 +43,7 @@ public abstract class FindAction extends SelectionParseAction { if (object instanceof ISourceReference) searchJob = new PDOMSearchElementQuery(getScope(), (ISourceReference)object, getLimitTo()); } else if (selection instanceof ITextSelection) { + ITextSelection selNode = getSelection((ITextSelection)selection); ICElement element = fEditor.getInputCElement(); while (element != null && !(element instanceof ITranslationUnit)) element = element.getParent(); @@ -50,7 +51,7 @@ public abstract class FindAction extends SelectionParseAction { searchJob = new PDOMSearchTextSelectionQuery( getScope(), (ITranslationUnit)element, - (ITextSelection)selection, + selNode, getLimitTo()); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java index 0f175adab29..4c39b9dac9e 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java @@ -27,11 +27,12 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jface.text.ITextSelection; import org.eclipse.swt.widgets.Display; public class OpenDeclarationsAction extends SelectionParseAction { public static final IASTName[] BLANK_NAME_ARRAY = new IASTName[0]; - SelSearchNode selNode; + ITextSelection selNode; /** * Creates a new action with the given editor @@ -50,8 +51,8 @@ public class OpenDeclarationsAction extends SelectionParseAction { protected IStatus run(IProgressMonitor monitor) { try { - int selectionStart = selNode.selStart; - int selectionLength = selNode.selEnd - selNode.selStart; + int selectionStart = selNode.getOffset(); + int selectionLength = selNode.getLength(); IWorkingCopy workingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(fEditor.getEditorInput()); if (workingCopy == null) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java index c155809fe0d..b40d0a7213b 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java @@ -23,6 +23,7 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jface.text.ITextSelection; import org.eclipse.swt.widgets.Display; /** @@ -33,7 +34,7 @@ import org.eclipse.swt.widgets.Display; public class OpenDefinitionAction extends SelectionParseAction { public static final IASTName[] BLANK_NAME_ARRAY = new IASTName[0]; - SelSearchNode selNode; + ITextSelection selNode; /** * Creates a new action with the given editor @@ -52,8 +53,8 @@ public class OpenDefinitionAction extends SelectionParseAction { protected IStatus run(IProgressMonitor monitor) { try { - int selectionStart = selNode.selStart; - int selectionLength = selNode.selEnd - selNode.selStart; + int selectionStart = selNode.getOffset(); + int selectionLength = selNode.getLength(); IWorkingCopy workingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(fEditor.getEditorInput()); if (workingCopy == null) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/SelectionParseAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/SelectionParseAction.java index 213a4042995..1310cd2a030 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/SelectionParseAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/SelectionParseAction.java @@ -48,6 +48,7 @@ import org.eclipse.jface.action.IStatusLineManager; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.text.TextSelection; import org.eclipse.jface.viewers.ISelection; import org.eclipse.search.ui.NewSearchUI; import org.eclipse.ui.IEditorInput; @@ -185,7 +186,7 @@ public class SelectionParseAction extends Action { } //TODO: Change this to work with qualified identifiers - public SelSearchNode getSelection( int fPos ) { + public ITextSelection getSelection( int fPos ) { IDocumentProvider prov = ( fEditor != null ) ? fEditor.getDocumentProvider() : null; IDocument doc = ( prov != null ) ? prov.getDocument(fEditor.getEditorInput()) : null; @@ -233,8 +234,6 @@ public class SelectionParseAction extends Action { catch(BadLocationException e){ } - SelSearchNode sel = new SelSearchNode(); - boolean selectedOperator=false; if (selectedWord != null && selectedWord.indexOf(OPERATOR) >= 0 && fPos >= fStartPos + selectedWord.indexOf(OPERATOR) && fPos < fStartPos + selectedWord.indexOf(OPERATOR) + OPERATOR.length()) { selectedOperator=true; @@ -248,11 +247,7 @@ public class SelectionParseAction extends Action { actualEnd=(actualEnd>0?actualEnd:fEndPos); - try { - sel.selText = doc.get(actualStart, actualEnd - actualStart); - } catch (BadLocationException e) {} - sel.selStart = actualStart; - sel.selEnd = actualEnd; + return new TextSelection(doc, actualStart, actualEnd - actualStart); // TODO Devin this only works for definitions of destructors right now // if there is a destructor and the cursor is in the destructor name's segment then get the entire destructor } else if (selectedWord != null && selectedWord.indexOf('~') >= 0 && fPos - 2 >= fStartPos + selectedWord.lastIndexOf(new String(Keywords.cpCOLONCOLON))) { @@ -271,28 +266,14 @@ public class SelectionParseAction extends Action { // if the cursor is after the destructor name then use the regular boundaries if (fPos >= actualStart + length) { - try { - sel.selText = doc.get(nonJavaStart, (nonJavaEnd - nonJavaStart)); - } catch (BadLocationException e) {} - sel.selStart = nonJavaStart; - sel.selEnd = nonJavaEnd; + return new TextSelection(doc, nonJavaStart, length); } else { - try { - sel.selText = doc.get(actualStart, length); - } catch (BadLocationException e) {} - sel.selStart = actualStart; - sel.selEnd = actualStart + length; + return new TextSelection(doc, actualStart, length); } } else { // otherwise use the non-java identifier parts as boundaries for the selection - try { - sel.selText = doc.get(nonJavaStart, (nonJavaEnd - nonJavaStart)); - } catch (BadLocationException e) {} - sel.selStart = nonJavaStart; - sel.selEnd = nonJavaEnd; + return new TextSelection(doc, nonJavaStart, nonJavaEnd - nonJavaStart); } - - return sel; } private int getOperatorActualEnd(IDocument doc, int index) { @@ -507,22 +488,15 @@ public class SelectionParseAction extends Action { * Return the selected string from the editor * @return The string currently selected, or null if there is no valid selection */ - protected SelSearchNode getSelection( ITextSelection textSelection ) { + protected ITextSelection getSelection( ITextSelection textSelection ) { if( textSelection == null ) return null; - String seltext = textSelection.getText(); - SelSearchNode sel = null; - if ( seltext == null || seltext.length() == 0 ) { - int selStart = textSelection.getOffset(); - sel = getSelection(selStart); + if (textSelection.getLength() == 0) { + return getSelection(textSelection.getOffset()); } else { - sel = new SelSearchNode(); - sel.selText= seltext; - sel.selStart = textSelection.getOffset(); - sel.selEnd = textSelection.getOffset() + textSelection.getLength(); + return textSelection; } - return sel; } protected ISelection getSelection() { @@ -534,13 +508,7 @@ public class SelectionParseAction extends Action { return sel; } - protected class SelSearchNode{ - public String selText; - public int selStart; - public int selEnd; - } - - protected SelSearchNode getSelectedStringFromEditor() { + protected ITextSelection getSelectedStringFromEditor() { ISelection selection = getSelection(); if( selection == null || !(selection instanceof ITextSelection) ) return null;