Search in sources :

Example 1 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project KaiZen-OpenAPI-Editor by RepreZen.

the class TextDocumentMarkerResolution method openTextEditor.

protected ITextEditor openTextEditor(IFile file) throws CoreException {
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IEditorPart part;
    try {
        part = IDE.openEditor(page, file, true);
    } catch (PartInitException e) {
        throw new CoreException(createStatus(e, "Cannot open editor"));
    }
    if (!(part instanceof ITextEditor)) {
        throw new CoreException(createStatus(null, "The editor is not TextEditor: " + part));
    }
    return (ITextEditor) part;
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) CoreException(org.eclipse.core.runtime.CoreException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException)

Example 2 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project KaiZen-OpenAPI-Editor by RepreZen.

the class TextDocumentMarkerResolution method run.

public void run(IMarker marker) {
    try {
        IResource resource = marker.getResource();
        if (resource.getType() != IResource.FILE) {
            throw new CoreException(createStatus(null, "The editor is not a File: " + resource.getName()));
        }
        IFile file = (IFile) resource;
        ITextEditor editor = openTextEditor(file);
        IDocument document = editor.getDocumentProvider().getDocument(new FileEditorInput(file));
        if (document == null) {
            throw new CoreException(createStatus(null, "The document is null"));
        }
        IRegion region = processFix(document, marker);
        if (region != null) {
            editor.selectAndReveal(region.getOffset(), region.getLength());
        }
    } catch (CoreException e) {
        Activator.getDefault().getLog().log(e.getStatus());
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) CoreException(org.eclipse.core.runtime.CoreException) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IResource(org.eclipse.core.resources.IResource) IDocument(org.eclipse.jface.text.IDocument) IRegion(org.eclipse.jface.text.IRegion)

Example 3 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project eclipse.platform.text by eclipse.

the class TextEditorActionContributor method doSetActiveEditor.

/**
 * Internally sets the active editor to the actions provided by this contributor.
 * Cannot be overridden by subclasses.
 *
 * @param part the editor
 */
private void doSetActiveEditor(final IEditorPart part) {
    ITextEditor textEditor = null;
    if (part instanceof ITextEditor)
        textEditor = (ITextEditor) part;
    /**
     * The global actions to be connected with editor actions
     */
    IActionBars actionBars = getActionBars();
    actionBars.setGlobalActionHandler(IDEActionFactory.ADD_TASK.getId(), getAction(textEditor, IDEActionFactory.ADD_TASK.getId()));
    actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK.getId(), getAction(textEditor, IDEActionFactory.BOOKMARK.getId()));
    IAction action = getAction(textEditor, ITextEditorActionConstants.NEXT);
    actionBars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_NEXT_ANNOTATION, action);
    actionBars.setGlobalActionHandler(ITextEditorActionConstants.NEXT, action);
    action = getAction(textEditor, ITextEditorActionConstants.PREVIOUS);
    actionBars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_PREVIOUS_ANNOTATION, action);
    actionBars.setGlobalActionHandler(ITextEditorActionConstants.PREVIOUS, action);
    action = getAction(textEditor, ITextEditorActionConstants.REFRESH);
    actionBars.setGlobalActionHandler(ITextEditorActionConstants.REFRESH, action);
    fChangeEncodingAction.setAction(getAction(textEditor, ITextEditorActionConstants.CHANGE_ENCODING));
    IAction quickAssistAction = getAction(textEditor, ITextEditorActionConstants.QUICK_ASSIST);
    fQuickAssistAction.setAction(quickAssistAction);
    if (textEditor == null)
        return;
    // Update Quick Assist menu entry - for now don't show disabled entry
    IMenuManager menuMgr = textEditor.getEditorSite().getActionBars().getMenuManager();
    IMenuManager editMenu = menuMgr.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
    if (editMenu != null) {
        boolean isEnabled = quickAssistAction != null && quickAssistAction.isEnabled();
        fQuickAssistMenuEntry.setVisible(isEnabled);
        editMenu.update(true);
    }
    fRetargetShowInformationAction.setAction(getAction(textEditor, ITextEditorActionConstants.SHOW_INFORMATION));
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IAction(org.eclipse.jface.action.IAction) IMenuManager(org.eclipse.jface.action.IMenuManager) IActionBars(org.eclipse.ui.IActionBars)

Example 4 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project eclipse.platform.text by eclipse.

