blob: ee0ab35358105dfa5f8861fa06efafe7ed243590 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
/*******************************************************************************
* Copyright (c) 2000, 2012 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text.spelling;
import org.eclipse.cdt.internal.ui.text.spelling.engine.ISpellCheckEngine;
import org.eclipse.cdt.internal.ui.text.spelling.engine.ISpellChecker;
import org.eclipse.cdt.ui.CDTSharedImages;
import org.eclipse.cdt.ui.text.ICCompletionProposal;
import org.eclipse.cdt.ui.text.IInvocationContext;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.texteditor.spelling.SpellingProblem;
/**
* Proposal to ignore the word during the current editing session.
*/
public class WordIgnoreProposal implements ICCompletionProposal {
/** The invocation context */
private IInvocationContext fContext;
/** The word to ignore */
private String fWord;
/**
* Creates a new spell ignore proposal.
*
* @param word The word to ignore
* @param context The invocation context
*/
public WordIgnoreProposal(final String word, final IInvocationContext context) {
fWord = word;
fContext = context;
}
/*
* @see org.eclipse.jface.text.contentassist.ICompletionProposal#apply(org.eclipse.jface.text.IDocument)
*/
@Override
public final void apply(final IDocument document) {
final ISpellCheckEngine engine = SpellCheckEngine.getInstance();
final ISpellChecker checker = engine.getSpellChecker();
if (checker != null) {
checker.ignoreWord(fWord);
if (fContext instanceof IQuickAssistInvocationContext) {
ISourceViewer sourceViewer = ((IQuickAssistInvocationContext) fContext).getSourceViewer();
if (sourceViewer != null) {
SpellingProblem.removeAll(sourceViewer, fWord);
}
}
}
}
/*
* @see org.eclipse.jface.text.contentassist.ICompletionProposal#getAdditionalProposalInfo()
*/
@Override
public String getAdditionalProposalInfo() {
return NLS.bind(Messages.Spelling_ignore_info, WordCorrectionProposal.getHtmlRepresentation(fWord));
}
/*
* @see org.eclipse.jface.text.contentassist.ICompletionProposal#getContextInformation()
*/
@Override
public final IContextInformation getContextInformation() {
return null;
}
/*
* @see org.eclipse.jface.text.contentassist.ICompletionProposal#getDisplayString()
*/
@Override
public String getDisplayString() {
return NLS.bind(Messages.Spelling_ignore_label, fWord);
}
/*
* @see org.eclipse.jface.text.contentassist.ICompletionProposal#getImage()
*/
@Override
public Image getImage() {
return CDTSharedImages.getImage(CDTSharedImages.IMG_OBJS_NLS_NEVER_TRANSLATE);
}
/*
* @see org.eclipse.cdt.ui.text.java.IJavaCompletionProposal#getRelevance()
*/
@Override
public final int getRelevance() {
return Integer.MIN_VALUE + 1;
}
/*
* @see org.eclipse.jface.text.contentassist.ICompletionProposal#getSelection(org.eclipse.jface.text.IDocument)
*/
@Override
public final Point getSelection(final IDocument document) {
return new Point(fContext.getSelectionOffset(), fContext.getSelectionLength());
}
@Override
public String getIdString() {
return fWord;
}
}
|