1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
12 package net.sourceforge.phpdt.internal.ui.text.spelling;
14 import java.text.MessageFormat;
16 import net.sourceforge.phpdt.internal.ui.PHPUIMessages;
17 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
18 import net.sourceforge.phpdt.internal.ui.text.java.IInvocationContext;
19 import net.sourceforge.phpdt.internal.ui.text.java.IPHPCompletionProposal;
20 import net.sourceforge.phpdt.internal.ui.text.spelling.engine.ISpellCheckEngine;
21 import net.sourceforge.phpdt.internal.ui.text.spelling.engine.ISpellChecker;
22 import net.sourceforge.phpdt.ui.PreferenceConstants;
24 import org.eclipse.jface.text.IDocument;
25 import org.eclipse.jface.text.contentassist.IContextInformation;
26 import org.eclipse.swt.graphics.Image;
27 import org.eclipse.swt.graphics.Point;
30 * Proposal to ignore the word during the current editing session.
34 public class WordIgnoreProposal implements IPHPCompletionProposal {
36 /** The invocation context */
37 private IInvocationContext fContext;
39 /** The word to ignore */
43 * Creates a new spell ignore proposal.
48 * The invocation context
50 public WordIgnoreProposal(final String word,
51 final IInvocationContext context) {
57 * @see org.eclipse.jface.text.contentassist.ICompletionProposal#apply(org.eclipse.jface.text.IDocument)
59 public final void apply(final IDocument document) {
61 final ISpellCheckEngine engine = SpellCheckEngine.getInstance();
62 final ISpellChecker checker = engine.createSpellChecker(engine
63 .getLocale(), PreferenceConstants.getPreferenceStore());
66 checker.ignoreWord(fWord);
70 * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getAdditionalProposalInfo()
72 public String getAdditionalProposalInfo() {
75 PHPUIMessages.getString("Spelling.ignore.info"), new String[] { WordCorrectionProposal.getHtmlRepresentation(fWord) }); //$NON-NLS-1$
79 * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getContextInformation()
81 public final IContextInformation getContextInformation() {
86 * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getDisplayString()
88 public String getDisplayString() {
89 return MessageFormat.format(PHPUIMessages
90 .getString("Spelling.ignore.label"), new String[] { fWord }); //$NON-NLS-1$
94 * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getImage()
96 public Image getImage() {
97 return PHPUiImages.get(PHPUiImages.IMG_OBJS_NLS_NEVER_TRANSLATE);
101 * @see net.sourceforge.phpdt.ui.text.java.IJavaCompletionProposal#getRelevance()
103 public final int getRelevance() {
104 return Integer.MIN_VALUE + 1;
108 * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getSelection(org.eclipse.jface.text.IDocument)
110 public final Point getSelection(final IDocument document) {
111 return new Point(fContext.getSelectionOffset(), fContext
112 .getSelectionLength());