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 {
|
|
104 /** The ruler's annotation model. */
|
|
105 private IAnnotationModel fAnnotationModel;
|
|
106 /** <code>true</code> if changes should be displayed using character indications instead of background colors. */
|
|
107 private bool fCharacterDisplay;
|
|
108 /**
|
|
109 * The revision painter strategy.
|
|
110 *
|
|
111 * @since 3.2
|
|
112 */
|
|
113 private final RevisionPainter fRevisionPainter;
|
|
114 /**
|
|
115 * The diff information painter strategy.
|
|
116 *
|
|
117 * @since 3.2
|
|
118 */
|
|
119 private final DiffPainter fDiffPainter;
|
|
120 /**
|
|
121 * Whether to show number or to behave like a change ruler column.
|
|
122 * @since 3.3
|
|
123 */
|
|
124 private bool fShowNumbers= true;
|
|
125
|
|
126 /**
|
|
127 * Creates a new instance.
|
|
128 *
|
|
129 * @param sharedColors the shared colors provider to use
|
|
130 */
|
|
131 public LineNumberChangeRulerColumn(ISharedTextColors sharedColors) {
|
|
132 Assert.isNotNull(sharedColors);
|
|
133 fRevisionPainter= new RevisionPainter(this, sharedColors);
|
|
134 fDiffPainter= new DiffPainter(this, sharedColors);
|
|
135 }
|
|
136
|
|
137 /*
|
|
138 * @see dwtx.jface.text.source.LineNumberRulerColumn#createControl(dwtx.jface.text.source.CompositeRuler, dwt.widgets.Composite)
|
|
139 */
|
|
140 public Control createControl(CompositeRuler parentRuler, Composite parentControl) {
|
|
141 Control control= super.createControl(parentRuler, parentControl);
|
|
142 fRevisionPainter.setParentRuler(parentRuler);
|
|
143 fDiffPainter.setParentRuler(parentRuler);
|
|
144 return control;
|
|
145 }
|
|
146
|
|
147 /*
|
|
148 * @see dwtx.jface.text.source.IVerticalRulerInfo#getLineOfLastMouseButtonActivity()
|
|
149 */
|
|
150 public int getLineOfLastMouseButtonActivity() {
|
|
151 return getParentRuler().getLineOfLastMouseButtonActivity();
|
|
152 }
|
|
153
|
|
154 /*
|
|
155 * @see dwtx.jface.text.source.IVerticalRulerInfo#toDocumentLineNumber(int)
|
|
156 */
|
|
157 public int toDocumentLineNumber(int y_coordinate) {
|
|
158 return getParentRuler().toDocumentLineNumber(y_coordinate);
|
|
159 }
|
|
160
|
|
161 /*
|
|
162 * @see IVerticalRulerColumn#setModel(IAnnotationModel)
|
|
163 */
|
|
164 public void setModel(IAnnotationModel model) {
|
|
165 setAnnotationModel(model);
|
|
166 fRevisionPainter.setModel(model);
|
|
167 fDiffPainter.setModel(model);
|
|
168 updateNumberOfDigits();
|
|
169 computeIndentations();
|
|
170 layout(true);
|
|
171 postRedraw();
|
|
172 }
|
|
173
|
|
174 private void setAnnotationModel(IAnnotationModel model) {
|
|
175 if (fAnnotationModel !is model)
|
|
176 fAnnotationModel= model;
|
|
177 }
|
|
178
|
|
179
|
|
180 /**
|
|
181 * Sets the display mode of the ruler. If character mode is set to <code>true</code>, diff
|
|
182 * information will be displayed textually on the line number ruler.
|
|
183 *
|
|
184 * @param characterMode <code>true</code> if diff information is to be displayed textually.
|
|
185 */
|
|
186 public void setDisplayMode(bool characterMode) {
|
|
187 if (characterMode !is fCharacterDisplay) {
|
|
188 fCharacterDisplay= characterMode;
|
|
189 updateNumberOfDigits();
|
|
190 computeIndentations();
|
|
191 layout(true);
|
|
192 }
|
|
193 }
|
|
194
|
|
195 /*
|
|
196 * @see dwtx.jface.text.source.IVerticalRulerInfoExtension#getModel()
|
|
197 */
|
|
198 public IAnnotationModel getModel() {
|
|
199 return fAnnotationModel;
|
|
200 }
|
|
201
|
|
202 /*
|
|
203 * @see dwtx.jface.text.source.LineNumberRulerColumn#createDisplayString(int)
|
|
204 */
|
|
205 protected String createDisplayString(int line) {
|
|
206 StringBuffer buffer= new StringBuffer();
|
|
207 if (fShowNumbers)
|
|
208 buffer.append(super.createDisplayString(line));
|
|
209 if (fCharacterDisplay && getModel() !is null)
|
|
210 buffer.append(fDiffPainter.getDisplayCharacter(line));
|
|
211 return buffer.toString();
|
|
212 }
|
|
213
|
|
214 /*
|
|
215 * @see dwtx.jface.text.source.LineNumberRulerColumn#computeNumberOfDigits()
|
|
216 */
|
|
217 protected int computeNumberOfDigits() {
|
|
218 int digits;
|
|
219 if (fCharacterDisplay && getModel() !is null) {
|
|
220 if (fShowNumbers)
|
|
221 digits= super.computeNumberOfDigits() + 1;
|
|
222 else
|
|
223 digits= 1;
|
|
224 } else {
|
|
225 if (fShowNumbers)
|
|
226 digits= super.computeNumberOfDigits();
|
|
227 else
|
|
228 digits= 0;
|
|
229 }
|
|
230 if (fRevisionPainter.hasInformation())
|
|
231 digits+= fRevisionPainter.getRequiredWidth();
|
|
232 return digits;
|
|
233 }
|
|
234
|
|
235 /*
|
|
236 * @see dwtx.jface.text.source.IVerticalRulerInfoExtension#addVerticalRulerListener(dwtx.jface.text.source.IVerticalRulerListener)
|
|
237 */
|
|
238 public void addVerticalRulerListener(IVerticalRulerListener listener) {
|
|
239 throw new UnsupportedOperationException();
|
|
240 }
|
|
241
|
|
242 /*
|
|
243 * @see dwtx.jface.text.source.IVerticalRulerInfoExtension#removeVerticalRulerListener(dwtx.jface.text.source.IVerticalRulerListener)
|
|
244 */
|
|
245 public void removeVerticalRulerListener(IVerticalRulerListener listener) {
|
|
246 throw new UnsupportedOperationException();
|
|
247 }
|
|
248
|
|
249 /*
|
|
250 * @see dwtx.jface.text.source.LineNumberRulerColumn#doPaint(dwt.graphics.GC)
|
|
251 */
|
|
252 void doPaint(GC gc, ILineRange visibleLines) {
|
|
253 Color foreground= gc.getForeground();
|
|
254 if (visibleLines !is null) {
|
|
255 if (fRevisionPainter.hasInformation())
|
|
256 fRevisionPainter.paint(gc, visibleLines);
|
|
257 else if (fDiffPainter.hasInformation()) // don't paint quick diff colors if revisions are painted
|
|
258 fDiffPainter.paint(gc, visibleLines);
|
|
259 }
|
|
260 gc.setForeground(foreground);
|
|
261 if (fShowNumbers || fCharacterDisplay)
|
|
262 super.doPaint(gc, visibleLines);
|
|
263 }
|
|
264
|
|
265 /*
|
|
266 * @see dwtx.jface.text.source.IVerticalRulerInfoExtension#getHover()
|
|
267 */
|
|
268 public IAnnotationHover getHover() {
|
|
269 int activeLine= getParentRuler().getLineOfLastMouseButtonActivity();
|
|
270 if (fRevisionPainter.hasHover(activeLine))
|
|
271 return fRevisionPainter.getHover();
|
|
272 if (fDiffPainter.hasHover(activeLine))
|
|
273 return fDiffPainter.getHover();
|
|
274 return null;
|
|
275 }
|
|
276
|
|
277 /*
|
|
278 * @see dwtx.jface.text.source.IChangeRulerColumn#setHover(dwtx.jface.text.source.IAnnotationHover)
|
|
279 */
|
|
280 public void setHover(IAnnotationHover hover) {
|
|
281 fRevisionPainter.setHover(hover);
|
|
282 fDiffPainter.setHover(hover);
|
|
283 }
|
|
284
|
|
285 /*
|
|
286 * @see dwtx.jface.text.source.IChangeRulerColumn#setBackground(dwt.graphics.Color)
|
|
287 */
|
|
288 public void setBackground(Color background) {
|
|
289 super.setBackground(background);
|
|
290 fRevisionPainter.setBackground(background);
|
|
291 fDiffPainter.setBackground(background);
|
|
292 }
|
|
293
|
|
294 /*
|
|
295 * @see dwtx.jface.text.source.IChangeRulerColumn#setAddedColor(dwt.graphics.Color)
|
|
296 */
|
|
297 public void setAddedColor(Color addedColor) {
|
|
298 fDiffPainter.setAddedColor(addedColor);
|
|
299 }
|
|
300
|
|
301 /*
|
|
302 * @see dwtx.jface.text.source.IChangeRulerColumn#setChangedColor(dwt.graphics.Color)
|
|
303 */
|
|
304 public void setChangedColor(Color changedColor) {
|
|
305 fDiffPainter.setChangedColor(changedColor);
|
|
306 }
|
|
307
|
|
308 /*
|
|
309 * @see dwtx.jface.text.source.IChangeRulerColumn#setDeletedColor(dwt.graphics.Color)
|
|
310 */
|
|
311 public void setDeletedColor(Color deletedColor) {
|
|
312 fDiffPainter.setDeletedColor(deletedColor);
|
|
313 }
|
|
314
|
|
315 /*
|
|
316 * @see dwtx.jface.text.revisions.IRevisionRulerColumn#setRevisionInformation(dwtx.jface.text.revisions.RevisionInformation)
|
|
317 */
|
|
318 public void setRevisionInformation(RevisionInformation info) {
|
|
319 fRevisionPainter.setRevisionInformation(info);
|
|
320 updateNumberOfDigits();
|
|
321 computeIndentations();
|
|
322 layout(true);
|
|
323 postRedraw();
|
|
324 }
|
|
325
|
|
326 /*
|
|
327 * @see dwtx.jface.text.revisions.IRevisionRulerColumnExtension#getRevisionSelectionProvider()
|
|
328 * @since 3.2
|
|
329 */
|
|
330 public ISelectionProvider getRevisionSelectionProvider() {
|
|
331 return fRevisionPainter.getRevisionSelectionProvider();
|
|
332 }
|
|
333
|
|
334 /*
|
|
335 * @see dwtx.jface.text.revisions.IRevisionRulerColumnExtension#setRenderingMode(dwtx.jface.text.revisions.IRevisionRulerColumnExtension.RenderingMode)
|
|
336 * @since 3.3
|
|
337 */
|
|
338 public void setRevisionRenderingMode(RenderingMode renderingMode) {
|
|
339 fRevisionPainter.setRenderingMode(renderingMode);
|
|
340 }
|
|
341
|
|
342 /**
|
|
343 * Sets the line number display mode.
|
|
344 *
|
|
345 * @param showNumbers <code>true</code> to show numbers, <code>false</code> to only show
|
|
346 * diff / revision info.
|
|
347 * @since 3.3
|
|
348 */
|
|
349 public void showLineNumbers(bool showNumbers) {
|
|
350 if (fShowNumbers !is showNumbers) {
|
|
351 fShowNumbers= showNumbers;
|
|
352 updateNumberOfDigits();
|
|
353 computeIndentations();
|
|
354 layout(true);
|
|
355 }
|
|
356 }
|
|
357
|
|
358 /*
|
|
359 * @see dwtx.jface.text.source.LineNumberRulerColumn#getWidth()
|
|
360 * @since 3.3
|
|
361 */
|
|
362 public int getWidth() {
|
|
363 int width= super.getWidth();
|
|
364 return width > 0 ? width : 8; // minimal width to display quick diff / revisions if no textual info is shown
|
|
365 }
|
|
366
|
|
367 /**
|
|
368 * Returns <code>true</code> if the ruler is showing line numbers, <code>false</code>
|
|
369 * otherwise
|
|
370 *
|
|
371 * @return <code>true</code> if line numbers are shown, <code>false</code> otherwise
|
|
372 * @since 3.3
|
|
373 */
|
|
374 public bool isShowingLineNumbers() {
|
|
375 return fShowNumbers;
|
|
376 }
|
|
377
|
|
378 /**
|
|
379 * Returns <code>true</code> if the ruler is showing revision information, <code>false</code>
|
|
380 * otherwise
|
|
381 *
|
|
382 * @return <code>true</code> if revision information is shown, <code>false</code> otherwise
|
|
383 * @since 3.3
|
|
384 */
|
|
385 public bool isShowingRevisionInformation() {
|
|
386 return fRevisionPainter.hasInformation();
|
|
387 }
|
|
388
|
|
389 /**
|
|
390 * Returns <code>true</code> if the ruler is showing change information, <code>false</code>
|
|
391 * otherwise
|
|
392 *
|
|
393 * @return <code>true</code> if change information is shown, <code>false</code> otherwise
|
|
394 * @since 3.3
|
|
395 */
|
|
396 public bool isShowingChangeInformation() {
|
|
397 return fDiffPainter.hasInformation();
|
|
398 }
|
|
399
|
|
400 /*
|
|
401 * @see dwtx.jface.text.revisions.IRevisionRulerColumnExtension#showRevisionAuthor(bool)
|
|
402 * @since 3.3
|
|
403 */
|
|
404 public void showRevisionAuthor(bool show) {
|
|
405 fRevisionPainter.showRevisionAuthor(show);
|
|
406 updateNumberOfDigits();
|
|
407 computeIndentations();
|
|
408 layout(true);
|
|
409 postRedraw();
|
|
410 }
|
|
411
|
|
412 /*
|
|
413 * @see dwtx.jface.text.revisions.IRevisionRulerColumnExtension#showRevisionId(bool)
|
|
414 * @since 3.3
|
|
415 */
|
|
416 public void showRevisionId(bool show) {
|
|
417 fRevisionPainter.showRevisionId(show);
|
|
418 updateNumberOfDigits();
|
|
419 computeIndentations();
|
|
420 layout(true);
|
|
421 postRedraw();
|
|
422 }
|
|
423
|
|
424 /*
|
|
425 * @see dwtx.jface.text.revisions.IRevisionRulerColumnExtension#addRevisionListener(dwtx.jface.text.revisions.IRevisionListener)
|
|
426 * @since 3.3
|
|
427 */
|
|
428 public void addRevisionListener(IRevisionListener listener) {
|
|
429 fRevisionPainter.addRevisionListener(listener);
|
|
430 }
|
|
431
|
|
432 /*
|
|
433 * @see dwtx.jface.text.revisions.IRevisionRulerColumnExtension#removeRevisionListener(dwtx.jface.text.revisions.IRevisionListener)
|
|
434 * @since 3.3
|
|
435 */
|
|
436 public void removeRevisionListener(IRevisionListener listener) {
|
|
437 fRevisionPainter.removeRevisionListener(listener);
|
|
438 }
|
|
439
|
|
440 /*
|
|
441 * @see dwtx.jface.text.source.LineNumberRulerColumn#handleDispose()
|
|
442 * @since 3.3
|
|
443 */
|
|
444 protected void handleDispose() {
|
|
445 fRevisionPainter.setParentRuler(null);
|
|
446 fRevisionPainter.setModel(null);
|
|
447 fDiffPainter.setParentRuler(null);
|
|
448 fDiffPainter.setModel(null);
|
|
449 super.handleDispose();
|
|
450 }
|
|
451 }
|