Search in sources :

Example 1 with AbstractMarkerAnnotationModel

use of org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel in project xtext-eclipse by eclipse.

the class XtextMarkerRulerAction method hasQuickFixableAnnotationInCurrentLine.

protected boolean hasQuickFixableAnnotationInCurrentLine() {
    try {
        AbstractMarkerAnnotationModel annotationModel = getAnnotationModel();
        if (annotationModel == null)
            return false;
        int line = ruler.getLineOfLastMouseButtonActivity();
        IDocument document = getDocument();
        IRegion region = document.getLineInformation(line);
        Iterator<?> iterator = annotationModel.getAnnotationIterator(region.getOffset(), region.getLength(), true, true);
        while (iterator.hasNext()) {
            Object element = iterator.next();
            if (element instanceof XtextAnnotation) {
                XtextAnnotation annotation = (XtextAnnotation) element;
                if (annotation.isQuickFixable())
                    return true;
            } else if (element instanceof MarkerAnnotation) {
                MarkerAnnotation annotation = (MarkerAnnotation) element;
                if (annotation.isQuickFixableStateSet() && annotation.isQuickFixable())
                    return true;
            }
        }
    } catch (BadLocationException e) {
    // Ignore -> false is returned anyway
    }
    return false;
}
Also used : XtextAnnotation(org.eclipse.xtext.ui.editor.validation.XtextAnnotation) MarkerAnnotation(org.eclipse.ui.texteditor.MarkerAnnotation) AbstractMarkerAnnotationModel(org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel) Point(org.eclipse.swt.graphics.Point) IDocument(org.eclipse.jface.text.IDocument) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 2 with AbstractMarkerAnnotationModel

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

the class TextFileDocumentProvider method resetDocument.

