129
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2007 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.source.SourceViewerConfiguration;
|
|
14
|
|
15 import dwt.dwthelper.utils;
|
|
16
|
|
17
|
|
18 import java.util.Arrays;
|
|
19
|
|
20 import dwt.DWT;
|
|
21 import dwt.graphics.RGB;
|
|
22 import dwt.widgets.Shell;
|
|
23 import dwtx.jface.text.DefaultAutoIndentStrategy;
|
|
24 import dwtx.jface.text.DefaultInformationControl;
|
|
25 import dwtx.jface.text.DefaultTextDoubleClickStrategy;
|
|
26 import dwtx.jface.text.IAutoEditStrategy;
|
|
27 import dwtx.jface.text.IAutoIndentStrategy;
|
|
28 import dwtx.jface.text.IDocument;
|
|
29 import dwtx.jface.text.IDocumentExtension3;
|
|
30 import dwtx.jface.text.IInformationControl;
|
|
31 import dwtx.jface.text.IInformationControlCreator;
|
|
32 import dwtx.jface.text.ITextDoubleClickStrategy;
|
|
33 import dwtx.jface.text.ITextHover;
|
|
34 import dwtx.jface.text.ITextViewerExtension2;
|
|
35 import dwtx.jface.text.IUndoManager;
|
|
36 import dwtx.jface.text.TextViewerUndoManager;
|
|
37 import dwtx.jface.text.contentassist.IContentAssistant;
|
|
38 import dwtx.jface.text.formatter.IContentFormatter;
|
|
39 import dwtx.jface.text.hyperlink.DefaultHyperlinkPresenter;
|
|
40 import dwtx.jface.text.hyperlink.IHyperlinkDetector;
|
|
41 import dwtx.jface.text.hyperlink.IHyperlinkPresenter;
|
|
42 import dwtx.jface.text.hyperlink.URLHyperlinkDetector;
|
|
43 import dwtx.jface.text.information.IInformationPresenter;
|
|
44 import dwtx.jface.text.presentation.IPresentationReconciler;
|
|
45 import dwtx.jface.text.presentation.PresentationReconciler;
|
|
46 import dwtx.jface.text.quickassist.IQuickAssistAssistant;
|
|
47 import dwtx.jface.text.reconciler.IReconciler;
|
|
48
|
|
49
|
|
50 /**
|
|
51 * This class bundles the configuration space of a source viewer. Instances of
|
|
52 * this class are passed to the <code>configure</code> method of
|
|
53 * <code>ISourceViewer</code>.
|
|
54 * <p>
|
|
55 * Each method in this class get as argument the source viewer for which it
|
|
56 * should provide a particular configuration setting such as a presentation
|
|
57 * reconciler. Based on its specific knowledge about the returned object, the
|
|
58 * configuration might share such objects or compute them according to some
|
|
59 * rules.</p>
|
|
60 * <p>
|
|
61 * Clients should subclass and override just those methods which must be
|
|
62 * specific to their needs.</p>
|
|
63 *
|
|
64 * @see dwtx.jface.text.source.ISourceViewer
|
|
65 */
|
|
66 public class SourceViewerConfiguration {
|
|
67
|
|
68
|
|
69 /**
|
|
70 * Creates a new source viewer configuration that behaves according to
|
|
71 * specification of this class' methods.
|
|
72 */
|
|
73 public SourceViewerConfiguration() {
|
|
74 super();
|
|
75 }
|
|
76
|
|
77 /**
|
|
78 * Returns the visual width of the tab character. This implementation always
|
|
79 * returns 4.
|
|
80 *
|
|
81 * @param sourceViewer the source viewer to be configured by this configuration
|
|
82 * @return the tab width
|
|
83 */
|
|
84 public int getTabWidth(ISourceViewer sourceViewer) {
|
|
85 return 4;
|
|
86 }
|
|
87
|
|
88 /**
|
|
89 * Returns the undo manager for the given source viewer. This implementation
|
|
90 * always returns a new instance of <code>DefaultUndoManager</code> whose
|
|
91 * history length is set to 25.
|
|
92 *
|
|
93 * @param sourceViewer the source viewer to be configured by this configuration
|
|
94 * @return an undo manager or <code>null</code> if no undo/redo should not be supported
|
|
95 */
|
|
96 public IUndoManager getUndoManager(ISourceViewer sourceViewer) {
|
|
97 return new TextViewerUndoManager(25);
|
|
98 }
|
|
99
|
|
100 /**
|
|
101 * Returns the reconciler ready to be used with the given source viewer.
|
|
102 * This implementation always returns <code>null</code>.
|
|
103 *
|
|
104 * @param sourceViewer the source viewer to be configured by this configuration
|
|
105 * @return a reconciler or <code>null</code> if reconciling should not be supported
|
|
106 */
|
|
107 public IReconciler getReconciler(ISourceViewer sourceViewer) {
|
|
108 return null;
|
|
109 }
|
|
110
|
|
111 /**
|
|
112 * Returns the presentation reconciler ready to be used with the given source viewer.
|
|
113 *
|
|
114 * @param sourceViewer the source viewer
|
|
115 * @return the presentation reconciler or <code>null</code> if presentation reconciling should not be supported
|
|
116 */
|
|
117 public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
|
|
118 PresentationReconciler reconciler= new PresentationReconciler();
|
|
119 reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
|
|
120 return reconciler;
|
|
121 }
|
|
122
|
|
123 /**
|
|
124 * Returns the content formatter ready to be used with the given source viewer.
|
|
125 * This implementation always returns <code>null</code>.
|
|
126 *
|
|
127 * @param sourceViewer the source viewer to be configured by this configuration
|
|
128 * @return a content formatter or <code>null</code> if formatting should not be supported
|
|
129 */
|
|
130 public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
|
|
131 return null;
|
|
132 }
|
|
133
|
|
134 /**
|
|
135 * Returns the content assistant ready to be used with the given source viewer.
|
|
136 * This implementation always returns <code>null</code>.
|
|
137 *
|
|
138 * @param sourceViewer the source viewer to be configured by this configuration
|
|
139 * @return a content assistant or <code>null</code> if content assist should not be supported
|
|
140 */
|
|
141 public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
|
|
142 return null;
|
|
143 }
|
|
144
|
|
145 /**
|
|
146 * Returns the quick assist assistant ready to be used with the given
|
|
147 * source viewer.
|
|
148 * This implementation always returns <code>null</code>.
|
|
149 *
|
|
150 * @param sourceViewer the source viewer to be configured by this configuration
|
|
151 * @return a quick assist assistant or <code>null</code> if quick assist should not be supported
|
|
152 * @since 3.2
|
|
153 */
|
|
154 public IQuickAssistAssistant getQuickAssistAssistant(ISourceViewer sourceViewer) {
|
|
155 return null;
|
|
156 }
|
|
157
|
|
158 /**
|
|
159 * Returns the auto indentation strategy ready to be used with the given source viewer
|
|
160 * when manipulating text of the given content type. This implementation always
|
|
161 * returns an new instance of <code>DefaultAutoIndentStrategy</code>.
|
|
162 *
|
|
163 * @param sourceViewer the source viewer to be configured by this configuration
|
|
164 * @param contentType the content type for which the strategy is applicable
|
|
165 * @return the auto indent strategy or <code>null</code> if automatic indentation is not to be enabled
|
|
166 * @deprecated since 3.1 use {@link #getAutoEditStrategies(ISourceViewer, String)} instead
|
|
167 */
|
|
168 public IAutoIndentStrategy getAutoIndentStrategy(ISourceViewer sourceViewer, String contentType) {
|
|
169 return new DefaultAutoIndentStrategy();
|
|
170 }
|
|
171
|
|
172 /**
|
|
173 * Returns the auto edit strategies ready to be used with the given source viewer
|
|
174 * when manipulating text of the given content type. For backward compatibility, this implementation always
|
|
175 * returns an array containing the result of {@link #getAutoIndentStrategy(ISourceViewer, String)}.
|
|
176 *
|
|
177 * @param sourceViewer the source viewer to be configured by this configuration
|
|
178 * @param contentType the content type for which the strategies are applicable
|
|
179 * @return the auto edit strategies or <code>null</code> if automatic editing is not to be enabled
|
|
180 * @since 3.1
|
|
181 */
|
|
182 public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) {
|
|
183 return new IAutoEditStrategy[] { getAutoIndentStrategy(sourceViewer, contentType) };
|
|
184 }
|
|
185
|
|
186 /**
|
|
187 * Returns the default prefixes to be used by the line-prefix operation
|
|
188 * in the given source viewer for text of the given content type. This implementation always
|
|
189 * returns <code>null</code>.
|
|
190 *
|
|
191 * @param sourceViewer the source viewer to be configured by this configuration
|
|
192 * @param contentType the content type for which the prefix is applicable
|
|
193 * @return the default prefixes or <code>null</code> if the prefix operation should not be supported
|
|
194 * @since 2.0
|
|
195 */
|
|
196 public String[] getDefaultPrefixes(ISourceViewer sourceViewer, String contentType) {
|
|
197 return null;
|
|
198 }
|
|
199
|
|
200 /**
|
|
201 * Returns the double-click strategy ready to be used in this viewer when double clicking
|
|
202 * onto text of the given content type. This implementation always returns a new instance of
|
|
203 * <code>DefaultTextDoubleClickStrategy</code>.
|
|
204 *
|
|
205 * @param sourceViewer the source viewer to be configured by this configuration
|
|
206 * @param contentType the content type for which the strategy is applicable
|
|
207 * @return a double-click strategy or <code>null</code> if double clicking should not be supported
|
|
208 */
|
|
209 public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) {
|
|
210 return new DefaultTextDoubleClickStrategy();
|
|
211 }
|
|
212
|
|
213 /**
|
|
214 * Returns the prefixes to be used by the line-shift operation. This implementation
|
|
215 * always returns <code>new String[] { "\t", " ", "" }</code>.
|
|
216 * <p>
|
|
217 * <strong>Note:</strong> <em>This default is incorrect but cannot be changed in order not
|
|
218 * to break any existing clients. Subclasses should overwrite this method and
|
|
219 * use {@link #getIndentPrefixesForTab(int)} if applicable.</em>
|
|
220 *
|
|
221 * @param sourceViewer the source viewer to be configured by this configuration
|
|
222 * @param contentType the content type for which the prefix is applicable
|
|
223 * @return the prefixes or <code>null</code> if the prefix operation should not be supported
|
|
224 */
|
|
225 public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
|
|
226 return new String[] { "\t", " ", "" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
227 }
|
|
228
|
|
229 /**
|
|
230 * Computes and returns the indent prefixes for tab indentation
|
|
231 * which is represented as <code>tabSizeInSpaces</code>.
|
|
232 *
|
|
233 * @param tabWidth the display tab width
|
|
234 * @return the indent prefixes
|
|
235 * @see #getIndentPrefixes(ISourceViewer, String)
|
|
236 * @since 3.3
|
|
237 */
|
|
238 protected String[] getIndentPrefixesForTab(int tabWidth) {
|
|
239 String[] indentPrefixes= new String[tabWidth + 2];
|
|
240 for (int i= 0; i <= tabWidth; i++) {
|
|
241 char[] spaceChars= new char[i];
|
|
242 Arrays.fill(spaceChars, ' ');
|
|
243 String spaces= new String(spaceChars);
|
|
244 if (i < tabWidth)
|
|
245 indentPrefixes[i]= spaces + '\t';
|
|
246 else
|
|
247 indentPrefixes[i]= new String(spaces);
|
|
248 }
|
|
249 indentPrefixes[tabWidth + 1]= ""; //$NON-NLS-1$
|
|
250 return indentPrefixes;
|
|
251 }
|
|
252
|
|
253 /**
|
|
254 * Returns the annotation hover which will provide the information to be
|
|
255 * shown in a hover popup window when requested for the given
|
|
256 * source viewer. This implementation always returns <code>null</code>.
|
|
257 *
|
|
258 * @param sourceViewer the source viewer to be configured by this configuration
|
|
259 * @return an annotation hover or <code>null</code> if no hover support should be installed
|
|
260 */
|
|
261 public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
|
|
262 return null;
|
|
263 }
|
|
264
|
|
265 /**
|
|
266 * Returns the annotation hover which will provide the information to be
|
|
267 * shown in a hover popup window when requested for the overview ruler
|
|
268 * of the given source viewer.This implementation always returns the general
|
|
269 * annotation hover returned by <code>getAnnotationHover</code>.
|
|
270 *
|
|
271 * @param sourceViewer the source viewer to be configured by this configuration
|
|
272 * @return an annotation hover or <code>null</code> if no hover support should be installed
|
|
273 * @since 3.0
|
|
274 */
|
|
275 public IAnnotationHover getOverviewRulerAnnotationHover(ISourceViewer sourceViewer) {
|
|
276 return getAnnotationHover(sourceViewer);
|
|
277 }
|
|
278
|
|
279 /**
|
|
280 * Returns the DWT event state masks for which text hover are configured for
|
|
281 * the given content type.
|
|
282 *
|
|
283 * @param sourceViewer the source viewer to be configured by this configuration
|
|
284 * @param contentType the content type
|
|
285 * @return an <code>int</code> array with the configured DWT event state masks
|
|
286 * or <code>null</code> if text hovers are not supported for the given content type
|
|
287 * @since 2.1
|
|
288 */
|
|
289 public int[] getConfiguredTextHoverStateMasks(ISourceViewer sourceViewer, String contentType) {
|
|
290 return null;
|
|
291 }
|
|
292
|
|
293 /**
|
|
294 * Returns the text hover which will provide the information to be shown
|
|
295 * in a text hover popup window when requested for the given source viewer and
|
|
296 * the given content type. This implementation always returns <code>
|
|
297 * null</code>.
|
|
298 *
|
|
299 * @param sourceViewer the source viewer to be configured by this configuration
|
|
300 * @param contentType the content type
|
|
301 * @param stateMask the DWT event state mask
|
|
302 * @return a text hover or <code>null</code> if no hover support should be installed
|
|
303 * @since 2.1
|
|
304 */
|
|
305 public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType, int stateMask) {
|
|
306 if (stateMask is ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK)
|
|
307 return getTextHover(sourceViewer, contentType);
|
|
308 return null;
|
|
309 }
|
|
310
|
|
311 /**
|
|
312 * Returns the text hover which will provide the information to be shown
|
|
313 * in a text hover popup window when requested for the given source viewer and
|
|
314 * the given content type. This implementation always returns <code>
|
|
315 * null</code>.
|
|
316 *
|
|
317 * @param sourceViewer the source viewer to be configured by this configuration
|
|
318 * @param contentType the content type
|
|
319 * @return a text hover or <code>null</code> if no hover support should be installed
|
|
320 */
|
|
321 public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
|
|
322 return null;
|
|
323 }
|
|
324
|
|
325 /**
|
|
326 * Returns the information control creator. The creator is a factory creating information
|
|
327 * controls for the given source viewer. This implementation always returns a creator for
|
|
328 * <code>DefaultInformationControl</code> instances.
|
|
329 *
|
|
330 * @param sourceViewer the source viewer to be configured by this configuration
|
|
331 * @return the information control creator or <code>null</code> if no information support should be installed
|
|
332 * @since 2.0
|
|
333 */
|
|
334 public IInformationControlCreator getInformationControlCreator(ISourceViewer sourceViewer) {
|
|
335 return new IInformationControlCreator() {
|
|
336 public IInformationControl createInformationControl(Shell parent) {
|
|
337 return new DefaultInformationControl(parent);
|
|
338 }
|
|
339 };
|
|
340 }
|
|
341
|
|
342 /**
|
|
343 * Returns the information presenter which will determine and shown
|
|
344 * information requested for the current cursor position. This implementation
|
|
345 * always returns <code>null</code>.
|
|
346 *
|
|
347 * @param sourceViewer the source viewer to be configured by this configuration
|
|
348 * @return an information presenter <code>null</code> if no information presenter should be installed
|
|
349 * @since 2.0
|
|
350 */
|
|
351 public IInformationPresenter getInformationPresenter(ISourceViewer sourceViewer) {
|
|
352 return null;
|
|
353 }
|
|
354
|
|
355 /**
|
|
356 * Returns all configured content types for the given source viewer. This list
|
|
357 * tells the caller which content types must be configured for the given source
|
|
358 * viewer, i.e. for which content types the given source viewer's functionalities
|
|
359 * must be specified. This implementation always returns <code>
|
|
360 * new String[] { IDocument.DEFAULT_CONTENT_TYPE }</code>.
|
|
361 *
|
|
362 * @param sourceViewer the source viewer to be configured by this configuration
|
|
363 * @return the configured content types for the given viewer
|
|
364 */
|
|
365 public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
|
|
366 return new String[] { IDocument.DEFAULT_CONTENT_TYPE };
|
|
367 }
|
|
368
|
|
369 /**
|
|
370 * Returns the configured partitioning for the given source viewer. The partitioning is
|
|
371 * used when the querying content types from the source viewer's input document. This
|
|
372 * implementation always returns <code>IDocumentExtension3.DEFAULT_PARTITIONING</code>.
|
|
373 *
|
|
374 * @param sourceViewer the source viewer to be configured by this configuration
|
|
375 * @return the configured partitioning
|
|
376 * @see #getConfiguredContentTypes(ISourceViewer)
|
|
377 * @since 3.0
|
|
378 */
|
|
379 public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) {
|
|
380 return IDocumentExtension3.DEFAULT_PARTITIONING;
|
|
381 }
|
|
382
|
|
383 /**
|
|
384 * Returns the hyperlink detectors which be used to detect hyperlinks
|
|
385 * in the given source viewer. This
|
|
386 * implementation always returns an array with an URL hyperlink detector.
|
|
387 *
|
|
388 * @param sourceViewer the source viewer to be configured by this configuration
|
|
389 * @return an array with hyperlink detectors or <code>null</code> if no hyperlink support should be installed
|
|
390 * @since 3.1
|
|
391 */
|
|
392 public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
|
|
393 if (sourceViewer is null)
|
|
394 return null;
|
|
395
|
|
396 return new IHyperlinkDetector[] { new URLHyperlinkDetector() };
|
|
397 }
|
|
398
|
|
399 /**
|
|
400 * Returns the hyperlink presenter for the given source viewer.
|
|
401 * This implementation always returns the {@link DefaultHyperlinkPresenter}.
|
|
402 *
|
|
403 * @param sourceViewer the source viewer to be configured by this configuration
|
|
404 * @return the hyperlink presenter or <code>null</code> if no hyperlink support should be installed
|
|
405 * @since 3.1
|
|
406 */
|
|
407 public IHyperlinkPresenter getHyperlinkPresenter(ISourceViewer sourceViewer) {
|
|
408 return new DefaultHyperlinkPresenter(new RGB(0, 0, 255));
|
|
409 }
|
|
410
|
|
411 /**
|
|
412 * Returns the DWT event state mask which in combination
|
|
413 * with the left mouse button activates hyperlinking.
|
|
414 * This implementation always returns the {@link DWT#MOD1}.
|
|
415 *
|
|
416 * @param sourceViewer the source viewer to be configured by this configuration
|
|
417 * @return the DWT event state mask to activate hyperlink mode
|
|
418 * @since 3.1
|
|
419 */
|
|
420 public int getHyperlinkStateMask(ISourceViewer sourceViewer) {
|
|
421 return DWT.MOD1;
|
|
422 }
|
|
423 }
|