private ITextSelection getTextSelection(XtextEditor activeXtextEditor) { return (ITextSelection) activeXtextEditor.getSelectionProvider().getSelection(); }
private void installSelectionChangedListener() { selectionChangedListener = new ISelectionChangedListener() { public void selectionChanged(final SelectionChangedEvent event) { updateStatusLine(); } }; final ISelectionProvider selectionProvider = getSelectionProvider(); if (selectionProvider instanceof IPostSelectionProvider) { final IPostSelectionProvider postSelectionProvider = (IPostSelectionProvider) selectionProvider; postSelectionProvider.addPostSelectionChangedListener(selectionChangedListener); } else { getSelectionProvider().addSelectionChangedListener(selectionChangedListener); } }
private void uninstallSelectionChangedListener() { ISelectionProvider selectionProvider = getSelectionProvider(); if (selectionProvider != null) { if (selectionProvider instanceof IPostSelectionProvider) { final IPostSelectionProvider postSelectionProvider = (IPostSelectionProvider) selectionProvider; postSelectionProvider.removePostSelectionChangedListener(selectionChangedListener); } else { selectionProvider.removeSelectionChangedListener(selectionChangedListener); } } }
public void disconnect(XtextEditor editor) { ((IPostSelectionProvider) editor.getSelectionProvider()) .removePostSelectionChangedListener(getSelectionChangedListener()); }
public void connect(XtextEditor editor, boolean isMarkOccurrences) { this.editor = editor; ((IPostSelectionProvider) editor.getSelectionProvider()) .addPostSelectionChangedListener(getSelectionChangedListener()); this.isMarkOccurrences = isMarkOccurrences; }
public void setMarkOccurrences(boolean isMarkOccurrences) { this.isMarkOccurrences = isMarkOccurrences; doMarkOccurrences(editor.getSelectionProvider().getSelection()); }
protected void assertState(String string, XtextEditor editor) { int cursor = string.indexOf('|'); assertEquals(string.replace("|", ""), editor.getDocument().get()); ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection(); assertEquals("unexpected cursor position:",cursor, selection.getOffset()); }
protected void assertState(String string, XtextEditor editor) { int cursor = string.indexOf('|'); assertEquals(string.replace("|", ""), editor.getDocument().get()); ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection(); assertEquals("unexpected cursor position:",cursor, selection.getOffset()); }
public Object execute(ExecutionEvent event) throws ExecutionException { try { XtextEditor editor = EditorUtils.getActiveXtextEditor(event); if (editor != null) { final ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection(); editor.getDocument().readOnly(new IUnitOfWork.Void<XtextResource>() { @Override public void process(XtextResource state) throws Exception { EObject target = eObjectAtOffsetHelper.resolveElementAt(state, selection.getOffset()); findReferences(target); } }); } } catch (Exception e) { LOG.error(Messages.FindReferencesHandler_3, e); } return null; }
protected void assertState(XtextEditor editor, String string) { int cursor = string.indexOf('|'); assertEquals(string.replace("|", ""), editor.getDocument().get()); ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection(); assertEquals("unexpected cursor position:",cursor, selection.getOffset()); }
protected void assertState(String string, XtextEditor editor) { int cursor = string.indexOf('|'); assertEquals(string.replace("|", ""), editor.getDocument().get()); ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection(); assertEquals("unexpected cursor position:",cursor, selection.getOffset()); }
protected void selectText(XtextEditor editor,int relativeToCurrentOffset,int length) throws Exception { ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection(); editor.getInternalSourceViewer().setSelectedRange(selection.getOffset()+relativeToCurrentOffset, length); }
protected void selectText(XtextEditor editor,int relativeToCurrentOffset,int length) throws Exception { ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection(); editor.getInternalSourceViewer().setSelectedRange(selection.getOffset()+relativeToCurrentOffset, length); }
@Override public void run() { ITextSelection selection = (ITextSelection) xtextEditor.getSelectionProvider().getSelection(); ITextRegion currentEditorSelection = new TextRegion(selection.getOffset(), selection.getLength()); ITextRegion nextSelection = xtextEditor.getDocument().readOnly(createTextSelectionWork(currentEditorSelection)); if (nextSelection == null || nextSelection == ITextRegion.EMPTY_REGION || nextSelection.equals(currentEditorSelection)) { return; } xtextEditor.selectAndReveal(nextSelection.getOffset(), nextSelection.getLength()); }
protected void updateStatusLine() { final ITextSelection selection = (ITextSelection) getSelectionProvider().getSelection(); final Annotation annotation = getAnnotation(selection.getOffset(), selection.getLength()); String message = null; if (annotation != null) { updateMarkerViews(annotation); if (isProblemMarkerAnnotation(annotation)) { message = annotation.getText(); } } setStatusLineMessage(message); }
public Object execute(ExecutionEvent event) throws ExecutionException { XtextEditor xtextEditor = EditorUtils.getActiveXtextEditor(event); if (xtextEditor != null) { ITextSelection selection = (ITextSelection) xtextEditor.getSelectionProvider().getSelection(); IRegion region = new Region(selection.getOffset(), selection.getLength()); ISourceViewer internalSourceViewer = xtextEditor.getInternalSourceViewer(); IHyperlink[] hyperlinks = getDetector().detectHyperlinks(internalSourceViewer, region, false); if (hyperlinks != null && hyperlinks.length > 0) { IHyperlink hyperlink = hyperlinks[0]; hyperlink.open(); } } return null; }
if (editor != null) { syncUtil.totalSync(preferences.isSaveAllBeforeRefactoring(), renameRefactoringController.getActiveLinkedMode() == null); final ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection(); IRenameElementContext renameElementContext = editor.getDocument().readOnly( new IUnitOfWork<IRenameElementContext, XtextResource>() {
@Override public void run() { IXtextDocument document = editor.getDocument(); ISelection selection = editor.getSelectionProvider().getSelection(); if (selection instanceof TextSelection) { TextSelection textSelection = (TextSelection) selection; if (textSelection.getLength()==0) { IRegion region = matcher.match(document, textSelection.getOffset()); if (region != null) { if (region.getOffset()+1==textSelection.getOffset()) { editor.selectAndReveal(region.getOffset()+region.getLength(),0); } else { editor.selectAndReveal(region.getOffset()+1,0); } } } } }
@Override public void launch(IEditorPart editor, String mode) { final XtextEditor xtextEditor = EditorUtils.getXtextEditor(editor); final ISelection selection = xtextEditor.getSelectionProvider().getSelection(); if (selection instanceof ITextSelection) { final ITextSelection sel = (ITextSelection) selection; final EObject obj = xtextEditor.getDocument().readOnly(resource -> { final IParseResult parseRes = resource.getParseResult(); if (parseRes == null) { return null; } final ICompositeNode rootNode = parseRes.getRootNode(); final ILeafNode node = NodeModelUtils.findLeafNodeAtOffset(rootNode, sel.getOffset()); return NodeModelUtils.findActualSemanticObjectFor(node); }); if (obj != null) { final EObject elt = EcoreUtil2.getContainerOfType(obj, getValidEObjectType()); if (elt != null) { searchAndLaunch(mode, elt); return; } } } else if (selection != null) { launch(selection, mode); return; } // Default launching searchAndLaunch(mode, xtextEditor.getResource()); }