Search in sources :

Example 51 with IEditorInput

use of org.eclipse.ui.IEditorInput in project eclipse.platform.text by eclipse.

the class MarkerRulerAction method getResource.

/**
 * Returns the resource for which to create the marker,
 * or <code>null</code> if there is no applicable resource.
 *
 * @return the resource for which to create the marker or <code>null</code>
 */
protected IResource getResource() {
    IEditorInput input = fTextEditor.getEditorInput();
    IResource resource = input.getAdapter(IFile.class);
    if (resource == null)
        resource = input.getAdapter(IResource.class);
    return resource;
}
Also used : IEditorInput(org.eclipse.ui.IEditorInput) IResource(org.eclipse.core.resources.IResource)

Example 52 with IEditorInput

use of org.eclipse.ui.IEditorInput in project eclipse.platform.text by eclipse.

the class SelectMarkerRulerAction method gotoMarker.

private void gotoMarker(IMarker marker) {
    // Use the provided adapter if any
    IGotoMarker gotoMarkerAdapter = fTextEditor.getAdapter(IGotoMarker.class);
    if (gotoMarkerAdapter != null) {
        gotoMarkerAdapter.gotoMarker(marker);
        return;
    }
    int start = MarkerUtilities.getCharStart(marker);
    int end = MarkerUtilities.getCharEnd(marker);
    boolean selectLine = start < 0 || end < 0;
    IDocumentProvider documentProvider = fTextEditor.getDocumentProvider();
    IEditorInput editorInput = fTextEditor.getEditorInput();
    // look up the current range of the marker when the document has been edited
    IAnnotationModel model = documentProvider.getAnnotationModel(editorInput);
    if (model instanceof AbstractMarkerAnnotationModel) {
        AbstractMarkerAnnotationModel markerModel = (AbstractMarkerAnnotationModel) model;
        Position pos = markerModel.getMarkerPosition(marker);
        if (pos != null && !pos.isDeleted()) {
            // use position instead of marker values
            start = pos.getOffset();
            end = pos.getOffset() + pos.getLength();
        }
        if (pos != null && pos.isDeleted()) {
            // do nothing if position has been deleted
            return;
        }
    }
    IDocument document = documentProvider.getDocument(editorInput);
    if (selectLine) {
        int line;
        try {
            if (start >= 0)
                line = document.getLineOfOffset(start);
            else {
                line = MarkerUtilities.getLineNumber(marker);
                // Marker line numbers are 1-based
                --line;
            }
            end = start + document.getLineLength(line) - 1;
        } catch (BadLocationException e) {
            return;
        }
    }
    int length = document.getLength();
    if (end - 1 < length && start < length)
        fTextEditor.selectAndReveal(start, end - start);
}
Also used : Position(org.eclipse.jface.text.Position) IGotoMarker(org.eclipse.ui.ide.IGotoMarker) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IEditorInput(org.eclipse.ui.IEditorInput) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 53 with IEditorInput

use of org.eclipse.ui.IEditorInput in project eclipse.platform.text by eclipse.

the class SpellingProblem method removeAllInActiveEditor.

/**
 * Removes all spelling problems that are reported
 * for the given <code>word</code> in the active editor.
 * <p>
 * <em>This a workaround to fix bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=134338
 * for 3.2 at the time where spelling still resides in JDT Text.
 * Once we move the spell check engine along with its quick fixes
 * down to Platform Text we need to provide the proposals with
 * a way to access the annotation model.</em>
 * </p>
 *
 * @param editor the text editor, if <code>null</code> this method does nothing
 * @param word the word for which to remove the problems or <code>null</code> to remove all
 * @since 3.3
 * @deprecated As of 3.4, replaced by {@link #removeAll(ISourceViewer, String)}
 */
