Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 63 additions & 3 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,63 @@
*.cs text diff=csharp
*.sln text eol=crlf
*.csproj text eol=crlf
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp

###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary

###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary

###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
2 changes: 2 additions & 0 deletions ICSharpCode.AvalonEdit.Sample/Window1.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public Window1()
foldingUpdateTimer.Interval = TimeSpan.FromSeconds(2);
foldingUpdateTimer.Tick += delegate { UpdateFoldings(); };
foldingUpdateTimer.Start();

Search.SearchPanel.Install(textEditor);
}

string currentFileName;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFrameworks>net6.0-windows;netcoreapp3.1;net462</TargetFrameworks>
<TargetFrameworks>net6.0-windows;netcoreapp3.1;net472</TargetFrameworks>
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
<DefineConstants>TRACE</DefineConstants>
Expand Down
1 change: 1 addition & 0 deletions ICSharpCode.AvalonEdit/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/ICSharpCode.AvalonEdit.xml
8 changes: 7 additions & 1 deletion ICSharpCode.AvalonEdit/ICSharpCode.AvalonEdit.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFrameworks>net6.0-windows;netcoreapp3.1;net462</TargetFrameworks>
<TargetFrameworks>net6.0-windows;netcoreapp3.1;net472</TargetFrameworks>
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
<DefineConstants>TRACE</DefineConstants>
Expand Down Expand Up @@ -66,4 +66,10 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Resource Include="Search\replacenext.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Search\replaceall.png" />
</ItemGroup>
</Project>
14 changes: 14 additions & 0 deletions ICSharpCode.AvalonEdit/Search/Localization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ public virtual string FindPreviousText {
get { return "Find previous (Shift+F3)"; }
}

/// <summary>
/// Default: 'Replace next (ALT+R)'
/// </summary>
public virtual string ReplaceNextText {
get { return "Replace next (ALT+R)"; }
}

/// <summary>
/// Default: 'Replace all (ALT+A)'
/// </summary>
public virtual string ReplaceAllText {
get { return "Replace all (ALT+A)"; }
}

/// <summary>
/// Default: 'Error: '
/// </summary>
Expand Down
65 changes: 64 additions & 1 deletion ICSharpCode.AvalonEdit/Search/SearchCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ namespace ICSharpCode.AvalonEdit.Search
/// </summary>
public static class SearchCommands
{
/// <summary>
/// Opens the Find panel
/// </summary>
public static readonly RoutedCommand Find = new RoutedCommand(
"Find", typeof(SearchPanel),
new InputGestureCollection { new KeyGesture(Key.F, ModifierKeys.Control) }
);

/// <summary>
/// Opens the Replace panel
/// </summary>
public static readonly RoutedCommand Replace = new RoutedCommand(
"Replace", typeof(SearchPanel),
new InputGestureCollection { new KeyGesture(Key.H, ModifierKeys.Control) }
);

/// <summary>
/// Finds the next occurrence in the file.
/// </summary>
Expand All @@ -46,6 +62,22 @@ public static class SearchCommands
new InputGestureCollection { new KeyGesture(Key.F3, ModifierKeys.Shift) }
);

/// <summary>
/// Replaces the current occurrence and finds the next occurrence in the file.
/// </summary>
public static readonly RoutedCommand ReplaceNext = new RoutedCommand(
"ReplaceNext", typeof(SearchPanel),
new InputGestureCollection { new KeyGesture(Key.R, ModifierKeys.Alt) }
);

/// <summary>
/// Replaces all occurrence in the file.
/// </summary>
public static readonly RoutedCommand ReplaceAll = new RoutedCommand(
"ReplaceAll", typeof(SearchPanel),
new InputGestureCollection { new KeyGesture(Key.A, ModifierKeys.Alt) }
);

/// <summary>
/// Closes the SearchPanel.
/// </summary>
Expand All @@ -70,23 +102,40 @@ internal SearchInputHandler(TextArea textArea, SearchPanel panel)
internal void RegisterGlobalCommands(CommandBindingCollection commandBindings)
{
commandBindings.Add(new CommandBinding(ApplicationCommands.Find, ExecuteFind));
commandBindings.Add(new CommandBinding(ApplicationCommands.Replace, ExecuteReplace));
commandBindings.Add(new CommandBinding(SearchCommands.Find, ExecuteFind));
commandBindings.Add(new CommandBinding(SearchCommands.Replace, ExecuteReplace));
commandBindings.Add(new CommandBinding(SearchCommands.FindNext, ExecuteFindNext, CanExecuteWithOpenSearchPanel));
commandBindings.Add(new CommandBinding(SearchCommands.FindPrevious, ExecuteFindPrevious, CanExecuteWithOpenSearchPanel));
commandBindings.Add(new CommandBinding(SearchCommands.ReplaceNext, ExecuteReplaceNext, CanExecuteWithOpenSearchPanel));
commandBindings.Add(new CommandBinding(SearchCommands.ReplaceAll, ExecuteReplaceAll, CanExecuteWithOpenSearchPanel));
}

void RegisterCommands(ICollection<CommandBinding> commandBindings)
{
commandBindings.Add(new CommandBinding(ApplicationCommands.Find, ExecuteFind));
commandBindings.Add(new CommandBinding(ApplicationCommands.Replace, ExecuteReplace));
commandBindings.Add(new CommandBinding(SearchCommands.Find, ExecuteFind));
commandBindings.Add(new CommandBinding(SearchCommands.Replace, ExecuteReplace));
commandBindings.Add(new CommandBinding(SearchCommands.FindNext, ExecuteFindNext, CanExecuteWithOpenSearchPanel));
commandBindings.Add(new CommandBinding(SearchCommands.FindPrevious, ExecuteFindPrevious, CanExecuteWithOpenSearchPanel));
commandBindings.Add(new CommandBinding(SearchCommands.ReplaceNext, ExecuteReplaceNext, CanExecuteWithOpenSearchPanel));
commandBindings.Add(new CommandBinding(SearchCommands.ReplaceAll, ExecuteReplaceAll, CanExecuteWithOpenSearchPanel));
commandBindings.Add(new CommandBinding(SearchCommands.CloseSearchPanel, ExecuteCloseSearchPanel, CanExecuteWithOpenSearchPanel));
}

SearchPanel panel;

void ExecuteFind(object sender, ExecutedRoutedEventArgs e)
{
panel.Open();
panel.Open(false);
if (!(TextArea.Selection.IsEmpty || TextArea.Selection.IsMultiline))
panel.SearchPattern = TextArea.Selection.GetText();
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Input, (Action)delegate { panel.Reactivate(); });
}

void ExecuteReplace(object sender, ExecutedRoutedEventArgs e) {
panel.Open(true);
if (!(TextArea.Selection.IsEmpty || TextArea.Selection.IsMultiline))
panel.SearchPattern = TextArea.Selection.GetText();
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Input, (Action)delegate { panel.Reactivate(); });
Expand Down Expand Up @@ -119,6 +168,20 @@ void ExecuteFindPrevious(object sender, ExecutedRoutedEventArgs e)
e.Handled = true;
}
}

void ExecuteReplaceNext(object sender, ExecutedRoutedEventArgs e) {
if (!panel.IsClosed) {
panel.ReplaceNext();
e.Handled = true;
}
}

void ExecuteReplaceAll(object sender, ExecutedRoutedEventArgs e) {
if (!panel.IsClosed) {
panel.ReplaceAll();
e.Handled = true;
}
}

void ExecuteCloseSearchPanel(object sender, ExecutedRoutedEventArgs e)
{
Expand Down
Loading