@Override
public void resetDocument(Object element) throws CoreException {
    final FileInfo info = fFileInfoMap.get(element);
    if (info != null) {
        DocumentProviderOperation operation = new DocumentProviderOperation() {

            @Override
            protected void execute(IProgressMonitor monitor) throws CoreException {
                info.fTextFileBuffer.revert(monitor);
                if (info.fModel instanceof AbstractMarkerAnnotationModel) {
                    AbstractMarkerAnnotationModel markerModel = (AbstractMarkerAnnotationModel) info.fModel;
                    markerModel.resetMarkers();
                }
            }

            @Override
            public ISchedulingRule getSchedulingRule() {
                if (info.fElement instanceof IFileEditorInput) {
                    IFileEditorInput input = (IFileEditorInput) info.fElement;
                    return fResourceRuleFactory.refreshRule((input).getFile());
                }
                return null;
            }
        };
        executeOperation(operation, getProgressMonitor());
    } else {
        getParentProvider().resetDocument(element);
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFileInfo(org.eclipse.core.filesystem.IFileInfo) AbstractMarkerAnnotationModel(org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel) IFileEditorInput(org.eclipse.ui.IFileEditorInput)

Example 3 with AbstractMarkerAnnotationModel

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

the class TextFileDocumentProvider method commitFileBuffer.

/**
 * Commits the given file info's file buffer by changing the contents
 * of the underlying file to the contents of this file buffer. After that
 * call, <code>isDirty</code> returns <code>false</code> and <code>isSynchronized</code>
 * returns <code>true</code>.
 *
 * @param monitor the progress monitor
 * @param info the element's file info object
 * @param overwrite indicates whether the underlying file should be overwritten if it is not synchronized with the file system
 * @throws CoreException if writing or accessing the underlying file fails
 */
protected void commitFileBuffer(IProgressMonitor monitor, FileInfo info, boolean overwrite) throws CoreException {
    Assert.isNotNull(info);
    /* https://bugs.eclipse.org/bugs/show_bug.cgi?id=98327
		 * Make sure file gets saved in commit() if the underlying file has been deleted */
    if (info.fElement instanceof IFileEditorInput) {
        IFileEditorInput input = (IFileEditorInput) info.fElement;
        IResource resource = input.getFile();
        if (!resource.isSynchronized(IResource.DEPTH_ZERO) && isDeleted(input))
            info.fTextFileBuffer.setDirty(true);
    }
    info.fTextFileBuffer.commit(monitor, overwrite);
    if (info.fModel instanceof AbstractMarkerAnnotationModel) {
        AbstractMarkerAnnotationModel model = (AbstractMarkerAnnotationModel) info.fModel;
        model.updateMarkers(info.fTextFileBuffer.getDocument());
    }
}
Also used : AbstractMarkerAnnotationModel(org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel) IFileEditorInput(org.eclipse.ui.IFileEditorInput) IResource(org.eclipse.core.resources.IResource)

Example 4 with AbstractMarkerAnnotationModel

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

the class FileDocumentProvider method doResetDocument.

@Override
protected void doResetDocument(Object element, IProgressMonitor monitor) throws CoreException {
    if (element instanceof IFileEditorInput) {
        IFileEditorInput input = (IFileEditorInput) element;
        try {
            refreshFile(input.getFile(), monitor);
            cacheEncodingState(element);
        } catch (CoreException x) {
            handleCoreException(x, TextEditorMessages.FileDocumentProvider_resetDocument);
        }
    }
    super.doResetDocument(element, monitor);
    IAnnotationModel model = getAnnotationModel(element);
    if (model instanceof AbstractMarkerAnnotationModel) {
        AbstractMarkerAnnotationModel markerModel = (AbstractMarkerAnnotationModel) model;
        markerModel.resetMarkers();
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) AbstractMarkerAnnotationModel(org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel) IFileEditorInput(org.eclipse.ui.IFileEditorInput) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel)

Example 5 with AbstractMarkerAnnotationModel

use of org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel in project webtools.sourceediting by eclipse.

the class ToggleBreakpointsTarget method toggleLineBreakpoints.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleLineBreakpoints(org.eclipse.ui.IWorkbenchPart,
	 *      org.eclipse.jface.viewers.ISelection)
	 */
public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
    ITextEditor editor = part.getAdapter(ITextEditor.class);
    if (selection instanceof ITextSelection) {
        ITextSelection textSelection = (ITextSelection) selection;
        IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
        int lineNumber = -1;
        try {
            lineNumber = document.getLineOfOffset(textSelection.getOffset());
        } catch (BadLocationException e) {
        }
        if (lineNumber >= 0) {
            ToggleBreakpointAction toggler = new ToggleBreakpointAction(editor, null);
            toggler.update();
            if (toggler.isEnabled()) {
                IResource resource = toggler.getResource();
                AbstractMarkerAnnotationModel model = toggler.getAnnotationModel();
                IBreakpoint[] breakpoints = getBreakpoints(resource, document, model, lineNumber);
                if (breakpoints.length > 0) {
                    IBreakpointManager breakpointManager = DebugPlugin.getDefault().getBreakpointManager();
                    for (int i = 0; i < breakpoints.length; i++) {
                        breakpoints[i].getMarker().delete();
                        breakpointManager.removeBreakpoint(breakpoints[i], true);
                    }
                } else {
                    toggler.createBreakpoints(lineNumber + 1);
                }
            }
        }
    }
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) AbstractMarkerAnnotationModel(org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel) IBreakpointManager(org.eclipse.debug.core.IBreakpointManager) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint) ITextSelection(org.eclipse.jface.text.ITextSelection) IDocument(org.eclipse.jface.text.IDocument) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint) BadLocationException(org.eclipse.jface.text.BadLocationException) IResource(org.eclipse.core.resources.IResource)

Aggregations

AbstractMarkerAnnotationModel (org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel)8 IResource (org.eclipse.core.resources.IResource)4 IDocument (org.eclipse.jface.text.IDocument)4 CoreException (org.eclipse.core.runtime.CoreException)3 IBreakpoint (org.eclipse.debug.core.model.IBreakpoint)3 IFileEditorInput (org.eclipse.ui.IFileEditorInput)3 IMarker (org.eclipse.core.resources.IMarker)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IFileInfo (org.eclipse.core.filesystem.IFileInfo)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IBreakpointManager (org.eclipse.debug.core.IBreakpointManager)1 IRegion (org.eclipse.jface.text.IRegion)1 ITextSelection (org.eclipse.jface.text.ITextSelection)1 Point (org.eclipse.swt.graphics.Point)1 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)1 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)1 MarkerAnnotation (org.eclipse.ui.texteditor.MarkerAnnotation)1