a8cfbf0f9bc7dd4385953f0eb3110a6d1718064a
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / text / spelling / WordIgnoreProposal.java
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
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11
12 package net.sourceforge.phpdt.internal.ui.text.spelling;
13
14 import java.text.MessageFormat;
15
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;
23
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;
28
29 /**
30  * Proposal to ignore the word during the current editing session.
31  * 
32  * @since 3.0
33  */
34 public class WordIgnoreProposal implements IPHPCompletionProposal {
35
36         /** The invocation context */
37         private IInvocationContext fContext;
38
39         /** The word to ignore */
40         private String fWord;
41
42         /**
43          * Creates a new spell ignore proposal.
44          * 
45          * @param word
46          *                   The word to ignore
47          * @param context
48          *                   The invocation context
49          */
50         public WordIgnoreProposal(final String word, final IInvocationContext context) {
51                 fWord= word;
52                 fContext= context;
53         }
54
55         /*
56          * @see org.eclipse.jface.text.contentassist.ICompletionProposal#apply(org.eclipse.jface.text.IDocument)
57          */
58         public final void apply(final IDocument document) {
59
60                 final ISpellCheckEngine engine= SpellCheckEngine.getInstance();
61                 final ISpellChecker checker= engine.createSpellChecker(engine.getLocale(), PreferenceConstants.getPreferenceStore());
62
63                 if (checker != null)
64                         checker.ignoreWord(fWord);
65         }
66
67         /*
68          * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getAdditionalProposalInfo()
69          */
70         public String getAdditionalProposalInfo() {
71                 return MessageFormat.format(PHPUIMessages.getString("Spelling.ignore.info"), new String[] { WordCorrectionProposal.getHtmlRepresentation(fWord)}); //$NON-NLS-1$
72         }
73
74         /*
75          * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getContextInformation()
76          */
77         public final IContextInformation getContextInformation() {
78                 return null;
79         }
80
81         /*
82          * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getDisplayString()
83          */
84         public String getDisplayString() {
85                 return MessageFormat.format(PHPUIMessages.getString("Spelling.ignore.label"), new String[] { fWord }); //$NON-NLS-1$
86         }
87
88         /*
89          * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getImage()
90          */
91         public Image getImage() {
92                 return PHPUiImages.get(PHPUiImages.IMG_OBJS_NLS_NEVER_TRANSLATE);
93         }
94         /*
95          * @see org.eclipse.jdt.ui.text.java.IJavaCompletionProposal#getRelevance()
96          */
97         public final int getRelevance() {
98                 return Integer.MIN_VALUE + 1;
99         }
100
101         /*
102          * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getSelection(org.eclipse.jface.text.IDocument)
103          */
104         public final Point getSelection(final IDocument document) {
105                 return new Point(fContext.getSelectionOffset(), fContext.getSelectionLength());
106         }
107 }