129
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 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.ITextViewer;
|
|
14
|
|
15 import dwt.dwthelper.utils;
|
|
16
|
|
17
|
|
18
|
|
19 import dwt.custom.StyledText;
|
|
20 import dwt.graphics.Color;
|
|
21 import dwt.graphics.Point;
|
|
22 import dwtx.jface.viewers.ISelectionProvider;
|
|
23
|
|
24
|
|
25 /**
|
|
26 * A text viewer connects a text widget with an
|
|
27 * {@link dwtx.jface.text.IDocument}. The document is used as the
|
|
28 * widget's text model.
|
|
29 * <p>
|
|
30 * It supports the following kinds of listeners:
|
|
31 * <ul>
|
|
32 * <li>view port listeners to inform about changes of the viewer's view port</li>
|
|
33 * <li>text listeners to inform about changes of the document and the
|
|
34 * subsequent viewer change</li>
|
|
35 * <li>text input listeners to inform about changes of the viewer's input
|
|
36 * document.</li>
|
|
37 * </ul>
|
|
38 * A text viewer supports a set of configuration options and plug-ins defining
|
|
39 * its behavior:
|
|
40 * <ul>
|
|
41 * <li>undo manager</li>
|
|
42 * <li>double click behavior</li>
|
|
43 * <li>auto indentation</li>
|
|
44 * <li>text hover</li>
|
|
45 * </ul>
|
|
46 * Installed plug-ins are not automatically activated. Plug-ins must be
|
|
47 * activated with the <code>activatePlugins</code> call. Most plug-ins can be
|
|
48 * defined per content type. Content types are derived from a partitioning of
|
|
49 * the text viewer's input document. In case of documents that support multiple
|
|
50 * partitionings, the implementer is responsible for determining the
|
|
51 * partitioning to use.
|
|
52 * <p>
|
|
53 * A text viewer also provides the concept of event consumption. Events handled
|
|
54 * by the viewer can be filtered and processed by a dynamic event consumer. With
|
|
55 * {@link dwtx.jface.text.ITextViewerExtension}, this mechanism has been
|
|
56 * replaced with the support for
|
|
57 * {@link dwt.custom.VerifyKeyListener}.
|
|
58 * <p>
|
|
59 * A text viewer provides several text editing functions, some of them are
|
|
60 * configurable, through a text operation target interface. It also supports a
|
|
61 * presentation mode in which it only shows a specified section of its document.
|
|
62 * By calling <code>setVisibleRegion</code> clients define which section is
|
|
63 * visible. Clients can get access to this section by calling
|
|
64 * <code>getVisibleRegion</code>. The viewer's presentation mode does not
|
|
65 * affect any client of the viewer other than text listeners. With
|
|
66 * {@link dwtx.jface.text.ITextViewerExtension5} the visible region
|
|
67 * support has been reworked. With that extension interface, text viewers are
|
|
68 * allowed to show fractions of their input document. I.e. a widget selection of
|
|
69 * two visually neighboring characters is no longer guaranteed to be two
|
|
70 * neighboring characters in the viewer's input document. Thus, viewers
|
|
71 * implementing {@link dwtx.jface.text.ITextViewerExtension5} are
|
|
72 * potentially forced to change the fractions of the input document that are
|
|
73 * shown when clients ask for the visible region.
|
|
74 * <p>
|
|
75 *
|
|
76 * In order to provide backward compatibility for clients of
|
|
77 * <code>ITextViewer</code>, extension interfaces are used as a means of
|
|
78 * evolution. The following extension interfaces exist:
|
|
79 * <ul>
|
|
80 * <li>{@link dwtx.jface.text.ITextViewerExtension} since version 2.0
|
|
81 * replacing the event consumer mechanism and introducing the concept of rewrite
|
|
82 * targets and means to manage the viewer's redraw behavior</li>
|
|
83 * <li>{@link dwtx.jface.text.ITextViewerExtension2}since version 2.1
|
|
84 * adding a way to invalidate a viewer's presentation and setters for hovers.
|
|
85 * </li>
|
|
86 * <li>{@link dwtx.jface.text.ITextViewerExtension3} since version 2.1
|
|
87 * which itself was replaced by
|
|
88 * {@link dwtx.jface.text.ITextViewerExtension5} in version 3.0</li>
|
|
89 * <li>{@link dwtx.jface.text.ITextViewerExtension4} since version 3.0
|
|
90 * introducing focus handling for widget token keepers and the concept of text
|
|
91 * presentation listeners.</li>
|
|
92 * <li>{@link dwtx.jface.text.ITextViewerExtension5} since version 3.0
|
|
93 * extending the visible region concept with explicit handling and conversion
|
|
94 * of widget and model coordinates.</li>
|
|
95 * <li>{@link dwtx.jface.text.ITextViewerExtension6} since version 3.1
|
|
96 * extending the text viewer with the ability to detect hyperlinks and access the undo manager.</li>
|
|
97 * <li>{@link dwtx.jface.text.ITextViewerExtension7} since version 3.3
|
|
98 * extending the text viewer with the ability to install tabs to spaces conversion.</li>
|
|
99 * <li>{@link dwtx.jface.text.ITextViewerExtension8} since version 3.4
|
|
100 * extending the text viewer with the ability to print and rich hover support.</li>
|
|
101 * </ul></p>
|
|
102 * <p>
|
|
103 * Clients may implement this interface and its extension interfaces or use the
|
|
104 * standard implementation {@link dwtx.jface.text.TextViewer}.</p>
|
|
105 *
|
|
106 * @see dwtx.jface.text.ITextViewerExtension
|
|
107 * @see dwtx.jface.text.ITextViewerExtension2
|
|
108 * @see dwtx.jface.text.ITextViewerExtension3
|
|
109 * @see dwtx.jface.text.ITextViewerExtension4
|
|
110 * @see dwtx.jface.text.ITextViewerExtension5
|
|
111 * @see dwtx.jface.text.ITextViewerExtension6
|
|
112 * @see dwtx.jface.text.ITextViewerExtension7
|
|
113 * @see dwtx.jface.text.ITextViewerExtension8
|
|
114 * @see dwtx.jface.text.IDocument
|
|
115 * @see dwtx.jface.text.ITextInputListener
|
|
116 * @see dwtx.jface.text.IViewportListener
|
|
117 * @see dwtx.jface.text.ITextListener
|
|
118 * @see dwtx.jface.text.IEventConsumer
|
|
119 */
|
|
120 public interface ITextViewer {
|
|
121
|
|
122
|
|
123 /* ---------- widget --------- */
|
|
124
|
|
125 /**
|
|
126 * Returns this viewer's DWT control, <code>null</code> if the control is disposed.
|
|
127 * <p>
|
|
128 * <em>Calling API directly on the widget can interfere with features provided
|
|
129 * by a text viewer. Clients who call API directly on the widget are responsible
|
|
130 * to resolve such conflicts on their side.</em>
|
|
131 * </p>
|
|
132 *
|
|
133 * @return the DWT control or <code>null</code>
|
|
134 */
|
|
135 StyledText getTextWidget();
|
|
136
|
|
137
|
|
138 /* --------- plug-ins --------- */
|
|
139
|
|
140 /**
|
|
141 * Sets this viewer's undo manager.
|
|
142 *
|
|
143 * @param undoManager the new undo manager. <code>null</code> is a valid argument.
|
|
144 */
|
|
145 void setUndoManager(IUndoManager undoManager);
|
|
146
|
|
147 /**
|
|
148 * Sets this viewer's text double click strategy for the given content type.
|
|
149 *
|
|
150 * @param strategy the new double click strategy. <code>null</code> is a valid argument.
|
|
151 * @param contentType the type for which the strategy is registered
|
|
152 */
|
|
153 void setTextDoubleClickStrategy(ITextDoubleClickStrategy strategy, String contentType);
|
|
154
|
|
155 /**
|
|
156 * Sets this viewer's auto indent strategy for the given content type. If
|
|
157 * the given strategy is <code>null</code> any installed strategy for the
|
|
158 * content type is removed. This method has been replaced by
|
|
159 * {@link ITextViewerExtension2#prependAutoEditStrategy(IAutoEditStrategy, String)} and
|
|
160 * {@link ITextViewerExtension2#removeAutoEditStrategy(IAutoEditStrategy, String)}.
|
|
161 * It is now equivalent to
|
|
162 * <pre>
|
|
163 * ITextViewerExtension2 extension= (ITextViewerExtension2) viewer;
|
|
164 * extension.removeAutoEditStrategy(oldStrategy, contentType);
|
|
165 * extension.prependAutoEditStrategy(strategy, contentType);
|
|
166 * </pre>
|
|
167 *
|
|
168 * @param strategy the new auto indent strategy. <code>null</code> is a
|
|
169 * valid argument.
|
|
170 * @param contentType the type for which the strategy is registered
|
|
171 * @deprecated since 3.1, use
|
|
172 * {@link ITextViewerExtension2#prependAutoEditStrategy(IAutoEditStrategy, String)} and
|
|
173 * {@link ITextViewerExtension2#removeAutoEditStrategy(IAutoEditStrategy, String)} instead
|
|
174 */
|
|
175 void setAutoIndentStrategy(IAutoIndentStrategy strategy, String contentType);
|
|
176
|
|
177 /**
|
|
178 * Sets this viewer's text hover for the given content type.
|
|
179 * <p>
|
|
180 * This method has been replaced by {@link ITextViewerExtension2#setTextHover(ITextHover, String, int)}.
|
|
181 * It is now equivalent to
|
|
182 * <pre>
|
|
183 * ITextViewerExtension2 extension= (ITextViewerExtension2) document;
|
|
184 * extension.setTextHover(textViewerHover, contentType, ITextViewerExtension2#DEFAULT_HOVER_STATE_MASK);
|
|
185 * </pre>
|
|
186 *
|
|
187 *
|
|
188 * @param textViewerHover the new hover. <code>null</code> is a valid
|
|
189 * argument.
|
|
190 * @param contentType the type for which the hover is registered
|
|
191 */
|
|
192 void setTextHover(ITextHover textViewerHover, String contentType);
|
|
193
|
|
194 /**
|
|
195 * Activates the installed plug-ins. If the plug-ins are already activated
|
|
196 * this call has no effect.
|
|
197 */
|
|
198 void activatePlugins();
|
|
199
|
|
200 /**
|
|
201 * Resets the installed plug-ins. If plug-ins change their state or
|
|
202 * behavior over the course of time, this method causes them to be set
|
|
203 * back to their initial state and behavior. E.g., if an {@link IUndoManager}
|
|
204 * has been installed on this text viewer, the manager's list of remembered
|
|
205 * text editing operations is removed.
|
|
206 */
|
|
207 void resetPlugins();
|
|
208
|
|
209
|
|
210
|
|
211 /* ---------- listeners ------------- */
|
|
212
|
|
213 /**
|
|
214 * Adds the given view port listener to this viewer. The listener
|
|
215 * is informed about all changes to the visible area of this viewer.
|
|
216 * If the listener is already registered with this viewer, this call
|
|
217 * has no effect.
|
|
218 *
|
|
219 * @param listener the listener to be added
|
|
220 */
|
|
221 void addViewportListener(IViewportListener listener);
|
|
222
|
|
223 /**
|
|
224 * Removes the given listener from this viewer's set of view port listeners.
|
|
225 * If the listener is not registered with this viewer, this call has
|
|
226 * no effect.
|
|
227 *
|
|
228 * @param listener the listener to be removed
|
|
229 */
|
|
230 void removeViewportListener(IViewportListener listener);
|
|
231
|
|
232 /**
|
|
233 * Adds a text listener to this viewer. If the listener is already registered
|
|
234 * with this viewer, this call has no effect.
|
|
235 *
|
|
236 * @param listener the listener to be added
|
|
237 */
|
|
238 void addTextListener(ITextListener listener);
|
|
239
|
|
240 /**
|
|
241 * Removes the given listener from this viewer's set of text listeners.
|
|
242 * If the listener is not registered with this viewer, this call has
|
|
243 * no effect.
|
|
244 *
|
|
245 * @param listener the listener to be removed
|
|
246 */
|
|
247 void removeTextListener(ITextListener listener);
|
|
248
|
|
249 /**
|
|
250 * Adds a text input listener to this viewer. If the listener is already registered
|
|
251 * with this viewer, this call has no effect.
|
|
252 *
|
|
253 * @param listener the listener to be added
|
|
254 */
|
|
255 void addTextInputListener(ITextInputListener listener);
|
|
256
|
|
257 /**
|
|
258 * Removes the given listener from this viewer's set of text input listeners.
|
|
259 * If the listener is not registered with this viewer, this call has
|
|
260 * no effect.
|
|
261 *
|
|
262 * @param listener the listener to be removed
|
|
263 */
|
|
264 void removeTextInputListener(ITextInputListener listener);
|
|
265
|
|
266
|
|
267
|
|
268 /* -------------- model manipulation ------------- */
|
|
269
|
|
270 /**
|
|
271 * Sets the given document as the text viewer's model and updates the
|
|
272 * presentation accordingly. An appropriate <code>TextEvent</code> is
|
|
273 * issued. This text event does not carry a related document event.
|
|
274 *
|
|
275 * @param document the viewer's new input document <code>null</code> if none
|
|
276 */
|
|
277 void setDocument(IDocument document);
|
|
278
|
|
279 /**
|
|
280 * Returns the text viewer's input document.
|
|
281 *
|
|
282 * @return the viewer's input document or <code>null</code> if none
|
|
283 */
|
|
284 IDocument getDocument();
|
|
285
|
|
286
|
|
287 /* -------------- event handling ----------------- */
|
|
288
|
|
289 /**
|
|
290 * Registers an event consumer with this viewer. This method has been
|
|
291 * replaces with the {@link dwt.custom.VerifyKeyListener}
|
|
292 * management methods in {@link ITextViewerExtension}.
|
|
293 *
|
|
294 * @param consumer the viewer's event consumer. <code>null</code> is a
|
|
295 * valid argument.
|
|
296 */
|
|
297 void setEventConsumer(IEventConsumer consumer);
|
|
298
|
|
299 /**
|
|
300 * Sets the editable state.
|
|
301 *
|
|
302 * @param editable the editable state
|
|
303 */
|
|
304 void setEditable(bool editable);
|
|
305
|
|
306 /**
|
|
307 * Returns whether the shown text can be manipulated.
|
|
308 *
|
|
309 * @return the viewer's editable state
|
|
310 */
|
|
311 bool isEditable();
|
|
312
|
|
313
|
|
314 /* ----------- visible region support ------------- */
|
|
315
|
|
316 /**
|
|
317 * Sets the given document as this viewer's model and
|
|
318 * exposes the specified region. An appropriate
|
|
319 * <code>TextEvent</code> is issued. The text event does not carry a
|
|
320 * related document event. This method is a convenience method for
|
|
321 * <code>setDocument(document);setVisibleRegion(offset, length)</code>.
|
|
322 *
|
|
323 * @param document the new input document or <code>null</code> if none
|
|
324 * @param modelRangeOffset the offset of the model range
|
|
325 * @param modelRangeLength the length of the model range
|
|
326 */
|
|
327 void setDocument(IDocument document, int modelRangeOffset, int modelRangeLength);
|
|
328
|
|
329 /**
|
|
330 * Defines and sets the region of this viewer's document which will be
|
|
331 * visible in the presentation. Every character inside the specified region
|
|
332 * is supposed to be visible in the viewer's widget after that call.
|
|
333 *
|
|
334 * @param offset the offset of the visible region
|
|
335 * @param length the length of the visible region
|
|
336 */
|
|
337 void setVisibleRegion(int offset, int length);
|
|
338
|
|
339 /**
|
|
340 * Resets the region of this viewer's document which is visible in the presentation.
|
|
341 * Afterwards, the whole input document is visible.
|
|
342 */
|
|
343 void resetVisibleRegion();
|
|
344
|
|
345 /**
|
|
346 * Returns the current visible region of this viewer's document. The result
|
|
347 * may differ from the argument passed to <code>setVisibleRegion</code> if
|
|
348 * the document has been modified since then. The visible region is supposed
|
|
349 * to be a consecutive region in viewer's input document and every character
|
|
350 * inside that region is supposed to visible in the viewer's widget.
|
|
351 * <p>
|
|
352 * Viewers implementing {@link ITextViewerExtension5} may be forced to
|
|
353 * change the fractions of the input document that are shown, in order to
|
|
354 * fulfill this contract.
|
|
355 *
|
|
356 * @return this viewer's current visible region
|
|
357 */
|
|
358 IRegion getVisibleRegion();
|
|
359
|
|
360 /**
|
|
361 * Returns whether a given range overlaps with the visible region of this
|
|
362 * viewer's document.
|
|
363 * <p>
|
|
364 * Viewers implementing {@link ITextViewerExtension5}may be forced to
|
|
365 * change the fractions of the input document that are shown in order to
|
|
366 * fulfill this request. This is because the overlap is supposed to be
|
|
367 * without gaps.
|
|
368 *
|
|
369 * @param offset the offset
|
|
370 * @param length the length
|
|
371 * @return <code>true</code> if the specified range overlaps with the
|
|
372 * visible region
|
|
373 */
|
|
374 bool overlapsWithVisibleRegion(int offset, int length);
|
|
375
|
|
376
|
|
377
|
|
378 /* ------------- presentation manipulation ----------- */
|
|
379
|
|
380 /**
|
|
381 * Applies the color information encoded in the given text presentation.
|
|
382 * <code>controlRedraw</code> tells this viewer whether it should take care of
|
|
383 * redraw management or not. If, e.g., this call is one in a sequence of multiple
|
|
384 * presentation calls, it is more appropriate to explicitly control redrawing at the
|
|
385 * beginning and the end of the sequence.
|
|
386 *
|
|
387 * @param presentation the presentation to be applied to this viewer
|
|
388 * @param controlRedraw indicates whether this viewer should manage redraws
|
|
389 */
|
|
390 void changeTextPresentation(TextPresentation presentation, bool controlRedraw);
|
|
391
|
|
392 /**
|
|
393 * Marks the currently applied text presentation as invalid. It is the
|
|
394 * viewer's responsibility to take any action it can to repair the text
|
|
395 * presentation.
|
|
396 * <p>
|
|
397 * See {@link ITextViewerExtension2#invalidateTextPresentation(int, int)}
|
|
398 * for a way to invalidate specific regions rather than the presentation as
|
|
399 * a whole.
|
|
400 *
|
|
401 * @since 2.0
|
|
402 */
|
|
403 void invalidateTextPresentation();
|
|
404
|
|
405 /**
|
|
406 * Applies the given color as text foreground color to this viewer's
|
|
407 * selection.
|
|
408 *
|
|
409 * @param color the color to be applied
|
|
410 */
|
|
411 void setTextColor(Color color);
|
|
412
|
|
413 /**
|
|
414 * Applies the given color as text foreground color to the specified section
|
|
415 * of this viewer. <code>controlRedraw</code> tells this viewer whether it
|
|
416 * should take care of redraw management or not.
|
|
417 *
|
|
418 * @param color the color to be applied
|
|
419 * @param offset the offset of the range to be changed
|
|
420 * @param length the length of the range to be changed
|
|
421 * @param controlRedraw indicates whether this viewer should manage redraws
|
|
422 */
|
|
423 void setTextColor(Color color, int offset, int length, bool controlRedraw);
|
|
424
|
|
425
|
|
426 /* --------- target handling and configuration ------------ */
|
|
427
|
|
428 /**
|
|
429 * Returns the text operation target of this viewer.
|
|
430 *
|
|
431 * @return the text operation target of this viewer
|
|
432 */
|
|
433 ITextOperationTarget getTextOperationTarget();
|
|
434
|
|
435 /**
|
|
436 * Returns the find/replace operation target of this viewer.
|
|
437 *
|
|
438 * @return the find/replace operation target of this viewer
|
|
439 */
|
|
440 IFindReplaceTarget getFindReplaceTarget();
|
|
441
|
|
442 /**
|
|
443 * Sets the strings that are used as prefixes when lines of the given content type
|
|
444 * are prefixed using the prefix text operation. The prefixes are considered equivalent.
|
|
445 * Inserting a prefix always inserts the defaultPrefixes[0].
|
|
446 * Removing a prefix removes all of the specified prefixes.
|
|
447 *
|
|
448 * @param defaultPrefixes the prefixes to be used
|
|
449 * @param contentType the content type for which the prefixes are specified
|
|
450 * @since 2.0
|
|
451 */
|
|
452 void setDefaultPrefixes(String[] defaultPrefixes, String contentType);
|
|
453
|
|
454 /**
|
|
455 * Sets the strings that are used as prefixes when lines of the given content type
|
|
456 * are shifted using the shift text operation. The prefixes are considered equivalent.
|
|
457 * Thus "\t" and " " can both be used as prefix characters.
|
|
458 * Shift right always inserts the indentPrefixes[0].
|
|
459 * Shift left removes all of the specified prefixes.
|
|
460 *
|
|
461 * @param indentPrefixes the prefixes to be used
|
|
462 * @param contentType the content type for which the prefixes are specified
|
|
463 */
|
|
464 void setIndentPrefixes(String[] indentPrefixes, String contentType);
|
|
465
|
|
466
|
|
467
|
|
468 /* --------- selection handling -------------- */
|
|
469
|
|
470 /**
|
|
471 * Sets the selection to the specified range.
|
|
472 *
|
|
473 * @param offset the offset of the selection range
|
|
474 * @param length the length of the selection range. A negative length places
|
|
475 * the caret at the visual start of the selection.
|
|
476 */
|
|
477 void setSelectedRange(int offset, int length);
|
|
478
|
|
479 /**
|
|
480 * Returns the range of the current selection in coordinates of this viewer's document.
|
|
481 *
|
|
482 * @return a <code>Point</code> with x as the offset and y as the length of the current selection
|
|
483 */
|
|
484 Point getSelectedRange();
|
|
485
|
|
486 /**
|
|
487 * Returns a selection provider dedicated to this viewer. Subsequent
|
|
488 * calls to this method return always the same selection provider.
|
|
489 *
|
|
490 * @return this viewer's selection provider
|
|
491 */
|
|
492 ISelectionProvider getSelectionProvider();
|
|
493
|
|
494
|
|
495 /* ------------- appearance manipulation --------------- */
|
|
496
|
|
497 /**
|
|
498 * Ensures that the given range is visible.
|
|
499 *
|
|
500 * @param offset the offset of the range to be revealed
|
|
501 * @param length the length of the range to be revealed
|
|
502 */
|
|
503 void revealRange(int offset, int length);
|
|
504
|
|
505 /**
|
|
506 * Scrolls the widget so that the given index is the line
|
|
507 * with the smallest line number of all visible lines.
|
|
508 *
|
|
509 * @param index the line which should become the top most line
|
|
510 */
|
|
511 void setTopIndex(int index);
|
|
512
|
|
513 /**
|
|
514 * Returns the visible line with the smallest line number.
|
|
515 *
|
|
516 * @return the number of the top most visible line
|
|
517 */
|
|
518 int getTopIndex();
|
|
519
|
|
520 /**
|
|
521 * Returns the document offset of the upper left corner of this viewer's view port.
|
|
522 *
|
|
523 * @return the upper left corner offset
|
|
524 */
|
|
525 int getTopIndexStartOffset();
|
|
526
|
|
527 /**
|
|
528 * Returns the visible line with the highest line number.
|
|
529 *
|
|
530 * @return the number of the bottom most line
|
|
531 */
|
|
532 int getBottomIndex();
|
|
533
|
|
534 /**
|
|
535 * Returns the document offset of the lower right
|
|
536 * corner of this viewer's view port. This is the visible character
|
|
537 * with the highest character position. If the content of this viewer
|
|
538 * is shorter, the position of the last character of the content is returned.
|
|
539 *
|
|
540 * @return the lower right corner offset
|
|
541 */
|
|
542 int getBottomIndexEndOffset();
|
|
543
|
|
544 /**
|
|
545 * Returns the vertical offset of the first visible line.
|
|
546 *
|
|
547 * @return the vertical offset of the first visible line
|
|
548 */
|
|
549 int getTopInset();
|
|
550 }
|