use of org.eclipse.jface.text.TextSelection in project abstools by abstools.
the class UtilityFunctions method jumpToPosition.
public static boolean jumpToPosition(IProject project, EditorPosition pos) {
ABSEditor targeteditor = UtilityFunctions.openABSEditorForFile(pos.getPath(), project);
if (targeteditor == null) {
return false;
}
IDocument doc = targeteditor.getDocumentProvider().getDocument(targeteditor.getEditorInput());
try {
int startoff = doc.getLineOffset(pos.getLinestart() - 1) + pos.getColstart() - 1;
targeteditor.getSelectionProvider().setSelection(new TextSelection(startoff, 0));
return true;
} catch (BadLocationException ex) {
Activator.logException(ex);
return false;
}
}
use of org.eclipse.jface.text.TextSelection in project abstools by abstools.
the class NewABSFileWizard method insertModuleDeclaration.
/**
* If the original selection
* @param targeteditor
* @throws BadLocationException
*/
private void insertModuleDeclaration(ABSEditor targeteditor) throws BadLocationException {
IDocument doc = targeteditor.getDocumentProvider().getDocument(targeteditor.getEditorInput());
ModulePath mp = getLastModulePathElement(selection);
if (mp != null) {
doc.replace(0, 0, "module " + mp.getModulePath() + ".");
targeteditor.getSelectionProvider().setSelection(new TextSelection(8 + mp.getModulePath().length(), 0));
} else {
doc.replace(0, 0, "module ");
targeteditor.getSelectionProvider().setSelection(new TextSelection(7, 0));
}
}
use of org.eclipse.jface.text.TextSelection in project ch.hsr.ifs.cdttesting by IFS-HSR.
the class Select method setInput.
@Override
public void setInput(final int from, final int to) {
boolean editorAreaVisible = window.getActivePage().isEditorAreaVisible();
IEditorPart activeEditor = window.getActivePage().getActiveEditor();
if (editorAreaVisible && activeEditor instanceof ITextEditor) {
ITextEditor editor = (ITextEditor) activeEditor;
editor.getSelectionProvider().setSelection(new TextSelection(from, to - from));
}
}
use of org.eclipse.jface.text.TextSelection in project ch.hsr.ifs.cdttesting by IFS-HSR.
the class ASTWidget method createNode.
private Node<Pair<Button, IASTNode>> createNode(final Button button, final IASTNode astNode) {
final Node<Pair<Button, IASTNode>> node = new Node<>(new Pair<>(button, astNode));
final Point minButtonSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
nodeHeight = Math.max(nodeHeight, minButtonSize.y);
node.setWidth(minButtonSize.x);
node.treatAsLeaf(true);
if (astNode instanceof ICPPASTTranslationUnit) {
button.setBackground(GOLDEN_YELLOW);
button.getFont().getFontData()[0].setStyle(SWT.BOLD);
}
button.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(final MouseEvent e) {
int selectKey = 0;
if (prefStore.getString(PreferenceConstants.P_HOW_TO_SELECT).equals(PreferenceConstants.P_SELECT_BY_RIGHT_CLICK)) {
selectKey = 3;
} else if (prefStore.getString(PreferenceConstants.P_HOW_TO_SELECT).equals(PreferenceConstants.P_SELECT_BY_LEFT_CLICK)) {
selectKey = 1;
}
if (e.button == selectKey) {
setNodeInNodeView(astNode);
}
if (e.button == 1) {
buildChildrenAndRefresh(node);
}
}
});
button.addMouseTrackListener(new MouseTrackListener() {
@Override
public void mouseHover(final MouseEvent e) {
if (prefStore.getString(PreferenceConstants.P_HOW_TO_SELECT).equals(PreferenceConstants.P_SELECT_BY_MOUSE_OVER)) {
setNodeInNodeView(astNode);
}
IASTFileLocation fileLocation = astNode.getFileLocation();
while (fileLocation.getContextInclusionStatement() != null) {
final IASTPreprocessorIncludeStatement contextInclusionStatement = fileLocation.getContextInclusionStatement();
fileLocation = contextInclusionStatement.getFileLocation();
}
final TextSelection textSelection = new TextSelection(fileLocation.getNodeOffset(), fileLocation.getNodeLength());
CUIPlugin.getActivePage().getActiveEditor().getEditorSite().getSelectionProvider().setSelection(textSelection);
}
@Override
public void mouseExit(final MouseEvent e) {
}
@Override
public void mouseEnter(final MouseEvent e) {
}
});
return node;
}
use of org.eclipse.jface.text.TextSelection in project webtools.sourceediting by eclipse.
the class StructuredSelectNextXMLHandler method getNewSelectionRegion2.
/**
* This method was separated out from getNewSelectionRegion2 because the
* code in here is allowed to be called recursively.
*
* @param indexedRegion
* @param textSelection
* @return new region to select or null if none
*/
private Region getNewSelectionRegion2(IndexedRegion indexedRegion, ITextSelection textSelection) {
Region newRegion = null;
if (indexedRegion instanceof Node) {
Node node = (Node) indexedRegion;
Node newNode = node.getNextSibling();
if (newNode == null) {
newNode = node.getParentNode();
if (newNode instanceof IndexedRegion) {
IndexedRegion newIndexedRegion = (IndexedRegion) newNode;
newRegion = new Region(newIndexedRegion.getStartOffset(), newIndexedRegion.getEndOffset() - newIndexedRegion.getStartOffset());
}
} else {
if (newNode instanceof IndexedRegion) {
IndexedRegion newIndexedRegion = (IndexedRegion) newNode;
newRegion = new Region(textSelection.getOffset(), newIndexedRegion.getEndOffset() - textSelection.getOffset());
if (newNode.getNodeType() == Node.TEXT_NODE) {
newRegion = getNewSelectionRegion2(newIndexedRegion, new TextSelection(newRegion.getOffset(), newRegion.getLength()));
}
}
}
}
return newRegion;
}
Aggregations