Mercurial > projects > dwt-addons
annotate dwtx/jface/text/source/ChangeRulerColumn.d @ 134:51e6e63f930e
Regex fix for casts
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 24 Aug 2008 01:46:20 +0200 |
parents | 7d818bd32d63 |
children | 65801ad2b265 |
rev | line source |
---|---|
129 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2006 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.ChangeRulerColumn; | |
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.SourceViewer; // packageimport | |
45 import dwtx.jface.text.source.SourceViewerConfiguration; // packageimport | |
46 import dwtx.jface.text.source.AnnotationBarHoverManager; // packageimport | |
47 import dwtx.jface.text.source.CompositeRuler; // packageimport | |
48 import dwtx.jface.text.source.ImageUtilities; // packageimport | |
49 import dwtx.jface.text.source.VisualAnnotationModel; // packageimport | |
50 import dwtx.jface.text.source.IAnnotationModel; // packageimport | |
51 import dwtx.jface.text.source.ISourceViewerExtension3; // packageimport | |
52 import dwtx.jface.text.source.ILineDiffInfo; // packageimport | |
53 import dwtx.jface.text.source.VerticalRulerEvent; // 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 | |
81 | |
82 | |
83 | |
84 import dwt.DWT; | |
85 import dwt.custom.StyledText; | |
86 import dwt.events.DisposeEvent; | |
87 import dwt.events.DisposeListener; | |
88 import dwt.events.MouseEvent; | |
89 import dwt.events.MouseListener; | |
90 import dwt.events.MouseMoveListener; | |
91 import dwt.events.PaintEvent; | |
92 import dwt.events.PaintListener; | |
93 import dwt.graphics.Color; | |
94 import dwt.graphics.Font; | |
95 import dwt.graphics.GC; | |
96 import dwt.graphics.Image; | |
97 import dwt.graphics.Point; | |
98 import dwt.graphics.Rectangle; | |
99 import dwt.widgets.Canvas; | |
100 import dwt.widgets.Composite; | |
101 import dwt.widgets.Control; | |
102 import dwt.widgets.Display; | |
103 import dwtx.core.runtime.Assert; | |
104 import dwtx.jface.internal.text.revisions.RevisionPainter; | |
105 import dwtx.jface.internal.text.source.DiffPainter; | |
106 import dwtx.jface.text.BadLocationException; | |
107 import dwtx.jface.text.IDocument; | |
108 import dwtx.jface.text.IRegion; | |
109 import dwtx.jface.text.ITextListener; | |
110 import dwtx.jface.text.ITextViewer; | |
111 import dwtx.jface.text.ITextViewerExtension5; | |
112 import dwtx.jface.text.IViewportListener; | |
113 import dwtx.jface.text.JFaceTextUtil; | |
114 import dwtx.jface.text.TextEvent; | |
115 import dwtx.jface.text.revisions.IRevisionRulerColumn; | |
116 import dwtx.jface.text.revisions.RevisionInformation; | |
117 import dwtx.jface.viewers.ISelectionProvider; | |
118 | |
119 /** | |
120 * A vertical ruler column displaying line numbers and serving as a UI for quick diff. | |
121 * Clients instantiate and configure object of this class. | |
122 * | |
123 * @since 3.0 | |
124 */ | |
125 public final class ChangeRulerColumn : IVerticalRulerColumn, IVerticalRulerInfo, IVerticalRulerInfoExtension, IChangeRulerColumn, IRevisionRulerColumn { | |
126 /** | |
127 * Handles all the mouse interaction in this line number ruler column. | |
128 */ | |
129 private class MouseHandler : MouseListener, MouseMoveListener { | |
130 | |
131 /* | |
132 * @see dwt.events.MouseListener#mouseUp(dwt.events.MouseEvent) | |
133 */ | |
134 public void mouseUp(MouseEvent event) { | |
135 } | |
136 | |
137 /* | |
138 * @see dwt.events.MouseListener#mouseDown(dwt.events.MouseEvent) | |
139 */ | |
140 public void mouseDown(MouseEvent event) { | |
141 fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y); | |
142 } | |
143 | |
144 /* | |
145 * @see dwt.events.MouseListener#mouseDoubleClick(dwt.events.MouseEvent) | |
146 */ | |
147 public void mouseDoubleClick(MouseEvent event) { | |
148 fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y); | |
149 } | |
150 | |
151 /* | |
152 * @see dwt.events.MouseMoveListener#mouseMove(dwt.events.MouseEvent) | |
153 */ | |
154 public void mouseMove(MouseEvent event) { | |
155 fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y); | |
156 } | |
157 } | |
158 | |
159 /** | |
160 * Internal listener class. | |
161 */ | |
162 private class InternalListener : IViewportListener, ITextListener { | |
163 | |
164 /* | |
165 * @see IViewportListener#viewportChanged(int) | |
166 */ | |
167 public void viewportChanged(int verticalPosition) { | |
168 if (verticalPosition !is fScrollPos) | |
169 redraw(); | |
170 } | |
171 | |
172 /* | |
173 * @see ITextListener#textChanged(TextEvent) | |
174 */ | |
175 public void textChanged(TextEvent event) { | |
176 | |
177 if (!event.getViewerRedrawState()) | |
178 return; | |
179 | |
180 if (fSensitiveToTextChanges || event.getDocumentEvent() is null) | |
181 postRedraw(); | |
182 | |
183 } | |
184 } | |
185 | |
186 /** | |
187 * The view(port) listener. | |
188 */ | |
189 private final InternalListener fInternalListener= new InternalListener(); | |
190 /** | |
191 * The mouse handler. | |
192 * @since 3.2 | |
193 */ | |
194 private final MouseHandler fMouseHandler= new MouseHandler(); | |
195 /** | |
196 * The revision painter. | |
197 * @since 3.2 | |
198 */ | |
199 private final RevisionPainter fRevisionPainter; | |
200 /** | |
201 * The diff info painter. | |
202 * @since 3.2 | |
203 */ | |
204 private final DiffPainter fDiffPainter; | |
205 | |
206 /** This column's parent ruler */ | |
207 private CompositeRuler fParentRuler; | |
208 /** Cached text viewer */ | |
209 private ITextViewer fCachedTextViewer; | |
210 /** Cached text widget */ | |
211 private StyledText fCachedTextWidget; | |
212 /** The columns canvas */ | |
213 private Canvas fCanvas; | |
214 /** The background color */ | |
215 private Color fBackground; | |
216 /** The ruler's annotation model. */ | |
217 private IAnnotationModel fAnnotationModel; | |
218 /** The width of the change ruler column. */ | |
219 private final int fWidth= 5; | |
220 | |
221 /** Cache for the actual scroll position in pixels */ | |
222 private int fScrollPos; | |
223 /** The buffer for double buffering */ | |
224 private Image fBuffer; | |
225 /** Indicates whether this column reacts on text change events */ | |
226 private bool fSensitiveToTextChanges= false; | |
227 | |
228 /** | |
229 * Creates a new ruler column. | |
230 * | |
231 * @deprecated since 3.2 use {@link #ChangeRulerColumn(ISharedTextColors)} instead | |
232 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
233 public this() { |
129 | 234 fRevisionPainter= null; |
235 fDiffPainter= new DiffPainter(this, null); | |
236 } | |
237 | |
238 /** | |
239 * Creates a new revision ruler column. | |
240 * | |
241 * @param sharedColors the colors to look up RGBs | |
242 * @since 3.2 | |
243 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
244 public this(ISharedTextColors sharedColors) { |
129 | 245 Assert.isNotNull(sharedColors); |
246 fRevisionPainter= new RevisionPainter(this, sharedColors); | |
247 fDiffPainter= new DiffPainter(this, null); // no shading | |
248 } | |
249 | |
250 /** | |
251 * Returns the System background color for list widgets. | |
252 * | |
253 * @return the System background color for list widgets | |
254 */ | |
255 private Color getBackground() { | |
256 if (fBackground is null) | |
257 return fCachedTextWidget.getDisplay().getSystemColor(DWT.COLOR_LIST_BACKGROUND); | |
258 return fBackground; | |
259 } | |
260 | |
261 /* | |
262 * @see IVerticalRulerColumn#createControl(CompositeRuler, Composite) | |
263 */ | |
264 public Control createControl(CompositeRuler parentRuler, Composite parentControl) { | |
265 | |
266 fParentRuler= parentRuler; | |
267 fCachedTextViewer= parentRuler.getTextViewer(); | |
268 fCachedTextWidget= fCachedTextViewer.getTextWidget(); | |
269 | |
270 fCanvas= new Canvas(parentControl, DWT.NONE); | |
271 fCanvas.setBackground(getBackground()); | |
272 | |
273 fCanvas.addPaintListener(new PaintListener() { | |
274 public void paintControl(PaintEvent event) { | |
275 if (fCachedTextViewer !is null) | |
276 doubleBufferPaint(event.gc); | |
277 } | |
278 }); | |
279 | |
280 fCanvas.addDisposeListener(new DisposeListener() { | |
281 public void widgetDisposed(DisposeEvent e) { | |
282 handleDispose(); | |
283 fCachedTextViewer= null; | |
284 fCachedTextWidget= null; | |
285 } | |
286 }); | |
287 | |
288 fCanvas.addMouseListener(fMouseHandler); | |
289 fCanvas.addMouseMoveListener(fMouseHandler); | |
290 | |
291 if (fCachedTextViewer !is null) { | |
292 | |
293 fCachedTextViewer.addViewportListener(fInternalListener); | |
294 fCachedTextViewer.addTextListener(fInternalListener); | |
295 } | |
296 | |
297 fRevisionPainter.setParentRuler(parentRuler); | |
298 fDiffPainter.setParentRuler(parentRuler); | |
299 | |
300 return fCanvas; | |
301 } | |
302 | |
303 /** | |
304 * Disposes the column's resources. | |
305 */ | |
306 protected void handleDispose() { | |
307 | |
308 if (fCachedTextViewer !is null) { | |
309 fCachedTextViewer.removeViewportListener(fInternalListener); | |
310 fCachedTextViewer.removeTextListener(fInternalListener); | |
311 } | |
312 | |
313 if (fBuffer !is null) { | |
314 fBuffer.dispose(); | |
315 fBuffer= null; | |
316 } | |
317 } | |
318 | |
319 /** | |
320 * Double buffer drawing. | |
321 * | |
322 * @param dest the GC to draw into | |
323 */ | |
324 private void doubleBufferPaint(GC dest) { | |
325 | |
326 Point size= fCanvas.getSize(); | |
327 | |
328 if (size.x <= 0 || size.y <= 0) | |
329 return; | |
330 | |
331 if (fBuffer !is null) { | |
332 Rectangle r= fBuffer.getBounds(); | |
333 if (r.width !is size.x || r.height !is size.y) { | |
334 fBuffer.dispose(); | |
335 fBuffer= null; | |
336 } | |
337 } | |
338 if (fBuffer is null) | |
339 fBuffer= new Image(fCanvas.getDisplay(), size.x, size.y); | |
340 | |
341 GC gc= new GC(fBuffer); | |
342 gc.setFont(fCanvas.getFont()); | |
343 | |
344 try { | |
345 gc.setBackground(getBackground()); | |
346 gc.fillRectangle(0, 0, size.x, size.y); | |
347 | |
348 doPaint(gc); | |
349 } finally { | |
350 gc.dispose(); | |
351 } | |
352 | |
353 dest.drawImage(fBuffer, 0, 0); | |
354 } | |
355 | |
356 /** | |
357 * Returns the view port height in lines. | |
358 * | |
359 * @return the view port height in lines | |
360 * @deprecated as of 3.2 the number of lines in the viewport cannot be computed because | |
361 * StyledText supports variable line heights | |
362 */ | |
363 protected int getVisibleLinesInViewport() { | |
364 // Hack to reduce amount of copied code. | |
365 return LineNumberRulerColumn.getVisibleLinesInViewport(fCachedTextWidget); | |
366 } | |
367 | |
368 /** | |
369 * Returns <code>true</code> if the viewport displays the entire viewer contents, i.e. the | |
370 * viewer is not vertically scrollable. | |
371 * | |
372 * @return <code>true</code> if the viewport displays the entire contents, <code>false</code> otherwise | |
373 * @since 3.2 | |
374 */ | |
375 protected final bool isViewerCompletelyShown() { | |
376 return JFaceTextUtil.isShowingEntireContents(fCachedTextWidget); | |
377 } | |
378 | |
379 /** | |
380 * Draws the ruler column. | |
381 * | |
382 * @param gc the GC to draw into | |
383 */ | |
384 private void doPaint(GC gc) { | |
385 ILineRange visibleModelLines= computeVisibleModelLines(); | |
386 if (visibleModelLines is null) | |
387 return; | |
388 | |
389 fSensitiveToTextChanges= isViewerCompletelyShown(); | |
390 | |
391 fScrollPos= fCachedTextWidget.getTopPixel(); | |
392 | |
393 fRevisionPainter.paint(gc, visibleModelLines); | |
394 if (!fRevisionPainter.hasInformation()) // don't paint quick diff colors if revisions are painted | |
395 fDiffPainter.paint(gc, visibleModelLines); | |
396 } | |
397 | |
398 /* | |
399 * @see IVerticalRulerColumn#redraw() | |
400 */ | |
401 public void redraw() { | |
402 | |
403 if (fCachedTextViewer !is null && fCanvas !is null && !fCanvas.isDisposed()) { | |
404 GC gc= new GC(fCanvas); | |
405 doubleBufferPaint(gc); | |
406 gc.dispose(); | |
407 } | |
408 } | |
409 | |
410 /* | |
411 * @see IVerticalRulerColumn#setFont(Font) | |
412 */ | |
413 public void setFont(Font font) { | |
414 } | |
415 | |
416 /** | |
417 * Returns the parent (composite) ruler of this ruler column. | |
418 * | |
419 * @return the parent ruler | |
420 * @since 3.0 | |
421 */ | |
422 private CompositeRuler getParentRuler() { | |
423 return fParentRuler; | |
424 } | |
425 | |
426 /* | |
427 * @see dwtx.jface.text.source.IVerticalRulerInfo#getLineOfLastMouseButtonActivity() | |
428 */ | |
429 public int getLineOfLastMouseButtonActivity() { | |
430 return getParentRuler().getLineOfLastMouseButtonActivity(); | |
431 } | |
432 | |
433 /* | |
434 * @see dwtx.jface.text.source.IVerticalRulerInfo#toDocumentLineNumber(int) | |
435 */ | |
436 public int toDocumentLineNumber(int y_coordinate) { | |
437 return getParentRuler().toDocumentLineNumber(y_coordinate); | |
438 } | |
439 | |
440 /* | |
441 * @see dwtx.jface.text.source.IVerticalRulerInfoExtension#getHover() | |
442 */ | |
443 public IAnnotationHover getHover() { | |
444 int activeLine= getParentRuler().getLineOfLastMouseButtonActivity(); | |
445 if (fRevisionPainter.hasHover(activeLine)) | |
446 return fRevisionPainter.getHover(); | |
447 if (fDiffPainter.hasHover(activeLine)) | |
448 return fDiffPainter.getHover(); | |
449 return null; | |
450 } | |
451 | |
452 /* | |
453 * @see dwtx.jface.text.source.IChangeRulerColumn#setHover(dwtx.jface.text.source.IAnnotationHover) | |
454 */ | |
455 public void setHover(IAnnotationHover hover) { | |
456 fRevisionPainter.setHover(hover); | |
457 fDiffPainter.setHover(hover); | |
458 } | |
459 | |
460 /* | |
461 * @see IVerticalRulerColumn#setModel(IAnnotationModel) | |
462 */ | |
463 public void setModel(IAnnotationModel model) { | |
464 setAnnotationModel(model); | |
465 fRevisionPainter.setModel(model); | |
466 fDiffPainter.setModel(model); | |
467 } | |
468 | |
469 private void setAnnotationModel(IAnnotationModel model) { | |
470 if (fAnnotationModel !is model) | |
471 fAnnotationModel= model; | |
472 } | |
473 | |
474 /* | |
475 * @see dwtx.jface.text.source.IChangeRulerColumn#setBackground(dwt.graphics.Color) | |
476 */ | |
477 public void setBackground(Color background) { | |
478 fBackground= background; | |
479 if (fCanvas !is null && !fCanvas.isDisposed()) | |
480 fCanvas.setBackground(getBackground()); | |
481 fRevisionPainter.setBackground(background); | |
482 fDiffPainter.setBackground(background); | |
483 } | |
484 | |
485 /* | |
486 * @see dwtx.jface.text.source.IChangeRulerColumn#setAddedColor(dwt.graphics.Color) | |
487 */ | |
488 public void setAddedColor(Color addedColor) { | |
489 fDiffPainter.setAddedColor(addedColor); | |
490 } | |
491 | |
492 /* | |
493 * @see dwtx.jface.text.source.IChangeRulerColumn#setChangedColor(dwt.graphics.Color) | |
494 */ | |
495 public void setChangedColor(Color changedColor) { | |
496 fDiffPainter.setChangedColor(changedColor); | |
497 } | |
498 | |
499 /* | |
500 * @see dwtx.jface.text.source.IChangeRulerColumn#setDeletedColor(dwt.graphics.Color) | |
501 */ | |
502 public void setDeletedColor(Color deletedColor) { | |
503 fDiffPainter.setDeletedColor(deletedColor); | |
504 } | |
505 | |
506 /* | |
507 * @see dwtx.jface.text.source.IVerticalRulerInfoExtension#getModel() | |
508 */ | |
509 public IAnnotationModel getModel() { | |
510 return fAnnotationModel; | |
511 } | |
512 | |
513 /* | |
514 * @see IVerticalRulerColumn#getControl() | |
515 */ | |
516 public Control getControl() { | |
517 return fCanvas; | |
518 } | |
519 | |
520 /* | |
521 * @see dwtx.jface.text.source.IVerticalRulerInfo#getWidth() | |
522 */ | |
523 public int getWidth() { | |
524 return fWidth; | |
525 } | |
526 | |
527 /** | |
528 * Triggers a redraw in the display thread. | |
529 */ | |
530 protected final void postRedraw() { | |
531 if (fCanvas !is null && !fCanvas.isDisposed()) { | |
532 Display d= fCanvas.getDisplay(); | |
533 if (d !is null) { | |
534 d.asyncExec(new Runnable() { | |
535 public void run() { | |
536 redraw(); | |
537 } | |
538 }); | |
539 } | |
540 } | |
541 } | |
542 | |
543 /* | |
544 * @see dwtx.jface.text.source.IVerticalRulerInfoExtension#addVerticalRulerListener(dwtx.jface.text.source.IVerticalRulerListener) | |
545 */ | |
546 public void addVerticalRulerListener(IVerticalRulerListener listener) { | |
547 throw new UnsupportedOperationException(); | |
548 } | |
549 | |
550 /* | |
551 * @see dwtx.jface.text.source.IVerticalRulerInfoExtension#removeVerticalRulerListener(dwtx.jface.text.source.IVerticalRulerListener) | |
552 */ | |
553 public void removeVerticalRulerListener(IVerticalRulerListener listener) { | |
554 throw new UnsupportedOperationException(); | |
555 } | |
556 | |
557 /** | |
558 * Computes the document based line range visible in the text widget. | |
559 * | |
560 * @return the document based line range visible in the text widget | |
561 * @since 3.2 | |
562 */ | |
563 private final ILineRange computeVisibleModelLines() { | |
564 IDocument doc= fCachedTextViewer.getDocument(); | |
565 if (doc is null) | |
566 return null; | |
567 | |
568 int topLine; | |
569 IRegion coverage; | |
570 | |
571 if (fCachedTextViewer instanceof ITextViewerExtension5) { | |
134 | 572 ITextViewerExtension5 extension= cast(ITextViewerExtension5) fCachedTextViewer; |
129 | 573 |
574 // ITextViewer.getTopIndex returns the fully visible line, but we want the partially | |
575 // visible one | |
576 int widgetTopLine= JFaceTextUtil.getPartialTopIndex(fCachedTextWidget); | |
577 topLine= extension.widgetLine2ModelLine(widgetTopLine); | |
578 | |
579 coverage= extension.getModelCoverage(); | |
580 | |
581 } else { | |
582 topLine= JFaceTextUtil.getPartialTopIndex(fCachedTextViewer); | |
583 coverage= fCachedTextViewer.getVisibleRegion(); | |
584 } | |
585 | |
586 int bottomLine= fCachedTextViewer.getBottomIndex(); | |
587 if (bottomLine !is -1) | |
588 ++ bottomLine; | |
589 | |
590 // clip by coverage window | |
591 try { | |
592 int firstLine= doc.getLineOfOffset(coverage.getOffset()); | |
593 if (firstLine > topLine) | |
594 topLine= firstLine; | |
595 | |
596 int lastLine= doc.getLineOfOffset(coverage.getOffset() + coverage.getLength()); | |
597 if (lastLine < bottomLine || bottomLine is -1) | |
598 bottomLine= lastLine; | |
599 } catch (BadLocationException x) { | |
600 x.printStackTrace(); | |
601 return null; | |
602 } | |
603 | |
604 ILineRange visibleModelLines= new LineRange(topLine, bottomLine - topLine + 1); | |
605 return visibleModelLines; | |
606 } | |
607 | |
608 /* | |
609 * @see dwtx.jface.text.revisions.IRevisionRulerColumn#setRevisionInformation(dwtx.jface.text.revisions.RevisionInformation) | |
610 */ | |
611 public void setRevisionInformation(RevisionInformation info) { | |
612 fRevisionPainter.setRevisionInformation(info); | |
613 fRevisionPainter.setBackground(getBackground()); | |
614 } | |
615 | |
616 /** | |
617 * Returns the revision selection provider. | |
618 * | |
619 * @return the revision selection provider | |
620 * @since 3.2 | |
621 */ | |
622 public ISelectionProvider getRevisionSelectionProvider() { | |
623 return fRevisionPainter.getRevisionSelectionProvider(); | |
624 } | |
625 } |