8 changed files with 162 additions and 135 deletions
@ -1,58 +0,0 @@
@@ -1,58 +0,0 @@
|
||||
// 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) |
||||
{ |
||||
if (searchPattern == null) |
||||
throw new ArgumentNullException("searchPattern"); |
||||
RegexOptions options = RegexOptions.Compiled; |
||||
if (ignoreCase) |
||||
options |= RegexOptions.IgnoreCase; |
||||
if (!useRegularExpressions) |
||||
searchPattern = Regex.Escape(searchPattern); |
||||
if (matchWholeWords) |
||||
searchPattern = "\\b" + searchPattern + "\\b"; |
||||
try { |
||||
Regex pattern = new Regex(searchPattern, options); |
||||
return new DefaultSearchStrategy(pattern); |
||||
} catch (ArgumentException ex) { |
||||
throw new SearchPatternException(ex.Message, ex); |
||||
} |
||||
} |
||||
|
||||
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,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.Collections.Generic; |
||||
using System.Text.RegularExpressions; |
||||
|
||||
using ICSharpCode.AvalonEdit.Document; |
||||
|
||||
namespace ICSharpCode.AvalonEdit.Search |
||||
{ |
||||
class RegexSearchStrategy : ISearchStrategy |
||||
{ |
||||
readonly Regex searchPattern; |
||||
|
||||
public RegexSearchStrategy(Regex searchPattern) |
||||
{ |
||||
this.searchPattern = searchPattern; |
||||
} |
||||
|
||||
public IEnumerable<ISearchResult> FindAll(ITextSource document) |
||||
{ |
||||
foreach (Match result in searchPattern.Matches(document.Text)) { |
||||
yield return new SearchResult { StartOffset = result.Index, Length = result.Length }; |
||||
} |
||||
} |
||||
} |
||||
|
||||
class SearchResult : TextSegment, ISearchResult |
||||
{ |
||||
} |
||||
} |
@ -1,44 +1,41 @@
@@ -1,44 +1,41 @@
|
||||
<?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" 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="White" BorderBrush="DimGray" BorderThickness="1" HorizontalAlignment="Right" VerticalAlignment="Top" Cursor="Arrow"> |
||||
<Grid> |
||||
<Grid.RowDefinitions> |
||||
<RowDefinition Height="Auto" /> |
||||
<RowDefinition Height="Auto" /> |
||||
</Grid.RowDefinitions> |
||||
<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> |
||||
</StackPanel> |
||||
<TextBlock Name="messageView" Grid.Row="1" Margin="3" Visibility="Collapsed" TextWrapping="Wrap" /> |
||||
</Grid> |
||||
<StackPanel Orientation="Horizontal"> |
||||
<TextBox x:FieldModifier="private" Name="searchTextBox" Focusable="True" Width="100" Height="24" Margin="3,3,3,0" PreviewKeyDown="SearchLayerKeyDown" AcceptsTab="True"> |
||||
<TextBox.Text> |
||||
<Binding Path="SearchPattern" UpdateSourceTrigger="PropertyChanged"> |
||||
<Binding.ValidationRules> |
||||
<ExceptionValidationRule /> |
||||
</Binding.ValidationRules> |
||||
</Binding> |
||||
</TextBox.Text> |
||||
</TextBox> |
||||
<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 (Shift+F3)"> |
||||
<Image Width="16" Height="16" Stretch="Fill" Source="prev.png" /> |
||||
</Button> |
||||
<Button Margin="3" Height="24" Width="24" Command="local:SearchCommands.FindNext" ToolTip="Find Next (F3)"> |
||||
<Image Width="16" Height="16" Stretch="Fill" Source="next.png" /> |
||||
</Button> |
||||
<Button Click="CloseClick" HorizontalAlignment="Right" VerticalAlignment="Top" Height="16" Width="16"> |
||||
<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> |
||||
</StackPanel> |
||||
</Border> |
||||
</UserControl> |
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
// 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.Text.RegularExpressions; |
||||
|
||||
namespace ICSharpCode.AvalonEdit.Search |
||||
{ |
||||
public class SearchStrategyFactory |
||||
{ |
||||
public static ISearchStrategy Create(string searchPattern, bool ignoreCase, bool useRegularExpressions, bool matchWholeWords) |
||||
{ |
||||
if (searchPattern == null) |
||||
throw new ArgumentNullException("searchPattern"); |
||||
RegexOptions options = RegexOptions.Compiled | RegexOptions.Multiline; |
||||
if (ignoreCase) |
||||
options |= RegexOptions.IgnoreCase; |
||||
if (!useRegularExpressions) |
||||
searchPattern = Regex.Escape(searchPattern); |
||||
if (matchWholeWords) |
||||
searchPattern = "\\b" + searchPattern + "\\b"; |
||||
try { |
||||
Regex pattern = new Regex(searchPattern, options); |
||||
return new RegexSearchStrategy(pattern); |
||||
} catch (ArgumentException ex) { |
||||
throw new SearchPatternException(ex.Message, ex); |
||||
} |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue