Skip to content
Browse files

implemented improvements suggested by Adam (BlueNinja) - http://commu…

  • Loading branch information...
1 parent d9a90d7 commit 5c9b0b7ec5aae7da141fbb4b4f6d396d991f0402 @siegfriedpammer siegfriedpammer committed Feb 3, 2011
Showing with 35 additions and 8 deletions.
  1. +35 −8 src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin.cs
View
43 src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin.cs
@@ -10,7 +10,7 @@
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media;
-
+using System.Windows.Threading;
using ICSharpCode.AvalonEdit.AddIn.Options;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Editing;
@@ -33,6 +33,10 @@ public class ChangeMarkerMargin : AbstractMargin, IDisposable
public ChangeMarkerMargin(IChangeWatcher changeWatcher)
{
this.changeWatcher = changeWatcher;
+ this.delayTimer = new DispatcherTimer() {
+ Interval = TimeSpan.FromMilliseconds(displayDelayMs)
+ };
+ delayTimer.Tick += delegate { DisplayTooltip(); };
changeWatcher.ChangeOccurred += ChangeOccurred;
}
@@ -82,13 +86,22 @@ protected override void OnTextViewChanged(TextView oldTextView, TextView newText
if (oldTextView != null) {
oldTextView.VisualLinesChanged -= VisualLinesChanged;
oldTextView.ScrollOffsetChanged -= ScrollOffsetChanged;
+ ((TextArea)oldTextView.Services.GetService(typeof(TextArea))).KeyDown -= TextViewKeyDown;
}
base.OnTextViewChanged(oldTextView, newTextView);
if (newTextView != null) {
newTextView.VisualLinesChanged += VisualLinesChanged;
newTextView.ScrollOffsetChanged += ScrollOffsetChanged;
+ ((TextArea)newTextView.Services.GetService(typeof(TextArea))).KeyDown += TextViewKeyDown;
}
}
+
+ void TextViewKeyDown(object sender, KeyEventArgs e)
+ {
+ // close tooltip on pressing Esc
+ if (e.Key == Key.Escape)
+ tooltip.IsOpen = false;
+ }
void ChangeOccurred(object sender, EventArgs e)
{
@@ -115,10 +128,26 @@ protected override Size MeasureOverride(Size availableSize)
Popup tooltip = new Popup() { StaysOpen = false };
ITextMarker marker;
ITextMarkerService markerService;
+ DispatcherTimer delayTimer;
- protected override void OnMouseMove(MouseEventArgs e)
+
+ /// <summary>
+ /// Time the mouse has to hover over the change margin before it displays the diff tooltip.
+ /// </summary>
+ const int displayDelayMs = 1000;
+
+ protected override void OnMouseEnter(MouseEventArgs e)
{
- int line = GetLineFromMousePosition(e);
+ delayTimer.Start();
+
+ base.OnMouseEnter(e);
+ }
+
+ void DisplayTooltip()
+ {
+ delayTimer.Stop();
+
+ int line = GetLineFromMousePosition();
if (line == 0)
return;
@@ -206,30 +235,28 @@ protected override void OnMouseMove(MouseEventArgs e)
tooltip.Closed += delegate {
if (marker != null) markerService.Remove(marker);
};
-
tooltip.HorizontalOffset = -10;
tooltip.VerticalOffset =
TextView.GetVisualTopByDocumentLine(startLine) - TextView.ScrollOffset.Y;
tooltip.Placement = PlacementMode.Top;
tooltip.PlacementTarget = this.TextView;
}
-
- base.OnMouseMove(e);
}
protected override void OnMouseLeave(MouseEventArgs e)
{
+ delayTimer.Stop();
if (marker != null && !tooltip.IsOpen)
markerService.Remove(marker);
base.OnMouseLeave(e);
}
- int GetLineFromMousePosition(MouseEventArgs e)
+ int GetLineFromMousePosition()
{
TextView textView = this.TextView;
if (textView == null)
return 0;
- VisualLine vl = textView.GetVisualLineFromVisualTop(e.GetPosition(textView).Y + textView.ScrollOffset.Y);
+ VisualLine vl = textView.GetVisualLineFromVisualTop(Mouse.GetPosition(textView).Y + textView.ScrollOffset.Y);
if (vl == null)
return 0;
return vl.FirstDocumentLine.LineNumber;

0 comments on commit 5c9b0b7

Please sign in to comment.
Something went wrong with that request. Please try again.