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;
}
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);
}
}
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());
}
}
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();
}
}
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);
}
}
}
}
}
Aggregations