public String getCurrentEditorContent() { final IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() .getActiveEditor(); if (!(editor instanceof ITextEditor)) return null; ITextEditor ite = (ITextEditor)editor; IDocument doc = ite.getDocumentProvider().getDocument(ite.getEditorInput()); return doc.get(); }
private void revealLine(ITextEditor editor, int lineNumber) throws BadLocationException { IDocument document= editor.getDocumentProvider().getDocument(editor.getEditorInput()); IRegion region= document.getLineInformation(lineNumber - 1); editor.selectAndReveal(region.getOffset(), 0); }
/** * Creates a new instance. * * @param bundle the resource bundle * @param prefix a prefix to be prepended to the various resource keys (described in * <code>ResourceAction</code> constructor), or <code>null</code> if none * @param editor the text editor */ public AddBlockCommentAction(ResourceBundle bundle, String prefix, ITextEditor editor) { super(bundle, prefix, editor); action= editor.getAction("Format"); //$NON-NLS-1$ }
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); ITextEditor editor = (ITextEditor) page.getActiveEditor(); IJavaElement elem = JavaUI.getEditorInputJavaElement(editor.getEditorInput()); if (elem instanceof ICompilationUnit) { ITextSelection sel = (ITextSelection) editor.getSelectionProvider().getSelection(); IJavaElement selected = ((ICompilationUnit) elem).getElementAt(sel.getOffset()); if (selected != null && selected.getElementType() == IJavaElement.METHOD) { return (IMethod) selected; } } return null;
private boolean computeEnablement(ITextEditor editor) { if (editor == null) return false; ITextOperationTarget target= editor.getAdapter(ITextOperationTarget.class); if (target == null || ! target.canDoOperation(ISourceViewer.CONTENTASSIST_PROPOSALS)) return false; IJavaProject javaProject = EditorUtility.getJavaProject(editor.getEditorInput()); if (! fCategory.matches(javaProject)) return false; ISelection selection= editor.getSelectionProvider().getSelection(); return isValidSelection(selection); }
protected void reveal(ITextEditor textEditor) { if (fRange != null) { textEditor.selectAndReveal(fRange.getOffset(), fRange.getLength()); } }
public RefreshEditorAction(ITextEditor textEditor) { super(textEditor.getSite()); fTextEditor= textEditor; update(); }
void method (String text) { IEditorPart part = Workbench.getInstance().getWorkbenchWindows()[0].getActivePage().getActiveEditor(); IEditorInput editorInput = part.getEditorInput(); if (part instanceof ITextEditor) { ITextEditor textEditor = (ITextEditor) part; IDocument doc = textEditor.getDocumentProvider().getDocument(editorInput); ITextSelection sel = textEditor.getSelectionProvider().getSelection(); doc.replace(sel.getOffset(), sel.getLength(), text); } }
/** * Returns the encoding support of the action's editor. * * @return the encoding support of the action's editor or <code>null</code> if none */ private IEncodingSupport getEncodingSupport() { ITextEditor editor= getTextEditor(); if (editor != null) return editor.getAdapter(IEncodingSupport.class); return null; }
@Override public void runWithEvent(Event event) { if (fIsEditable) { ITextOperationTarget operation = fTextEditor.getAdapter(ITextOperationTarget.class); final int opCode = ISourceViewer.QUICK_ASSIST; if (operation != null && operation.canDoOperation(opCode)) { fTextEditor.selectAndReveal(fPosition.getOffset(), fPosition.getLength()); operation.doOperation(opCode); } return; } super.run(); }
public void uninstall(ISelectionListenerWithAST listener) { fAstListeners.remove(listener); if (isEmpty()) { fPart.getEditorSite().getPage().removePostSelectionListener(fPostSelectionListener); ISelectionProvider selectionProvider= fPart.getSelectionProvider(); if (selectionProvider != null) selectionProvider.removeSelectionChangedListener(fSelectionListener); } }
private boolean computeEnablement(ITextEditor editor) { if (editor == null) return false; ITextOperationTarget target= (ITextOperationTarget) editor.getAdapter(ITextOperationTarget.class); boolean hasContentAssist= target != null && target.canDoOperation(ISourceViewer.CONTENTASSIST_PROPOSALS); if (!hasContentAssist) return false; ISelection selection= editor.getSelectionProvider().getSelection(); return isValidSelection(selection); }
/** * Returns the editor's selection provider. * * @return the editor's selection provider or <code>null</code> */ private ISelectionProvider getSelectionProvider() { ITextEditor editor= getTextEditor(); if (editor != null) { return editor.getSelectionProvider(); } return null; }
/** * Ensures that the editor is modifyable. If the editor is an instance of * <code>ITextEditorExtension2</code>, its <code>validateEditorInputState</code> method * is called, otherwise, the result of <code>isEditable</code> is returned. * * @param editor the editor to be checked * @return <code>true</code> if the editor is editable, <code>false</code> otherwise */ protected boolean ensureEditable(ITextEditor editor) { Assert.isNotNull(editor); if (editor instanceof ITextEditorExtension2) { ITextEditorExtension2 ext= (ITextEditorExtension2) editor; return ext.validateEditorInputState(); } return editor.isEditable(); }
private boolean computeEnablement(ITextEditor editor) { if (editor == null) return false; ITextOperationTarget target= editor.getAdapter(ITextOperationTarget.class); if (target == null || ! target.canDoOperation(ISourceViewer.CONTENTASSIST_PROPOSALS)) return false; IJavaProject javaProject = EditorUtility.getJavaProject(editor.getEditorInput()); if (! fCategory.matches(javaProject)) return false; ISelection selection= editor.getSelectionProvider().getSelection(); return isValidSelection(selection); }
/** * Restores this location. */ public void restoreLocation() { if (fPosition == null || fPosition.isDeleted) return; IEditorPart part= getEditorPart(); if (part instanceof ITextEditor) { ITextEditor editor= (ITextEditor) getEditorPart(); editor.selectAndReveal(fPosition.offset, fPosition.length); } }
private Shell getShell() { ITextEditor editor= getTextEditor(); if (editor != null) { IWorkbenchPartSite site= editor.getSite(); Shell shell= site.getShell(); if (shell != null && !shell.isDisposed()) { return shell; } } return null; }
ITextEditor editor = (ITextEditor) HandlerUtil.getActiveEditor(event); ITextSelection sel = (ITextSelection) editor.getSelectionProvider().getSelection(); ITypeRoot typeRoot = JavaUI.getEditorInputTypeRoot(editor.getEditorInput()); ICompilationUnit icu = (ICompilationUnit) typeRoot.getAdapter(ICompilationUnit.class); CompilationUnit cu = parse(icu); NodeFinder finder = new NodeFinder(cu, sel.getOffset(), sel.getLength()); ASTNode node = finder.getCoveringNode();
/** * Returns the encoding support of the action's editor. * * @return the encoding support of the action's editor or <code>null</code> if none */ private IEncodingSupport getEncodingSupport() { ITextEditor editor= getTextEditor(); if (editor != null) return (IEncodingSupport) editor.getAdapter(IEncodingSupport.class); return null; }