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.source.SourceViewer;
|
|
14
|
131
|
15 import dwtx.jface.text.source.ISharedTextColors; // packageimport
|
|
16 import dwtx.jface.text.source.ILineRange; // packageimport
|
|
17 import dwtx.jface.text.source.IAnnotationPresentation; // packageimport
|
|
18 import dwtx.jface.text.source.IVerticalRulerInfoExtension; // packageimport
|
|
19 import dwtx.jface.text.source.ICharacterPairMatcher; // packageimport
|
|
20 import dwtx.jface.text.source.TextInvocationContext; // packageimport
|
|
21 import dwtx.jface.text.source.LineChangeHover; // packageimport
|
|
22 import dwtx.jface.text.source.IChangeRulerColumn; // packageimport
|
|
23 import dwtx.jface.text.source.IAnnotationMap; // packageimport
|
|
24 import dwtx.jface.text.source.IAnnotationModelListenerExtension; // packageimport
|
|
25 import dwtx.jface.text.source.ISourceViewerExtension2; // packageimport
|
|
26 import dwtx.jface.text.source.IAnnotationHover; // packageimport
|
|
27 import dwtx.jface.text.source.ContentAssistantFacade; // packageimport
|
|
28 import dwtx.jface.text.source.IAnnotationAccess; // packageimport
|
|
29 import dwtx.jface.text.source.IVerticalRulerExtension; // packageimport
|
|
30 import dwtx.jface.text.source.IVerticalRulerColumn; // packageimport
|
|
31 import dwtx.jface.text.source.LineNumberRulerColumn; // packageimport
|
|
32 import dwtx.jface.text.source.MatchingCharacterPainter; // packageimport
|
|
33 import dwtx.jface.text.source.IAnnotationModelExtension; // packageimport
|
|
34 import dwtx.jface.text.source.ILineDifferExtension; // packageimport
|
|
35 import dwtx.jface.text.source.DefaultCharacterPairMatcher; // packageimport
|
|
36 import dwtx.jface.text.source.LineNumberChangeRulerColumn; // packageimport
|
|
37 import dwtx.jface.text.source.IAnnotationAccessExtension; // packageimport
|
|
38 import dwtx.jface.text.source.ISourceViewer; // packageimport
|
|
39 import dwtx.jface.text.source.AnnotationModel; // packageimport
|
|
40 import dwtx.jface.text.source.ILineDifferExtension2; // packageimport
|
|
41 import dwtx.jface.text.source.IAnnotationModelListener; // packageimport
|
|
42 import dwtx.jface.text.source.IVerticalRuler; // packageimport
|
|
43 import dwtx.jface.text.source.DefaultAnnotationHover; // packageimport
|
|
44 import dwtx.jface.text.source.SourceViewerConfiguration; // packageimport
|
|
45 import dwtx.jface.text.source.AnnotationBarHoverManager; // packageimport
|
|
46 import dwtx.jface.text.source.CompositeRuler; // packageimport
|
|
47 import dwtx.jface.text.source.ImageUtilities; // packageimport
|
|
48 import dwtx.jface.text.source.VisualAnnotationModel; // packageimport
|
|
49 import dwtx.jface.text.source.IAnnotationModel; // packageimport
|
|
50 import dwtx.jface.text.source.ISourceViewerExtension3; // packageimport
|
|
51 import dwtx.jface.text.source.ILineDiffInfo; // packageimport
|
|
52 import dwtx.jface.text.source.VerticalRulerEvent; // packageimport
|
|
53 import dwtx.jface.text.source.ChangeRulerColumn; // packageimport
|
|
54 import dwtx.jface.text.source.ILineDiffer; // packageimport
|
|
55 import dwtx.jface.text.source.AnnotationModelEvent; // packageimport
|
|
56 import dwtx.jface.text.source.AnnotationColumn; // packageimport
|
|
57 import dwtx.jface.text.source.AnnotationRulerColumn; // packageimport
|
|
58 import dwtx.jface.text.source.IAnnotationHoverExtension; // packageimport
|
|
59 import dwtx.jface.text.source.AbstractRulerColumn; // packageimport
|
|
60 import dwtx.jface.text.source.ISourceViewerExtension; // packageimport
|
|
61 import dwtx.jface.text.source.AnnotationMap; // packageimport
|
|
62 import dwtx.jface.text.source.IVerticalRulerInfo; // packageimport
|
|
63 import dwtx.jface.text.source.IAnnotationModelExtension2; // packageimport
|
|
64 import dwtx.jface.text.source.LineRange; // packageimport
|
|
65 import dwtx.jface.text.source.IAnnotationAccessExtension2; // packageimport
|
|
66 import dwtx.jface.text.source.VerticalRuler; // packageimport
|
|
67 import dwtx.jface.text.source.JFaceTextMessages; // packageimport
|
|
68 import dwtx.jface.text.source.IOverviewRuler; // packageimport
|
|
69 import dwtx.jface.text.source.Annotation; // packageimport
|
|
70 import dwtx.jface.text.source.IVerticalRulerListener; // packageimport
|
|
71 import dwtx.jface.text.source.ISourceViewerExtension4; // packageimport
|
|
72 import dwtx.jface.text.source.AnnotationPainter; // packageimport
|
|
73 import dwtx.jface.text.source.IAnnotationHoverExtension2; // packageimport
|
|
74 import dwtx.jface.text.source.OverviewRuler; // packageimport
|
|
75 import dwtx.jface.text.source.OverviewRulerHoverManager; // packageimport
|
|
76
|
|
77
|
129
|
78 import dwt.dwthelper.utils;
|
|
79
|
|
80 import java.util.Iterator;
|
|
81 import java.util.Stack;
|
|
82
|
|
83 import dwt.DWT;
|
|
84 import dwt.graphics.Point;
|
|
85 import dwt.graphics.Rectangle;
|
|
86 import dwt.widgets.Canvas;
|
|
87 import dwt.widgets.Composite;
|
|
88 import dwt.widgets.Control;
|
|
89 import dwt.widgets.Layout;
|
|
90 import dwtx.jface.internal.text.NonDeletingPositionUpdater;
|
|
91 import dwtx.jface.internal.text.StickyHoverManager;
|
|
92 import dwtx.jface.text.AbstractHoverInformationControlManager;
|
|
93 import dwtx.jface.text.BadLocationException;
|
|
94 import dwtx.jface.text.BadPositionCategoryException;
|
|
95 import dwtx.jface.text.DocumentRewriteSession;
|
|
96 import dwtx.jface.text.DocumentRewriteSessionType;
|
|
97 import dwtx.jface.text.IDocument;
|
|
98 import dwtx.jface.text.IDocumentExtension4;
|
|
99 import dwtx.jface.text.IPositionUpdater;
|
|
100 import dwtx.jface.text.IRegion;
|
|
101 import dwtx.jface.text.IRewriteTarget;
|
|
102 import dwtx.jface.text.ISlaveDocumentManager;
|
|
103 import dwtx.jface.text.ISlaveDocumentManagerExtension;
|
|
104 import dwtx.jface.text.ITextViewerExtension2;
|
|
105 import dwtx.jface.text.Position;
|
|
106 import dwtx.jface.text.Region;
|
|
107 import dwtx.jface.text.TextViewer;
|
|
108 import dwtx.jface.text.contentassist.IContentAssistant;
|
|
109 import dwtx.jface.text.contentassist.IContentAssistantExtension4;
|
|
110 import dwtx.jface.text.formatter.FormattingContext;
|
|
111 import dwtx.jface.text.formatter.FormattingContextProperties;
|
|
112 import dwtx.jface.text.formatter.IContentFormatter;
|
|
113 import dwtx.jface.text.formatter.IContentFormatterExtension;
|
|
114 import dwtx.jface.text.formatter.IFormattingContext;
|
|
115 import dwtx.jface.text.hyperlink.IHyperlinkDetector;
|
|
116 import dwtx.jface.text.information.IInformationPresenter;
|
|
117 import dwtx.jface.text.presentation.IPresentationReconciler;
|
|
118 import dwtx.jface.text.projection.ChildDocument;
|
|
119 import dwtx.jface.text.quickassist.IQuickAssistAssistant;
|
|
120 import dwtx.jface.text.quickassist.IQuickAssistInvocationContext;
|
|
121 import dwtx.jface.text.reconciler.IReconciler;
|
|
122
|
|
123 /**
|
|
124 * DWT based implementation of
|
|
125 * {@link dwtx.jface.text.source.ISourceViewer} and its extension
|
|
126 * interfaces. The same rules apply as for
|
|
127 * {@link dwtx.jface.text.TextViewer}. A source viewer uses an
|
|
128 * <code>IVerticalRuler</code> as its annotation presentation area. The
|
|
129 * vertical ruler is a small strip shown left of the viewer's text widget. A
|
|
130 * source viewer uses an <code>IOverviewRuler</code> as its presentation area
|
|
131 * for the annotation overview. The overview ruler is a small strip shown right
|
|
132 * of the viewer's text widget.
|
|
133 * <p>
|
|
134 * Clients are supposed to instantiate a source viewer and subsequently to
|
|
135 * communicate with it exclusively using the <code>ISourceViewer</code> and
|
|
136 * its extension interfaces.</p>
|
|
137 * <p>
|
|
138 * Clients may subclass this class but should expect some breakage by future releases.</p>
|
|
139 */
|
|
140 public class SourceViewer : TextViewer , ISourceViewer, ISourceViewerExtension, ISourceViewerExtension2, ISourceViewerExtension3, ISourceViewerExtension4 {
|
|
141
|
|
142
|
|
143 /**
|
|
144 * Layout of a source viewer. Vertical ruler, text widget, and overview ruler are shown side by side.
|
|
145 */
|
|
146 protected class RulerLayout : Layout {
|
|
147
|
|
148 /** The gap between the text viewer and the vertical ruler. */
|
|
149 protected int fGap;
|
|
150
|
|
151 /**
|
|
152 * Creates a new ruler layout with the given gap between text viewer and vertical ruler.
|
|
153 *
|
|
154 * @param gap the gap between text viewer and vertical ruler
|
|
155 */
|
|
156 public RulerLayout(int gap) {
|
|
157 fGap= gap;
|
|
158 }
|
|
159
|
|
160 /*
|
|
161 * @see Layout#computeSize(Composite, int, int, bool)
|
|
162 */
|
|
163 protected Point computeSize(Composite composite, int wHint, int hHint, bool flushCache) {
|
|
164 Control[] children= composite.getChildren();
|
|
165 Point s= children[children.length - 1].computeSize(DWT.DEFAULT, DWT.DEFAULT, flushCache);
|
|
166 if (fVerticalRuler !is null && fIsVerticalRulerVisible)
|
|
167 s.x += fVerticalRuler.getWidth() + fGap;
|
|
168 return s;
|
|
169 }
|
|
170
|
|
171 /*
|
|
172 * @see Layout#layout(Composite, bool)
|
|
173 */
|
|
174 protected void layout(Composite composite, bool flushCache) {
|
|
175 Rectangle clArea= composite.getClientArea();
|
|
176 Rectangle trim= getTextWidget().computeTrim(0, 0, 0, 0);
|
|
177 int topTrim= - trim.y;
|
|
178 int scrollbarHeight= trim.height - topTrim; // scrollbar is only under the client area
|
|
179
|
|
180 int x= clArea.x;
|
|
181 int width= clArea.width;
|
|
182
|
|
183 if (fOverviewRuler !is null && fIsOverviewRulerVisible) {
|
|
184 int overviewRulerWidth= fOverviewRuler.getWidth();
|
|
185 fOverviewRuler.getControl().setBounds(clArea.x + clArea.width - overviewRulerWidth - 1, clArea.y + scrollbarHeight, overviewRulerWidth, clArea.height - 3*scrollbarHeight);
|
|
186 fOverviewRuler.getHeaderControl().setBounds(clArea.x + clArea.width - overviewRulerWidth - 1, clArea.y, overviewRulerWidth, scrollbarHeight);
|
|
187
|
|
188 width -= overviewRulerWidth + fGap;
|
|
189 }
|
|
190
|
|
191 if (fVerticalRuler !is null && fIsVerticalRulerVisible) {
|
|
192 int verticalRulerWidth= fVerticalRuler.getWidth();
|
|
193 final Control verticalRulerControl= fVerticalRuler.getControl();
|
|
194 int oldWidth= verticalRulerControl.getBounds().width;
|
|
195 verticalRulerControl.setBounds(clArea.x, clArea.y + topTrim, verticalRulerWidth, clArea.height - scrollbarHeight - topTrim);
|
|
196 if (flushCache && getVisualAnnotationModel() !is null && oldWidth is verticalRulerWidth)
|
|
197 verticalRulerControl.redraw();
|
|
198
|
|
199 x += verticalRulerWidth + fGap;
|
|
200 width -= verticalRulerWidth + fGap;
|
|
201 }
|
|
202
|
|
203 getTextWidget().setBounds(x, clArea.y, width, clArea.height);
|
|
204 }
|
|
205 }
|
|
206
|
|
207 /**
|
|
208 * The size of the gap between the vertical ruler and the text widget
|
|
209 * (value <code>2</code>).
|
|
210 * <p>
|
|
211 * Note: As of 3.2, the text editor framework is no longer using 2 as
|
|
212 * gap but 1, see {{@link #GAP_SIZE_1 }.
|
|
213 * </p>
|
|
214 */
|
|
215 protected final static int GAP_SIZE= 2;
|
|
216 /**
|
|
217 * The size of the gap between the vertical ruler and the text widget
|
|
218 * (value <code>1</code>).
|
|
219 * @since 3.2
|
|
220 */
|
|
221 protected final static int GAP_SIZE_1= 1;
|
|
222 /**
|
|
223 * Partial name of the position category to manage remembered selections.
|
|
224 * @since 3.0
|
|
225 */
|
|
226 protected final static String _SELECTION_POSITION_CATEGORY= "__selection_category"; //$NON-NLS-1$
|
|
227 /**
|
|
228 * Key of the model annotation model inside the visual annotation model.
|
|
229 * @since 3.0
|
|
230 */
|
|
231 protected final static Object MODEL_ANNOTATION_MODEL= new Object();
|
|
232
|
|
233 /** The viewer's content assistant */
|
|
234 protected IContentAssistant fContentAssistant;
|
|
235 /**
|
|
236 * The viewer's facade to its content assistant.
|
|
237 * @since 3.4
|
|
238 */
|
|
239 private ContentAssistantFacade fContentAssistantFacade;
|
|
240 /**
|
|
241 * Flag indicating whether the viewer's content assistant is installed.
|
|
242 * @since 2.0
|
|
243 */
|
|
244 protected bool fContentAssistantInstalled;
|
|
245 /**
|
|
246 * This viewer's quick assist assistant.
|
|
247 * @since 3.2
|
|
248 */
|
|
249 protected IQuickAssistAssistant fQuickAssistAssistant;
|
|
250 /**
|
|
251 * Flag indicating whether this viewer's quick assist assistant is installed.
|
|
252 * @since 3.2
|
|
253 */
|
|
254 protected bool fQuickAssistAssistantInstalled;
|
|
255 /** The viewer's content formatter */
|
|
256 protected IContentFormatter fContentFormatter;
|
|
257 /** The viewer's model reconciler */
|
|
258 protected IReconciler fReconciler;
|
|
259 /** The viewer's presentation reconciler */
|
|
260 protected IPresentationReconciler fPresentationReconciler;
|
|
261 /** The viewer's annotation hover */
|
|
262 protected IAnnotationHover fAnnotationHover;
|
|
263 /**
|
|
264 * Stack of saved selections in the underlying document
|
|
265 * @since 3.0
|
|
266 */
|
|
267 protected final Stack fSelections= new Stack();
|
|
268 /**
|
|
269 * Position updater for saved selections
|
|
270 * @since 3.0
|
|
271 */
|
|
272 protected IPositionUpdater fSelectionUpdater= null;
|
|
273 /**
|
|
274 * Position category used by the selection updater
|
|
275 * @since 3.0
|
|
276 */
|
|
277 protected String fSelectionCategory;
|
|
278 /**
|
|
279 * The viewer's overview ruler annotation hover
|
|
280 * @since 3.0
|
|
281 */
|
|
282 protected IAnnotationHover fOverviewRulerAnnotationHover;
|
|
283 /**
|
|
284 * The viewer's information presenter
|
|
285 * @since 2.0
|
|
286 */
|
|
287 protected IInformationPresenter fInformationPresenter;
|
|
288
|
|
289 /** Visual vertical ruler */
|
|
290 private IVerticalRuler fVerticalRuler;
|
|
291 /** Visibility of vertical ruler */
|
|
292 private bool fIsVerticalRulerVisible;
|
|
293 /** The DWT widget used when supporting a vertical ruler */
|
|
294 private Composite fComposite;
|
|
295 /** The vertical ruler's annotation model */
|
|
296 private IAnnotationModel fVisualAnnotationModel;
|
|
297 /** The viewer's range indicator to be shown in the vertical ruler */
|
|
298 private Annotation fRangeIndicator;
|
|
299 /** The viewer's vertical ruler hovering controller */
|
|
300 private AnnotationBarHoverManager fVerticalRulerHoveringController;
|
|
301 /**
|
|
302 * The viewer's overview ruler hovering controller
|
|
303 * @since 2.1
|
|
304 */
|
|
305 private AbstractHoverInformationControlManager fOverviewRulerHoveringController;
|
|
306
|
|
307 /**
|
|
308 * The overview ruler.
|
|
309 * @since 2.1
|
|
310 */
|
|
311 private IOverviewRuler fOverviewRuler;
|
|
312 /**
|
|
313 * The visibility of the overview ruler
|
|
314 * @since 2.1
|
|
315 */
|
|
316 private bool fIsOverviewRulerVisible;
|
|
317
|
|
318
|
|
319 /**
|
|
320 * Constructs a new source viewer. The vertical ruler is initially visible.
|
|
321 * The viewer has not yet been initialized with a source viewer configuration.
|
|
322 *
|
|
323 * @param parent the parent of the viewer's control
|
|
324 * @param ruler the vertical ruler used by this source viewer
|
|
325 * @param styles the DWT style bits for the viewer's control,
|
|
326 * <em>if <code>DWT.WRAP</code> is set then a custom document adapter needs to be provided, see {@link #createDocumentAdapter()}
|
|
327 */
|
|
328 public SourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
|
|
329 this(parent, ruler, null, false, styles);
|
|
330 }
|
|
331
|
|
332 /**
|
|
333 * Constructs a new source viewer. The vertical ruler is initially visible.
|
|
334 * The overview ruler visibility is controlled by the value of <code>showAnnotationsOverview</code>.
|
|
335 * The viewer has not yet been initialized with a source viewer configuration.
|
|
336 *
|
|
337 * @param parent the parent of the viewer's control
|
|
338 * @param verticalRuler the vertical ruler used by this source viewer
|
|
339 * @param overviewRuler the overview ruler
|
|
340 * @param showAnnotationsOverview <code>true</code> if the overview ruler should be visible, <code>false</code> otherwise
|
|
341 * @param styles the DWT style bits for the viewer's control,
|
|
342 * <em>if <code>DWT.WRAP</code> is set then a custom document adapter needs to be provided, see {@link #createDocumentAdapter()}
|
|
343 * @since 2.1
|
|
344 */
|
|
345 public SourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler, bool showAnnotationsOverview, int styles) {
|
|
346 super();
|
|
347
|
|
348 fVerticalRuler= verticalRuler;
|
|
349 fIsVerticalRulerVisible= (verticalRuler !is null);
|
|
350 fOverviewRuler= overviewRuler;
|
|
351 fIsOverviewRulerVisible= (showAnnotationsOverview && overviewRuler !is null);
|
|
352
|
|
353 createControl(parent, styles);
|
|
354 }
|
|
355
|
|
356 /*
|
|
357 * @see TextViewer#createControl(Composite, int)
|
|
358 */
|
|
359 protected void createControl(Composite parent, int styles) {
|
|
360
|
|
361 if (fVerticalRuler !is null || fOverviewRuler !is null) {
|
|
362 styles= (styles & ~DWT.BORDER);
|
|
363 fComposite= new Canvas(parent, DWT.NONE);
|
|
364 fComposite.setLayout(createLayout());
|
|
365 parent= fComposite;
|
|
366 }
|
|
367
|
|
368 super.createControl(parent, styles);
|
|
369
|
|
370 if (fVerticalRuler !is null)
|
|
371 fVerticalRuler.createControl(fComposite, this);
|
|
372 if (fOverviewRuler !is null)
|
|
373 fOverviewRuler.createControl(fComposite, this);
|
|
374 }
|
|
375
|
|
376 /**
|
|
377 * Creates the layout used for this viewer.
|
|
378 * Subclasses may override this method.
|
|
379 *
|
|
380 * @return the layout used for this viewer
|
|
381 * @since 3.0
|
|
382 */
|
|
383 protected Layout createLayout() {
|
|
384 return new RulerLayout(GAP_SIZE_1);
|
|
385 }
|
|
386
|
|
387 /*
|
|
388 * @see TextViewer#getControl()
|
|
389 */
|
|
390 public Control getControl() {
|
|
391 if (fComposite !is null)
|
|
392 return fComposite;
|
|
393 return super.getControl();
|
|
394 }
|
|
395
|
|
396 /*
|
|
397 * @see ISourceViewer#setAnnotationHover(IAnnotationHover)
|
|
398 */
|
|
399 public void setAnnotationHover(IAnnotationHover annotationHover) {
|
|
400 fAnnotationHover= annotationHover;
|
|
401 }
|
|
402
|
|
403 /**
|
|
404 * Sets the overview ruler's annotation hover of this source viewer.
|
|
405 * The annotation hover provides the information to be displayed in a hover
|
|
406 * popup window if requested over the overview rulers area. The annotation
|
|
407 * hover is assumed to be line oriented.
|
|
408 *
|
|
409 * @param annotationHover the hover to be used, <code>null</code> is a valid argument
|
|
410 * @since 3.0
|
|
411 */
|
|
412 public void setOverviewRulerAnnotationHover(IAnnotationHover annotationHover) {
|
|
413 fOverviewRulerAnnotationHover= annotationHover;
|
|
414 }
|
|
415
|
|
416 /*
|
|
417 * @see ISourceViewer#configure(SourceViewerConfiguration)
|
|
418 */
|
|
419 public void configure(SourceViewerConfiguration configuration) {
|
|
420
|
|
421 if (getTextWidget() is null)
|
|
422 return;
|
|
423
|
|
424 setDocumentPartitioning(configuration.getConfiguredDocumentPartitioning(this));
|
|
425
|
|
426 // install content type independent plug-ins
|
|
427 fPresentationReconciler= configuration.getPresentationReconciler(this);
|
|
428 if (fPresentationReconciler !is null)
|
|
429 fPresentationReconciler.install(this);
|
|
430
|
|
431 fReconciler= configuration.getReconciler(this);
|
|
432 if (fReconciler !is null)
|
|
433 fReconciler.install(this);
|
|
434
|
|
435 fContentAssistant= configuration.getContentAssistant(this);
|
|
436 if (fContentAssistant !is null) {
|
|
437 fContentAssistant.install(this);
|
|
438 if (fContentAssistant instanceof IContentAssistantExtension4 && fContentAssistant instanceof IContentAssistantExtension4)
|
|
439 fContentAssistantFacade= new ContentAssistantFacade(fContentAssistant);
|
|
440 fContentAssistantInstalled= true;
|
|
441 }
|
|
442
|
|
443 fQuickAssistAssistant= configuration.getQuickAssistAssistant(this);
|
|
444 if (fQuickAssistAssistant !is null) {
|
|
445 fQuickAssistAssistant.install(this);
|
|
446 fQuickAssistAssistantInstalled= true;
|
|
447 }
|
|
448
|
|
449 fContentFormatter= configuration.getContentFormatter(this);
|
|
450
|
|
451 fInformationPresenter= configuration.getInformationPresenter(this);
|
|
452 if (fInformationPresenter !is null)
|
|
453 fInformationPresenter.install(this);
|
|
454
|
|
455 setUndoManager(configuration.getUndoManager(this));
|
|
456
|
|
457 getTextWidget().setTabs(configuration.getTabWidth(this));
|
|
458
|
|
459 setAnnotationHover(configuration.getAnnotationHover(this));
|
|
460 setOverviewRulerAnnotationHover(configuration.getOverviewRulerAnnotationHover(this));
|
|
461
|
|
462 setHoverControlCreator(configuration.getInformationControlCreator(this));
|
|
463
|
|
464 setHyperlinkPresenter(configuration.getHyperlinkPresenter(this));
|
|
465 IHyperlinkDetector[] hyperlinkDetectors= configuration.getHyperlinkDetectors(this);
|
|
466 int eventStateMask= configuration.getHyperlinkStateMask(this);
|
|
467 setHyperlinkDetectors(hyperlinkDetectors, eventStateMask);
|
|
468
|
|
469 // install content type specific plug-ins
|
|
470 String[] types= configuration.getConfiguredContentTypes(this);
|
|
471 for (int i= 0; i < types.length; i++) {
|
|
472
|
|
473 String t= types[i];
|
|
474
|
|
475 setAutoEditStrategies(configuration.getAutoEditStrategies(this, t), t);
|
|
476 setTextDoubleClickStrategy(configuration.getDoubleClickStrategy(this, t), t);
|
|
477
|
|
478 int[] stateMasks= configuration.getConfiguredTextHoverStateMasks(this, t);
|
|
479 if (stateMasks !is null) {
|
|
480 for (int j= 0; j < stateMasks.length; j++) {
|
|
481 int stateMask= stateMasks[j];
|
|
482 setTextHover(configuration.getTextHover(this, t, stateMask), t, stateMask);
|
|
483 }
|
|
484 } else {
|
|
485 setTextHover(configuration.getTextHover(this, t), t, ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
|
|
486 }
|
|
487
|
|
488 String[] prefixes= configuration.getIndentPrefixes(this, t);
|
|
489 if (prefixes !is null && prefixes.length > 0)
|
|
490 setIndentPrefixes(prefixes, t);
|
|
491
|
|
492 prefixes= configuration.getDefaultPrefixes(this, t);
|
|
493 if (prefixes !is null && prefixes.length > 0)
|
|
494 setDefaultPrefixes(prefixes, t);
|
|
495 }
|
|
496
|
|
497 activatePlugins();
|
|
498 }
|
|
499
|
|
500 /**
|
|
501 * After this method has been executed the caller knows that any installed annotation hover has been installed.
|
|
502 */
|
|
503 protected void ensureAnnotationHoverManagerInstalled() {
|
|
504 if (fVerticalRuler !is null && (fAnnotationHover !is null || !isVerticalRulerOnlyShowingAnnotations()) && fVerticalRulerHoveringController is null && fHoverControlCreator !is null) {
|
|
505 fVerticalRulerHoveringController= new AnnotationBarHoverManager(fVerticalRuler, this, fAnnotationHover, fHoverControlCreator);
|
|
506 fVerticalRulerHoveringController.install(fVerticalRuler.getControl());
|
|
507 fVerticalRulerHoveringController.getInternalAccessor().setInformationControlReplacer(new StickyHoverManager(this));
|
|
508 }
|
|
509 }
|
|
510
|
|
511 /**
|
|
512 * After this method has been executed the caller knows that any installed overview hover has been installed.
|
|
513 */
|
|
514 protected void ensureOverviewHoverManagerInstalled() {
|
|
515 if (fOverviewRuler !is null && fOverviewRulerAnnotationHover !is null && fOverviewRulerHoveringController is null && fHoverControlCreator !is null) {
|
|
516 fOverviewRulerHoveringController= new OverviewRulerHoverManager(fOverviewRuler, this, fOverviewRulerAnnotationHover, fHoverControlCreator);
|
|
517 fOverviewRulerHoveringController.install(fOverviewRuler.getControl());
|
|
518 fOverviewRulerHoveringController.getInternalAccessor().setInformationControlReplacer(new StickyHoverManager(this));
|
|
519 }
|
|
520 }
|
|
521
|
|
522 /*
|
|
523 * @see dwtx.jface.text.TextViewer#setHoverEnrichMode(dwtx.jface.text.ITextViewerExtension8.EnrichMode)
|
|
524 * @since 3.4
|
|
525 */
|
|
526 public void setHoverEnrichMode(EnrichMode mode) {
|
|
527 super.setHoverEnrichMode(mode);
|
|
528 if (fVerticalRulerHoveringController !is null)
|
|
529 fVerticalRulerHoveringController.getInternalAccessor().setHoverEnrichMode(mode);
|
|
530 if (fOverviewRulerHoveringController !is null)
|
|
531 fOverviewRulerHoveringController.getInternalAccessor().setHoverEnrichMode(mode);
|
|
532 }
|
|
533
|
|
534 /*
|
|
535 * @see TextViewer#activatePlugins()
|
|
536 */
|
|
537 public void activatePlugins() {
|
|
538 ensureAnnotationHoverManagerInstalled();
|
|
539 ensureOverviewHoverManagerInstalled();
|
|
540 super.activatePlugins();
|
|
541 }
|
|
542
|
|
543 /*
|
|
544 * @see ISourceViewer#setDocument(IDocument, IAnnotationModel)
|
|
545 */
|
|
546 public void setDocument(IDocument document) {
|
|
547 setDocument(document, null, -1, -1);
|
|
548 }
|
|
549
|
|
550 /*
|
|
551 * @see ISourceViewer#setDocument(IDocument, IAnnotationModel, int, int)
|
|
552 */
|
|
553 public void setDocument(IDocument document, int visibleRegionOffset, int visibleRegionLength) {
|
|
554 setDocument(document, null, visibleRegionOffset, visibleRegionLength);
|
|
555 }
|
|
556
|
|
557 /*
|
|
558 * @see ISourceViewer#setDocument(IDocument, IAnnotationModel)
|
|
559 */
|
|
560 public void setDocument(IDocument document, IAnnotationModel annotationModel) {
|
|
561 setDocument(document, annotationModel, -1, -1);
|
|
562 }
|
|
563
|
|
564 /**
|
|
565 * Creates the visual annotation model on top of the given annotation model.
|
|
566 *
|
|
567 * @param annotationModel the wrapped annotation model
|
|
568 * @return the visual annotation model on top of the given annotation model
|
|
569 * @since 3.0
|
|
570 */
|
|
571 protected IAnnotationModel createVisualAnnotationModel(IAnnotationModel annotationModel) {
|
|
572 IAnnotationModelExtension model= new AnnotationModel();
|
|
573 model.addAnnotationModel(MODEL_ANNOTATION_MODEL, annotationModel);
|
|
574 return (IAnnotationModel) model;
|
|
575 }
|
|
576
|
|
577 /**
|
|
578 * Disposes the visual annotation model.
|
|
579 *
|
|
580 * @since 3.1
|
|
581 */
|
|
582 protected void disposeVisualAnnotationModel() {
|
|
583 if (fVisualAnnotationModel !is null) {
|
|
584 if (getDocument() !is null)
|
|
585 fVisualAnnotationModel.disconnect(getDocument());
|
|
586
|
|
587 if ( fVisualAnnotationModel instanceof IAnnotationModelExtension)
|
|
588 ((IAnnotationModelExtension)fVisualAnnotationModel).removeAnnotationModel(MODEL_ANNOTATION_MODEL);
|
|
589
|
|
590 fVisualAnnotationModel= null;
|
|
591 }
|
|
592 }
|
|
593
|
|
594 /*
|
|
595 * @see ISourceViewer#setDocument(IDocument, IAnnotationModel, int, int)
|
|
596 */
|
|
597 public void setDocument(IDocument document, IAnnotationModel annotationModel, int modelRangeOffset, int modelRangeLength) {
|
|
598 disposeVisualAnnotationModel();
|
|
599
|
|
600 if (annotationModel !is null && document !is null) {
|
|
601 fVisualAnnotationModel= createVisualAnnotationModel(annotationModel);
|
|
602 fVisualAnnotationModel.connect(document);
|
|
603 }
|
|
604
|
|
605 if (modelRangeOffset is -1 && modelRangeLength is -1)
|
|
606 super.setDocument(document);
|
|
607 else
|
|
608 super.setDocument(document, modelRangeOffset, modelRangeLength);
|
|
609
|
|
610 if (fVerticalRuler !is null)
|
|
611 fVerticalRuler.setModel(fVisualAnnotationModel);
|
|
612
|
|
613 if (fOverviewRuler !is null)
|
|
614 fOverviewRuler.setModel(fVisualAnnotationModel);
|
|
615 }
|
|
616
|
|
617 /*
|
|
618 * @see ISourceViewer#getAnnotationModel()
|
|
619 */
|
|
620 public IAnnotationModel getAnnotationModel() {
|
|
621 if (fVisualAnnotationModel instanceof IAnnotationModelExtension) {
|
|
622 IAnnotationModelExtension extension= (IAnnotationModelExtension) fVisualAnnotationModel;
|
|
623 return extension.getAnnotationModel(MODEL_ANNOTATION_MODEL);
|
|
624 }
|
|
625 return null;
|
|
626 }
|
|
627
|
|
628 /*
|
|
629 * @see dwtx.jface.text.source.ISourceViewerExtension3#getQuickAssistAssistant()
|
|
630 * @since 3.2
|
|
631 */
|
|
632 public IQuickAssistAssistant getQuickAssistAssistant() {
|
|
633 return fQuickAssistAssistant;
|
|
634 }
|
|
635
|
|
636 /**
|
|
637 * {@inheritDoc}
|
|
638 *
|
|
639 * @since 3.4
|
|
640 */
|
|
641 public final ContentAssistantFacade getContentAssistantFacade() {
|
|
642 return fContentAssistantFacade;
|
|
643 }
|
|
644
|
|
645 /*
|
|
646 * @see dwtx.jface.text.source.ISourceViewerExtension3#getQuickAssistInvocationContext()
|
|
647 * @since 3.2
|
|
648 */
|
|
649 public IQuickAssistInvocationContext getQuickAssistInvocationContext() {
|
|
650 Point selection= getSelectedRange();
|
|
651 return new TextInvocationContext(this, selection.x, selection.x);
|
|
652 }
|
|
653
|
|
654 /*
|
|
655 * @see dwtx.jface.text.source.ISourceViewerExtension2#getVisualAnnotationModel()
|
|
656 * @since 3.0
|
|
657 */
|
|
658 public IAnnotationModel getVisualAnnotationModel() {
|
|
659 return fVisualAnnotationModel;
|
|
660 }
|
|
661
|
|
662 /*
|
|
663 * @see dwtx.jface.text.source.ISourceViewerExtension2#unconfigure()
|
|
664 * @since 3.0
|
|
665 */
|
|
666 public void unconfigure() {
|
|
667 clearRememberedSelection();
|
|
668
|
|
669 if (fPresentationReconciler !is null) {
|
|
670 fPresentationReconciler.uninstall();
|
|
671 fPresentationReconciler= null;
|
|
672 }
|
|
673
|
|
674 if (fReconciler !is null) {
|
|
675 fReconciler.uninstall();
|
|
676 fReconciler= null;
|
|
677 }
|
|
678
|
|
679 if (fContentAssistant !is null) {
|
|
680 fContentAssistant.uninstall();
|
|
681 fContentAssistantInstalled= false;
|
|
682 fContentAssistant= null;
|
|
683 if (fContentAssistantFacade !is null)
|
|
684 fContentAssistantFacade= null;
|
|
685 }
|
|
686
|
|
687 if (fQuickAssistAssistant !is null) {
|
|
688 fQuickAssistAssistant.uninstall();
|
|
689 fQuickAssistAssistantInstalled= false;
|
|
690 fQuickAssistAssistant= null;
|
|
691 }
|
|
692
|
|
693 fContentFormatter= null;
|
|
694
|
|
695 if (fInformationPresenter !is null) {
|
|
696 fInformationPresenter.uninstall();
|
|
697 fInformationPresenter= null;
|
|
698 }
|
|
699
|
|
700 fAutoIndentStrategies= null;
|
|
701 fDoubleClickStrategies= null;
|
|
702 fTextHovers= null;
|
|
703 fIndentChars= null;
|
|
704 fDefaultPrefixChars= null;
|
|
705
|
|
706 if (fVerticalRulerHoveringController !is null) {
|
|
707 fVerticalRulerHoveringController.dispose();
|
|
708 fVerticalRulerHoveringController= null;
|
|
709 }
|
|
710
|
|
711 if (fOverviewRulerHoveringController !is null) {
|
|
712 fOverviewRulerHoveringController.dispose();
|
|
713 fOverviewRulerHoveringController= null;
|
|
714 }
|
|
715
|
|
716 if (fUndoManager !is null) {
|
|
717 fUndoManager.disconnect();
|
|
718 fUndoManager= null;
|
|
719 }
|
|
720
|
|
721 setHyperlinkDetectors(null, DWT.NONE);
|
|
722 }
|
|
723
|
|
724 /*
|
|
725 * @see dwtx.jface.text.TextViewer#handleDispose()
|
|
726 */
|
|
727 protected void handleDispose() {
|
|
728 unconfigure();
|
|
729
|
|
730 disposeVisualAnnotationModel();
|
|
731
|
|
732 fVerticalRuler= null;
|
|
733
|
|
734 fOverviewRuler= null;
|
|
735
|
|
736 // http://dev.eclipse.org/bugs/show_bug.cgi?id=15300
|
|
737 fComposite= null;
|
|
738
|
|
739 super.handleDispose();
|
|
740 }
|
|
741
|
|
742 /*
|
|
743 * @see ITextOperationTarget#canDoOperation(int)
|
|
744 */
|
|
745 public bool canDoOperation(int operation) {
|
|
746
|
|
747 if (getTextWidget() is null || (!redraws() && operation !is FORMAT))
|
|
748 return false;
|
|
749
|
|
750 if (operation is CONTENTASSIST_PROPOSALS)
|
|
751 return fContentAssistant !is null && fContentAssistantInstalled && isEditable();
|
|
752
|
|
753 if (operation is CONTENTASSIST_CONTEXT_INFORMATION)
|
|
754 return fContentAssistant !is null && fContentAssistantInstalled && isEditable();
|
|
755
|
|
756 if (operation is QUICK_ASSIST)
|
|
757 return fQuickAssistAssistant !is null && fQuickAssistAssistantInstalled && isEditable();
|
|
758
|
|
759 if (operation is INFORMATION)
|
|
760 return fInformationPresenter !is null;
|
|
761
|
|
762 if (operation is FORMAT) {
|
|
763 return fContentFormatter !is null && isEditable();
|
|
764 }
|
|
765
|
|
766 return super.canDoOperation(operation);
|
|
767 }
|
|
768
|
|
769 /**
|
|
770 * Creates a new formatting context for a format operation.
|
|
771 * <p>
|
|
772 * After the use of the context, clients are required to call
|
|
773 * its <code>dispose</code> method.
|
|
774 *
|
|
775 * @return The new formatting context
|
|
776 * @since 3.0
|
|
777 */
|
|
778 protected IFormattingContext createFormattingContext() {
|
|
779 return new FormattingContext();
|
|
780 }
|
|
781
|
|
782 /**
|
|
783 * Remembers and returns the current selection. The saved selection can be restored
|
|
784 * by calling <code>restoreSelection()</code>.
|
|
785 *
|
|
786 * @return the current selection
|
|
787 * @see dwtx.jface.text.ITextViewer#getSelectedRange()
|
|
788 * @since 3.0
|
|
789 */
|
|
790 protected Point rememberSelection() {
|
|
791
|
|
792 final Point selection= getSelectedRange();
|
|
793 final IDocument document= getDocument();
|
|
794
|
|
795 if (fSelections.isEmpty()) {
|
|
796 fSelectionCategory= _SELECTION_POSITION_CATEGORY + hashCode();
|
|
797 fSelectionUpdater= new NonDeletingPositionUpdater(fSelectionCategory);
|
|
798 document.addPositionCategory(fSelectionCategory);
|
|
799 document.addPositionUpdater(fSelectionUpdater);
|
|
800 }
|
|
801
|
|
802 try {
|
|
803
|
|
804 final Position position= new Position(selection.x, selection.y);
|
|
805 document.addPosition(fSelectionCategory, position);
|
|
806 fSelections.push(position);
|
|
807
|
|
808 } catch (BadLocationException exception) {
|
|
809 // Should not happen
|
|
810 } catch (BadPositionCategoryException exception) {
|
|
811 // Should not happen
|
|
812 }
|
|
813
|
|
814 return selection;
|
|
815 }
|
|
816
|
|
817 /**
|
|
818 * Restores a previously saved selection in the document.
|
|
819 * <p>
|
|
820 * If no selection was previously saved, nothing happens.
|
|
821 *
|
|
822 * @since 3.0
|
|
823 */
|
|
824 protected void restoreSelection() {
|
|
825
|
|
826 if (!fSelections.isEmpty()) {
|
|
827
|
|
828 final IDocument document= getDocument();
|
|
829 final Position position= (Position) fSelections.pop();
|
|
830
|
|
831 try {
|
|
832 document.removePosition(fSelectionCategory, position);
|
|
833 Point currentSelection= getSelectedRange();
|
|
834 if (currentSelection is null || currentSelection.x !is position.getOffset() || currentSelection.y !is position.getLength())
|
|
835 setSelectedRange(position.getOffset(), position.getLength());
|
|
836
|
|
837 if (fSelections.isEmpty())
|
|
838 clearRememberedSelection();
|
|
839 } catch (BadPositionCategoryException exception) {
|
|
840 // Should not happen
|
|
841 }
|
|
842 }
|
|
843 }
|
|
844
|
|
845 protected void clearRememberedSelection() {
|
|
846 if (!fSelections.isEmpty())
|
|
847 fSelections.clear();
|
|
848
|
|
849 IDocument document= getDocument();
|
|
850 if (document !is null && fSelectionUpdater !is null) {
|
|
851 document.removePositionUpdater(fSelectionUpdater);
|
|
852 try {
|
|
853 document.removePositionCategory(fSelectionCategory);
|
|
854 } catch (BadPositionCategoryException e) {
|
|
855 // ignore
|
|
856 }
|
|
857 }
|
|
858 fSelectionUpdater= null;
|
|
859 fSelectionCategory= null;
|
|
860 }
|
|
861
|
|
862 /*
|
|
863 * @see ITextOperationTarget#doOperation(int)
|
|
864 */
|
|
865 public void doOperation(int operation) {
|
|
866
|
|
867 if (getTextWidget() is null || (!redraws() && operation !is FORMAT))
|
|
868 return;
|
|
869
|
|
870 switch (operation) {
|
|
871 case CONTENTASSIST_PROPOSALS:
|
|
872 fContentAssistant.showPossibleCompletions();
|
|
873 return;
|
|
874 case CONTENTASSIST_CONTEXT_INFORMATION:
|
|
875 fContentAssistant.showContextInformation();
|
|
876 return;
|
|
877 case QUICK_ASSIST:
|
|
878 // FIXME: must find a way to post to the status line
|
|
879 /* String msg= */ fQuickAssistAssistant.showPossibleQuickAssists();
|
|
880 // setStatusLineErrorMessage(msg);
|
|
881 return;
|
|
882 case INFORMATION:
|
|
883 fInformationPresenter.showInformation();
|
|
884 return;
|
|
885 case FORMAT:
|
|
886 {
|
|
887 final Point selection= rememberSelection();
|
|
888 final IRewriteTarget target= getRewriteTarget();
|
|
889 final IDocument document= getDocument();
|
|
890 IFormattingContext context= null;
|
|
891 DocumentRewriteSession rewriteSession= null;
|
|
892
|
|
893 if (document instanceof IDocumentExtension4) {
|
|
894 IDocumentExtension4 extension= (IDocumentExtension4) document;
|
|
895 DocumentRewriteSessionType type= selection.y is 0 || selection.y > 1000 ? DocumentRewriteSessionType.SEQUENTIAL : DocumentRewriteSessionType.UNRESTRICTED_SMALL;
|
|
896 rewriteSession= extension.startRewriteSession(type);
|
|
897 } else {
|
|
898 setRedraw(false);
|
|
899 target.beginCompoundChange();
|
|
900 }
|
|
901
|
|
902 try {
|
|
903
|
|
904 final String rememberedContents= document.get();
|
|
905
|
|
906 try {
|
|
907
|
|
908 if (fContentFormatter instanceof IContentFormatterExtension) {
|
|
909 final IContentFormatterExtension extension= (IContentFormatterExtension) fContentFormatter;
|
|
910 context= createFormattingContext();
|
|
911 if (selection.y is 0) {
|
|
912 context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.TRUE);
|
|
913 } else {
|
|
914 context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.FALSE);
|
|
915 context.setProperty(FormattingContextProperties.CONTEXT_REGION, new Region(selection.x, selection.y));
|
|
916 }
|
|
917 extension.format(document, context);
|
|
918 } else {
|
|
919 IRegion r;
|
|
920 if (selection.y is 0) {
|
|
921 IRegion coverage= getModelCoverage();
|
|
922 r= coverage is null ? new Region(0, 0) : coverage;
|
|
923 } else {
|
|
924 r= new Region(selection.x, selection.y);
|
|
925 }
|
|
926 fContentFormatter.format(document, r);
|
|
927 }
|
|
928
|
|
929 updateSlaveDocuments(document);
|
|
930
|
|
931 } catch (RuntimeException x) {
|
|
932 // fire wall for https://bugs.eclipse.org/bugs/show_bug.cgi?id=47472
|
|
933 // if something went wrong we undo the changes we just did
|
|
934 // TODO to be removed after 3.0 M8
|
|
935 document.set(rememberedContents);
|
|
936 throw x;
|
|
937 }
|
|
938
|
|
939 } finally {
|
|
940
|
|
941 if (document instanceof IDocumentExtension4) {
|
|
942 IDocumentExtension4 extension= (IDocumentExtension4) document;
|
|
943 extension.stopRewriteSession(rewriteSession);
|
|
944 } else {
|
|
945 target.endCompoundChange();
|
|
946 setRedraw(true);
|
|
947 }
|
|
948
|
|
949 restoreSelection();
|
|
950 if (context !is null)
|
|
951 context.dispose();
|
|
952 }
|
|
953 return;
|
|
954 }
|
|
955 default:
|
|
956 super.doOperation(operation);
|
|
957 }
|
|
958 }
|
|
959
|
|
960 /**
|
|
961 * Updates all slave documents of the given document. This default implementation calls <code>updateSlaveDocument</code>
|
|
962 * for their current visible range. Subclasses may reimplement.
|
|
963 *
|
|
964 * @param masterDocument the master document
|
|
965 * @since 3.0
|
|
966 */
|
|
967 protected void updateSlaveDocuments(IDocument masterDocument) {
|
|
968 ISlaveDocumentManager manager= getSlaveDocumentManager();
|
|
969 if (manager instanceof ISlaveDocumentManagerExtension) {
|
|
970 ISlaveDocumentManagerExtension extension= (ISlaveDocumentManagerExtension) manager;
|
|
971 IDocument[] slaves= extension.getSlaveDocuments(masterDocument);
|
|
972 if (slaves !is null) {
|
|
973 for (int i= 0; i < slaves.length; i++) {
|
|
974 if (slaves[i] instanceof ChildDocument) {
|
|
975 ChildDocument child= (ChildDocument) slaves[i];
|
|
976 Position p= child.getParentDocumentRange();
|
|
977 try {
|
|
978
|
|
979 if (!updateSlaveDocument(child, p.getOffset(), p.getLength()))
|
|
980 child.repairLineInformation();
|
|
981
|
|
982 } catch (BadLocationException e) {
|
|
983 // ignore
|
|
984 }
|
|
985 }
|
|
986 }
|
|
987 }
|
|
988 }
|
|
989 }
|
|
990
|
|
991 /*
|
|
992 * @see ITextOperationTargetExtension#enableOperation(int, bool)
|
|
993 * @since 2.0
|
|
994 */
|
|
995 public void enableOperation(int operation, bool enable) {
|
|
996
|
|
997 switch (operation) {
|
|
998 case CONTENTASSIST_PROPOSALS:
|
|
999 case CONTENTASSIST_CONTEXT_INFORMATION: {
|
|
1000
|
|
1001 if (fContentAssistant is null)
|
|
1002 return;
|
|
1003
|
|
1004 if (enable) {
|
|
1005 if (!fContentAssistantInstalled) {
|
|
1006 fContentAssistant.install(this);
|
|
1007 fContentAssistantInstalled= true;
|
|
1008 }
|
|
1009 } else if (fContentAssistantInstalled) {
|
|
1010 fContentAssistant.uninstall();
|
|
1011 fContentAssistantInstalled= false;
|
|
1012 }
|
|
1013 break;
|
|
1014 }
|
|
1015 case QUICK_ASSIST: {
|
|
1016
|
|
1017 if (fQuickAssistAssistant is null)
|
|
1018 return;
|
|
1019
|
|
1020 if (enable) {
|
|
1021 if (!fQuickAssistAssistantInstalled) {
|
|
1022 fQuickAssistAssistant.install(this);
|
|
1023 fQuickAssistAssistantInstalled= true;
|
|
1024 }
|
|
1025 } else if (fContentAssistantInstalled) {
|
|
1026 fQuickAssistAssistant.uninstall();
|
|
1027 fContentAssistantInstalled= false;
|
|
1028 }
|
|
1029 }
|
|
1030 }
|
|
1031 }
|
|
1032
|
|
1033 /*
|
|
1034 * @see ISourceViewer#setRangeIndicator(Annotation)
|
|
1035 */
|
|
1036 public void setRangeIndicator(Annotation rangeIndicator) {
|
|
1037 fRangeIndicator= rangeIndicator;
|
|
1038 }
|
|
1039
|
|
1040 /*
|
|
1041 * @see ISourceViewer#setRangeIndication(int, int, bool)
|
|
1042 */
|
|
1043 public void setRangeIndication(int start, int length, bool moveCursor) {
|
|
1044
|
|
1045 if (moveCursor) {
|
|
1046 setSelectedRange(start, 0);
|
|
1047 revealRange(start, length);
|
|
1048 }
|
|
1049
|
|
1050 if (fRangeIndicator !is null && fVisualAnnotationModel instanceof IAnnotationModelExtension) {
|
|
1051 IAnnotationModelExtension extension= (IAnnotationModelExtension) fVisualAnnotationModel;
|
|
1052 extension.modifyAnnotationPosition(fRangeIndicator, new Position(start, length));
|
|
1053 }
|
|
1054 }
|
|
1055
|
|
1056 /*
|
|
1057 * @see ISourceViewer#getRangeIndication()
|
|
1058 */
|
|
1059 public IRegion getRangeIndication() {
|
|
1060 if (fRangeIndicator !is null && fVisualAnnotationModel !is null) {
|
|
1061 Position position= fVisualAnnotationModel.getPosition(fRangeIndicator);
|
|
1062 if (position !is null)
|
|
1063 return new Region(position.getOffset(), position.getLength());
|
|
1064 }
|
|
1065
|
|
1066 return null;
|
|
1067 }
|
|
1068
|
|
1069 /*
|
|
1070 * @see ISourceViewer#removeRangeIndication()
|
|
1071 */
|
|
1072 public void removeRangeIndication() {
|
|
1073 if (fRangeIndicator !is null && fVisualAnnotationModel !is null)
|
|
1074 fVisualAnnotationModel.removeAnnotation(fRangeIndicator);
|
|
1075 }
|
|
1076
|
|
1077 /*
|
|
1078 * @see ISourceViewer#showAnnotations(bool)
|
|
1079 */
|
|
1080 public void showAnnotations(bool show) {
|
|
1081 bool old= fIsVerticalRulerVisible;
|
|
1082
|
|
1083 fIsVerticalRulerVisible= (fVerticalRuler !is null && (show || !isVerticalRulerOnlyShowingAnnotations()));
|
|
1084 if (old !is fIsVerticalRulerVisible && fComposite !is null && !fComposite.isDisposed())
|
|
1085 fComposite.layout();
|
|
1086
|
|
1087 if (fIsVerticalRulerVisible && show)
|
|
1088 ensureAnnotationHoverManagerInstalled();
|
|
1089 else if (fVerticalRulerHoveringController !is null) {
|
|
1090 fVerticalRulerHoveringController.dispose();
|
|
1091 fVerticalRulerHoveringController= null;
|
|
1092 }
|
|
1093 }
|
|
1094
|
|
1095 /**
|
|
1096 * Tells whether the vertical ruler only acts as annotation ruler.
|
|
1097 *
|
|
1098 * @return <code>true</code> if the vertical ruler only show annotations
|
|
1099 * @since 3.3
|
|
1100 */
|
|
1101 private bool isVerticalRulerOnlyShowingAnnotations() {
|
|
1102 if (fVerticalRuler instanceof VerticalRuler)
|
|
1103 return true;
|
|
1104
|
|
1105 if (fVerticalRuler instanceof CompositeRuler) {
|
|
1106 Iterator iter= ((CompositeRuler)fVerticalRuler).getDecoratorIterator();
|
|
1107 return iter.hasNext() && iter.next() instanceof AnnotationRulerColumn && !iter.hasNext();
|
|
1108 }
|
|
1109 return false;
|
|
1110 }
|
|
1111
|
|
1112 /**
|
|
1113 * Returns the vertical ruler of this viewer.
|
|
1114 *
|
|
1115 * @return the vertical ruler of this viewer
|
|
1116 * @since 3.0
|
|
1117 */
|
|
1118 protected final IVerticalRuler getVerticalRuler() {
|
|
1119 return fVerticalRuler;
|
|
1120 }
|
|
1121
|
|
1122 /*
|
|
1123 * @see dwtx.jface.text.source.ISourceViewerExtension#showAnnotationsOverview(bool)
|
|
1124 * @since 2.1
|
|
1125 */
|
|
1126 public void showAnnotationsOverview(bool show) {
|
|
1127 bool old= fIsOverviewRulerVisible;
|
|
1128 fIsOverviewRulerVisible= (show && fOverviewRuler !is null);
|
|
1129 if (old !is fIsOverviewRulerVisible) {
|
|
1130 if (fComposite !is null && !fComposite.isDisposed())
|
|
1131 fComposite.layout();
|
|
1132 if (fIsOverviewRulerVisible) {
|
|
1133 ensureOverviewHoverManagerInstalled();
|
|
1134 } else if (fOverviewRulerHoveringController !is null) {
|
|
1135 fOverviewRulerHoveringController.dispose();
|
|
1136 fOverviewRulerHoveringController= null;
|
|
1137 }
|
|
1138 }
|
|
1139 }
|
|
1140
|
|
1141 /*
|
|
1142 * @see dwtx.jface.text.source.ISourceViewer#getCurrentAnnotationHover()
|
|
1143 * @since 3.2
|
|
1144 */
|
|
1145 public IAnnotationHover getCurrentAnnotationHover() {
|
|
1146 if (fVerticalRulerHoveringController is null)
|
|
1147 return null;
|
|
1148 return fVerticalRulerHoveringController.getCurrentAnnotationHover();
|
|
1149 }
|
|
1150 }
|