diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.csproj b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.csproj index 93fa348b5f..2cfdad60d5 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.csproj +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.csproj @@ -94,6 +94,11 @@ + + FocusHighlight.xaml + Code + + @@ -160,6 +165,7 @@ + SharpDevelopCompletionWindow.cs diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs index 6c38f49666..331ee27a25 100755 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs @@ -14,7 +14,7 @@ using System.Windows.Controls.Primitives; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; - +using System.Windows.Threading; using ICSharpCode.AvalonEdit.AddIn.Options; using ICSharpCode.AvalonEdit.AddIn.Snippets; using ICSharpCode.AvalonEdit.Editing; @@ -26,6 +26,7 @@ using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Editor.AvalonEdit; using ICSharpCode.SharpDevelop.Editor.Commands; +using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Refactoring; using Ast = ICSharpCode.NRefactory.Ast; @@ -449,6 +450,22 @@ namespace ICSharpCode.AvalonEdit.AddIn // the adapter sets the caret position and takes care of scrolling this.Adapter.JumpTo(line, column); this.Focus(); + + Dispatcher.Invoke(DispatcherPriority.Background, (Action)DisplayFocusHighlight); + } + + void DisplayFocusHighlight() + { + TextArea textArea = Adapter.GetService(typeof(TextArea)) as TextArea; + + if (textArea == null) + return; + + AdornerLayer layer = AdornerLayer.GetAdornerLayer(textArea.TextView); + FocusHighlightAdorner adorner = new FocusHighlightAdorner(textArea.TextView, textArea.Caret.CalculateCaretRectangle().Location - textArea.TextView.ScrollOffset - new Vector(3, 6.75)); + layer.Add(adorner); + + WorkbenchSingleton.CallLater(TimeSpan.FromSeconds(1), (Action)(() => layer.Remove(adorner))); } #region UpdateParseInformation - Folding diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/FocusHighlight.xaml b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/FocusHighlight.xaml new file mode 100644 index 0000000000..7c684608e0 --- /dev/null +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/FocusHighlight.xaml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/FocusHighlight.xaml.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/FocusHighlight.xaml.cs new file mode 100644 index 0000000000..72ddc8e2cd --- /dev/null +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/FocusHighlight.xaml.cs @@ -0,0 +1,26 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; + +namespace ICSharpCode.AvalonEdit.AddIn +{ + /// + /// Interaction logic for FocusHighlight.xaml + /// + public partial class FocusHighlight : UserControl + { + public FocusHighlight() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/FocusHighlightAdorner.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/FocusHighlightAdorner.cs new file mode 100644 index 0000000000..b84a85efd9 --- /dev/null +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/FocusHighlightAdorner.cs @@ -0,0 +1,85 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Windows; +using System.Windows.Documents; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Threading; + +namespace ICSharpCode.AvalonEdit.AddIn +{ + /// + /// Description of FocusHighlightAdorner. + /// + public class FocusHighlightAdorner : Adorner + { + FocusHighlight highlight; + + public FocusHighlightAdorner(UIElement adornedElement, Point origin) + : base(adornedElement) + { + this.Highlight = new FocusHighlight() { + RenderTransform = new TranslateTransform(origin.X, origin.Y), + }; + } + + /// + /// Gets/sets the visual child. + /// + protected FocusHighlight Highlight { + get { return highlight; } + set { + RemoveVisualChild(highlight); + highlight = value; + AddVisualChild(highlight); + InvalidateMeasure(); + } + } + + /// + /// Gets the visual child. + /// + protected override Visual GetVisualChild(int index) + { + if (index == 0 && highlight != null) + return highlight; + else + throw new ArgumentOutOfRangeException("index"); + } + + /// + /// Gets the number of visual children. + /// + protected override int VisualChildrenCount { + get { return highlight != null ? 1 : 0; } + } + + /// + /// Measure the visual child. + /// + protected override Size MeasureOverride(Size availableSize) + { + if (highlight != null) { + highlight.Measure(availableSize); + return availableSize; + } else { + return base.MeasureOverride(availableSize); + } + } + + /// + /// Arrange the visual child. + /// + protected override Size ArrangeOverride(Size finalSize) + { + if (highlight != null) { + highlight.Arrange(new Rect(new Point(0, 0), finalSize)); + return finalSize; + } else { + return base.ArrangeOverride(finalSize); + } + } + } +}