|
|
|
|
@ -3,6 +3,7 @@
@@ -3,6 +3,7 @@
|
|
|
|
|
|
|
|
|
|
using System; |
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
using System.Linq; |
|
|
|
|
using System.Text; |
|
|
|
|
using System.Text.RegularExpressions; |
|
|
|
|
using System.Windows; |
|
|
|
|
@ -30,13 +31,16 @@ namespace ICSharpCode.AvalonEdit.Search
@@ -30,13 +31,16 @@ namespace ICSharpCode.AvalonEdit.Search
|
|
|
|
|
SearchResult currentResult; |
|
|
|
|
FoldingManager foldingManager; |
|
|
|
|
|
|
|
|
|
public bool UseRegex { get { return useRegex.IsChecked == true; } } |
|
|
|
|
public bool MatchCase { get { return matchCase.IsChecked == true; } } |
|
|
|
|
public bool WholeWords { get { return wholeWords.IsChecked == true; } } |
|
|
|
|
bool UseRegex { get { return useRegex.IsChecked == true; } } |
|
|
|
|
bool MatchCase { get { return matchCase.IsChecked == true; } } |
|
|
|
|
bool WholeWords { get { return wholeWords.IsChecked == true; } } |
|
|
|
|
|
|
|
|
|
string searchPattern; |
|
|
|
|
ISearchStrategy strategy; |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets/sets the content of the search box and the search string.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string SearchPattern { |
|
|
|
|
get { return searchPattern; } |
|
|
|
|
set { |
|
|
|
|
@ -45,18 +49,16 @@ namespace ICSharpCode.AvalonEdit.Search
@@ -45,18 +49,16 @@ namespace ICSharpCode.AvalonEdit.Search
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void UpdateSearch(bool throwException = true) |
|
|
|
|
void UpdateSearch() |
|
|
|
|
{ |
|
|
|
|
if (!string.IsNullOrEmpty(searchPattern)) { |
|
|
|
|
try { |
|
|
|
|
strategy = SearchStrategyFactory.Create(searchPattern, !MatchCase, UseRegex, WholeWords); |
|
|
|
|
DoSearch(true); |
|
|
|
|
} catch (SearchPatternException) { |
|
|
|
|
if (throwException) throw; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
messageView.IsOpen = false; |
|
|
|
|
strategy = SearchStrategyFactory.Create(searchPattern ?? "", !MatchCase, UseRegex, WholeWords); |
|
|
|
|
DoSearch(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a new SearchPanel and attaches it to a text area.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public SearchPanel(TextArea textArea) |
|
|
|
|
{ |
|
|
|
|
if (textArea == null) |
|
|
|
|
@ -73,13 +75,25 @@ namespace ICSharpCode.AvalonEdit.Search
@@ -73,13 +75,25 @@ namespace ICSharpCode.AvalonEdit.Search
|
|
|
|
|
textArea.Document.TextChanged += delegate { DoSearch(false); }; |
|
|
|
|
this.Loaded += delegate { searchTextBox.Focus(); }; |
|
|
|
|
|
|
|
|
|
useRegex.Checked += delegate { UpdateSearch(false); }; |
|
|
|
|
matchCase.Checked += delegate { UpdateSearch(false); }; |
|
|
|
|
wholeWords.Checked += delegate { UpdateSearch(false); }; |
|
|
|
|
useRegex.Checked += ValidateSearchText; |
|
|
|
|
matchCase.Checked += ValidateSearchText; |
|
|
|
|
wholeWords.Checked += ValidateSearchText; |
|
|
|
|
|
|
|
|
|
useRegex.Unchecked += ValidateSearchText; |
|
|
|
|
matchCase.Unchecked += ValidateSearchText; |
|
|
|
|
wholeWords.Unchecked += ValidateSearchText; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
useRegex.Unchecked += delegate { UpdateSearch(false); }; |
|
|
|
|
matchCase.Unchecked += delegate { UpdateSearch(false); }; |
|
|
|
|
wholeWords.Unchecked += delegate { UpdateSearch(false); }; |
|
|
|
|
void ValidateSearchText(object sender, RoutedEventArgs e) |
|
|
|
|
{ |
|
|
|
|
var be = searchTextBox.GetBindingExpression(TextBox.TextProperty); |
|
|
|
|
try { |
|
|
|
|
Validation.ClearInvalid(be); |
|
|
|
|
UpdateSearch(); |
|
|
|
|
} catch (SearchPatternException ex) { |
|
|
|
|
var ve = new ValidationError(be.ParentBinding.ValidationRules[0], be, ex.Message, ex); |
|
|
|
|
Validation.MarkInvalid(be, ve); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
@ -91,6 +105,9 @@ namespace ICSharpCode.AvalonEdit.Search
@@ -91,6 +105,9 @@ namespace ICSharpCode.AvalonEdit.Search
|
|
|
|
|
searchTextBox.SelectAll(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Moves to the next occurrence in the file.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void FindNext() |
|
|
|
|
{ |
|
|
|
|
SearchResult result = null; |
|
|
|
|
@ -104,6 +121,9 @@ namespace ICSharpCode.AvalonEdit.Search
@@ -104,6 +121,9 @@ namespace ICSharpCode.AvalonEdit.Search
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Moves to the previous occurrence in the file.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void FindPrevious() |
|
|
|
|
{ |
|
|
|
|
SearchResult result = null; |
|
|
|
|
@ -155,17 +175,21 @@ namespace ICSharpCode.AvalonEdit.Search
@@ -155,17 +175,21 @@ namespace ICSharpCode.AvalonEdit.Search
|
|
|
|
|
{ |
|
|
|
|
switch (e.Key) { |
|
|
|
|
case Key.Enter: |
|
|
|
|
try { |
|
|
|
|
messageView.IsOpen = false; |
|
|
|
|
messageView.Content = null; |
|
|
|
|
UpdateSearch(); |
|
|
|
|
} catch (SearchPatternException ex) { |
|
|
|
|
messageView.Content = "Error: " + ex.Message; |
|
|
|
|
e.Handled = true; |
|
|
|
|
messageView.IsOpen = false; |
|
|
|
|
if ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift) |
|
|
|
|
FindPrevious(); |
|
|
|
|
else |
|
|
|
|
FindNext(); |
|
|
|
|
var error = Validation.GetErrors(searchTextBox).FirstOrDefault(); |
|
|
|
|
if (error != null) { |
|
|
|
|
messageView.Content = "Error: " + error.ErrorContent; |
|
|
|
|
messageView.PlacementTarget = searchTextBox; |
|
|
|
|
messageView.IsOpen = true; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case Key.Escape: |
|
|
|
|
e.Handled = true; |
|
|
|
|
CloseClick(sender, e); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|