use of org.eclipse.core.resources.IMarker in project eclipse.platform.text by eclipse.
the class SelectMarkerRulerAction method run.
@Override
public void run() {
IMarker marker = chooseMarker(getMarkers());
if (marker == null)
return;
IWorkbenchPage page = fTextEditor.getSite().getPage();
MarkerViewUtil.showMarker(page, marker, false);
gotoMarker(marker);
}
use of org.eclipse.core.resources.IMarker in project eclipse.platform.text by eclipse.
the class SelectMarkerRulerAction method hasMarkers.
/**
* Returns <code>true</code> iff there are any markers which include the ruler's line of activity.
*
* @return <code>true</code> iff there are any markers which include the ruler's line of activity.
* @since 3.3
*/
protected final boolean hasMarkers() {
final IResource resource = getResource();
if (resource == null || !resource.exists())
return false;
final IDocument document = getDocument();
if (document == null)
return false;
final AbstractMarkerAnnotationModel model = getAnnotationModel();
if (model == null)
return false;
final IMarker[] allMarkers;
try {
allMarkers = resource.findMarkers(null, true, IResource.DEPTH_ZERO);
} catch (CoreException x) {
handleCoreException(x, TextEditorMessages.SelectMarkerRulerAction_getMarker);
return false;
}
if (allMarkers.length == 0)
return false;
final int activeLine = fRuler.getLineOfLastMouseButtonActivity();
if (activeLine == -1)
return false;
Iterator<Annotation> it;
try {
IRegion line = document.getLineInformation(activeLine);
it = model.getAnnotationIterator(line.getOffset(), line.getLength() + 1, true, true);
} catch (BadLocationException e) {
logException(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.OK, e.getLocalizedMessage(), e));
it = model.getAnnotationIterator();
}
while (it.hasNext()) {
Annotation annotation = it.next();
if (annotation instanceof MarkerAnnotation) {
Position position = model.getPosition(annotation);
if (includesLine(position, document, activeLine)) {
return true;
}
}
}
return false;
}
use of org.eclipse.core.resources.IMarker in project eclipse.platform.text by eclipse.
the class MarkerResoltionQuickAssistProcessor method computeQuickAssistProposals.
@Override
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) {
IAnnotationModel annotationModel = invocationContext.getSourceViewer().getAnnotationModel();
Collection<MarkerAnnotation> annotations = new HashSet<>();
annotationModel.getAnnotationIterator().forEachRemaining(annotation -> {
Position position = annotationModel.getPosition(annotation);
if (invocationContext.getOffset() >= position.getOffset() && invocationContext.getOffset() + Math.max(0, invocationContext.getLength()) <= position.getOffset() + position.getLength() && annotation instanceof MarkerAnnotation) {
annotations.add((MarkerAnnotation) annotation);
}
});
Collection<MarkerResolutionCompletionProposal> resolutions = new ArrayList<>();
for (MarkerAnnotation annotation : annotations) {
IMarker marker = annotation.getMarker();
for (IMarkerResolution resolution : IDE.getMarkerHelpRegistry().getResolutions(marker)) {
resolutions.add(new MarkerResolutionCompletionProposal(marker, resolution));
}
}
return resolutions.toArray(new ICompletionProposal[resolutions.size()]);
}
use of org.eclipse.core.resources.IMarker in project eclipse.platform.text by eclipse.
the class EditorOpener method showWithMarker.
private void showWithMarker(IEditorPart editor, IFile file, int offset, int length) throws PartInitException {
IMarker marker = null;
try {
marker = file.createMarker(NewSearchUI.SEARCH_MARKER);
HashMap<String, Integer> attributes = new HashMap<>(4);
attributes.put(IMarker.CHAR_START, Integer.valueOf(offset));
attributes.put(IMarker.CHAR_END, Integer.valueOf(offset + length));
marker.setAttributes(attributes);
IDE.gotoMarker(editor, marker);
} catch (CoreException e) {
throw new PartInitException(SearchMessages.FileSearchPage_error_marker, e);
} finally {
if (marker != null)
try {
marker.delete();
} catch (CoreException e) {
// ignore
}
}
}
use of org.eclipse.core.resources.IMarker in project eclipse.platform.text by eclipse.
the class RemoveMatchAction method getMarkers.
private IMarker[] getMarkers(ISelection s) {
if (!(s instanceof IStructuredSelection) || s.isEmpty())
return null;
IStructuredSelection selection = (IStructuredSelection) s;
int size = selection.size();
if (size != 1)
return null;
if (selection.getFirstElement() instanceof ISearchResultViewEntry) {
IMarker marker = ((ISearchResultViewEntry) selection.getFirstElement()).getSelectedMarker();
if (marker != null)
return new IMarker[] { marker };
}
return null;
}
Aggregations