Mercurial > projects > dwt-addons
annotate dwtx/jface/text/source/LineNumberChangeRulerColumn.d @ 172:d994a8b2cdf7
again compile fixes
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 10 Sep 2008 23:14:02 +0200 |
parents | 1a5b8f8129df |
children |
rev | line source |
---|---|
129 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2007 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.LineNumberChangeRulerColumn; | |
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.IAnnotationAccessExtension; // packageimport | |
37 import dwtx.jface.text.source.ISourceViewer; // packageimport | |
38 import dwtx.jface.text.source.AnnotationModel; // packageimport | |
39 import dwtx.jface.text.source.ILineDifferExtension2; // packageimport | |
40 import dwtx.jface.text.source.IAnnotationModelListener; // packageimport | |
41 import dwtx.jface.text.source.IVerticalRuler; // packageimport | |
42 import dwtx.jface.text.source.DefaultAnnotationHover; // packageimport | |
43 import dwtx.jface.text.source.SourceViewer; // packageimport | |
44 import dwtx.jface.text.source.SourceViewerConfiguration; // packageimport | |
45 import dwtx.jface.text.source.AnnotationBarHoverManager; // packageimport | |
46 import dwtx.jface.text.source.CompositeRuler; // packageimport | |
47 import dwtx.jface.text.source.ImageUtilities; // packageimport | |
48 import dwtx.jface.text.source.VisualAnnotationModel; // packageimport | |
49 import dwtx.jface.text.source.IAnnotationModel; // packageimport | |
50 import dwtx.jface.text.source.ISourceViewerExtension3; // packageimport | |
51 import dwtx.jface.text.source.ILineDiffInfo; // packageimport | |
52 import dwtx.jface.text.source.VerticalRulerEvent; // packageimport | |
53 import dwtx.jface.text.source.ChangeRulerColumn; // packageimport | |
54 import dwtx.jface.text.source.ILineDiffer; // packageimport | |
55 import dwtx.jface.text.source.AnnotationModelEvent; // packageimport | |
56 import dwtx.jface.text.source.AnnotationColumn; // packageimport | |
57 import dwtx.jface.text.source.AnnotationRulerColumn; // packageimport | |
58 import dwtx.jface.text.source.IAnnotationHoverExtension; // packageimport | |
59 import dwtx.jface.text.source.AbstractRulerColumn; // packageimport | |
60 import dwtx.jface.text.source.ISourceViewerExtension; // packageimport | |
61 import dwtx.jface.text.source.AnnotationMap; // packageimport | |
62 import dwtx.jface.text.source.IVerticalRulerInfo; // packageimport | |
63 import dwtx.jface.text.source.IAnnotationModelExtension2; // packageimport | |
64 import dwtx.jface.text.source.LineRange; // packageimport | |
65 import dwtx.jface.text.source.IAnnotationAccessExtension2; // packageimport | |
66 import dwtx.jface.text.source.VerticalRuler; // packageimport | |
67 import dwtx.jface.text.source.JFaceTextMessages; // packageimport | |
68 import dwtx.jface.text.source.IOverviewRuler; // packageimport | |
69 import dwtx.jface.text.source.Annotation; // packageimport | |
70 import dwtx.jface.text.source.IVerticalRulerListener; // packageimport | |
71 import dwtx.jface.text.source.ISourceViewerExtension4; // packageimport | |
72 import dwtx.jface.text.source.AnnotationPainter; // packageimport | |
73 import dwtx.jface.text.source.IAnnotationHoverExtension2; // packageimport | |
74 import dwtx.jface.text.source.OverviewRuler; // packageimport | |
75 import dwtx.jface.text.source.OverviewRulerHoverManager; // packageimport | |
76 | |
77 | |
129 | 78 import dwt.dwthelper.utils; |
79 | |
80 | |
81 | |
82 | |
83 | |
84 import dwt.graphics.Color; | |
85 import dwt.graphics.GC; | |
86 import dwt.widgets.Composite; | |
87 import dwt.widgets.Control; | |
88 import dwtx.core.runtime.Assert; | |
89 import dwtx.jface.internal.text.revisions.RevisionPainter; | |
90 import dwtx.jface.internal.text.source.DiffPainter; | |
91 import dwtx.jface.text.revisions.IRevisionListener; | |
92 import dwtx.jface.text.revisions.IRevisionRulerColumn; | |
93 import dwtx.jface.text.revisions.IRevisionRulerColumnExtension; | |
94 import dwtx.jface.text.revisions.RevisionInformation; | |
95 import dwtx.jface.viewers.ISelectionProvider; | |
96 | |
97 /** | |
98 * A vertical ruler column displaying line numbers and serving as a UI for quick diff. | |
99 * Clients usually instantiate and configure object of this class. | |
100 * | |
101 * @since 3.0 | |
102 */ | |
103 public final class LineNumberChangeRulerColumn : LineNumberRulerColumn , IVerticalRulerInfo, IVerticalRulerInfoExtension, IChangeRulerColumn, IRevisionRulerColumn, IRevisionRulerColumnExtension { | |
162 | 104 |
105 public Control getControl() { | |
106 return super.getControl(); | |
107 } | |
108 | |
129 | 109 /** The ruler's annotation model. */ |
110 private IAnnotationModel fAnnotationModel; | |
111 /** <code>true</code> if changes should be displayed using character indications instead of background colors. */ | |
112 private bool fCharacterDisplay; | |
113 /** | |
114 * The revision painter strategy. | |
162 | 115 * |
129 | 116 * @since 3.2 |
117 */ | |
146 | 118 private const RevisionPainter fRevisionPainter; |
162 | 119 /** |
129 | 120 * The diff information painter strategy. |
162 | 121 * |
129 | 122 * @since 3.2 |
123 */ | |
146 | 124 private const DiffPainter fDiffPainter; |
129 | 125 /** |
126 * Whether to show number or to behave like a change ruler column. | |
127 * @since 3.3 | |
128 */ | |
129 private bool fShowNumbers= true; | |
130 | |
131 /** | |
132 * Creates a new instance. | |
133 * | |
134 * @param sharedColors the shared colors provider to use | |
135 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
136 public this(ISharedTextColors sharedColors) { |
162 | 137 Assert.isNotNull(cast(Object)sharedColors); |
129 | 138 fRevisionPainter= new RevisionPainter(this, sharedColors); |
139 fDiffPainter= new DiffPainter(this, sharedColors); | |
140 } | |
162 | 141 |
129 | 142 /* |
143 * @see dwtx.jface.text.source.LineNumberRulerColumn#createControl(dwtx.jface.text.source.CompositeRuler, dwt.widgets.Composite) | |
144 */ | |
145 public Control createControl(CompositeRuler parentRuler, Composite parentControl) { | |
146 Control control= super.createControl(parentRuler, parentControl); | |
147 fRevisionPainter.setParentRuler(parentRuler); | |
148 fDiffPainter.setParentRuler(parentRuler); | |
149 return control; | |
150 } | |
162 | 151 |
129 | 152 /* |
153 * @see dwtx.jface.text.source.IVerticalRulerInfo#getLineOfLastMouseButtonActivity() | |
154 */ | |
155 public int getLineOfLastMouseButtonActivity() { | |
156 return getParentRuler().getLineOfLastMouseButtonActivity(); | |
157 } | |
158 | |
159 /* | |
160 * @see dwtx.jface.text.source.IVerticalRulerInfo#toDocumentLineNumber(int) | |
161 */ | |
162 public int toDocumentLineNumber(int y_coordinate) { | |
163 return getParentRuler().toDocumentLineNumber(y_coordinate); | |
164 } | |
165 | |
166 /* | |
167 * @see IVerticalRulerColumn#setModel(IAnnotationModel) | |
168 */ | |
169 public void setModel(IAnnotationModel model) { | |
170 setAnnotationModel(model); | |
171 fRevisionPainter.setModel(model); | |
172 fDiffPainter.setModel(model); | |
173 updateNumberOfDigits(); | |
174 computeIndentations(); | |
175 layout(true); | |
176 postRedraw(); | |
177 } | |
162 | 178 |
129 | 179 private void setAnnotationModel(IAnnotationModel model) { |
180 if (fAnnotationModel !is model) | |
181 fAnnotationModel= model; | |
182 } | |
183 | |
184 | |
185 /** | |
186 * Sets the display mode of the ruler. If character mode is set to <code>true</code>, diff | |
187 * information will be displayed textually on the line number ruler. | |
188 * | |
189 * @param characterMode <code>true</code> if diff information is to be displayed textually. | |
190 */ | |
191 public void setDisplayMode(bool characterMode) { | |
192 if (characterMode !is fCharacterDisplay) { | |
193 fCharacterDisplay= characterMode; | |
194 updateNumberOfDigits(); | |
195 computeIndentations(); | |
196 layout(true); | |
197 } | |
198 } | |
199 | |
200 /* | |
201 * @see dwtx.jface.text.source.IVerticalRulerInfoExtension#getModel() | |
202 */ | |
203 public IAnnotationModel getModel() { | |
204 return fAnnotationModel; | |
205 } | |
206 | |
207 /* | |
208 * @see dwtx.jface.text.source.LineNumberRulerColumn#createDisplayString(int) | |
209 */ | |
210 protected String createDisplayString(int line) { | |
211 StringBuffer buffer= new StringBuffer(); | |
212 if (fShowNumbers) | |
213 buffer.append(super.createDisplayString(line)); | |
214 if (fCharacterDisplay && getModel() !is null) | |
215 buffer.append(fDiffPainter.getDisplayCharacter(line)); | |
216 return buffer.toString(); | |
217 } | |
218 | |
219 /* | |
220 * @see dwtx.jface.text.source.LineNumberRulerColumn#computeNumberOfDigits() | |
221 */ | |
222 protected int computeNumberOfDigits() { | |
223 int digits; | |
224 if (fCharacterDisplay && getModel() !is null) { | |
225 if (fShowNumbers) | |
226 digits= super.computeNumberOfDigits() + 1; | |
227 else | |
228 digits= 1; | |
229 } else { | |
230 if (fShowNumbers) | |
231 digits= super.computeNumberOfDigits(); | |
232 else | |
233 digits= 0; | |
234 } | |
235 if (fRevisionPainter.hasInformation()) | |
236 digits+= fRevisionPainter.getRequiredWidth(); | |
237 return digits; | |
238 } | |
239 | |
240 /* | |
241 * @see dwtx.jface.text.source.IVerticalRulerInfoExtension#addVerticalRulerListener(dwtx.jface.text.source.IVerticalRulerListener) | |
242 */ | |
243 public void addVerticalRulerListener(IVerticalRulerListener listener) { | |
244 throw new UnsupportedOperationException(); | |
245 } | |
246 | |
247 /* | |
248 * @see dwtx.jface.text.source.IVerticalRulerInfoExtension#removeVerticalRulerListener(dwtx.jface.text.source.IVerticalRulerListener) | |
249 */ | |
250 public void removeVerticalRulerListener(IVerticalRulerListener listener) { | |
251 throw new UnsupportedOperationException(); | |
252 } | |
162 | 253 |
129 | 254 /* |
255 * @see dwtx.jface.text.source.LineNumberRulerColumn#doPaint(dwt.graphics.GC) | |
256 */ | |
257 void doPaint(GC gc, ILineRange visibleLines) { | |
258 Color foreground= gc.getForeground(); | |
259 if (visibleLines !is null) { | |
260 if (fRevisionPainter.hasInformation()) | |
261 fRevisionPainter.paint(gc, visibleLines); | |
262 else if (fDiffPainter.hasInformation()) // don't paint quick diff colors if revisions are painted | |
263 fDiffPainter.paint(gc, visibleLines); | |
264 } | |
265 gc.setForeground(foreground); | |
266 if (fShowNumbers || fCharacterDisplay) | |
267 super.doPaint(gc, visibleLines); | |
268 } | |
162 | 269 |
129 | 270 /* |
271 * @see dwtx.jface.text.source.IVerticalRulerInfoExtension#getHover() | |
272 */ | |
273 public IAnnotationHover getHover() { | |
274 int activeLine= getParentRuler().getLineOfLastMouseButtonActivity(); | |
275 if (fRevisionPainter.hasHover(activeLine)) | |
276 return fRevisionPainter.getHover(); | |
277 if (fDiffPainter.hasHover(activeLine)) | |
278 return fDiffPainter.getHover(); | |
279 return null; | |
280 } | |
281 | |
282 /* | |
283 * @see dwtx.jface.text.source.IChangeRulerColumn#setHover(dwtx.jface.text.source.IAnnotationHover) | |
284 */ | |
285 public void setHover(IAnnotationHover hover) { | |
286 fRevisionPainter.setHover(hover); | |
287 fDiffPainter.setHover(hover); | |
288 } | |
289 | |
290 /* | |
291 * @see dwtx.jface.text.source.IChangeRulerColumn#setBackground(dwt.graphics.Color) | |
292 */ | |
293 public void setBackground(Color background) { | |
294 super.setBackground(background); | |
295 fRevisionPainter.setBackground(background); | |
296 fDiffPainter.setBackground(background); | |
297 } | |
298 | |
299 /* | |
300 * @see dwtx.jface.text.source.IChangeRulerColumn#setAddedColor(dwt.graphics.Color) | |
301 */ | |
302 public void setAddedColor(Color addedColor) { | |
303 fDiffPainter.setAddedColor(addedColor); | |
304 } | |
305 | |
306 /* | |
307 * @see dwtx.jface.text.source.IChangeRulerColumn#setChangedColor(dwt.graphics.Color) | |
308 */ | |
309 public void setChangedColor(Color changedColor) { | |
310 fDiffPainter.setChangedColor(changedColor); | |
311 } | |
312 | |
313 /* | |
314 * @see dwtx.jface.text.source.IChangeRulerColumn#setDeletedColor(dwt.graphics.Color) | |
315 */ | |
316 public void setDeletedColor(Color deletedColor) { | |
317 fDiffPainter.setDeletedColor(deletedColor); | |
318 } | |
162 | 319 |
129 | 320 /* |
321 * @see dwtx.jface.text.revisions.IRevisionRulerColumn#setRevisionInformation(dwtx.jface.text.revisions.RevisionInformation) | |
322 */ | |
323 public void setRevisionInformation(RevisionInformation info) { | |
324 fRevisionPainter.setRevisionInformation(info); | |
325 updateNumberOfDigits(); | |
326 computeIndentations(); | |
327 layout(true); | |
328 postRedraw(); | |
329 } | |
330 | |
331 /* | |
332 * @see dwtx.jface.text.revisions.IRevisionRulerColumnExtension#getRevisionSelectionProvider() | |
333 * @since 3.2 | |
334 */ | |
335 public ISelectionProvider getRevisionSelectionProvider() { | |
336 return fRevisionPainter.getRevisionSelectionProvider(); | |
337 } | |
338 | |
339 /* | |
340 * @see dwtx.jface.text.revisions.IRevisionRulerColumnExtension#setRenderingMode(dwtx.jface.text.revisions.IRevisionRulerColumnExtension.RenderingMode) | |
341 * @since 3.3 | |
342 */ | |
343 public void setRevisionRenderingMode(RenderingMode renderingMode) { | |
344 fRevisionPainter.setRenderingMode(renderingMode); | |
345 } | |
346 | |
347 /** | |
348 * Sets the line number display mode. | |
162 | 349 * |
129 | 350 * @param showNumbers <code>true</code> to show numbers, <code>false</code> to only show |
351 * diff / revision info. | |
352 * @since 3.3 | |
353 */ | |
354 public void showLineNumbers(bool showNumbers) { | |
355 if (fShowNumbers !is showNumbers) { | |
356 fShowNumbers= showNumbers; | |
357 updateNumberOfDigits(); | |
358 computeIndentations(); | |
359 layout(true); | |
360 } | |
361 } | |
362 | |
363 /* | |
364 * @see dwtx.jface.text.source.LineNumberRulerColumn#getWidth() | |
365 * @since 3.3 | |
366 */ | |
367 public int getWidth() { | |
368 int width= super.getWidth(); | |
369 return width > 0 ? width : 8; // minimal width to display quick diff / revisions if no textual info is shown | |
370 } | |
371 | |
372 /** | |
373 * Returns <code>true</code> if the ruler is showing line numbers, <code>false</code> | |
374 * otherwise | |
162 | 375 * |
129 | 376 * @return <code>true</code> if line numbers are shown, <code>false</code> otherwise |
377 * @since 3.3 | |
378 */ | |
379 public bool isShowingLineNumbers() { | |
380 return fShowNumbers; | |
381 } | |
382 | |
383 /** | |
384 * Returns <code>true</code> if the ruler is showing revision information, <code>false</code> | |
385 * otherwise | |
162 | 386 * |
129 | 387 * @return <code>true</code> if revision information is shown, <code>false</code> otherwise |
388 * @since 3.3 | |
389 */ | |
390 public bool isShowingRevisionInformation() { | |
391 return fRevisionPainter.hasInformation(); | |
392 } | |
393 | |
394 /** | |
395 * Returns <code>true</code> if the ruler is showing change information, <code>false</code> | |
396 * otherwise | |
162 | 397 * |
129 | 398 * @return <code>true</code> if change information is shown, <code>false</code> otherwise |
399 * @since 3.3 | |
400 */ | |
401 public bool isShowingChangeInformation() { | |
402 return fDiffPainter.hasInformation(); | |
403 } | |
404 | |
405 /* | |
406 * @see dwtx.jface.text.revisions.IRevisionRulerColumnExtension#showRevisionAuthor(bool) | |
407 * @since 3.3 | |
408 */ | |
409 public void showRevisionAuthor(bool show) { | |
410 fRevisionPainter.showRevisionAuthor(show); | |
411 updateNumberOfDigits(); | |
412 computeIndentations(); | |
413 layout(true); | |
414 postRedraw(); | |
415 } | |
416 | |
417 /* | |
418 * @see dwtx.jface.text.revisions.IRevisionRulerColumnExtension#showRevisionId(bool) | |
419 * @since 3.3 | |
420 */ | |
421 public void showRevisionId(bool show) { | |
422 fRevisionPainter.showRevisionId(show); | |
423 updateNumberOfDigits(); | |
424 computeIndentations(); | |
425 layout(true); | |
426 postRedraw(); | |
427 } | |
428 | |
429 /* | |
430 * @see dwtx.jface.text.revisions.IRevisionRulerColumnExtension#addRevisionListener(dwtx.jface.text.revisions.IRevisionListener) | |
431 * @since 3.3 | |
432 */ | |
433 public void addRevisionListener(IRevisionListener listener) { | |
434 fRevisionPainter.addRevisionListener(listener); | |
435 } | |
436 | |
437 /* | |
438 * @see dwtx.jface.text.revisions.IRevisionRulerColumnExtension#removeRevisionListener(dwtx.jface.text.revisions.IRevisionListener) | |
439 * @since 3.3 | |
440 */ | |
441 public void removeRevisionListener(IRevisionListener listener) { | |
442 fRevisionPainter.removeRevisionListener(listener); | |
443 } | |
162 | 444 |
129 | 445 /* |
446 * @see dwtx.jface.text.source.LineNumberRulerColumn#handleDispose() | |
447 * @since 3.3 | |
448 */ | |
449 protected void handleDispose() { | |
450 fRevisionPainter.setParentRuler(null); | |
451 fRevisionPainter.setModel(null); | |
452 fDiffPainter.setParentRuler(null); | |
453 fDiffPainter.setModel(null); | |
454 super.handleDispose(); | |
455 } | |
456 } |