@Deprecated
public static void removeAllInActiveEditor(ITextEditor editor, String word) {
    if (editor == null)
        return;
    IDocumentProvider documentProvider = editor.getDocumentProvider();
    if (documentProvider == null)
        return;
    IEditorInput editorInput = editor.getEditorInput();
    if (editorInput == null)
        return;
    IAnnotationModel model = documentProvider.getAnnotationModel(editorInput);
    if (model == null)
        return;
    IDocument document = documentProvider.getDocument(editorInput);
    if (document == null)
        return;
    boolean supportsBatchReplace = (model instanceof IAnnotationModelExtension);
    List<Annotation> toBeRemovedAnnotations = new ArrayList<>();
    Iterator<Annotation> iter = model.getAnnotationIterator();
    while (iter.hasNext()) {
        Annotation annotation = iter.next();
        if (SpellingAnnotation.TYPE.equals(annotation.getType())) {
            boolean doRemove = word == null;
            if (word == null)
                doRemove = true;
            else {
                String annotationWord = null;
                Position pos = model.getPosition(annotation);
                try {
                    annotationWord = document.get(pos.getOffset(), pos.getLength());
                } catch (BadLocationException e) {
                    continue;
                }
                doRemove = word.equals(annotationWord);
            }
            if (doRemove) {
                if (supportsBatchReplace)
                    toBeRemovedAnnotations.add(annotation);
                else
                    model.removeAnnotation(annotation);
            }
        }
    }
    if (supportsBatchReplace && !toBeRemovedAnnotations.isEmpty()) {
        Annotation[] annotationArray = toBeRemovedAnnotations.toArray(new Annotation[toBeRemovedAnnotations.size()]);
        ((IAnnotationModelExtension) model).replaceAnnotations(annotationArray, null);
    }
}
Also used : Position(org.eclipse.jface.text.Position) ArrayList(java.util.ArrayList) IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) Annotation(org.eclipse.jface.text.source.Annotation) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IEditorInput(org.eclipse.ui.IEditorInput) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 54 with IEditorInput

use of org.eclipse.ui.IEditorInput in project eclipse.platform.text by eclipse.

the class UntitledTextFileWizard method performFinish.

@Override
public boolean performFinish() {
    IFileStore fileStore = queryFileStore();
    IEditorInput input = createEditorInput(fileStore);
    String editorId = getEditorId(fileStore);
    IWorkbenchPage page = fWindow.getActivePage();
    try {
        page.openEditor(input, editorId);
    } catch (PartInitException e) {
        EditorsPlugin.log(e);
        return false;
    }
    return true;
}
Also used : IFileStore(org.eclipse.core.filesystem.IFileStore) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput)

Example 55 with IEditorInput

use of org.eclipse.ui.IEditorInput in project eclipse.platform.text by eclipse.

the class AbstractDecoratedTextEditor method handleEditorInputChanged.

@Override
protected void handleEditorInputChanged() {
    final IDocumentProvider provider = getDocumentProvider();
    IEditorInput input = getEditorInput();
    if (provider != null && input != null) {
        if (!isDirty() && input.getAdapter(IFile.class) != null) {
            if (Platform.getPreferencesService().getBoolean(ResourcesPlugin.PI_RESOURCES, ResourcesPlugin.PREF_LIGHTWEIGHT_AUTO_REFRESH, false, null))
                return;
        }
    }
    super.handleEditorInputChanged();
}
Also used : IEditorInput(org.eclipse.ui.IEditorInput) IURIEditorInput(org.eclipse.ui.IURIEditorInput)

Aggregations

IEditorInput (org.eclipse.ui.IEditorInput)135 IFile (org.eclipse.core.resources.IFile)38 IEditorPart (org.eclipse.ui.IEditorPart)37 PartInitException (org.eclipse.ui.PartInitException)31 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)28 CoreException (org.eclipse.core.runtime.CoreException)25 IFileEditorInput (org.eclipse.ui.IFileEditorInput)22 IDocument (org.eclipse.jface.text.IDocument)17 IEditorReference (org.eclipse.ui.IEditorReference)17 FileEditorInput (org.eclipse.ui.part.FileEditorInput)16 File (java.io.File)14 ArrayList (java.util.ArrayList)14 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)14 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)14 IResource (org.eclipse.core.resources.IResource)13 Shell (org.eclipse.swt.widgets.Shell)13 IViewPart (org.eclipse.ui.IViewPart)13 IPath (org.eclipse.core.runtime.IPath)12 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)12 FileStoreEditorInput (org.eclipse.ui.ide.FileStoreEditorInput)11