Omaha #3453 Refreshing the viewer on every spell check job to correctly update underlining.
Change-Id: I5e037a7b3e85fd794966bd351ae37777abb0d193 Former-commit-id:6d49b0f7ae
[formerly8b6fd81e10
[formerly f27b34bc0aa50d13415dde6153676d3a9484c9ab]] Former-commit-id:8b6fd81e10
Former-commit-id:fc1487a56b
This commit is contained in:
parent
ee4c4fd502
commit
0b67acf5ee
1 changed files with 46 additions and 3 deletions
|
@ -34,6 +34,8 @@ import org.eclipse.jface.text.TextViewer;
|
|||
import org.eclipse.jface.text.contentassist.ICompletionProposal;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.StyleRange;
|
||||
import org.eclipse.swt.events.DisposeEvent;
|
||||
import org.eclipse.swt.events.DisposeListener;
|
||||
import org.eclipse.swt.events.MenuAdapter;
|
||||
import org.eclipse.swt.events.MenuEvent;
|
||||
import org.eclipse.swt.events.MouseAdapter;
|
||||
|
@ -66,6 +68,8 @@ import com.raytheon.uf.viz.spellchecker.jobs.EnhancedSpellCheckJob;
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Jun 18, 2014 3453 rblum Initial creation
|
||||
* Aug 06, 2014 3453 rblum Refreshing all viewers on enable/
|
||||
* disable of spell checking.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -82,6 +86,8 @@ public class SpellCheckTextViewer extends TextViewer implements
|
|||
|
||||
private volatile boolean checkingSpelling = false;
|
||||
|
||||
private static List<SpellCheckTextViewer> textViewers = new ArrayList<SpellCheckTextViewer>();
|
||||
|
||||
private Map<Range<Integer>, SpellingProblem> ranges;
|
||||
|
||||
/**
|
||||
|
@ -94,11 +100,12 @@ public class SpellCheckTextViewer extends TextViewer implements
|
|||
ranges = new HashMap<Range<Integer>, SpellingProblem>();
|
||||
store = EditorsUI.getPreferenceStore();
|
||||
setDocument(new Document());
|
||||
textViewers.add(this);
|
||||
ITextListener listener = new ITextListener() {
|
||||
@Override
|
||||
public void textChanged(TextEvent event) {
|
||||
if (checkingSpelling == false) {
|
||||
scheduleSpellJob(false);
|
||||
scheduleSpellJob(true);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -126,7 +133,7 @@ public class SpellCheckTextViewer extends TextViewer implements
|
|||
store.setValue(
|
||||
SpellingService.PREFERENCE_SPELLING_ENABLED,
|
||||
true);
|
||||
scheduleSpellJob(true);
|
||||
refreshAllTextViewers(true);
|
||||
}
|
||||
});
|
||||
} else if (problem != null) {
|
||||
|
@ -150,6 +157,15 @@ public class SpellCheckTextViewer extends TextViewer implements
|
|||
}
|
||||
}
|
||||
});
|
||||
getTextWidget().addDisposeListener(new DisposeListener() {
|
||||
|
||||
@Override
|
||||
public void widgetDisposed(DisposeEvent e) {
|
||||
if (textViewers.contains(SpellCheckTextViewer.this)) {
|
||||
textViewers.remove(SpellCheckTextViewer.this);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -229,12 +245,38 @@ public class SpellCheckTextViewer extends TextViewer implements
|
|||
public void widgetSelected(SelectionEvent e) {
|
||||
ICompletionProposal prop = (ICompletionProposal) item.getData();
|
||||
prop.apply(getDocument());
|
||||
refresh();
|
||||
scheduleSpellJob(true);
|
||||
refreshAllTextViewers(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Cycles through all the SpellCheckTextViewers and issues a refresh or
|
||||
* schedules a EnhancedSpellCheckJob for each one.
|
||||
*
|
||||
* @param issueSpellCheck
|
||||
* Determines to schedule a spell check or to refresh.
|
||||
*/
|
||||
private void refreshAllTextViewers(boolean issueSpellCheck) {
|
||||
for (SpellCheckTextViewer viewer : textViewers) {
|
||||
if (viewer.getDocument() != null) {
|
||||
if (issueSpellCheck) {
|
||||
viewer.scheduleSpellJob(true);
|
||||
} else {
|
||||
viewer.refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules a EnhancedSpellCheckJob for the SpellCheckTextViewer if spell
|
||||
* checking is enabled.
|
||||
*
|
||||
* @param entireDocument
|
||||
* Spell check the entire document or the current line.
|
||||
*/
|
||||
private void scheduleSpellJob(boolean entireDocument) {
|
||||
if (store.getBoolean(SpellingService.PREFERENCE_SPELLING_ENABLED)) {
|
||||
EnhancedSpellCheckJob job = new EnhancedSpellCheckJob(
|
||||
|
@ -254,6 +296,7 @@ public class SpellCheckTextViewer extends TextViewer implements
|
|||
job.setCollector(SpellCheckTextViewer.this);
|
||||
checkingSpelling = true;
|
||||
job.schedule();
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue