1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

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.

This commit is contained in:
Doug Schaefer 2006-05-28 00:05:41 +00:00
parent 7626fb1115
commit 090476da2d
4 changed files with 21 additions and 50 deletions

View file

@ -43,6 +43,7 @@ public abstract class FindAction extends SelectionParseAction {
if (object instanceof ISourceReference) if (object instanceof ISourceReference)
searchJob = new PDOMSearchElementQuery(getScope(), (ISourceReference)object, getLimitTo()); searchJob = new PDOMSearchElementQuery(getScope(), (ISourceReference)object, getLimitTo());
} else if (selection instanceof ITextSelection) { } else if (selection instanceof ITextSelection) {
ITextSelection selNode = getSelection((ITextSelection)selection);
ICElement element = fEditor.getInputCElement(); ICElement element = fEditor.getInputCElement();
while (element != null && !(element instanceof ITranslationUnit)) while (element != null && !(element instanceof ITranslationUnit))
element = element.getParent(); element = element.getParent();
@ -50,7 +51,7 @@ public abstract class FindAction extends SelectionParseAction {
searchJob = new PDOMSearchTextSelectionQuery( searchJob = new PDOMSearchTextSelectionQuery(
getScope(), getScope(),
(ITranslationUnit)element, (ITranslationUnit)element,
(ITextSelection)selection, selNode,
getLimitTo()); getLimitTo());
} }
} }

View file

