public void spellingError(SpellCheckEvent event) { List<String> suggestions = new ArrayList<String>(); Iterator<Word> itr = event.getSuggestions().iterator(); while (itr.hasNext()) { Word word = itr.next(); suggestions.add(word.getWord()); } int pos = event.getWordContextPosition(); if (pos >= 0) { if ((pos == 0) || ((pos > 0) && // (_text.charAt(pos - 1) != '<') && (!_isInsideHtmlTag(pos)) && (_text.charAt(pos - 1) != '&') && (event.getInvalidWord().length() > 1))) { _invalidWords.add( new InvalidWord( event.getInvalidWord(), suggestions, event.getWordContext(), pos)); } } }
/** @param gc */ private void paintSpellError(GC gc) { if (ranges.isEmpty()) return; int lineStyle = gc.getLineStyle(); int lineWidth = gc.getLineWidth(); Color lineColor = gc.getForeground(); gc.setLineWidth(2); gc.setLineStyle(SWT.LINE_DOT); gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_RED)); int charCount = contentAdapter.getControlContents(control).length(); Rectangle clipping = gc.getClipping(); lineCache.clear(); for (Object obj : ranges.values().toArray()) { SpellCheckEvent range = (SpellCheckEvent) obj; int start = range.getWordContextPosition(); if (start < 0 || start >= charCount) continue; int length = Math.min(range.getInvalidWord().length(), charCount - start); if (length <= 0) continue; drawLines(gc, start, start + length - 1, clipping); } gc.setLineWidth(lineWidth); gc.setLineStyle(lineStyle); gc.setForeground(lineColor); }
@Override public void spellingError(SpellCheckEvent event) { List<String> suggestions = new ArrayList<String>(); for (Word word : (List<Word>) event.getSuggestions()) { suggestions.add(word.getWord()); } int pos = event.getWordContextPosition(); if (pos >= 0) { if ((pos == 0) || ((pos > 0) && // (_text.charAt(pos - 1) != '<') && (!_isInsideHtmlTag(pos)) && (_text.charAt(pos - 1) != '&') && (event.getInvalidWord().length() > 1))) { _invalidWords.add( new InvalidWord( event.getInvalidWord(), suggestions, event.getWordContext(), pos)); } } }
public void run() { if (!isActive()) return; String old = contentAdapter.getControlContents(control); int oldLength = old.length(); int start = range.getWordContextPosition(); String invalidWord = range.getInvalidWord(); int invalidLength = invalidWord.length(); if (start < oldLength && start + invalidLength <= oldLength) { contentAdapter.replaceControlContents(control, start, invalidLength, suggestion); check(Display.getCurrent()); } }
private SpellCheckEvent getCurrentRange() { int pos = contentAdapter.getCursorPosition(control); for (Entry<Integer, SpellCheckEvent> en : ranges.entrySet()) { SpellCheckEvent range = en.getValue(); int start = en.getKey().intValue(); int length = range.getInvalidWord().length(); if (start <= pos && pos <= start + length) { return range; } } return null; }
public void fillMenu(IMenuManager menu) { SpellCheckEvent range = getCurrentRange(); if (range != null) { List list = range.getSuggestions(); if (list.isEmpty()) { menu.add(new NoSuggestionAction()); } else { for (Object o : list) { String suggestion = o.toString(); menu.add(new SuggestionAction(range, suggestion)); } } menu.add(new Separator()); menu.add(new NewWordAction(range)); } }
public SuggestionAction(SpellCheckEvent range, String suggestion) { super(range.getInvalidWord() + " -> " + suggestion); // $NON-NLS-1$ this.range = range; this.suggestion = suggestion; }
public void spellingError(SpellCheckEvent event) { int start = event.getWordContextPosition(); ranges.put(Integer.valueOf(start), event); }