1
0
Fork 0
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:
Alain Magloire 2003-04-17 16:55:46 +00:00
parent 680f26d375
commit 49b2c967a1

View file

@ -14,8 +14,10 @@ import java.util.StringTokenizer;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel; 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.ISourceRange;
import org.eclipse.cdt.core.model.ISourceReference; 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.IContextMenuConstants;
import org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration; import org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration;
import org.eclipse.cdt.internal.ui.text.CTextTools; 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 selection to the source range. Optionally
* sets the current editor position. * 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. * @param moveCursor if true the editor is scrolled to show the range.
*/ */
public void setSelection(ISourceRange element, boolean moveCursor) { public void setSelection(ISourceRange element, boolean moveCursor) {
if (element != null) {
if (element == null) {
return;
}
try { try {
IRegion alternateRegion = null; IRegion alternateRegion = null;
int start= element.getStartPos(); int start= element.getStartPos();
@ -624,11 +661,9 @@ public class CEditor extends TextEditor implements ISelectionChangedListener {
updateStatusField(CTextEditorActionConstants.STATUS_CURSOR_POS); updateStatusField(CTextEditorActionConstants.STATUS_CURSOR_POS);
} }
return; return;
} catch (IllegalArgumentException x) { } catch (IllegalArgumentException x) {
} catch (BadLocationException e ) { } catch (BadLocationException e ) {
} }
}
if (moveCursor) if (moveCursor)
resetHighlightRange(); resetHighlightRange();