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