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