mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
new setSelection(ICElement) method
This commit is contained in:
parent
680f26d375
commit
49b2c967a1
1 changed files with 77 additions and 42 deletions
|
@ -14,8 +14,10 @@ import java.util.StringTokenizer;
|
|||
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ISourceRange;
|
||||
import org.eclipse.cdt.core.model.ISourceReference;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.internal.ui.IContextMenuConstants;
|
||||
import org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration;
|
||||
import org.eclipse.cdt.internal.ui.text.CTextTools;
|
||||
|
@ -578,6 +580,37 @@ public class CEditor extends TextEditor implements ISelectionChangedListener {
|
|||
}
|
||||
}
|
||||
|
||||
public void setSelection(ICElement element) {
|
||||
|
||||
if (element == null || element instanceof ITranslationUnit) {
|
||||
/*
|
||||
* If the element is an ITranslationUnit this unit is either the input
|
||||
* of this editor or not being displayed. In both cases, nothing should
|
||||
* happened.
|
||||
*/
|
||||
return;
|
||||
} if (element instanceof ISourceReference) {
|
||||
ISourceReference reference= (ISourceReference) element;
|
||||
// set hightlight range
|
||||
setSelection(reference, true);
|
||||
// set outliner selection
|
||||
//if (fOutlinePage != null) {
|
||||
// fOutlinePage.removeSelectionChangedListener(fSelectionChangedListener);
|
||||
// fOutlinePage.select(reference);
|
||||
// fOutlinePage.addSelectionChangedListener(fSelectionChangedListener);
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
public void setSelection(ISourceReference element, boolean moveCursor) {
|
||||
if (element != null) {
|
||||
try {
|
||||
setSelection(element.getSourceRange(), moveCursor);
|
||||
} catch (CModelException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current editor selection to the source range. Optionally
|
||||
* sets the current editor position.
|
||||
|
@ -586,7 +619,11 @@ public class CEditor extends TextEditor implements ISelectionChangedListener {
|
|||
* @param moveCursor if true the editor is scrolled to show the range.
|
||||
*/
|
||||
public void setSelection(ISourceRange element, boolean moveCursor) {
|
||||
if (element != null) {
|
||||
|
||||
if (element == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
IRegion alternateRegion = null;
|
||||
int start= element.getStartPos();
|
||||
|
@ -624,11 +661,9 @@ public class CEditor extends TextEditor implements ISelectionChangedListener {
|
|||
updateStatusField(CTextEditorActionConstants.STATUS_CURSOR_POS);
|
||||
}
|
||||
return;
|
||||
|
||||
} catch (IllegalArgumentException x) {
|
||||
} catch (BadLocationException e ) {
|
||||
}
|
||||
}
|
||||
|
||||
if (moveCursor)
|
||||
resetHighlightRange();
|
||||
|
|
Loading…
Add table
Reference in a new issue