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
|
|
15 import dwt.dwthelper.utils;
|
|
16
|
|
17
|
|
18
|
|
19
|
|
20
|
|
21 import dwt.graphics.Color;
|
|
22 import dwt.graphics.GC;
|
|
23 import dwt.widgets.Composite;
|
|
24 import dwt.widgets.Control;
|
|
25 import dwtx.core.runtime.Assert;
|
|
26 import dwtx.jface.internal.text.revisions.RevisionPainter;
|
|
27 import dwtx.jface.internal.text.source.DiffPainter;
|
|
28 import dwtx.jface.text.revisions.IRevisionListener;
|
|
29 import dwtx.jface.text.revisions.IRevisionRulerColumn;
|
|
30 import dwtx.jface.text.revisions.IRevisionRulerColumnExtension;
|
|
31 import dwtx.jface.text.revisions.RevisionInformation;
|
|
32 import dwtx.jface.viewers.ISelectionProvider;
|
|
33
|
|
34 /**
|
|
35 * A vertical ruler column displaying line numbers and serving as a UI for quick diff.
|
|
36 * Clients usually instantiate and configure object of this class.
|
|
37 *
|
|
38 * @since 3.0
|
|
39 */
|
|
40 public final class LineNumberChangeRulerColumn : LineNumberRulerColumn , IVerticalRulerInfo, IVerticalRulerInfoExtension, IChangeRulerColumn, IRevisionRulerColumn, IRevisionRulerColumnExtension {
|
|
41 /** The ruler's annotation model. */
|
|
42 private IAnnotationModel fAnnotationModel;
|
|
43 /** <code>true</code> if changes should be displayed using character indications instead of background colors. */
|
|
44 private bool fCharacterDisplay;
|
|
45 /**
|
|
46 * The revision painter strategy.
|
|
47 *
|
|
48 * @since 3.2
|
|
49 */
|
|
50 private final RevisionPainter fRevisionPainter;
|
|
51 /**
|
|
52 * The diff information painter strategy.
|
|
53 *
|
|
54 * @since 3.2
|
|
55 */
|
|
56 private final DiffPainter fDiffPainter;
|
|
57 /**
|
|
58 * Whether to show number or to behave like a change ruler column.
|
|
59 * @since 3.3
|
|
60 */
|
|
61 private bool fShowNumbers= true;
|
|
62
|
|
63 /**
|
|
64 * Creates a new instance.
|
|
65 *
|
|
66 * @param sharedColors the shared colors provider to use
|
|
67 */
|
|
68 public LineNumberChangeRulerColumn(ISharedTextColors sharedColors) {
|
|
69 Assert.isNotNull(sharedColors);
|
|
70 fRevisionPainter= new RevisionPainter(this, sharedColors);
|
|
71 fDiffPainter= new DiffPainter(this, sharedColors);
|
|
72 }
|
|
73
|
|
74 /*
|
|
75 * @see dwtx.jface.text.source.LineNumberRulerColumn#createControl(dwtx.jface.text.source.CompositeRuler, dwt.widgets.Composite)
|
|
76 */
|
|
77 public Control createControl(CompositeRuler parentRuler, Composite parentControl) {
|
|
78 Control control= super.createControl(parentRuler, parentControl);
|
|
79 fRevisionPainter.setParentRuler(parentRuler);
|
|
80 fDiffPainter.setParentRuler(parentRuler);
|
|
81 return control;
|
|
82 }
|
|
83
|
|
84 /*
|
|
85 * @see dwtx.jface.text.source.IVerticalRulerInfo#getLineOfLastMouseButtonActivity()
|
|
86 */
|
|
87 public int getLineOfLastMouseButtonActivity() {
|
|
88 return getParentRuler().getLineOfLastMouseButtonActivity();
|
|
89 }
|
|
90
|
|
91 /*
|
|
92 * @see dwtx.jface.text.source.IVerticalRulerInfo#toDocumentLineNumber(int)
|
|
93 */
|
|
94 public int toDocumentLineNumber(int y_coordinate) {
|
|
95 return getParentRuler().toDocumentLineNumber(y_coordinate);
|
|
96 }
|
|
97
|
|
98 /*
|
|
99 * @see IVerticalRulerColumn#setModel(IAnnotationModel)
|
|
100 */
|
|
101 public void setModel(IAnnotationModel model) {
|
|
102 setAnnotationModel(model);
|
|
103 fRevisionPainter.setModel(model);
|
|
104 fDiffPainter.setModel(model);
|
|
105 updateNumberOfDigits();
|
|
106 computeIndentations();
|
|
107 layout(true);
|
|
108 postRedraw();
|
|
109 }
|
|
110
|
|
111 private void setAnnotationModel(IAnnotationModel model) {
|
|
112 if (fAnnotationModel !is model)
|
|
113 fAnnotationModel= model;
|
|
114 }
|
|
115
|
|
116
|
|
117 /**
|
|
118 * Sets the display mode of the ruler. If character mode is set to <code>true</code>, diff
|
|
119 * information will be displayed textually on the line number ruler.
|
|
120 *
|
|
121 * @param characterMode <code>true</code> if diff information is to be displayed textually.
|
|
122 */
|
|
123 public void setDisplayMode(bool characterMode) {
|
|
124 if (characterMode !is fCharacterDisplay) {
|
|
125 fCharacterDisplay= characterMode;
|
|
126 updateNumberOfDigits();
|
|
127 computeIndentations();
|
|
128 layout(true);
|
|
129 }
|
|
130 }
|
|
131
|
|
132 /*
|
|
133 * @see dwtx.jface.text.source.IVerticalRulerInfoExtension#getModel()
|
|
134 */
|
|
135 public IAnnotationModel getModel() {
|
|
136 return fAnnotationModel;
|
|
137 }
|
|
138
|
|
139 /*
|
|
140 * @see dwtx.jface.text.source.LineNumberRulerColumn#createDisplayString(int)
|
|
141 */
|
|
142 protected String createDisplayString(int line) {
|
|
143 StringBuffer buffer= new StringBuffer();
|
|
144 if (fShowNumbers)
|
|
145 buffer.append(super.createDisplayString(line));
|
|
146 if (fCharacterDisplay && getModel() !is null)
|
|
147 buffer.append(fDiffPainter.getDisplayCharacter(line));
|
|
148 return buffer.toString();
|
|
149 }
|
|
150
|
|
151 /*
|
|
152 * @see dwtx.jface.text.source.LineNumberRulerColumn#computeNumberOfDigits()
|
|
153 */
|
|
154 protected int computeNumberOfDigits() {
|
|
155 int digits;
|
|
156 if (fCharacterDisplay && getModel() !is null) {
|
|
157 if (fShowNumbers)
|
|
158 digits= super.computeNumberOfDigits() + 1;
|
|
159 else
|
|
160 digits= 1;
|
|
161 } else {
|
|
162 if (fShowNumbers)
|
|
163 digits= super.computeNumberOfDigits();
|
|
164 else
|
|
165 digits= 0;
|
|
166 }
|
|
167 if (fRevisionPainter.hasInformation())
|
|
168 digits+= fRevisionPainter.getRequiredWidth();
|
|
169 return digits;
|
|
170 }
|
|
171
|
|
172 /*
|
|
173 * @see dwtx.jface.text.source.IVerticalRulerInfoExtension#addVerticalRulerListener(dwtx.jface.text.source.IVerticalRulerListener)
|
|
174 */
|
|
175 public void addVerticalRulerListener(IVerticalRulerListener listener) {
|
|
176 throw new UnsupportedOperationException();
|
|
177 }
|
|
178
|
|
179 /*
|
|
180 * @see dwtx.jface.text.source.IVerticalRulerInfoExtension#removeVerticalRulerListener(dwtx.jface.text.source.IVerticalRulerListener)
|
|
181 */
|
|
182 public void removeVerticalRulerListener(IVerticalRulerListener listener) {
|
|
183 throw new UnsupportedOperationException();
|
|
184 }
|
|
185
|
|
186 /*
|
|
187 * @see dwtx.jface.text.source.LineNumberRulerColumn#doPaint(dwt.graphics.GC)
|
|
188 */
|
|
189 void doPaint(GC gc, ILineRange visibleLines) {
|
|
190 Color foreground= gc.getForeground();
|
|
191 if (visibleLines !is null) {
|
|
192 if (fRevisionPainter.hasInformation())
|
|
193 fRevisionPainter.paint(gc, visibleLines);
|
|
194 else if (fDiffPainter.hasInformation()) // don't paint quick diff colors if revisions are painted
|
|
195 fDiffPainter.paint(gc, visibleLines);
|
|
196 }
|
|
197 gc.setForeground(foreground);
|
|
198 if (fShowNumbers || fCharacterDisplay)
|
|
199 super.doPaint(gc, visibleLines);
|
|
200 }
|
|
201
|
|
202 /*
|
|
203 * @see dwtx.jface.text.source.IVerticalRulerInfoExtension#getHover()
|
|
204 */
|
|
205 public IAnnotationHover getHover() {
|
|
206 int activeLine= getParentRuler().getLineOfLastMouseButtonActivity();
|
|
207 if (fRevisionPainter.hasHover(activeLine))
|
|
208 return fRevisionPainter.getHover();
|
|
209 if (fDiffPainter.hasHover(activeLine))
|
|
210 return fDiffPainter.getHover();
|
|
211 return null;
|
|
212 }
|
|
213
|
|
214 /*
|
|
215 * @see dwtx.jface.text.source.IChangeRulerColumn#setHover(dwtx.jface.text.source.IAnnotationHover)
|
|
216 */
|
|
217 public void setHover(IAnnotationHover hover) {
|
|
218 fRevisionPainter.setHover(hover);
|
|
219 fDiffPainter.setHover(hover);
|
|
220 }
|
|
221
|
|
222 /*
|
|
223 * @see dwtx.jface.text.source.IChangeRulerColumn#setBackground(dwt.graphics.Color)
|
|
224 */
|
|
225 public void setBackground(Color background) {
|
|
226 super.setBackground(background);
|
|
227 fRevisionPainter.setBackground(background);
|
|
228 fDiffPainter.setBackground(background);
|
|
229 }
|
|
230
|
|
231 /*
|
|
232 * @see dwtx.jface.text.source.IChangeRulerColumn#setAddedColor(dwt.graphics.Color)
|
|
233 */
|
|
234 public void setAddedColor(Color addedColor) {
|
|
235 fDiffPainter.setAddedColor(addedColor);
|
|
236 }
|
|
237
|
|
238 /*
|
|
239 * @see dwtx.jface.text.source.IChangeRulerColumn#setChangedColor(dwt.graphics.Color)
|
|
240 */
|
|
241 public void setChangedColor(Color changedColor) {
|
|
242 fDiffPainter.setChangedColor(changedColor);
|
|
243 }
|
|
244
|
|
245 /*
|
|
246 * @see dwtx.jface.text.source.IChangeRulerColumn#setDeletedColor(dwt.graphics.Color)
|
|
247 */
|
|
248 public void setDeletedColor(Color deletedColor) {
|
|
249 fDiffPainter.setDeletedColor(deletedColor);
|
|
250 }
|
|
251
|
|
252 /*
|
|
253 * @see dwtx.jface.text.revisions.IRevisionRulerColumn#setRevisionInformation(dwtx.jface.text.revisions.RevisionInformation)
|
|
254 */
|
|
255 public void setRevisionInformation(RevisionInformation info) {
|
|
256 fRevisionPainter.setRevisionInformation(info);
|
|
257 updateNumberOfDigits();
|
|
258 computeIndentations();
|
|
259 layout(true);
|
|
260 postRedraw();
|
|
261 }
|
|
262
|
|
263 /*
|
|
264 * @see dwtx.jface.text.revisions.IRevisionRulerColumnExtension#getRevisionSelectionProvider()
|
|
265 * @since 3.2
|
|
266 */
|
|
267 public ISelectionProvider getRevisionSelectionProvider() {
|
|
268 return fRevisionPainter.getRevisionSelectionProvider();
|
|
269 }
|
|
270
|
|
271 /*
|
|
272 * @see dwtx.jface.text.revisions.IRevisionRulerColumnExtension#setRenderingMode(dwtx.jface.text.revisions.IRevisionRulerColumnExtension.RenderingMode)
|
|
273 * @since 3.3
|
|
274 */
|
|
275 public void setRevisionRenderingMode(RenderingMode renderingMode) {
|
|
276 fRevisionPainter.setRenderingMode(renderingMode);
|
|
277 }
|
|
278
|
|
279 /**
|
|
280 * Sets the line number display mode.
|
|
281 *
|
|
282 * @param showNumbers <code>true</code> to show numbers, <code>false</code> to only show
|
|
283 * diff / revision info.
|
|
284 * @since 3.3
|
|
285 */
|
|
286 public void showLineNumbers(bool showNumbers) {
|
|
287 if (fShowNumbers !is showNumbers) {
|
|
288 fShowNumbers= showNumbers;
|
|
289 updateNumberOfDigits();
|
|
290 computeIndentations();
|
|
291 layout(true);
|
|
292 }
|
|
293 }
|
|
294
|
|
295 /*
|
|
296 * @see dwtx.jface.text.source.LineNumberRulerColumn#getWidth()
|
|
297 * @since 3.3
|
|
298 */
|
|
299 public int getWidth() {
|
|
300 int width= super.getWidth();
|
|
301 return width > 0 ? width : 8; // minimal width to display quick diff / revisions if no textual info is shown
|
|
302 }
|
|
303
|
|
304 /**
|
|
305 * Returns <code>true</code> if the ruler is showing line numbers, <code>false</code>
|
|
306 * otherwise
|
|
307 *
|
|
308 * @return <code>true</code> if line numbers are shown, <code>false</code> otherwise
|
|
309 * @since 3.3
|
|
310 */
|
|
311 public bool isShowingLineNumbers() {
|
|
312 return fShowNumbers;
|
|
313 }
|
|
314
|
|
315 /**
|
|
316 * Returns <code>true</code> if the ruler is showing revision information, <code>false</code>
|
|
317 * otherwise
|
|
318 *
|
|
319 * @return <code>true</code> if revision information is shown, <code>false</code> otherwise
|
|
320 * @since 3.3
|
|
321 */
|
|
322 public bool isShowingRevisionInformation() {
|
|
323 return fRevisionPainter.hasInformation();
|
|
324 }
|
|
325
|
|
326 /**
|
|
327 * Returns <code>true</code> if the ruler is showing change information, <code>false</code>
|
|
328 * otherwise
|
|
329 *
|
|
330 * @return <code>true</code> if change information is shown, <code>false</code> otherwise
|
|
331 * @since 3.3
|
|
332 */
|
|
333 public bool isShowingChangeInformation() {
|
|
334 return fDiffPainter.hasInformation();
|
|
335 }
|
|
336
|
|
337 /*
|
|
338 * @see dwtx.jface.text.revisions.IRevisionRulerColumnExtension#showRevisionAuthor(bool)
|
|
339 * @since 3.3
|
|
340 */
|
|
341 public void showRevisionAuthor(bool show) {
|
|
342 fRevisionPainter.showRevisionAuthor(show);
|
|
343 updateNumberOfDigits();
|
|
344 computeIndentations();
|
|
345 layout(true);
|
|
346 postRedraw();
|
|
347 }
|
|
348
|
|
349 /*
|
|
350 * @see dwtx.jface.text.revisions.IRevisionRulerColumnExtension#showRevisionId(bool)
|
|
351 * @since 3.3
|
|
352 */
|
|
353 public void showRevisionId(bool show) {
|
|
354 fRevisionPainter.showRevisionId(show);
|
|
355 updateNumberOfDigits();
|
|
356 computeIndentations();
|
|
357 layout(true);
|
|
358 postRedraw();
|
|
359 }
|
|
360
|
|
361 /*
|
|
362 * @see dwtx.jface.text.revisions.IRevisionRulerColumnExtension#addRevisionListener(dwtx.jface.text.revisions.IRevisionListener)
|
|
363 * @since 3.3
|
|
364 */
|
|
365 public void addRevisionListener(IRevisionListener listener) {
|
|
366 fRevisionPainter.addRevisionListener(listener);
|
|
367 }
|
|
368
|
|
369 /*
|
|
370 * @see dwtx.jface.text.revisions.IRevisionRulerColumnExtension#removeRevisionListener(dwtx.jface.text.revisions.IRevisionListener)
|
|
371 * @since 3.3
|
|
372 */
|
|
373 public void removeRevisionListener(IRevisionListener listener) {
|
|
374 fRevisionPainter.removeRevisionListener(listener);
|
|
375 }
|
|
376
|
|
377 /*
|
|
378 * @see dwtx.jface.text.source.LineNumberRulerColumn#handleDispose()
|
|
379 * @since 3.3
|
|
380 */
|
|
381 protected void handleDispose() {
|
|
382 fRevisionPainter.setParentRuler(null);
|
|
383 fRevisionPainter.setModel(null);
|
|
384 fDiffPainter.setParentRuler(null);
|
|
385 fDiffPainter.setModel(null);
|
|
386 super.handleDispose();
|
|
387 }
|
|
388 }
|