129
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2006, 2008 IBM Corporation and others.
|
|
3 * All rights reserved. This program and the accompanying materials
|
|
4 * are made available under the terms of the Eclipse Public License v1.0
|
|
5 * which accompanies this distribution, and is available at
|
|
6 * http://www.eclipse.org/legal/epl-v10.html
|
|
7 *
|
|
8 * Contributors:
|
|
9 * IBM Corporation - initial API and implementation
|
|
10 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
|
12 *******************************************************************************/
|
|
13 module dwtx.jface.text.quickassist.QuickAssistAssistant;
|
|
14
|
|
15 import dwt.dwthelper.utils;
|
|
16
|
|
17
|
|
18
|
|
19
|
|
20 import dwt.graphics.Color;
|
|
21 import dwtx.core.commands.IHandler;
|
|
22 import dwtx.jface.text.IDocument;
|
|
23 import dwtx.jface.text.IInformationControlCreator;
|
|
24 import dwtx.jface.text.ITextViewer;
|
|
25 import dwtx.jface.text.contentassist.ContentAssistant;
|
|
26 import dwtx.jface.text.contentassist.ICompletionListener;
|
|
27 import dwtx.jface.text.contentassist.ICompletionProposal;
|
|
28 import dwtx.jface.text.contentassist.IContentAssistProcessor;
|
|
29 import dwtx.jface.text.contentassist.IContextInformation;
|
|
30 import dwtx.jface.text.contentassist.IContextInformationValidator;
|
|
31 import dwtx.jface.text.source.Annotation;
|
|
32 import dwtx.jface.text.source.ISourceViewer;
|
|
33 import dwtx.jface.text.source.TextInvocationContext;
|
|
34
|
|
35
|
|
36 /**
|
|
37 * Default implementation of <code>IQuickAssistAssistant</code>.
|
|
38 *
|
|
39 * @since 3.2
|
|
40 */
|
|
41 public class QuickAssistAssistant : IQuickAssistAssistant, IQuickAssistAssistantExtension {
|
|
42
|
|
43
|
|
44 private static final class QuickAssistAssistantImpl : ContentAssistant {
|
|
45 /*
|
|
46 * @see dwtx.jface.text.contentassist.ContentAssistant#possibleCompletionsClosed()
|
|
47 */
|
|
48 public void possibleCompletionsClosed() {
|
|
49 super.possibleCompletionsClosed();
|
|
50 }
|
|
51
|
|
52 /*
|
|
53 * @see dwtx.jface.text.contentassist.ContentAssistant#hide()
|
|
54 * @since 3.4
|
|
55 */
|
|
56 protected void hide() {
|
|
57 super.hide();
|
|
58 }
|
|
59 }
|
|
60
|
|
61
|
|
62 private static final class ContentAssistProcessor : IContentAssistProcessor {
|
|
63
|
|
64 private IQuickAssistProcessor fQuickAssistProcessor;
|
|
65
|
|
66 ContentAssistProcessor(IQuickAssistProcessor processor) {
|
|
67 fQuickAssistProcessor= processor;
|
|
68 }
|
|
69
|
|
70 /*
|
|
71 * @see dwtx.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(dwtx.jface.text.ITextViewer, int)
|
|
72 */
|
|
73 public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
|
|
74 // panic code - should not happen
|
|
75 if (!(viewer instanceof ISourceViewer))
|
|
76 return null;
|
|
77
|
|
78 return fQuickAssistProcessor.computeQuickAssistProposals(new TextInvocationContext((ISourceViewer)viewer, offset, -1));
|
|
79 }
|
|
80
|
|
81 /*
|
|
82 * @see dwtx.jface.text.contentassist.IContentAssistProcessor#computeContextInformation(dwtx.jface.text.ITextViewer, int)
|
|
83 */
|
|
84 public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
|
|
85 return null;
|
|
86 }
|
|
87
|
|
88 /*
|
|
89 * @see dwtx.jface.text.contentassist.IContentAssistProcessor#getCompletionProposalAutoActivationCharacters()
|
|
90 */
|
|
91 public char[] getCompletionProposalAutoActivationCharacters() {
|
|
92 return null;
|
|
93 }
|
|
94
|
|
95 /*
|
|
96 * @see dwtx.jface.text.contentassist.IContentAssistProcessor#getContextInformationAutoActivationCharacters()
|
|
97 */
|
|
98 public char[] getContextInformationAutoActivationCharacters() {
|
|
99 return null;
|
|
100 }
|
|
101
|
|
102 /*
|
|
103 * @see dwtx.jface.text.contentassist.IContentAssistProcessor#getErrorMessage()
|
|
104 */
|
|
105 public String getErrorMessage() {
|
|
106 return null;
|
|
107 }
|
|
108
|
|
109 /*
|
|
110 * @see dwtx.jface.text.contentassist.IContentAssistProcessor#getContextInformationValidator()
|
|
111 */
|
|
112 public IContextInformationValidator getContextInformationValidator() {
|
|
113 return null;
|
|
114 }
|
|
115
|
|
116 }
|
|
117
|
|
118 private QuickAssistAssistantImpl fQuickAssistAssistantImpl;
|
|
119 private IQuickAssistProcessor fQuickAssistProcessor;
|
|
120
|
|
121 public QuickAssistAssistant() {
|
|
122 fQuickAssistAssistantImpl= new QuickAssistAssistantImpl();
|
|
123 fQuickAssistAssistantImpl.enableAutoActivation(false);
|
|
124 fQuickAssistAssistantImpl.enableAutoInsert(false);
|
|
125 }
|
|
126
|
|
127 /*
|
|
128 * @see dwtx.jface.text.quickassist.IQuickAssistAssistant#showPossibleQuickAssists()
|
|
129 */
|
|
130 public String showPossibleQuickAssists() {
|
|
131 return fQuickAssistAssistantImpl.showPossibleCompletions();
|
|
132 }
|
|
133
|
|
134 /*
|
|
135 * @see dwtx.jface.text.quickassist.IQuickAssistAssistant#getQuickAssistProcessor(java.lang.String)
|
|
136 */
|
|
137 public IQuickAssistProcessor getQuickAssistProcessor() {
|
|
138 return fQuickAssistProcessor;
|
|
139 }
|
|
140
|
|
141 /*
|
|
142 * @see dwtx.jface.text.quickassist.IQuickAssistAssistant#setQuickAssistProcessor(dwtx.jface.text.quickassist.IQuickAssistProcessor)
|
|
143 */
|
|
144 public void setQuickAssistProcessor(IQuickAssistProcessor processor) {
|
|
145 fQuickAssistProcessor= processor;
|
|
146 fQuickAssistAssistantImpl.setDocumentPartitioning("__" + getClass().getName() + "_partitioning"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
147 fQuickAssistAssistantImpl.setContentAssistProcessor(new ContentAssistProcessor(processor), IDocument.DEFAULT_CONTENT_TYPE);
|
|
148 }
|
|
149
|
|
150 /*
|
|
151 * @see dwtx.jface.text.quickassist.IQuickAssistAssistant#canFix(dwtx.jface.text.source.Annotation)
|
|
152 */
|
|
153 public bool canFix(Annotation annotation) {
|
|
154 return fQuickAssistProcessor !is null && fQuickAssistProcessor.canFix(annotation);
|
|
155 }
|
|
156
|
|
157 /*
|
|
158 * @see dwtx.jface.text.quickassist.IQuickAssistAssistant#canAssist(dwtx.jface.text.quickassist.IQuickAssistInvocationContext)
|
|
159 */
|
|
160 public bool canAssist(IQuickAssistInvocationContext invocationContext) {
|
|
161 return fQuickAssistProcessor !is null && fQuickAssistProcessor.canAssist(invocationContext);
|
|
162 }
|
|
163
|
|
164 /*
|
|
165 * @see dwtx.jface.text.quickassist.IQuickAssistAssistant#install(dwtx.jface.text.ITextViewer)
|
|
166 */
|
|
167 public void install(ISourceViewer sourceViewer) {
|
|
168 fQuickAssistAssistantImpl.install(sourceViewer);
|
|
169 }
|
|
170
|
|
171 /*
|
|
172 * @see dwtx.jface.text.quickassist.IQuickAssistAssistant#setInformationControlCreator(dwtx.jface.text.IInformationControlCreator)
|
|
173 */
|
|
174 public void setInformationControlCreator(IInformationControlCreator creator) {
|
|
175 fQuickAssistAssistantImpl.setInformationControlCreator(creator);
|
|
176 }
|
|
177
|
|
178 /*
|
|
179 * @see dwtx.jface.text.quickassist.IQuickAssistAssistant#uninstall()
|
|
180 */
|
|
181 public void uninstall() {
|
|
182 fQuickAssistAssistantImpl.uninstall();
|
|
183 }
|
|
184
|
|
185 /*
|
|
186 * @see dwtx.jface.text.quickassist.IQuickAssistAssistant#setProposalSelectorBackground(dwt.graphics.Color)
|
|
187 */
|
|
188 public void setProposalSelectorBackground(Color background) {
|
|
189 fQuickAssistAssistantImpl.setProposalSelectorBackground(background);
|
|
190 }
|
|
191
|
|
192 /*
|
|
193 * @see dwtx.jface.text.quickassist.IQuickAssistAssistant#setProposalSelectorForeground(dwt.graphics.Color)
|
|
194 */
|
|
195 public void setProposalSelectorForeground(Color foreground) {
|
|
196 fQuickAssistAssistantImpl.setProposalSelectorForeground(foreground);
|
|
197 }
|
|
198
|
|
199 /**
|
|
200 * Callback to signal this quick assist assistant that the presentation of the
|
|
201 * possible completions has been stopped.
|
|
202 */
|
|
203 protected void possibleCompletionsClosed() {
|
|
204 fQuickAssistAssistantImpl.possibleCompletionsClosed();
|
|
205 }
|
|
206
|
|
207 /*
|
|
208 * @see dwtx.jface.text.quickassist.IQuickAssistAssistant#addCompletionListener(dwtx.jface.text.contentassist.ICompletionListener)
|
|
209 */
|
|
210 public void addCompletionListener(ICompletionListener listener) {
|
|
211 fQuickAssistAssistantImpl.addCompletionListener(listener);
|
|
212 }
|
|
213
|
|
214 /*
|
|
215 * @see dwtx.jface.text.quickassist.IQuickAssistAssistant#removeCompletionListener(dwtx.jface.text.contentassist.ICompletionListener)
|
|
216 */
|
|
217 public void removeCompletionListener(ICompletionListener listener) {
|
|
218 fQuickAssistAssistantImpl.removeCompletionListener(listener);
|
|
219 }
|
|
220
|
|
221 /*
|
|
222 * @see dwtx.jface.text.quickassist.IQuickAssistAssistant#setStatusLineVisible(bool)
|
|
223 */
|
|
224 public void setStatusLineVisible(bool show) {
|
|
225 fQuickAssistAssistantImpl.setStatusLineVisible(show);
|
|
226
|
|
227 }
|
|
228
|
|
229 /*
|
|
230 * @see dwtx.jface.text.quickassist.IQuickAssistAssistant#setStatusMessage(java.lang.String)
|
|
231 */
|
|
232 public void setStatusMessage(String message) {
|
|
233 fQuickAssistAssistantImpl.setStatusMessage(message);
|
|
234 }
|
|
235
|
|
236 /**
|
|
237 * {@inheritDoc}
|
|
238 *
|
|
239 * @since 3.4
|
|
240 */
|
|
241 public final IHandler getHandler(String commandId) {
|
|
242 return fQuickAssistAssistantImpl.getHandler(commandId);
|
|
243 }
|
|
244
|
|
245 /**
|
|
246 * Hides any open pop-ups.
|
|
247 *
|
|
248 * @since 3.4
|
|
249 */
|
|
250 protected void hide() {
|
|
251 fQuickAssistAssistantImpl.hide();
|
|
252 }
|
|
253
|
|
254 /**
|
|
255 * {@inheritDoc}
|
|
256 *
|
|
257 * @since 3.4
|
|
258 */
|
|
259 public void enableColoredLabels(bool isEnabled) {
|
|
260 fQuickAssistAssistantImpl.enableColoredLabels(isEnabled);
|
|
261 }
|
|
262
|
|
263 }
|