@ -27,11 +27,12 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Display;
public class OpenDeclarationsAction extends SelectionParseAction { public class OpenDeclarationsAction extends SelectionParseAction {
public static final IASTName[] BLANK_NAME_ARRAY = new IASTName[0]; public static final IASTName[] BLANK_NAME_ARRAY = new IASTName[0];
SelSearchNode selNode; ITextSelection selNode;
/** /**
* Creates a new action with the given editor * Creates a new action with the given editor
@ -50,8 +51,8 @@ public class OpenDeclarationsAction extends SelectionParseAction {
protected IStatus run(IProgressMonitor monitor) { protected IStatus run(IProgressMonitor monitor) {
try { try {
int selectionStart = selNode.selStart; int selectionStart = selNode.getOffset();
int selectionLength = selNode.selEnd - selNode.selStart; int selectionLength = selNode.getLength();
IWorkingCopy workingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(fEditor.getEditorInput()); IWorkingCopy workingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(fEditor.getEditorInput());
if (workingCopy == null) if (workingCopy == null)

View file

@ -23,6 +23,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Display;
/** /**
@ -33,7 +34,7 @@ import org.eclipse.swt.widgets.Display;
public class OpenDefinitionAction extends SelectionParseAction { public class OpenDefinitionAction extends SelectionParseAction {
public static final IASTName[] BLANK_NAME_ARRAY = new IASTName[0]; public static final IASTName[] BLANK_NAME_ARRAY = new IASTName[0];
SelSearchNode selNode; ITextSelection selNode;
/** /**
* Creates a new action with the given editor * Creates a new action with the given editor
@ -52,8 +53,8 @@ public class OpenDefinitionAction extends SelectionParseAction {
protected IStatus run(IProgressMonitor monitor) { protected IStatus run(IProgressMonitor monitor) {
try { try {
int selectionStart = selNode.selStart; int selectionStart = selNode.getOffset();
int selectionLength = selNode.selEnd - selNode.selStart; int selectionLength = selNode.getLength();
IWorkingCopy workingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(fEditor.getEditorInput()); IWorkingCopy workingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(fEditor.getEditorInput());
if (workingCopy == null) if (workingCopy == null)

View file

@ -48,6 +48,7 @@ import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelection;
import org.eclipse.search.ui.NewSearchUI; import org.eclipse.search.ui.NewSearchUI;
import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorInput;
@ -185,7 +186,7 @@ public class SelectionParseAction extends Action {
} }
//TODO: Change this to work with qualified identifiers //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; IDocumentProvider prov = ( fEditor != null ) ? fEditor.getDocumentProvider() : null;
IDocument doc = ( prov != null ) ? prov.getDocument(fEditor.getEditorInput()) : null; IDocument doc = ( prov != null ) ? prov.getDocument(fEditor.getEditorInput()) : null;
@ -233,8 +234,6 @@ public class SelectionParseAction extends Action {
catch(BadLocationException e){ catch(BadLocationException e){
} }
SelSearchNode sel = new SelSearchNode();
boolean selectedOperator=false; boolean selectedOperator=false;
if (selectedWord != null && selectedWord.indexOf(OPERATOR) >= 0 && fPos >= fStartPos + selectedWord.indexOf(OPERATOR) && fPos < fStartPos + selectedWord.indexOf(OPERATOR) + OPERATOR.length()) { if (selectedWord != null && selectedWord.indexOf(OPERATOR) >= 0 && fPos >= fStartPos + selectedWord.indexOf(OPERATOR) && fPos < fStartPos + selectedWord.indexOf(OPERATOR) + OPERATOR.length()) {
selectedOperator=true; selectedOperator=true;
@ -248,11 +247,7 @@ public class SelectionParseAction extends Action {
actualEnd=(actualEnd>0?actualEnd:fEndPos); actualEnd=(actualEnd>0?actualEnd:fEndPos);
try { return new TextSelection(doc, actualStart, actualEnd - actualStart);
sel.selText = doc.get(actualStart, actualEnd - actualStart);
} catch (BadLocationException e) {}
sel.selStart = actualStart;
sel.selEnd = actualEnd;
// TODO Devin this only works for definitions of destructors right now // 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 // 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))) { } 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 the cursor is after the destructor name then use the regular boundaries
if (fPos >= actualStart + length) { if (fPos >= actualStart + length) {
try { return new TextSelection(doc, nonJavaStart, length);
sel.selText = doc.get(nonJavaStart, (nonJavaEnd - nonJavaStart));
} catch (BadLocationException e) {}
sel.selStart = nonJavaStart;
sel.selEnd = nonJavaEnd;
} else { } else {
try { return new TextSelection(doc, actualStart, length);
sel.selText = doc.get(actualStart, length);
} catch (BadLocationException e) {}
sel.selStart = actualStart;
sel.selEnd = actualStart + length;
} }
} else { } else {
// otherwise use the non-java identifier parts as boundaries for the selection // otherwise use the non-java identifier parts as boundaries for the selection
try { return new TextSelection(doc, nonJavaStart, nonJavaEnd - nonJavaStart);
sel.selText = doc.get(nonJavaStart, (nonJavaEnd - nonJavaStart));
} catch (BadLocationException e) {}
sel.selStart = nonJavaStart;
sel.selEnd = nonJavaEnd;
} }
return sel;
} }
private int getOperatorActualEnd(IDocument doc, int index) { 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 selected string from the editor
* @return The string currently selected, or null if there is no valid selection * @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 ) if( textSelection == null )
return null; return null;
String seltext = textSelection.getText(); if (textSelection.getLength() == 0) {
SelSearchNode sel = null; return getSelection(textSelection.getOffset());
if ( seltext == null || seltext.length() == 0 ) {
int selStart = textSelection.getOffset();
sel = getSelection(selStart);
} else { } else {
sel = new SelSearchNode(); return textSelection;
sel.selText= seltext;
sel.selStart = textSelection.getOffset();
sel.selEnd = textSelection.getOffset() + textSelection.getLength();
} }
return sel;
} }
protected ISelection getSelection() { protected ISelection getSelection() {
@ -534,13 +508,7 @@ public class SelectionParseAction extends Action {
return sel; return sel;
} }
protected class SelSearchNode{ protected ITextSelection getSelectedStringFromEditor() {
public String selText;
public int selStart;
public int selEnd;
}
protected SelSearchNode getSelectedStringFromEditor() {
ISelection selection = getSelection(); ISelection selection = getSelection();
if( selection == null || !(selection instanceof ITextSelection) ) if( selection == null || !(selection instanceof ITextSelection) )
return null; return null;