Browse Source

code clean-up

pull/23/head
Siegfried Pammer 14 years ago
parent
commit
63af0b8341
  1. 89
      src/AddIns/Misc/SearchAndReplace/Project/Gui/DefaultSearchResult.cs
  2. 99
      src/AddIns/Misc/SearchAndReplace/Project/Gui/ObserverSearchResult.cs
  3. 1
      src/AddIns/Misc/SearchAndReplace/Project/SearchAndReplace.csproj

89
src/AddIns/Misc/SearchAndReplace/Project/Gui/DefaultSearchResult.cs

@ -5,16 +5,12 @@ using System; @@ -5,16 +5,12 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Threading;
using ICSharpCode.Core;
using ICSharpCode.Core.Presentation;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Editor.Search;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Widgets.Resources;
namespace SearchAndReplace
{
@ -138,87 +134,4 @@ namespace SearchAndReplace @@ -138,87 +134,4 @@ namespace SearchAndReplace
return osr;
}
}
public class ObserverSearchResult : DefaultSearchResult, IObserver<SearchedFile>
{
Button stopButton;
bool finished;
public ObserverSearchResult(string title)
{
rootNode = new SearchRootNode(title, new List<SearchResultMatch>());
}
public IDisposable Registration { get; set; }
public override object GetControl()
{
WorkbenchSingleton.AssertMainThread();
if (resultsTreeViewInstance == null)
resultsTreeViewInstance = new ResultsTreeView();
rootNode.GroupResultsByFile(ResultsTreeView.GroupResultsByFile);
resultsTreeViewInstance.ItemsSource = new object[] { rootNode };
return resultsTreeViewInstance;
}
public override IList GetToolbarItems()
{
var items = base.GetToolbarItems();
if (!finished) {
stopButton = new Button { Content = new Image { Height = 16, Source = PresentationResourceService.GetBitmapSource("Icons.16x16.Debug.StopProcess") } };
stopButton.Click += StopButtonClick;
items.Add(stopButton);
}
return items;
}
void StopButtonClick(object sender, RoutedEventArgs e)
{
try {
stopButton.Visibility = Visibility.Hidden;
if (Registration != null) Registration.Dispose();
} finally {
finished = true;
}
}
void IObserver<SearchedFile>.OnNext(SearchedFile value)
{
rootNode.Add(value);
}
void IObserver<SearchedFile>.OnError(Exception error)
{
// flatten AggregateException and
// filter OperationCanceledException
try {
if (error is AggregateException)
((AggregateException)error).Flatten().Handle(ex => ex is OperationCanceledException);
else if (!(error is OperationCanceledException))
throw error;
} catch (Exception ex) {
MessageService.ShowException(ex);
}
OnCompleted();
}
void OnCompleted()
{
try {
stopButton.Visibility = Visibility.Collapsed;
if (Registration != null)
Registration.Dispose();
} finally {
finished = true;
}
}
void IObserver<SearchedFile>.OnCompleted()
{
OnCompleted();
}
}
}

99
src/AddIns/Misc/SearchAndReplace/Project/Gui/ObserverSearchResult.cs

@ -0,0 +1,99 @@ @@ -0,0 +1,99 @@
// 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;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using ICSharpCode.Core;
using ICSharpCode.Core.Presentation;
using ICSharpCode.SharpDevelop.Editor.Search;
using ICSharpCode.SharpDevelop.Gui;
namespace SearchAndReplace
{
public class ObserverSearchResult : DefaultSearchResult, IObserver<SearchedFile>
{
Button stopButton;
bool finished;
public ObserverSearchResult(string title)
{
rootNode = new SearchRootNode(title, new List<SearchResultMatch>());
}
public IDisposable Registration { get; set; }
public override object GetControl()
{
WorkbenchSingleton.AssertMainThread();
if (resultsTreeViewInstance == null)
resultsTreeViewInstance = new ResultsTreeView();
rootNode.GroupResultsByFile(ResultsTreeView.GroupResultsByFile);
resultsTreeViewInstance.ItemsSource = new object[] { rootNode };
return resultsTreeViewInstance;
}
public override IList GetToolbarItems()
{
var items = base.GetToolbarItems();
if (!finished) {
stopButton = new Button { Content = new Image { Height = 16, Source = PresentationResourceService.GetBitmapSource("Icons.16x16.Debug.StopProcess") } };
stopButton.Click += StopButtonClick;
items.Add(stopButton);
}
return items;
}
void StopButtonClick(object sender, RoutedEventArgs e)
{
try {
stopButton.Visibility = Visibility.Hidden;
if (Registration != null) Registration.Dispose();
} finally {
finished = true;
}
}
void IObserver<SearchedFile>.OnNext(SearchedFile value)
{
rootNode.Add(value);
}
void IObserver<SearchedFile>.OnError(Exception error)
{
// flatten AggregateException and
// filter OperationCanceledException
try {
if (error is AggregateException)
((AggregateException)error).Flatten().Handle(ex => ex is OperationCanceledException);
else if (!(error is OperationCanceledException))
throw error;
} catch (Exception ex) {
MessageService.ShowException(ex);
}
OnCompleted();
}
void OnCompleted()
{
try {
stopButton.Visibility = Visibility.Collapsed;
if (Registration != null)
Registration.Dispose();
} finally {
finished = true;
}
}
void IObserver<SearchedFile>.OnCompleted()
{
OnCompleted();
}
}
}

1
src/AddIns/Misc/SearchAndReplace/Project/SearchAndReplace.csproj

@ -72,6 +72,7 @@ @@ -72,6 +72,7 @@
<Compile Include="Engine\Enums.cs" />
<Compile Include="Engine\SearchManager.cs" />
<Compile Include="Gui\DefaultSearchResult.cs" />
<Compile Include="Gui\ObserverSearchResult.cs" />
<Compile Include="Gui\ResultsTreeView.cs">
<SubType>Code</SubType>
<DependentUpon>ResultsTreeView.xaml</DependentUpon>

Loading…
Cancel
Save