Browse Source

display a focus highlight when moving the caret by JumpTo()

pull/15/head
Siegfried Pammer 15 years ago
parent
commit
e379983c8a
  1. 6
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.csproj
  2. 19
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs
  3. 35
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/FocusHighlight.xaml
  4. 26
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/FocusHighlight.xaml.cs
  5. 85
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/FocusHighlightAdorner.cs

6
src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.csproj

@ -94,6 +94,11 @@ @@ -94,6 +94,11 @@
<Compile Include="Src\CodeEditorView.cs" />
<Compile Include="Src\ContextActionsRenderer.cs" />
<Compile Include="Src\ExpressionHighlightRenderer.cs" />
<Compile Include="Src\FocusHighlight.xaml.cs">
<DependentUpon>FocusHighlight.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\FocusHighlightAdorner.cs" />
<Compile Include="Src\NewLineConsistencyCheck.cs" />
<Compile Include="Src\SharpDevelopTextEditor.cs" />
<Compile Include="Src\Commands\FoldingCommands.cs" />
@ -160,6 +165,7 @@ @@ -160,6 +165,7 @@
<EmbeddedResource Include="Resources\ReverseIncrementalSearchCursor.cur" />
</ItemGroup>
<ItemGroup>
<Page Include="Src\FocusHighlight.xaml" />
<Page Include="Src\SharpDevelopCompletionWindow.xaml">
<DependentUpon>SharpDevelopCompletionWindow.cs</DependentUpon>
</Page>

19
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs

@ -14,7 +14,7 @@ using System.Windows.Controls.Primitives; @@ -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; @@ -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 @@ -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

35
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/FocusHighlight.xaml

@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
<UserControl x:Class="ICSharpCode.AvalonEdit.AddIn.FocusHighlight"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid HorizontalAlignment="Left" VerticalAlignment="Top">
<Border
Name="el"
CornerRadius="2"
BorderThickness="1"
BorderBrush="Black">
<Border.Triggers>
<EventTrigger RoutedEvent="Border.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="el"
Storyboard.TargetProperty="Width"
From="2" To="12" Duration="0:0:0.4"
AutoReverse="True" RepeatBehavior="1x" />
<DoubleAnimation
Storyboard.TargetName="el"
Storyboard.TargetProperty="Height"
From="17" To="27" Duration="0:0:0.4"
AutoReverse="True" RepeatBehavior="1x" />
<DoubleAnimation
Storyboard.TargetName="el"
Storyboard.TargetProperty="Opacity"
From="1" To="0" Duration="0:0:0.2" BeginTime="0:0:0.6"
RepeatBehavior="1x" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Border.Triggers>
</Border>
</Grid>
</UserControl>

26
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/FocusHighlight.xaml.cs

@ -0,0 +1,26 @@ @@ -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
{
/// <summary>
/// Interaction logic for FocusHighlight.xaml
/// </summary>
public partial class FocusHighlight : UserControl
{
public FocusHighlight()
{
InitializeComponent();
}
}
}

85
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/FocusHighlightAdorner.cs

@ -0,0 +1,85 @@ @@ -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
{
/// <summary>
/// Description of FocusHighlightAdorner.
/// </summary>
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),
};
}
/// <summary>
/// Gets/sets the visual child.
/// </summary>
protected FocusHighlight Highlight {
get { return highlight; }
set {
RemoveVisualChild(highlight);
highlight = value;
AddVisualChild(highlight);
InvalidateMeasure();
}
}
/// <summary>
/// Gets the visual child.
/// </summary>
protected override Visual GetVisualChild(int index)
{
if (index == 0 && highlight != null)
return highlight;
else
throw new ArgumentOutOfRangeException("index");
}
/// <summary>
/// Gets the number of visual children.
/// </summary>
protected override int VisualChildrenCount {
get { return highlight != null ? 1 : 0; }
}
/// <summary>
/// Measure the visual child.
/// </summary>
protected override Size MeasureOverride(Size availableSize)
{
if (highlight != null) {
highlight.Measure(availableSize);
return availableSize;
} else {
return base.MeasureOverride(availableSize);
}
}
/// <summary>
/// Arrange the visual child.
/// </summary>
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);
}
}
}
}
Loading…
Cancel
Save