diff options
author | Dani Megert | 2007-06-27 09:33:55 +0000 |
---|---|---|
committer | Dani Megert | 2007-06-27 09:33:55 +0000 |
commit | 90d8c52bfc9f0800c020ee016b1c7c207d3a5ef6 (patch) | |
tree | ea5f9febbe6046629bb94110f623df3b44a72fbc /org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/spelling/SpellingProblem.java | |
parent | 04bdab4a6ccbd55c6d985d075438805b2a645d74 (diff) | |
download | eclipse.platform.text-90d8c52bfc9f0800c020ee016b1c7c207d3a5ef6.tar.gz eclipse.platform.text-90d8c52bfc9f0800c020ee016b1c7c207d3a5ef6.tar.xz eclipse.platform.text-90d8c52bfc9f0800c020ee016b1c7c207d3a5ef6.zip |
Fixed bug 194574: [api][spell checking] Source viewer: Ignoring or adding word does not remove squiggles
Diffstat (limited to 'org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/spelling/SpellingProblem.java')
-rw-r--r-- | org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/spelling/SpellingProblem.java | 70 |
1 files changed, 69 insertions, 1 deletions
diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/spelling/SpellingProblem.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/spelling/SpellingProblem.java index 78c6fb3e716..7f049b4fd94 100644 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/spelling/SpellingProblem.java +++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/spelling/SpellingProblem.java @@ -8,20 +8,23 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ - package org.eclipse.ui.texteditor.spelling; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import org.eclipse.core.runtime.Assert; + import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.Position; import org.eclipse.jface.text.contentassist.ICompletionProposal; +import org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext; import org.eclipse.jface.text.source.Annotation; import org.eclipse.jface.text.source.IAnnotationModel; import org.eclipse.jface.text.source.IAnnotationModelExtension; +import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.texteditor.IDocumentProvider; @@ -55,6 +58,7 @@ public abstract class SpellingProblem { * @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)} */ public static void removeAllInActiveEditor(ITextEditor editor, String word) { if (editor == null) @@ -109,6 +113,59 @@ public abstract class SpellingProblem { ((IAnnotationModelExtension)model).replaceAnnotations(annotationArray, null); } } + + /** + * Removes all spelling problems that are reported + * for the given <code>word</code> in the active editor. + * + * @param sourceViewer the source viewer + * @param word the word for which to remove the problems or <code>null</code> to remove all + * @since 3.4 + */ + public static void removeAll(ISourceViewer sourceViewer, String word) { + Assert.isNotNull(sourceViewer); + + IAnnotationModel model= sourceViewer.getAnnotationModel(); + if (model == null) + return; + + IDocument document= sourceViewer.getDocument(); + if (document == null) + return; + + boolean supportsBatchReplace= (model instanceof IAnnotationModelExtension); + List toBeRemovedAnnotations= new ArrayList(); + Iterator iter= model.getAnnotationIterator(); + while (iter.hasNext()) { + Annotation 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= (Annotation[])toBeRemovedAnnotations.toArray(new Annotation[toBeRemovedAnnotations.size()]); + ((IAnnotationModelExtension)model).replaceAnnotations(annotationArray, null); + } + } /** * Returns the offset of the incorrectly spelled region. @@ -137,4 +194,15 @@ public abstract class SpellingProblem { * @return the proposals for the incorrectly spelled region */ public abstract ICompletionProposal[] getProposals(); + + /** + * Returns the proposals for the incorrectly spelled region. + * + * @param context the invocation context or <code>null</code> if none + * @return the proposals for the incorrectly spelled region + * @since 3.4 + */ + public ICompletionProposal[] getProposals(IQuickAssistInvocationContext context) { + return getProposals(); + } } |