13 changed files with 379 additions and 68 deletions
@ -0,0 +1,52 @@
@@ -0,0 +1,52 @@
|
||||
// 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.Text.RegularExpressions; |
||||
using System.Windows; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Controls.Primitives; |
||||
using System.Windows.Data; |
||||
using System.Windows.Documents; |
||||
using System.Windows.Input; |
||||
using System.Windows.Media; |
||||
using System.Windows.Threading; |
||||
using ICSharpCode.AvalonEdit.Document; |
||||
using ICSharpCode.AvalonEdit.Editing; |
||||
using ICSharpCode.AvalonEdit.Folding; |
||||
using ICSharpCode.AvalonEdit.Rendering; |
||||
|
||||
namespace ICSharpCode.AvalonEdit.Search |
||||
{ |
||||
class DefaultSearchStrategy : ISearchStrategy |
||||
{ |
||||
readonly Regex searchPattern; |
||||
|
||||
public DefaultSearchStrategy(Regex searchPattern) |
||||
{ |
||||
this.searchPattern = searchPattern; |
||||
} |
||||
|
||||
public static ISearchStrategy Create(string searchPattern, bool ignoreCase, bool useRegularExpressions, bool matchWholeWords) |
||||
{ |
||||
RegexOptions options = RegexOptions.Compiled; |
||||
if (ignoreCase) |
||||
options |= RegexOptions.IgnoreCase; |
||||
if (!useRegularExpressions) |
||||
searchPattern = Regex.Escape(searchPattern); |
||||
if (matchWholeWords) |
||||
searchPattern = "\\b" + searchPattern + "\\b"; |
||||
Regex pattern = new Regex(searchPattern, options); |
||||
return new DefaultSearchStrategy(pattern); |
||||
} |
||||
|
||||
public IEnumerable<ISearchResult> FindAll(ITextSource document) |
||||
{ |
||||
foreach (Match result in searchPattern.Matches(document.Text)) { |
||||
yield return new SearchResult { StartOffset = result.Index, Length = result.Length }; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,60 @@
@@ -0,0 +1,60 @@
|
||||
// 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.Controls; |
||||
using System.Windows.Controls.Primitives; |
||||
using System.Windows.Input; |
||||
|
||||
namespace ICSharpCode.AvalonEdit.Search |
||||
{ |
||||
/// <summary>
|
||||
/// A button that opens a drop-down menu when clicked.
|
||||
/// </summary>
|
||||
class DropDownButton : ButtonBase |
||||
{ |
||||
public static readonly DependencyProperty DropDownContentProperty |
||||
= DependencyProperty.Register("DropDownContent", typeof(Popup), |
||||
typeof(DropDownButton), new FrameworkPropertyMetadata(null)); |
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")] |
||||
protected static readonly DependencyPropertyKey IsDropDownContentOpenPropertyKey |
||||
= DependencyProperty.RegisterReadOnly("IsDropDownContentOpen", typeof(bool), |
||||
typeof(DropDownButton), new FrameworkPropertyMetadata(false)); |
||||
|
||||
public static readonly DependencyProperty IsDropDownContentOpenProperty = IsDropDownContentOpenPropertyKey.DependencyProperty; |
||||
|
||||
static DropDownButton() |
||||
{ |
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(DropDownButton), new FrameworkPropertyMetadata(typeof(DropDownButton))); |
||||
} |
||||
|
||||
public Popup DropDownContent { |
||||
get { return (Popup)GetValue(DropDownContentProperty); } |
||||
set { SetValue(DropDownContentProperty, value); } |
||||
} |
||||
|
||||
public bool IsDropDownContentOpen { |
||||
get { return (bool)GetValue(IsDropDownContentOpenProperty); } |
||||
protected set { SetValue(IsDropDownContentOpenPropertyKey, value); } |
||||
} |
||||
|
||||
protected override void OnClick() |
||||
{ |
||||
if (DropDownContent != null && !IsDropDownContentOpen) { |
||||
DropDownContent.Placement = PlacementMode.Bottom; |
||||
DropDownContent.PlacementTarget = this; |
||||
DropDownContent.IsOpen = true; |
||||
DropDownContent.Closed += DropDownContent_Closed; |
||||
this.IsDropDownContentOpen = true; |
||||
} |
||||
} |
||||
|
||||
void DropDownContent_Closed(object sender, EventArgs e) |
||||
{ |
||||
((Popup)sender).Closed -= DropDownContent_Closed; |
||||
this.IsDropDownContentOpen = false; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,71 @@
@@ -0,0 +1,71 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
xmlns:local="clr-namespace:ICSharpCode.AvalonEdit.Search" |
||||
> |
||||
<!-- Colors for DropDownButton and SplitButton --> |
||||
<SolidColorBrush x:Key="{ComponentResourceKey {x:Type local:DropDownButton}, ActiveBorder}" Color="#FF0A246A"/> |
||||
<SolidColorBrush x:Key="{ComponentResourceKey {x:Type local:DropDownButton}, ActiveBackground}" Color="#FFB6BDD2"/> |
||||
|
||||
<!-- Style and Template for DropDownButton --> |
||||
<Style TargetType="{x:Type local:DropDownButton}"> |
||||
<Setter Property="TextElement.Foreground" Value = "{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" /> |
||||
<Setter Property="Control.Padding" Value="2,2,2,2"/> |
||||
<Setter Property="Border.BorderThickness" Value="1,1,1,1"/> |
||||
<Setter Property="Panel.Background" Value="Transparent"/> |
||||
<Setter Property="Border.BorderBrush" Value="Transparent"/> |
||||
<Setter Property="FrameworkElement.HorizontalAlignment" Value="Center"/> |
||||
<Setter Property="FrameworkElement.VerticalAlignment" Value="Center"/> |
||||
<Setter Property="Control.HorizontalContentAlignment" Value="Center"/> |
||||
<Setter Property="Control.VerticalContentAlignment" Value="Center"/> |
||||
<Setter Property="Template"> |
||||
<Setter.Value> |
||||
<ControlTemplate TargetType="local:DropDownButton" |
||||
xmlns:s="clr-namespace:System;assembly=mscorlib"> |
||||
<Border |
||||
BorderThickness="{TemplateBinding Border.BorderThickness}" |
||||
BorderBrush="{TemplateBinding Border.BorderBrush}" |
||||
Background="{TemplateBinding Panel.Background}" |
||||
Name="OuterBorder" |
||||
SnapsToDevicePixels="True" |
||||
> |
||||
<StackPanel Orientation="Horizontal"> |
||||
<ContentPresenter |
||||
Margin="{TemplateBinding Control.Padding}" |
||||
Content="{TemplateBinding ContentControl.Content}" |
||||
ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" |
||||
ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}" |
||||
HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}" |
||||
VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}" |
||||
SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" /> |
||||
<Path Margin="0,2,2,2" |
||||
Data = "M0,0 L1,0 0.5,1 z" |
||||
Fill = "{TemplateBinding TextElement.Foreground}" |
||||
Width = "7" |
||||
Height = "3.5" |
||||
Stretch = "Fill"/> |
||||
</StackPanel> |
||||
</Border> |
||||
<ControlTemplate.Triggers> |
||||
<Trigger Property="UIElement.IsMouseOver" Value="True"> |
||||
<Setter Property="Border.BorderBrush" TargetName="OuterBorder" Value="{DynamicResource {ComponentResourceKey {x:Type local:DropDownButton}, ActiveBorder}}" /> |
||||
<Setter Property="Panel.Background" TargetName="OuterBorder" Value="{DynamicResource {ComponentResourceKey {x:Type local:DropDownButton}, ActiveBackground}}"/> |
||||
</Trigger> |
||||
<Trigger Property="UIElement.IsKeyboardFocused" Value="True"> |
||||
<Setter Property="Border.BorderBrush" TargetName="OuterBorder" Value="{DynamicResource {ComponentResourceKey {x:Type local:DropDownButton}, ActiveBorder}}"/> |
||||
<Setter Property="Panel.Background" TargetName="OuterBorder" Value="{DynamicResource {ComponentResourceKey {x:Type local:DropDownButton}, ActiveBackground}}"/> |
||||
</Trigger> |
||||
<Trigger Property="UIElement.IsEnabled" Value="False"> |
||||
<Setter Property="TextElement.Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> |
||||
</Trigger> |
||||
<Trigger Property="local:DropDownButton.IsDropDownContentOpen" Value="True"> |
||||
<Setter Property="Border.BorderBrush" TargetName="OuterBorder" Value="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" /> |
||||
<Setter Property="Border.BorderThickness" TargetName="OuterBorder" Value="1,1,1,0" /> |
||||
<Setter Property="Border.Padding" TargetName="OuterBorder" Value="0,0,0,1" /> |
||||
<Setter Property="Panel.Background" TargetName="OuterBorder" Value="Transparent"/> |
||||
</Trigger> |
||||
</ControlTemplate.Triggers> |
||||
</ControlTemplate> |
||||
</Setter.Value> |
||||
</Setter> |
||||
</Style> |
||||
</ResourceDictionary> |
||||
@ -0,0 +1,22 @@
@@ -0,0 +1,22 @@
|
||||
// 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 ICSharpCode.AvalonEdit.Document; |
||||
|
||||
namespace ICSharpCode.AvalonEdit.Search |
||||
{ |
||||
/// <summary>
|
||||
/// Description of ISearchStrategy.
|
||||
/// </summary>
|
||||
public interface ISearchStrategy |
||||
{ |
||||
IEnumerable<ISearchResult> FindAll(ITextSource document); |
||||
} |
||||
|
||||
public interface ISearchResult : ISegment |
||||
{ |
||||
|
||||
} |
||||
} |
||||
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
// 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.Linq; |
||||
using System.Windows; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Input; |
||||
using System.Windows.Media; |
||||
|
||||
using ICSharpCode.AvalonEdit.Document; |
||||
using ICSharpCode.AvalonEdit.Editing; |
||||
using ICSharpCode.AvalonEdit.Rendering; |
||||
|
||||
namespace ICSharpCode.AvalonEdit.Search |
||||
{ |
||||
public static class SearchCommands |
||||
{ |
||||
public static readonly RoutedCommand FindNext = new RoutedCommand( |
||||
"FindNext", typeof(SearchPanel), |
||||
new InputGestureCollection { new KeyGesture(Key.F3) } |
||||
); |
||||
public static readonly RoutedCommand FindPrevious = new RoutedCommand( |
||||
"FindPrevious", typeof(SearchPanel), |
||||
new InputGestureCollection { new KeyGesture(Key.F3, ModifierKeys.Control) } |
||||
); |
||||
} |
||||
|
||||
class SearchResult : TextSegment, ISearchResult |
||||
{ |
||||
} |
||||
} |
||||
@ -1,24 +1,37 @@
@@ -1,24 +1,37 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<UserControl x:Class="ICSharpCode.AvalonEdit.Search.SearchPanel" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> |
||||
<UserControl x:Class="ICSharpCode.AvalonEdit.Search.SearchPanel" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:ICSharpCode.AvalonEdit.Search" FocusManager.IsFocusScope="True" PreviewKeyDown="SearchLayerKeyDown"> |
||||
<UserControl.Resources> |
||||
<BitmapImage x:Key="PrevImage" UriSource="prev.png" /> |
||||
<BitmapImage x:Key="NextImage" UriSource="next.png" /> |
||||
</UserControl.Resources> |
||||
<Border Background="WhiteSmoke" HorizontalAlignment="Right" VerticalAlignment="Top" Cursor="Arrow"> |
||||
<Border Background="White" BorderBrush="DimGray" BorderThickness="1" HorizontalAlignment="Right" VerticalAlignment="Top" Cursor="Arrow"> |
||||
<StackPanel Orientation="Horizontal" Margin="3"> |
||||
<TextBox Name="searchTextBox" Focusable="True" Width="100" Height="24" Margin="3,3,3,0" TextChanged="SearchTextBoxTextChanged" PreviewKeyDown="SearchLayerKeyDown" /> |
||||
<local:DropDownButton Height="24"> |
||||
<local:DropDownButton.DropDownContent> |
||||
<Popup StaysOpen="False"> |
||||
<Border Background="White" BorderBrush="DimGray" BorderThickness="1"> |
||||
<StackPanel Orientation="Vertical"> |
||||
<CheckBox x:FieldModifier="private" x:Name="matchCase" Content="Match case" Margin="3" /> |
||||
<CheckBox x:FieldModifier="private" x:Name="wholeWords" Content="Match whole words" Margin="3" /> |
||||
<CheckBox x:FieldModifier="private" x:Name="useRegex" Content="Use Regular Expressions" Margin="3" /> |
||||
</StackPanel> |
||||
</Border> |
||||
</Popup> |
||||
</local:DropDownButton.DropDownContent> |
||||
</local:DropDownButton> |
||||
<Button Margin="3" Height="24" Width="24" Command="local:SearchCommands.FindPrevious" ToolTip="Find Next (Ctrl+F3)"> |
||||
<Image Width="16" Height="16" Stretch="Fill" Source="{StaticResource PrevImage}" /> |
||||
</Button> |
||||
<Button Margin="3" Height="24" Width="24" Command="local:SearchCommands.FindNext" ToolTip="Find Next (F3)"> |
||||
<Image Width="16" Height="16" Stretch="Fill" Source="{StaticResource NextImage}" /> |
||||
</Button> |
||||
<Button Click="CloseClick" Margin="3" Height="16" Width="16" VerticalContentAlignment="Top" HorizontalContentAlignment="Left"> |
||||
<Grid> |
||||
<Line X1="2" Y1="2" X2="8" Y2="8" Stroke="Black" StrokeThickness="1" /> |
||||
<Line X1="8" Y1="2" X2="2" Y2="8" Stroke="Black" StrokeThickness="1" /> |
||||
</Grid> |
||||
</Button> |
||||
<TextBox Name="searchTextBox" Width="100" Height="24" Margin="3" TextChanged="SearchTextBoxTextChanged" /> |
||||
<Button Margin="3" Height="24" Width="24" Click="PrevClick"> |
||||
<Image Width="16" Height="16" Stretch="Fill" Source="{StaticResource PrevImage}" /> |
||||
</Button> |
||||
<Button Margin="3" Height="24" Width="24" Click="NextClick"> |
||||
<Image Width="16" Height="16" Stretch="Fill" Source="{StaticResource NextImage}" /> |
||||
</Button> |
||||
</StackPanel> |
||||
</Border> |
||||
</UserControl> |
||||
Loading…
Reference in new issue