Mercurial > projects > dwt-addons
annotate dwtx/jface/text/source/AnnotationBarHoverManager.d @ 159:7926b636c282
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 27 Aug 2008 01:57:58 +0200 |
parents | a9566845f1cb |
children | 1a5b8f8129df |
rev | line source |
---|---|
129 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2008 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.AnnotationBarHoverManager; | |
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.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 | |
129 | 77 import dwt.dwthelper.utils; |
153
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
145
diff
changeset
|
78 import dwtx.dwtxhelper.Collection; |
129 | 79 |
80 import dwt.DWT; | |
81 import dwt.custom.StyledText; | |
82 import dwt.events.ControlEvent; | |
83 import dwt.events.ControlListener; | |
84 import dwt.events.DisposeEvent; | |
85 import dwt.events.DisposeListener; | |
86 import dwt.events.KeyEvent; | |
87 import dwt.events.KeyListener; | |
88 import dwt.events.MouseEvent; | |
89 import dwt.events.MouseListener; | |
90 import dwt.events.MouseMoveListener; | |
91 import dwt.events.MouseTrackAdapter; | |
92 import dwt.events.ShellEvent; | |
93 import dwt.events.ShellListener; | |
94 import dwt.graphics.Point; | |
95 import dwt.graphics.Rectangle; | |
96 import dwt.widgets.Control; | |
97 import dwt.widgets.Display; | |
98 import dwt.widgets.Event; | |
99 import dwt.widgets.Listener; | |
100 import dwtx.core.runtime.Assert; | |
101 import dwtx.jface.internal.text.InformationControlReplacer; | |
102 import dwtx.jface.internal.text.InternalAccessor; | |
103 import dwtx.jface.text.AbstractHoverInformationControlManager; | |
104 import dwtx.jface.text.AbstractInformationControlManager; | |
105 import dwtx.jface.text.BadLocationException; | |
106 import dwtx.jface.text.IDocument; | |
107 import dwtx.jface.text.IInformationControl; | |
108 import dwtx.jface.text.IInformationControlCreator; | |
109 import dwtx.jface.text.IRegion; | |
110 import dwtx.jface.text.ITextViewerExtension5; | |
111 import dwtx.jface.text.JFaceTextUtil; | |
112 import dwtx.jface.text.Region; | |
113 import dwtx.jface.text.TextUtilities; | |
156 | 114 import dwtx.jface.text.ITextViewerExtension8; |
129 | 115 |
116 | |
117 /** | |
118 * This manager controls the layout, content, and visibility of an information | |
119 * control in reaction to mouse hover events issued by the vertical ruler of a | |
120 * source viewer. | |
121 * @since 2.0 | |
122 */ | |
123 public class AnnotationBarHoverManager : AbstractHoverInformationControlManager { | |
124 | |
125 /** | |
126 * The information control closer for the hover information. Closes the information control as soon as the mouse pointer leaves the subject area, a mouse button is pressed, the user presses a key, or the subject control is resized or moved. | |
145 | 127 * |
129 | 128 * @since 3.0 |
129 * @deprecated As of 3.4, no longer used as closer from super class is used | |
130 */ | |
131 protected class Closer : MouseTrackAdapter , IInformationControlCloser, MouseListener, MouseMoveListener, ControlListener, KeyListener, DisposeListener, ShellListener, Listener { | |
132 | |
133 /** The closer's subject control */ | |
134 private Control fSubjectControl; | |
135 /** The subject area */ | |
136 private Rectangle fSubjectArea; | |
137 /** Indicates whether this closer is active */ | |
138 private bool fIsActive= false; | |
139 /** The information control. */ | |
140 private IInformationControl fInformationControlToClose; | |
141 /** | |
142 * <code>true</code> if a wheel handler is installed. | |
143 * @since 3.2 | |
144 */ | |
145 private bool fHasWheelFilter= false; | |
146 /** | |
147 * The cached display. | |
148 * @since 3.2 | |
149 */ | |
150 private Display fDisplay; | |
151 | |
152 | |
153 /** | |
154 * Creates a new information control closer. | |
155 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
156 public this() { |
129 | 157 } |
158 | |
159 /* | |
160 * @see IInformationControlCloser#setSubjectControl(Control) | |
161 */ | |
162 public void setSubjectControl(Control control) { | |
163 fSubjectControl= control; | |
164 } | |
165 | |
166 /* | |
167 * @see IInformationControlCloser#setHoverControl(IHoverControl) | |
168 */ | |
169 public void setInformationControl(IInformationControl control) { | |
170 fInformationControlToClose= control; | |
171 } | |
172 | |
173 /* | |
174 * @see IInformationControlCloser#start(Rectangle) | |
175 */ | |
176 public void start(Rectangle subjectArea) { | |
177 | |
178 if (fIsActive) return; | |
179 fIsActive= true; | |
180 | |
181 fSubjectArea= subjectArea; | |
182 | |
183 fInformationControlToClose.addDisposeListener(this); | |
184 if (fSubjectControl !is null && !fSubjectControl.isDisposed()) { | |
185 fSubjectControl.addMouseListener(this); | |
186 fSubjectControl.addMouseMoveListener(this); | |
187 fSubjectControl.addMouseTrackListener(this); | |
188 fSubjectControl.getShell().addShellListener(this); | |
189 fSubjectControl.addControlListener(this); | |
190 fSubjectControl.addKeyListener(this); | |
145 | 191 |
129 | 192 fDisplay= fSubjectControl.getDisplay(); |
193 if (!fDisplay.isDisposed() && fHideOnMouseWheel) { | |
194 fHasWheelFilter= true; | |
195 fDisplay.addFilter(DWT.MouseWheel, this); | |
196 } | |
197 } | |
198 } | |
199 | |
200 /* | |
201 * @see IInformationControlCloser#stop() | |
202 */ | |
203 public void stop() { | |
204 | |
205 if (!fIsActive) | |
206 return; | |
207 fIsActive= false; | |
208 | |
209 if (fSubjectControl !is null && !fSubjectControl.isDisposed()) { | |
210 fSubjectControl.removeMouseListener(this); | |
211 fSubjectControl.removeMouseMoveListener(this); | |
212 fSubjectControl.removeMouseTrackListener(this); | |
213 fSubjectControl.getShell().removeShellListener(this); | |
214 fSubjectControl.removeControlListener(this); | |
215 fSubjectControl.removeKeyListener(this); | |
216 } | |
145 | 217 |
129 | 218 if (fDisplay !is null && !fDisplay.isDisposed() && fHasWheelFilter) |
219 fDisplay.removeFilter(DWT.MouseWheel, this); | |
220 fHasWheelFilter= false; | |
145 | 221 |
129 | 222 fDisplay= null; |
145 | 223 |
129 | 224 } |
225 | |
226 /** | |
227 * Stops the information control and if <code>delayRestart</code> is set allows restart only after a certain delay. | |
145 | 228 * |
129 | 229 * @param delayRestart <code>true</code> if restart should be delayed |
230 * @deprecated As of 3.4, replaced by {@link #stop()}. Note that <code>delayRestart</code> was never honored. | |
231 */ | |
232 protected void stop(bool delayRestart) { | |
233 stop(); | |
234 } | |
235 | |
236 /* | |
237 * @see dwt.events.MouseMoveListener#mouseMove(dwt.events.MouseEvent) | |
238 */ | |
239 public void mouseMove(MouseEvent event) { | |
240 if (!fSubjectArea.contains(event.x, event.y)) | |
241 hideInformationControl(); | |
242 } | |
243 | |
244 /* | |
245 * @see dwt.events.MouseListener#mouseUp(dwt.events.MouseEvent) | |
246 */ | |
247 public void mouseUp(MouseEvent event) { | |
248 } | |
249 | |
250 /* | |
251 * @see MouseListener#mouseDown(MouseEvent) | |
252 */ | |
253 public void mouseDown(MouseEvent event) { | |
254 hideInformationControl(); | |
255 } | |
256 | |
257 /* | |
258 * @see MouseListener#mouseDoubleClick(MouseEvent) | |
259 */ | |
260 public void mouseDoubleClick(MouseEvent event) { | |
261 hideInformationControl(); | |
262 } | |
145 | 263 |
129 | 264 /* |
265 * @see dwt.widgets.Listener#handleEvent(dwt.widgets.Event) | |
266 * @since 3.2 | |
267 */ | |
268 public void handleEvent(Event event) { | |
269 if (event.type is DWT.MouseWheel) | |
270 hideInformationControl(); | |
271 } | |
272 | |
273 /* | |
274 * @see MouseTrackAdapter#mouseExit(MouseEvent) | |
275 */ | |
276 public void mouseExit(MouseEvent event) { | |
277 if (!fAllowMouseExit) | |
278 hideInformationControl(); | |
279 } | |
280 | |
281 /* | |
282 * @see ControlListener#controlResized(ControlEvent) | |
283 */ | |
284 public void controlResized(ControlEvent event) { | |
285 hideInformationControl(); | |
286 } | |
287 | |
288 /* | |
289 * @see ControlListener#controlMoved(ControlEvent) | |
290 */ | |
291 public void controlMoved(ControlEvent event) { | |
292 hideInformationControl(); | |
293 } | |
294 | |
295 /* | |
296 * @see KeyListener#keyReleased(KeyEvent) | |
297 */ | |
298 public void keyReleased(KeyEvent event) { | |
299 } | |
300 | |
301 /* | |
302 * @see KeyListener#keyPressed(KeyEvent) | |
303 */ | |
304 public void keyPressed(KeyEvent event) { | |
305 hideInformationControl(); | |
306 } | |
307 | |
308 /* | |
309 * @see dwt.events.ShellListener#shellActivated(dwt.events.ShellEvent) | |
310 * @since 3.1 | |
311 */ | |
312 public void shellActivated(ShellEvent e) { | |
313 } | |
314 | |
315 /* | |
316 * @see dwt.events.ShellListener#shellClosed(dwt.events.ShellEvent) | |
317 * @since 3.1 | |
318 */ | |
319 public void shellClosed(ShellEvent e) { | |
320 } | |
321 | |
322 /* | |
323 * @see dwt.events.ShellListener#shellDeactivated(dwt.events.ShellEvent) | |
324 * @since 3.1 | |
325 */ | |
326 public void shellDeactivated(ShellEvent e) { | |
327 hideInformationControl(); | |
328 } | |
329 | |
330 /* | |
331 * @see dwt.events.ShellListener#shellDeiconified(dwt.events.ShellEvent) | |
332 * @since 3.1 | |
333 */ | |
334 public void shellDeiconified(ShellEvent e) { | |
335 } | |
336 | |
337 /* | |
338 * @see dwt.events.ShellListener#shellIconified(dwt.events.ShellEvent) | |
339 * @since 3.1 | |
340 */ | |
341 public void shellIconified(ShellEvent e) { | |
342 } | |
343 | |
344 /* | |
345 * @see dwt.events.DisposeListener#widgetDisposed(dwt.events.DisposeEvent) | |
346 */ | |
347 public void widgetDisposed(DisposeEvent e) { | |
348 hideInformationControl(); | |
349 } | |
350 } | |
351 | |
352 /** The source viewer the manager is connected to */ | |
353 private ISourceViewer fSourceViewer; | |
354 /** The vertical ruler the manager is registered with */ | |
355 private IVerticalRulerInfo fVerticalRulerInfo; | |
356 /** The annotation hover the manager uses to retrieve the information to display. Can be <code>null</code>. */ | |
357 private IAnnotationHover fAnnotationHover; | |
358 /** | |
359 * Indicates whether the mouse cursor is allowed to leave the subject area without closing the hover. | |
360 * @since 3.0 | |
361 */ | |
362 protected bool fAllowMouseExit= false; | |
363 /** | |
364 * Whether we should hide the over on mouse wheel action. | |
145 | 365 * |
129 | 366 * @since 3.2 |
367 */ | |
368 private bool fHideOnMouseWheel= true; | |
145 | 369 |
129 | 370 /** |
371 * The current annotation hover. | |
372 * @since 3.2 | |
373 */ | |
374 private IAnnotationHover fCurrentHover; | |
375 | |
376 /** | |
377 * Creates an annotation hover manager with the given parameters. In addition, | |
378 * the hovers anchor is RIGHT and the margin is 5 points to the right. | |
379 * | |
380 * @param sourceViewer the source viewer this manager connects to | |
381 * @param ruler the vertical ruler this manager connects to | |
382 * @param annotationHover the annotation hover providing the information to be displayed | |
383 * @param creator the information control creator | |
384 * @deprecated As of 2.1, replaced by {@link AnnotationBarHoverManager#AnnotationBarHoverManager(IVerticalRulerInfo, ISourceViewer, IAnnotationHover, IInformationControlCreator)} | |
385 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
386 public this(ISourceViewer sourceViewer, IVerticalRuler ruler, IAnnotationHover annotationHover, IInformationControlCreator creator) { |
129 | 387 this(ruler, sourceViewer, annotationHover, creator); |
388 } | |
389 | |
390 /** | |
391 * Creates an annotation hover manager with the given parameters. In addition, | |
392 * the hovers anchor is RIGHT and the margin is 5 points to the right. | |
393 * | |
394 * @param rulerInfo the vertical ruler this manager connects to | |
395 * @param sourceViewer the source viewer this manager connects to | |
396 * @param annotationHover the annotation hover providing the information to be displayed or <code>null</code> if none | |
397 * @param creator the information control creator | |
398 * @since 2.1 | |
399 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
400 public this(IVerticalRulerInfo rulerInfo, ISourceViewer sourceViewer, IAnnotationHover annotationHover, IInformationControlCreator creator) { |
129 | 401 super(creator); |
402 | |
403 Assert.isNotNull(sourceViewer); | |
404 | |
405 fSourceViewer= sourceViewer; | |
406 fVerticalRulerInfo= rulerInfo; | |
407 fAnnotationHover= annotationHover; | |
408 | |
409 setAnchor(ANCHOR_RIGHT); | |
410 setMargins(5, 0); | |
411 // use closer from super class | |
412 } | |
413 | |
414 /* | |
415 * @see dwtx.jface.text.AbstractInformationControlManager#computeInformation() | |
416 */ | |
417 protected void computeInformation() { | |
418 fAllowMouseExit= false; | |
419 MouseEvent event= getHoverEvent(); | |
420 IAnnotationHover hover= getHover(event); | |
421 if (hover is null) { | |
422 setInformation(null, null); | |
423 return; | |
424 } | |
425 | |
426 int line= getHoverLine(event); | |
427 | |
138 | 428 if ( cast(IAnnotationHoverExtension)hover ) { |
134 | 429 IAnnotationHoverExtension extension= cast(IAnnotationHoverExtension) hover; |
129 | 430 ILineRange range= extension.getHoverLineRange(fSourceViewer, line); |
431 setCustomInformationControlCreator(extension.getHoverControlCreator()); | |
432 range= adaptLineRange(range, line); | |
433 if (range !is null) | |
434 setInformation(extension.getHoverInfo(fSourceViewer, range, computeNumberOfVisibleLines()), computeArea(range)); | |
435 else | |
436 setInformation(null, null); | |
437 | |
438 } else { | |
439 setCustomInformationControlCreator(null); | |
440 setInformation(hover.getHoverInfo(fSourceViewer, line), computeArea(line)); | |
441 } | |
442 | |
443 } | |
145 | 444 |
129 | 445 /* |
446 * @see dwtx.jface.text.AbstractInformationControlManager#showInformationControl(dwt.graphics.Rectangle) | |
447 * @since 3.2 | |
448 */ | |
449 protected void showInformationControl(Rectangle subjectArea) { | |
450 super.showInformationControl(subjectArea); | |
451 fCurrentHover= getHover(getHoverEvent()); | |
452 } | |
145 | 453 |
129 | 454 /* |
455 * @see dwtx.jface.text.AbstractInformationControlManager#hideInformationControl() | |
456 * @since 3.2 | |
457 */ | |
458 protected void hideInformationControl() { | |
459 fCurrentHover= null; | |
460 super.hideInformationControl(); | |
461 } | |
462 | |
463 /** | |
464 * Adapts a given line range so that the result is a line range that does | |
465 * not overlap with any collapsed region and fits into the view port of the | |
466 * attached viewer. | |
467 * | |
468 * @param lineRange the original line range | |
469 * @param line the anchor line | |
470 * @return the adapted line range | |
471 * @since 3.0 | |
472 */ | |
473 private ILineRange adaptLineRange(ILineRange lineRange, int line) { | |
474 if (lineRange !is null) { | |
475 lineRange= adaptLineRangeToFolding(lineRange, line); | |
476 if (lineRange !is null) | |
477 return adaptLineRangeToViewport(lineRange); | |
478 } | |
479 return null; | |
480 } | |
481 | |
482 /** | |
483 * Adapts a given line range so that the result is a line range that does | |
484 * not overlap with any collapsed region of the attached viewer. | |
485 * | |
486 * @param lineRange the original line range | |
487 * @param line the anchor line | |
488 * @return the adapted line range | |
489 * @since 3.0 | |
490 */ | |
491 private ILineRange adaptLineRangeToFolding(ILineRange lineRange, int line) { | |
492 | |
138 | 493 if ( cast(ITextViewerExtension5)fSourceViewer ) { |
134 | 494 ITextViewerExtension5 extension= cast(ITextViewerExtension5) fSourceViewer; |
129 | 495 |
496 try { | |
497 IRegion region= convertToRegion(lineRange); | |
498 IRegion[] coverage= extension.getCoveredModelRanges(region); | |
499 if (coverage !is null && coverage.length > 0) { | |
500 IRegion container= findRegionContainingLine(coverage, line); | |
501 if (container !is null) | |
502 return convertToLineRange(container); | |
503 } | |
504 | |
505 } catch (BadLocationException x) { | |
506 } | |
507 | |
508 return null; | |
509 } | |
510 | |
511 return lineRange; | |
512 } | |
513 | |
514 /** | |
515 * Adapts a given line range so that the result is a line range that fits | |
516 * into the view port of the attached viewer. | |
517 * | |
518 * @param lineRange the original line range | |
519 * @return the adapted line range | |
520 * @since 3.0 | |
521 */ | |
522 private ILineRange adaptLineRangeToViewport(ILineRange lineRange) { | |
523 | |
524 try { | |
525 StyledText text= fSourceViewer.getTextWidget(); | |
526 | |
527 int topLine= text.getTopIndex(); | |
528 int rangeTopLine= getWidgetLineNumber(lineRange.getStartLine()); | |
529 int topDelta= Math.max(topLine - rangeTopLine, 0); | |
530 | |
531 Rectangle size= text.getClientArea(); | |
532 Rectangle trim= text.computeTrim(0, 0, 0, 0); | |
533 int height= size.height - trim.height; | |
145 | 534 |
129 | 535 int lines= JFaceTextUtil.getLineIndex(text, height) - text.getTopIndex(); |
145 | 536 |
129 | 537 int bottomLine= topLine + lines; |
145 | 538 |
129 | 539 int rangeBottomLine= getWidgetLineNumber(lineRange.getStartLine() + lineRange.getNumberOfLines() - 1); |
540 int bottomDelta= Math.max(rangeBottomLine - bottomLine, 0); | |
541 | |
542 return new LineRange(lineRange.getStartLine() + topDelta, lineRange.getNumberOfLines() - bottomDelta - topDelta); | |
543 | |
544 } catch (BadLocationException ex) { | |
545 } | |
546 | |
547 return null; | |
548 } | |
549 | |
550 /** | |
551 * Converts a line range into a character range. | |
552 * | |
553 * @param lineRange the line range | |
554 * @return the corresponding character range | |
555 * @throws BadLocationException in case the given line range is invalid | |
556 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
135
diff
changeset
|
557 private IRegion convertToRegion(ILineRange lineRange) { |
129 | 558 IDocument document= fSourceViewer.getDocument(); |
559 int startOffset= document.getLineOffset(lineRange.getStartLine()); | |
560 int endLine= lineRange.getStartLine() + Math.max(0, lineRange.getNumberOfLines() - 1); | |
561 IRegion lineInfo= document.getLineInformation(endLine); | |
562 int endOffset= lineInfo.getOffset() + lineInfo.getLength(); | |
563 return new Region(startOffset, endOffset - startOffset); | |
564 } | |
565 | |
566 /** | |
567 * Returns the region out of the given set that contains the given line or | |
568 * <code>null</code>. | |
569 * | |
570 * @param regions the set of regions | |
571 * @param line the line | |
572 * @return the region of the set that contains the line | |
573 * @throws BadLocationException in case line is invalid | |
574 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
135
diff
changeset
|
575 private IRegion findRegionContainingLine(IRegion[] regions, int line) { |
129 | 576 IDocument document= fSourceViewer.getDocument(); |
577 IRegion lineInfo= document.getLineInformation(line); | |
578 for (int i= 0; i < regions.length; i++) { | |
579 if (TextUtilities.overlaps(regions[i], lineInfo)) | |
580 return regions[i]; | |
581 } | |
582 return null; | |
583 } | |
584 | |
585 /** | |
586 * Converts a given character region into a line range. | |
587 * | |
588 * @param region the character region | |
589 * @return the corresponding line range | |
590 * @throws BadLocationException in case the given region in invalid | |
591 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
135
diff
changeset
|
592 private ILineRange convertToLineRange(IRegion region) { |
129 | 593 IDocument document= fSourceViewer.getDocument(); |
594 int startLine= document.getLineOfOffset(region.getOffset()); | |
595 int endLine= document.getLineOfOffset(region.getOffset() + region.getLength()); | |
596 return new LineRange(startLine, endLine - startLine + 1); | |
597 } | |
598 | |
599 /** | |
600 * Returns the visible area of the vertical ruler covered by the given line | |
601 * range. | |
602 * | |
603 * @param lineRange the line range | |
604 * @return the visible area | |
605 */ | |
606 private Rectangle computeArea(ILineRange lineRange) { | |
607 try { | |
608 StyledText text= fSourceViewer.getTextWidget(); | |
609 final int startLine= getWidgetLineNumber(lineRange.getStartLine()); | |
610 int y= JFaceTextUtil.computeLineHeight(text, 0, startLine, startLine) - text.getTopPixel(); | |
611 int height= JFaceTextUtil.computeLineHeight(text, startLine, startLine + lineRange.getNumberOfLines(), lineRange.getNumberOfLines()); | |
612 Point size= fVerticalRulerInfo.getControl().getSize(); | |
613 return new Rectangle(0, y, size.x, height); | |
614 } catch (BadLocationException x) { | |
615 } | |
616 return null; | |
617 } | |
618 | |
619 /** | |
620 * Returns the number of the currently visible lines. | |
621 * | |
622 * @return the number of the currently visible lines | |
623 * @deprecated to avoid deprecation warning | |
624 */ | |
625 private int computeNumberOfVisibleLines() { | |
626 // Hack to reduce amount of copied code. | |
627 return LineNumberRulerColumn.getVisibleLinesInViewport(fSourceViewer.getTextWidget()); | |
628 } | |
629 | |
630 /** | |
631 * Determines the hover to be used to display information based on the source of the | |
632 * mouse hover event. If <code>fVerticalRulerInfo</code> is not a composite ruler, the | |
633 * standard hover is returned. | |
634 * | |
635 * @param event the source of the mouse hover event | |
636 * @return the hover depending on <code>source</code>, or <code>fAnnotationHover</code> if none can be found. | |
637 * @since 3.0 | |
638 */ | |
639 private IAnnotationHover getHover(MouseEvent event) { | |
640 if (event is null || event.getSource() is null) | |
641 return fAnnotationHover; | |
642 | |
138 | 643 if ( cast(CompositeRuler)fVerticalRulerInfo ) { |
134 | 644 CompositeRuler comp= cast(CompositeRuler) fVerticalRulerInfo; |
129 | 645 for (Iterator it= comp.getDecoratorIterator(); it.hasNext();) { |
646 Object o= it.next(); | |
143 | 647 if ( cast(IVerticalRulerInfoExtension)o && cast(IVerticalRulerInfo)o ) { |
134 | 648 if ((cast(IVerticalRulerInfo) o).getControl() is event.getSource()) { |
649 IAnnotationHover hover= (cast(IVerticalRulerInfoExtension) o).getHover(); | |
129 | 650 if (hover !is null) |
651 return hover; | |
652 } | |
653 } | |
654 } | |
655 } | |
656 return fAnnotationHover; | |
657 } | |
658 | |
659 /** | |
660 * Returns the line of interest deduced from the mouse hover event. | |
661 * | |
662 * @param event a mouse hover event that triggered hovering | |
663 * @return the document model line number on which the hover event occurred or <code>-1</code> if there is no event | |
664 * @since 3.0 | |
665 */ | |
666 private int getHoverLine(MouseEvent event) { | |
667 return event is null ? -1 : fVerticalRulerInfo.toDocumentLineNumber(event.y); | |
668 } | |
669 | |
670 /** | |
671 * Returns for the widget line number for the given document line number. | |
672 * | |
673 * @param line the absolute line number | |
674 * @return the line number relative to the viewer's visible region | |
675 * @throws BadLocationException if <code>line</code> is not valid in the viewer's document | |
676 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
135
diff
changeset
|
677 private int getWidgetLineNumber(int line) { |
138 | 678 if ( cast(ITextViewerExtension5)fSourceViewer ) { |
134 | 679 ITextViewerExtension5 extension= cast(ITextViewerExtension5) fSourceViewer; |
129 | 680 return extension.modelLine2WidgetLine(line); |
681 } | |
682 | |
683 IRegion region= fSourceViewer.getVisibleRegion(); | |
684 int firstLine= fSourceViewer.getDocument().getLineOfOffset(region.getOffset()); | |
685 return line - firstLine; | |
686 } | |
687 | |
688 /** | |
689 * Determines graphical area covered by the given line. | |
690 * | |
691 * @param line the number of the line in the viewer whose graphical extend in the vertical ruler must be computed | |
692 * @return the graphical extend of the given line | |
693 */ | |
694 private Rectangle computeArea(int line) { | |
695 try { | |
696 StyledText text= fSourceViewer.getTextWidget(); | |
697 int widgetLine= getWidgetLineNumber(line); | |
698 int y= JFaceTextUtil.computeLineHeight(text, 0, widgetLine, widgetLine) - text.getTopPixel(); | |
699 Point size= fVerticalRulerInfo.getControl().getSize(); | |
700 return new Rectangle(0, y, size.x, text.getLineHeight(text.getOffsetAtLine(widgetLine))); | |
701 } catch (IllegalArgumentException ex) { | |
702 } catch (BadLocationException ex) { | |
703 } | |
704 return null; | |
705 } | |
706 | |
707 /** | |
708 * Returns the annotation hover for this hover manager. | |
709 * | |
710 * @return the annotation hover for this hover manager or <code>null</code> if none | |
711 * @since 2.1 | |
712 */ | |
713 protected IAnnotationHover getAnnotationHover() { | |
714 return fAnnotationHover; | |
715 } | |
716 | |
717 /** | |
718 * Returns the source viewer for this hover manager. | |
719 * | |
720 * @return the source viewer for this hover manager | |
721 * @since 2.1 | |
722 */ | |
723 protected ISourceViewer getSourceViewer() { | |
724 return fSourceViewer; | |
725 } | |
726 | |
727 /** | |
728 * Returns the vertical ruler info for this hover manager | |
729 * | |
730 * @return the vertical ruler info for this hover manager | |
731 * @since 2.1 | |
732 */ | |
733 protected IVerticalRulerInfo getVerticalRulerInfo() { | |
734 return fVerticalRulerInfo; | |
735 } | |
736 | |
737 /* | |
738 * @see dwtx.jface.text.AbstractInformationControlManager#computeSizeConstraints(dwt.widgets.Control, dwt.graphics.Rectangle, dwtx.jface.text.IInformationControl) | |
739 * @since 3.0 | |
740 */ | |
741 protected Point computeSizeConstraints(Control subjectControl, Rectangle subjectArea, IInformationControl informationControl) { | |
742 | |
743 Point constraints= super.computeSizeConstraints(subjectControl, subjectArea, informationControl); | |
744 | |
745 // make as big as text area, if possible | |
746 StyledText styledText= fSourceViewer.getTextWidget(); | |
747 if (styledText !is null) { | |
748 Rectangle r= styledText.getClientArea(); | |
749 if (r !is null) { | |
750 constraints.x= r.width; | |
751 constraints.y= r.height; | |
752 } | |
753 } | |
754 | |
755 return constraints; | |
756 } | |
757 | |
758 /* | |
759 * @see dwtx.jface.text.AbstractInformationControlManager#computeLocation(dwt.graphics.Rectangle, dwt.graphics.Point, dwtx.jface.text.AbstractInformationControlManager.Anchor) | |
760 * @since 3.0 | |
761 */ | |
762 protected Point computeLocation(Rectangle subjectArea, Point controlSize, Anchor anchor) { | |
763 MouseEvent event= getHoverEvent(); | |
764 IAnnotationHover hover= getHover(event); | |
765 | |
766 bool allowMouseExit= false; | |
138 | 767 if ( cast(IAnnotationHoverExtension)hover ) { |
134 | 768 IAnnotationHoverExtension extension= cast(IAnnotationHoverExtension) hover; |
129 | 769 allowMouseExit= extension.canHandleMouseCursor(); |
770 } | |
771 bool hideOnMouseWheel= true; | |
138 | 772 if ( cast(IAnnotationHoverExtension2)hover ) { |
134 | 773 IAnnotationHoverExtension2 extension= cast(IAnnotationHoverExtension2) hover; |
129 | 774 hideOnMouseWheel= !extension.canHandleMouseWheel(); |
775 } | |
776 fHideOnMouseWheel= hideOnMouseWheel; | |
777 | |
778 if (allowMouseExit) { | |
779 fAllowMouseExit= true; | |
780 | |
781 Control subjectControl= getSubjectControl(); | |
782 // return a location that just overlaps the annotation on the bar | |
783 if (anchor is AbstractInformationControlManager.ANCHOR_RIGHT) | |
784 return subjectControl.toDisplay(subjectArea.x - 4, subjectArea.y - 2); | |
785 else if (anchor is AbstractInformationControlManager.ANCHOR_LEFT) | |
786 return subjectControl.toDisplay(subjectArea.x + subjectArea.width - controlSize.x + 4, subjectArea.y - 2); | |
787 } | |
788 | |
789 fAllowMouseExit= false; | |
790 return super.computeLocation(subjectArea, controlSize, anchor); | |
791 } | |
792 | |
793 /** | |
794 * Returns the currently shown annotation hover or <code>null</code> if none | |
795 * hover is shown. | |
796 * | |
797 * @return the currently shown annotation hover or <code>null</code> | |
798 * @since 3.2 | |
799 */ | |
800 public IAnnotationHover getCurrentAnnotationHover() { | |
801 return fCurrentHover; | |
802 } | |
803 | |
804 /** | |
805 * Returns an adapter that gives access to internal methods. | |
806 * <p> | |
807 * <strong>Note:</strong> This method is not intended to be referenced or overridden by clients. | |
808 * </p> | |
145 | 809 * |
129 | 810 * @return the replaceable information control accessor |
811 * @since 3.4 | |
812 * @noreference This method is not intended to be referenced by clients. | |
813 * @nooverride This method is not intended to be re-implemented or extended by clients. | |
814 */ | |
815 public InternalAccessor getInternalAccessor() { | |
135 | 816 return new class() InternalAccessor { |
129 | 817 public IInformationControl getCurrentInformationControl() { |
145 | 818 return outer.superGetInternalAccessor().getCurrentInformationControl(); |
129 | 819 } |
145 | 820 |
129 | 821 public void setInformationControlReplacer(InformationControlReplacer replacer) { |
145 | 822 outer.superGetInternalAccessor().setInformationControlReplacer(replacer); |
129 | 823 } |
145 | 824 |
129 | 825 public InformationControlReplacer getInformationControlReplacer() { |
145 | 826 return outer.superGetInternalAccessor().getInformationControlReplacer(); |
129 | 827 } |
145 | 828 |
129 | 829 public bool canReplace(IInformationControl control) { |
145 | 830 return outer.superGetInternalAccessor().canReplace(control); |
129 | 831 } |
145 | 832 |
129 | 833 public bool isReplaceInProgress() { |
145 | 834 return outer.superGetInternalAccessor().isReplaceInProgress(); |
129 | 835 } |
145 | 836 |
129 | 837 public void replaceInformationControl(bool takeFocus) { |
145 | 838 outer.superGetInternalAccessor().replaceInformationControl(takeFocus); |
129 | 839 } |
840 | |
841 public void cropToClosestMonitor(Rectangle bounds) { | |
145 | 842 outer.superGetInternalAccessor().cropToClosestMonitor(bounds); |
129 | 843 } |
145 | 844 |
159 | 845 public void setHoverEnrichMode(ITextViewerExtension8_EnrichMode mode) { |
145 | 846 outer.superGetInternalAccessor().setHoverEnrichMode(mode); |
129 | 847 } |
145 | 848 |
129 | 849 public bool getAllowMouseExit() { |
850 return fAllowMouseExit; | |
851 } | |
852 }; | |
853 } | |
145 | 854 private InternalAccessor superGetInternalAccessor() { |
855 return super.getInternalAccessor(); | |
856 } | |
129 | 857 } |
858 |