Mercurial > projects > dwt-addons
annotate dwtx/jface/text/source/ChangeRulerColumn.d @ 159:7926b636c282
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 27 Aug 2008 01:57:58 +0200 |
parents | 75302ef3f92f |
children | 1a5b8f8129df |
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 } | |
159 | 185 |
129 | 186 /** |
159 | 187 * The view(port) listener. |
129 | 188 */ |
159 | 189 private const InternalListener fInternalListener; |
129 | 190 /** |
191 * The mouse handler. | |
192 * @since 3.2 | |
193 */ | |
159 | 194 private const MouseHandler fMouseHandler; |
129 | 195 /** |
196 * The revision painter. | |
197 * @since 3.2 | |
198 */ | |
146 | 199 private const RevisionPainter fRevisionPainter; |
129 | 200 /** |
201 * The diff info painter. | |
202 * @since 3.2 | |
203 */ | |
146 | 204 private const DiffPainter fDiffPainter; |
129 | 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. */ | |
146 | 219 private const int fWidth= 5; |
159 | 220 |
129 | 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 | |
159 | 228 private void instanceInit(){ |
229 fInternalListener= new InternalListener(); | |
230 fMouseHandler= new MouseHandler(); | |
231 } | |
129 | 232 /** |
233 * Creates a new ruler column. | |
159 | 234 * |
129 | 235 * @deprecated since 3.2 use {@link #ChangeRulerColumn(ISharedTextColors)} instead |
236 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
237 public this() { |
159 | 238 instanceInit(); |
129 | 239 fRevisionPainter= null; |
240 fDiffPainter= new DiffPainter(this, null); | |
241 } | |
159 | 242 |
129 | 243 /** |
244 * Creates a new revision ruler column. | |
159 | 245 * |
129 | 246 * @param sharedColors the colors to look up RGBs |
247 * @since 3.2 | |
248 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
249 public this(ISharedTextColors sharedColors) { |
159 | 250 instanceInit(); |
129 | 251 Assert.isNotNull(sharedColors); |
252 fRevisionPainter= new RevisionPainter(this, sharedColors); | |
253 fDiffPainter= new DiffPainter(this, null); // no shading | |
254 } | |
159 | 255 |
129 | 256 /** |
257 * Returns the System background color for list widgets. | |
258 * | |
259 * @return the System background color for list widgets | |
260 */ | |
261 private Color getBackground() { | |
262 if (fBackground is null) | |
263 return fCachedTextWidget.getDisplay().getSystemColor(DWT.COLOR_LIST_BACKGROUND); | |
264 return fBackground; | |
265 } | |
266 | |
267 /* | |
268 * @see IVerticalRulerColumn#createControl(CompositeRuler, Composite) | |
269 */ | |
270 public Control createControl(CompositeRuler parentRuler, Composite parentControl) { | |
271 | |
272 fParentRuler= parentRuler; | |
273 fCachedTextViewer= parentRuler.getTextViewer(); | |
274 fCachedTextWidget= fCachedTextViewer.getTextWidget(); | |
275 | |
276 fCanvas= new Canvas(parentControl, DWT.NONE); | |
277 fCanvas.setBackground(getBackground()); | |
278 | |
135 | 279 fCanvas.addPaintListener(new class() PaintListener { |
129 | 280 public void paintControl(PaintEvent event) { |
281 if (fCachedTextViewer !is null) | |
282 doubleBufferPaint(event.gc); | |
283 } | |
284 }); | |
285 | |
135 | 286 fCanvas.addDisposeListener(new class() DisposeListener { |
129 | 287 public void widgetDisposed(DisposeEvent e) { |
288 handleDispose(); | |
289 fCachedTextViewer= null; | |
290 fCachedTextWidget= null; | |
291 } | |
292 }); | |
293 | |
294 fCanvas.addMouseListener(fMouseHandler); | |
295 fCanvas.addMouseMoveListener(fMouseHandler); | |
296 | |
297 if (fCachedTextViewer !is null) { | |
298 | |
299 fCachedTextViewer.addViewportListener(fInternalListener); | |
300 fCachedTextViewer.addTextListener(fInternalListener); | |
301 } | |
159 | 302 |
129 | 303 fRevisionPainter.setParentRuler(parentRuler); |
304 fDiffPainter.setParentRuler(parentRuler); | |
305 | |
306 return fCanvas; | |
307 } | |
308 | |
309 /** | |
310 * Disposes the column's resources. | |
311 */ | |
312 protected void handleDispose() { | |
313 | |
314 if (fCachedTextViewer !is null) { | |
315 fCachedTextViewer.removeViewportListener(fInternalListener); | |
316 fCachedTextViewer.removeTextListener(fInternalListener); | |
317 } | |
318 | |
319 if (fBuffer !is null) { | |
320 fBuffer.dispose(); | |
321 fBuffer= null; | |
322 } | |
323 } | |
324 | |
325 /** | |
326 * Double buffer drawing. | |
327 * | |
328 * @param dest the GC to draw into | |
329 */ | |
330 private void doubleBufferPaint(GC dest) { | |
331 | |
332 Point size= fCanvas.getSize(); | |
333 | |
334 if (size.x <= 0 || size.y <= 0) | |
335 return; | |
336 | |
337 if (fBuffer !is null) { | |
338 Rectangle r= fBuffer.getBounds(); | |
339 if (r.width !is size.x || r.height !is size.y) { | |
340 fBuffer.dispose(); | |
341 fBuffer= null; | |
342 } | |
343 } | |
344 if (fBuffer is null) | |
345 fBuffer= new Image(fCanvas.getDisplay(), size.x, size.y); | |
346 | |
347 GC gc= new GC(fBuffer); | |
348 gc.setFont(fCanvas.getFont()); | |
349 | |
350 try { | |
351 gc.setBackground(getBackground()); | |
352 gc.fillRectangle(0, 0, size.x, size.y); | |
353 | |
354 doPaint(gc); | |
355 } finally { | |
356 gc.dispose(); | |
357 } | |
358 | |
359 dest.drawImage(fBuffer, 0, 0); | |
360 } | |
361 | |
362 /** | |
363 * Returns the view port height in lines. | |
159 | 364 * |
129 | 365 * @return the view port height in lines |
366 * @deprecated as of 3.2 the number of lines in the viewport cannot be computed because | |
367 * StyledText supports variable line heights | |
368 */ | |
369 protected int getVisibleLinesInViewport() { | |
370 // Hack to reduce amount of copied code. | |
371 return LineNumberRulerColumn.getVisibleLinesInViewport(fCachedTextWidget); | |
372 } | |
373 | |
374 /** | |
375 * Returns <code>true</code> if the viewport displays the entire viewer contents, i.e. the | |
376 * viewer is not vertically scrollable. | |
159 | 377 * |
129 | 378 * @return <code>true</code> if the viewport displays the entire contents, <code>false</code> otherwise |
379 * @since 3.2 | |
380 */ | |
381 protected final bool isViewerCompletelyShown() { | |
382 return JFaceTextUtil.isShowingEntireContents(fCachedTextWidget); | |
383 } | |
384 | |
385 /** | |
386 * Draws the ruler column. | |
387 * | |
388 * @param gc the GC to draw into | |
389 */ | |
390 private void doPaint(GC gc) { | |
391 ILineRange visibleModelLines= computeVisibleModelLines(); | |
392 if (visibleModelLines is null) | |
393 return; | |
394 | |
395 fSensitiveToTextChanges= isViewerCompletelyShown(); | |
396 | |
397 fScrollPos= fCachedTextWidget.getTopPixel(); | |
398 | |
399 fRevisionPainter.paint(gc, visibleModelLines); | |
400 if (!fRevisionPainter.hasInformation()) // don't paint quick diff colors if revisions are painted | |
401 fDiffPainter.paint(gc, visibleModelLines); | |
402 } | |
403 | |
404 /* | |
405 * @see IVerticalRulerColumn#redraw() | |
406 */ | |
407 public void redraw() { | |
408 | |
409 if (fCachedTextViewer !is null && fCanvas !is null && !fCanvas.isDisposed()) { | |
410 GC gc= new GC(fCanvas); | |
411 doubleBufferPaint(gc); | |
412 gc.dispose(); | |
413 } | |
414 } | |
415 | |
416 /* | |
417 * @see IVerticalRulerColumn#setFont(Font) | |
418 */ | |
419 public void setFont(Font font) { | |
420 } | |
421 | |
422 /** | |
423 * Returns the parent (composite) ruler of this ruler column. | |
424 * | |
425 * @return the parent ruler | |
426 * @since 3.0 | |
427 */ | |
428 private CompositeRuler getParentRuler() { | |
429 return fParentRuler; | |
430 } | |
431 | |
432 /* | |
433 * @see dwtx.jface.text.source.IVerticalRulerInfo#getLineOfLastMouseButtonActivity() | |
434 */ | |
435 public int getLineOfLastMouseButtonActivity() { | |
436 return getParentRuler().getLineOfLastMouseButtonActivity(); | |
437 } | |
438 | |
439 /* | |
440 * @see dwtx.jface.text.source.IVerticalRulerInfo#toDocumentLineNumber(int) | |
441 */ | |
442 public int toDocumentLineNumber(int y_coordinate) { | |
443 return getParentRuler().toDocumentLineNumber(y_coordinate); | |
444 } | |
445 | |
446 /* | |
447 * @see dwtx.jface.text.source.IVerticalRulerInfoExtension#getHover() | |
448 */ | |
449 public IAnnotationHover getHover() { | |
450 int activeLine= getParentRuler().getLineOfLastMouseButtonActivity(); | |
451 if (fRevisionPainter.hasHover(activeLine)) | |
452 return fRevisionPainter.getHover(); | |
453 if (fDiffPainter.hasHover(activeLine)) | |
454 return fDiffPainter.getHover(); | |
455 return null; | |
456 } | |
457 | |
458 /* | |
459 * @see dwtx.jface.text.source.IChangeRulerColumn#setHover(dwtx.jface.text.source.IAnnotationHover) | |
460 */ | |
461 public void setHover(IAnnotationHover hover) { | |
462 fRevisionPainter.setHover(hover); | |
463 fDiffPainter.setHover(hover); | |
464 } | |
465 | |
466 /* | |
467 * @see IVerticalRulerColumn#setModel(IAnnotationModel) | |
468 */ | |
469 public void setModel(IAnnotationModel model) { | |
470 setAnnotationModel(model); | |
471 fRevisionPainter.setModel(model); | |
472 fDiffPainter.setModel(model); | |
473 } | |
474 | |
475 private void setAnnotationModel(IAnnotationModel model) { | |
476 if (fAnnotationModel !is model) | |
477 fAnnotationModel= model; | |
478 } | |
479 | |
480 /* | |
481 * @see dwtx.jface.text.source.IChangeRulerColumn#setBackground(dwt.graphics.Color) | |
482 */ | |
483 public void setBackground(Color background) { | |
484 fBackground= background; | |
485 if (fCanvas !is null && !fCanvas.isDisposed()) | |
486 fCanvas.setBackground(getBackground()); | |
487 fRevisionPainter.setBackground(background); | |
488 fDiffPainter.setBackground(background); | |
489 } | |
490 | |
491 /* | |
492 * @see dwtx.jface.text.source.IChangeRulerColumn#setAddedColor(dwt.graphics.Color) | |
493 */ | |
494 public void setAddedColor(Color addedColor) { | |
495 fDiffPainter.setAddedColor(addedColor); | |
496 } | |
497 | |
498 /* | |
499 * @see dwtx.jface.text.source.IChangeRulerColumn#setChangedColor(dwt.graphics.Color) | |
500 */ | |
501 public void setChangedColor(Color changedColor) { | |
502 fDiffPainter.setChangedColor(changedColor); | |
503 } | |
504 | |
505 /* | |
506 * @see dwtx.jface.text.source.IChangeRulerColumn#setDeletedColor(dwt.graphics.Color) | |
507 */ | |
508 public void setDeletedColor(Color deletedColor) { | |
509 fDiffPainter.setDeletedColor(deletedColor); | |
510 } | |
511 | |
512 /* | |
513 * @see dwtx.jface.text.source.IVerticalRulerInfoExtension#getModel() | |
514 */ | |
515 public IAnnotationModel getModel() { | |
516 return fAnnotationModel; | |
517 } | |
518 | |
519 /* | |
520 * @see IVerticalRulerColumn#getControl() | |
521 */ | |
522 public Control getControl() { | |
523 return fCanvas; | |
524 } | |
525 | |
526 /* | |
527 * @see dwtx.jface.text.source.IVerticalRulerInfo#getWidth() | |
528 */ | |
529 public int getWidth() { | |
530 return fWidth; | |
531 } | |
532 | |
533 /** | |
534 * Triggers a redraw in the display thread. | |
535 */ | |
536 protected final void postRedraw() { | |
537 if (fCanvas !is null && !fCanvas.isDisposed()) { | |
538 Display d= fCanvas.getDisplay(); | |
539 if (d !is null) { | |
135 | 540 d.asyncExec(new class() Runnable { |
129 | 541 public void run() { |
542 redraw(); | |
543 } | |
544 }); | |
545 } | |
546 } | |
547 } | |
548 | |
549 /* | |
550 * @see dwtx.jface.text.source.IVerticalRulerInfoExtension#addVerticalRulerListener(dwtx.jface.text.source.IVerticalRulerListener) | |
551 */ | |
552 public void addVerticalRulerListener(IVerticalRulerListener listener) { | |
553 throw new UnsupportedOperationException(); | |
554 } | |
555 | |
556 /* | |
557 * @see dwtx.jface.text.source.IVerticalRulerInfoExtension#removeVerticalRulerListener(dwtx.jface.text.source.IVerticalRulerListener) | |
558 */ | |
559 public void removeVerticalRulerListener(IVerticalRulerListener listener) { | |
560 throw new UnsupportedOperationException(); | |
561 } | |
159 | 562 |
129 | 563 /** |
564 * Computes the document based line range visible in the text widget. | |
159 | 565 * |
129 | 566 * @return the document based line range visible in the text widget |
567 * @since 3.2 | |
568 */ | |
569 private final ILineRange computeVisibleModelLines() { | |
570 IDocument doc= fCachedTextViewer.getDocument(); | |
571 if (doc is null) | |
572 return null; | |
159 | 573 |
129 | 574 int topLine; |
575 IRegion coverage; | |
159 | 576 |
138 | 577 if ( cast(ITextViewerExtension5)fCachedTextViewer ) { |
134 | 578 ITextViewerExtension5 extension= cast(ITextViewerExtension5) fCachedTextViewer; |
159 | 579 |
129 | 580 // ITextViewer.getTopIndex returns the fully visible line, but we want the partially |
581 // visible one | |
582 int widgetTopLine= JFaceTextUtil.getPartialTopIndex(fCachedTextWidget); | |
583 topLine= extension.widgetLine2ModelLine(widgetTopLine); | |
159 | 584 |
129 | 585 coverage= extension.getModelCoverage(); |
159 | 586 |
129 | 587 } else { |
159 | 588 topLine= JFaceTextUtil.getPartialTopIndex(fCachedTextViewer); |
129 | 589 coverage= fCachedTextViewer.getVisibleRegion(); |
590 } | |
159 | 591 |
129 | 592 int bottomLine= fCachedTextViewer.getBottomIndex(); |
593 if (bottomLine !is -1) | |
594 ++ bottomLine; | |
159 | 595 |
129 | 596 // clip by coverage window |
597 try { | |
598 int firstLine= doc.getLineOfOffset(coverage.getOffset()); | |
599 if (firstLine > topLine) | |
600 topLine= firstLine; | |
159 | 601 |
129 | 602 int lastLine= doc.getLineOfOffset(coverage.getOffset() + coverage.getLength()); |
603 if (lastLine < bottomLine || bottomLine is -1) | |
604 bottomLine= lastLine; | |
605 } catch (BadLocationException x) { | |
606 x.printStackTrace(); | |
607 return null; | |
608 } | |
159 | 609 |
129 | 610 ILineRange visibleModelLines= new LineRange(topLine, bottomLine - topLine + 1); |
611 return visibleModelLines; | |
612 } | |
159 | 613 |
129 | 614 /* |
615 * @see dwtx.jface.text.revisions.IRevisionRulerColumn#setRevisionInformation(dwtx.jface.text.revisions.RevisionInformation) | |
616 */ | |
617 public void setRevisionInformation(RevisionInformation info) { | |
618 fRevisionPainter.setRevisionInformation(info); | |
619 fRevisionPainter.setBackground(getBackground()); | |
620 } | |
621 | |
622 /** | |
623 * Returns the revision selection provider. | |
159 | 624 * |
129 | 625 * @return the revision selection provider |
626 * @since 3.2 | |
627 */ | |
628 public ISelectionProvider getRevisionSelectionProvider() { | |
629 return fRevisionPainter.getRevisionSelectionProvider(); | |
630 } | |
631 } |