From 8ed2952096222ada45027685c0d344e19f759666 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 31 Jan 2014 21:44:18 +0100 Subject: [PATCH 1/2] display info group box next to insertion cursor --- .../Project/Src/Refactoring/EditorScript.cs | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/EditorScript.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/EditorScript.cs index 1dc3731452..eeffac97b6 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/EditorScript.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/EditorScript.cs @@ -275,10 +275,10 @@ namespace CSharpBinding.Refactoring } } - class InsertionCursorLayer : UIElement, IDisposable + class InsertionCursorLayer : Canvas, IDisposable { - string operation; - InsertionPoint[] insertionPoints; + readonly string operation; + readonly InsertionPoint[] insertionPoints; readonly TextArea editor; public int CurrentInsertionPoint { get; set; } @@ -300,8 +300,8 @@ namespace CSharpBinding.Refactoring this.editor.ActiveInputHandler = new InputHandler(this); this.editor.TextView.InsertLayer(this, KnownLayer.Text, LayerInsertionPosition.Above); this.editor.TextView.ScrollOffsetChanged += TextViewScrollOffsetChanged; + AddGroupBox(); ScrollToInsertionPoint(); - AttachToCodeEditor(); } static readonly Pen markerPen = new Pen(Brushes.Blue, 1); @@ -312,6 +312,7 @@ namespace CSharpBinding.Refactoring var pos = editor.TextView.GetVisualPosition(new TextViewPosition(currentInsertionPoint.Location), VisualYPosition.LineMiddle); var endPos = new Point(pos.X + editor.TextView.ActualWidth * 0.6, pos.Y); drawingContext.DrawLine(markerPen, pos - editor.TextView.ScrollOffset, endPos - editor.TextView.ScrollOffset); + SetGroupBoxPosition(); // HACK } void TextViewScrollOffsetChanged(object sender, EventArgs e) @@ -395,7 +396,6 @@ namespace CSharpBinding.Refactoring public void Dispose() { - groupBox.Remove(); editor.TextView.Layers.Remove(this); editor.ActiveInputHandler = editor.DefaultInputHandler; editor.TextView.ScrollOffsetChanged -= TextViewScrollOffsetChanged; @@ -410,8 +410,17 @@ namespace CSharpBinding.Refactoring { var location = insertionPoints[CurrentInsertionPoint].Location; editor.GetService().ScrollTo(location.Line, location.Column); + SetGroupBoxPosition(); } + void SetGroupBoxPosition() + { + var location = insertionPoints[CurrentInsertionPoint].Location; + var boxPosition = editor.TextView.GetVisualPosition(new TextViewPosition(location), VisualYPosition.LineMiddle) - editor.TextView.ScrollOffset + new Vector(editor.TextView.ActualWidth * 0.6 - 5, -groupBox.ActualHeight / 2.0); + Canvas.SetTop(groupBox, boxPosition.Y); + Canvas.SetLeft(groupBox, boxPosition.X); + } + void Cancel(object sender, ExecutedRoutedEventArgs e) { FireExited(false); @@ -432,13 +441,10 @@ namespace CSharpBinding.Refactoring } } - IOverlayUIElement groupBox; + GroupBox groupBox; - void AttachToCodeEditor() + void AddGroupBox() { - if (editor.Document == null) - return; // editor was disposed - var content = new StackPanel { Children = { new TextBlock { @@ -449,9 +455,15 @@ namespace CSharpBinding.Refactoring } }; - groupBox = editor.GetService().CreateOverlayUIElement(content); + groupBox = new GroupBox { + Background = Brushes.White, + BorderBrush = Brushes.Blue, + BorderThickness = new Thickness(1), + Header = operation, + Content = content + }; - groupBox.Title = operation; + Children.Add(groupBox); } } From d482cd4a73b43bc09b37f3d664d4893d2ecf4124 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 31 Jan 2014 22:42:25 +0100 Subject: [PATCH 2/2] add mouse navigation mode to InsertWithCursor --- .../Project/Src/Refactoring/EditorScript.cs | 71 ++++++++++++++++--- 1 file changed, 60 insertions(+), 11 deletions(-) diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/EditorScript.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/EditorScript.cs index eeffac97b6..de424e202c 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/EditorScript.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/EditorScript.cs @@ -282,6 +282,7 @@ namespace CSharpBinding.Refactoring readonly TextArea editor; public int CurrentInsertionPoint { get; set; } + int insertionPointNextToMouse = -1; public event EventHandler Exited; @@ -305,14 +306,70 @@ namespace CSharpBinding.Refactoring } static readonly Pen markerPen = new Pen(Brushes.Blue, 1); + static readonly Pen tempMarkerPen = new Pen(Brushes.Gray, 1); protected override void OnRender(DrawingContext drawingContext) { - var currentInsertionPoint = insertionPoints[CurrentInsertionPoint]; + DrawLineForInserionPoint(CurrentInsertionPoint, markerPen, drawingContext); + if (insertionPointNextToMouse > -1 && insertionPointNextToMouse != CurrentInsertionPoint) + DrawLineForInserionPoint(insertionPointNextToMouse, tempMarkerPen, drawingContext); + + SetGroupBoxPosition(); // HACK + } + + void DrawLineForInserionPoint(int index, Pen pen, DrawingContext drawingContext) + { + var currentInsertionPoint = insertionPoints[index]; var pos = editor.TextView.GetVisualPosition(new TextViewPosition(currentInsertionPoint.Location), VisualYPosition.LineMiddle); var endPos = new Point(pos.X + editor.TextView.ActualWidth * 0.6, pos.Y); - drawingContext.DrawLine(markerPen, pos - editor.TextView.ScrollOffset, endPos - editor.TextView.ScrollOffset); - SetGroupBoxPosition(); // HACK + drawingContext.DrawLine(pen, pos - editor.TextView.ScrollOffset, endPos - editor.TextView.ScrollOffset); + } + + protected override HitTestResult HitTestCore(PointHitTestParameters hitTestParameters) + { + return new PointHitTestResult(this, hitTestParameters.HitPoint); + } + + protected override void OnMouseMove(MouseEventArgs e) + { + insertionPointNextToMouse = FindNextInsertionPoint(e.GetPosition(this)); + e.Handled = true; + InvalidateVisual(); + base.OnMouseMove(e); + } + + protected override void OnMouseDown(MouseButtonEventArgs e) + { + if (e.LeftButton == MouseButtonState.Pressed) { + if (e.ClickCount > 1) { + FireExited(true); + } else { + CurrentInsertionPoint = insertionPointNextToMouse; + InvalidateVisual(); + } + e.Handled = true; + } + base.OnMouseDown(e); + } + + int FindNextInsertionPoint(Point point) + { + var position = editor.TextView.GetPosition(point + editor.TextView.ScrollOffset); + if (position == null) return -1; + + int insertionPoint = CurrentInsertionPoint; + int mouseLocationLine = position.Value.Location.Line; + int currentLocationLine = insertionPoints[insertionPoint].Location.Line; + + for (int i = 0; i < insertionPoints.Length; i++) { + var line = insertionPoints[i].Location.Line; + var diff = Math.Abs(line - mouseLocationLine); + if (Math.Abs(currentLocationLine - mouseLocationLine) > diff && diff < 2) { + insertionPoint = i; + currentLocationLine = line; + } + } + return insertionPoint; } void TextViewScrollOffsetChanged(object sender, EventArgs e) @@ -425,14 +482,6 @@ namespace CSharpBinding.Refactoring { FireExited(false); } - - /// - /// call this somewhere useful, please... :) - /// - public void EndMode() - { - FireExited(false); - } void FireExited(bool success) {