the class LastSaveReferenceProvider method readDocument.

/**
 * Reads in the saved document into <code>fReference</code>.
 *
 * @param monitor a progress monitor, or <code>null</code>
 * @param force <code>true</code> if the reference document should also
 *        be read if the current document is <code>null</code>,<code>false</code>
 *        if it should only be updated if it already existed.
 */
private void readDocument(IProgressMonitor monitor, boolean force) {
    // protect against concurrent disposal
    IDocumentProvider prov = fDocumentProvider;
    IEditorInput inp = fEditorInput;
    IDocument doc = fReference;
    ITextEditor editor = fEditor;
    if (prov instanceof IStorageDocumentProvider && inp instanceof IStorageEditorInput) {
        IStorageEditorInput input = (IStorageEditorInput) inp;
        IStorageDocumentProvider provider = (IStorageDocumentProvider) prov;
        if (doc == null)
            if (force || fDocumentRead)
                doc = new Document();
            else
                return;
        IJobManager jobMgr = Job.getJobManager();
        try {
            IStorage storage = input.getStorage();
            // check for null for backward compatibility (we used to check before...)
            if (storage == null)
                return;
            fProgressMonitor = monitor;
            ISchedulingRule rule = getSchedulingRule(storage);
            // delay for any other job requiring the lock on file
            try {
                lockDocument(monitor, jobMgr, rule);
                String encoding;
                if (storage instanceof IEncodedStorage)
                    encoding = ((IEncodedStorage) storage).getCharset();
                else
                    encoding = null;
                boolean skipUTF8BOM = isUTF8BOM(encoding, storage);
                setDocumentContent(doc, storage, encoding, monitor, skipUTF8BOM);
            } finally {
                unlockDocument(jobMgr, rule);
                fProgressMonitor = null;
            }
        } catch (CoreException e) {
            return;
        }
        if (monitor != null && monitor.isCanceled())
            return;
        // update state
        synchronized (fLock) {
            if (fDocumentProvider == provider && fEditorInput == input) {
                // only update state if our provider / input pair has not
                // been updated in between (dispose or setActiveEditor)
                fReference = doc;
                fDocumentRead = true;
                addElementStateListener(editor, prov);
            }
        }
    }
}
Also used : IStorageDocumentProvider(org.eclipse.ui.editors.text.IStorageDocumentProvider) IStorageEditorInput(org.eclipse.ui.IStorageEditorInput) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IEncodedStorage(org.eclipse.core.resources.IEncodedStorage) IJobManager(org.eclipse.core.runtime.jobs.IJobManager) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IStorage(org.eclipse.core.resources.IStorage) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) CoreException(org.eclipse.core.runtime.CoreException) IEditorInput(org.eclipse.ui.IEditorInput) IDocument(org.eclipse.jface.text.IDocument)

Example 5 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project eclipse.platform.text by eclipse.

the class QuickDiffRestoreAction method run.

@Override
public void run() {
    ITextEditor editor = getTextEditor();
    if (editor == null || !validateEditorInputState())
        return;
    IRewriteTarget target = editor.getAdapter(IRewriteTarget.class);
    if (target != null)
        target.beginCompoundChange();
    runCompoundChange();
    if (target != null)
        target.endCompoundChange();
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IRewriteTarget(org.eclipse.jface.text.IRewriteTarget)

Aggregations

ITextEditor (org.eclipse.ui.texteditor.ITextEditor)234 IEditorPart (org.eclipse.ui.IEditorPart)92 IDocument (org.eclipse.jface.text.IDocument)73 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)40 IFile (org.eclipse.core.resources.IFile)34 ITextSelection (org.eclipse.jface.text.ITextSelection)34 Test (org.junit.Test)31 BadLocationException (org.eclipse.jface.text.BadLocationException)27 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)25 PartInitException (org.eclipse.ui.PartInitException)23 ISelection (org.eclipse.jface.viewers.ISelection)19 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)17 IRegion (org.eclipse.jface.text.IRegion)16 Annotation (org.eclipse.jface.text.source.Annotation)16 ArrayList (java.util.ArrayList)15 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)15 IResource (org.eclipse.core.resources.IResource)14 IEditorInput (org.eclipse.ui.IEditorInput)14 CoreException (org.eclipse.core.runtime.CoreException)13 IWorkbench (org.eclipse.ui.IWorkbench)12