From 51642a5f3713d1f7eb477e75481ff4eed9e97644 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 23 Oct 2011 20:03:02 +0200 Subject: [PATCH] simplify Search*Nodes --- .../Project/Gui/DefaultSearchResult.cs | 98 +++++-------------- .../Project/Gui/SearchAndReplacePanel.cs | 2 +- .../Project/Gui/SearchFileNode.cs | 3 +- .../Project/Gui/SearchNode.cs | 2 +- .../Project/Gui/SearchResultNode.cs | 2 +- .../Project/Gui/SearchRootNode.cs | 2 +- .../Project/SearchAndReplace.addin | 2 +- 7 files changed, 30 insertions(+), 81 deletions(-) diff --git a/src/AddIns/Misc/SearchAndReplace/Project/Gui/DefaultSearchResult.cs b/src/AddIns/Misc/SearchAndReplace/Project/Gui/DefaultSearchResult.cs index 912ea2d18a..04088324dc 100644 --- a/src/AddIns/Misc/SearchAndReplace/Project/Gui/DefaultSearchResult.cs +++ b/src/AddIns/Misc/SearchAndReplace/Project/Gui/DefaultSearchResult.cs @@ -24,7 +24,11 @@ namespace SearchAndReplace public class DefaultSearchResult : ISearchResult { IList matches; - SearchRootNode rootNode; + protected SearchRootNode rootNode; + + protected DefaultSearchResult() + { + } public DefaultSearchResult(string title, IEnumerable matches) { @@ -42,9 +46,9 @@ namespace SearchAndReplace } } - static ResultsTreeView resultsTreeViewInstance; + protected static ResultsTreeView resultsTreeViewInstance; - public object GetControl() + public virtual object GetControl() { WorkbenchSingleton.AssertMainThread(); if (resultsTreeViewInstance == null) @@ -57,9 +61,14 @@ namespace SearchAndReplace static IList toolbarItems; static MenuItem flatItem, perFileItem; - public IList GetToolbarItems() + public virtual IList GetToolbarItems() { WorkbenchSingleton.AssertMainThread(); + return GetDefaultToolbarItems(); + } + + protected IList GetDefaultToolbarItems() + { if (toolbarItems == null) { toolbarItems = new List(); DropDownButton perFileDropDown = new DropDownButton(); @@ -130,23 +139,18 @@ namespace SearchAndReplace } } - public class ObserverSearchResult : ISearchResult, IObserver + public class ObserverSearchResult : DefaultSearchResult, IObserver { - static Button stopButton; - SearchRootNode rootNode; + Button stopButton; public ObserverSearchResult(string title) { - Text = title; rootNode = new SearchRootNode(title, new List()); } - public string Text { get; private set; } public IDisposable Registration { get; set; } - static ResultsTreeView resultsTreeViewInstance; - - public object GetControl() + public override object GetControl() { WorkbenchSingleton.AssertMainThread(); if (resultsTreeViewInstance == null) @@ -156,50 +160,16 @@ namespace SearchAndReplace return resultsTreeViewInstance; } - static IList toolbarItems; - static MenuItem flatItem, perFileItem; - - public IList GetToolbarItems() + public override IList GetToolbarItems() { - WorkbenchSingleton.AssertMainThread(); - if (toolbarItems == null) { - toolbarItems = new List(); - DropDownButton perFileDropDown = new DropDownButton(); - perFileDropDown.Content = new Image { Height = 16, Source = PresentationResourceService.GetBitmapSource("Icons.16x16.FindIcon") }; - perFileDropDown.SetValueToExtension(DropDownButton.ToolTipProperty, new LocalizeExtension("MainWindow.Windows.SearchResultPanel.SelectViewMode.ToolTip")); - - flatItem = new MenuItem(); - flatItem.SetValueToExtension(MenuItem.HeaderProperty, new LocalizeExtension("MainWindow.Windows.SearchResultPanel.Flat")); - flatItem.Click += delegate { SetPerFile(false); }; - - perFileItem = new MenuItem(); - perFileItem.SetValueToExtension(MenuItem.HeaderProperty, new LocalizeExtension("MainWindow.Windows.SearchResultPanel.PerFile")); - perFileItem.Click += delegate { SetPerFile(true); }; - - perFileDropDown.DropDownMenu = new ContextMenu(); - perFileDropDown.DropDownMenu.Items.Add(flatItem); - perFileDropDown.DropDownMenu.Items.Add(perFileItem); - toolbarItems.Add(perFileDropDown); - toolbarItems.Add(new Separator()); - - Button expandAll = new Button(); - expandAll.SetValueToExtension(Button.ToolTipProperty, new LocalizeExtension("MainWindow.Windows.SearchResultPanel.ExpandAll.ToolTip")); - expandAll.Content = new Image { Height = 16, Source = PresentationResourceService.GetBitmapSource("Icons.16x16.OpenAssembly") }; - expandAll.Click += delegate { ExpandCollapseAll(true); }; - toolbarItems.Add(expandAll); - - Button collapseAll = new Button(); - collapseAll.SetValueToExtension(Button.ToolTipProperty, new LocalizeExtension("MainWindow.Windows.SearchResultPanel.CollapseAll.ToolTip")); - collapseAll.Content = new Image { Height = 16, Source = PresentationResourceService.GetBitmapSource("Icons.16x16.Assembly") }; - collapseAll.Click += delegate { ExpandCollapseAll(false); }; - toolbarItems.Add(collapseAll); - - stopButton = new Button { Content = new Image { Height = 16, Source = PresentationResourceService.GetBitmapSource("Icons.16x16.Debug.StopProcess") } }; - stopButton.Click += StopButtonClick; - toolbarItems.Add(stopButton); - } + var items = base.GetToolbarItems(); + + stopButton = new Button { Content = new Image { Height = 16, Source = PresentationResourceService.GetBitmapSource("Icons.16x16.Debug.StopProcess") } }; + stopButton.Click += StopButtonClick; + + items.Add(stopButton); stopButton.Visibility = Visibility.Visible; - return toolbarItems; + return items; } void StopButtonClick(object sender, RoutedEventArgs e) @@ -208,25 +178,6 @@ namespace SearchAndReplace if (Registration != null) Registration.Dispose(); } - static void ExpandCollapseAll(bool newIsExpanded) - { - if (resultsTreeViewInstance != null) { - foreach (SearchNode node in resultsTreeViewInstance.ItemsSource.OfType().Flatten(n => n.Children)) { - node.IsExpanded = newIsExpanded; - } - } - } - - static void SetPerFile(bool perFile) - { - ResultsTreeView.GroupResultsByFile = perFile; - if (resultsTreeViewInstance != null) { - foreach (SearchRootNode node in resultsTreeViewInstance.ItemsSource.OfType()) { - node.GroupResultsByFile(perFile); - } - } - } - void IObserver.OnNext(SearchedFile value) { rootNode.Add(value); @@ -250,5 +201,4 @@ namespace SearchAndReplace OnCompleted(); } } - } diff --git a/src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchAndReplacePanel.cs b/src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchAndReplacePanel.cs index f82002ab3e..08dda7736c 100644 --- a/src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchAndReplacePanel.cs +++ b/src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchAndReplacePanel.cs @@ -122,7 +122,7 @@ namespace SearchAndReplace { WritebackOptions(); AsynchronousWaitDialog.RunInCancellableWaitDialog( - "Searching ...", "replaceall", + "Searching ...", null, monitor => { var results = SearchManager.FindAll(monitor, SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchStrategyType, SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, selection, false); SearchManager.ReplaceAll(results, SearchOptions.ReplacePattern, monitor.CancellationToken); diff --git a/src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchFileNode.cs b/src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchFileNode.cs index 9957ae012f..56e59f5f5a 100644 --- a/src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchFileNode.cs +++ b/src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchFileNode.cs @@ -12,10 +12,9 @@ using ICSharpCode.SharpDevelop.Editor.Search; namespace SearchAndReplace { - class SearchFileNode : SearchNode + public class SearchFileNode : SearchNode { public FileName FileName { get; private set; } - public SearchFileNode(FileName fileName, System.Collections.Generic.List resultNodes) { diff --git a/src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchNode.cs b/src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchNode.cs index 0cad40daa6..284a776150 100644 --- a/src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchNode.cs +++ b/src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchNode.cs @@ -9,7 +9,7 @@ using System.Windows.Media; namespace SearchAndReplace { - abstract class SearchNode : INotifyPropertyChanged + public abstract class SearchNode : INotifyPropertyChanged { bool isExpanded; diff --git a/src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchResultNode.cs b/src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchResultNode.cs index 0714c8e726..2f515b41ab 100644 --- a/src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchResultNode.cs +++ b/src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchResultNode.cs @@ -19,7 +19,7 @@ namespace SearchAndReplace /// /// Represents a search result. /// - sealed class SearchResultNode : SearchNode + public sealed class SearchResultNode : SearchNode { SearchResultMatch result; PermanentAnchor anchor; diff --git a/src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchRootNode.cs b/src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchRootNode.cs index 28fa97c0f6..7034997ffa 100644 --- a/src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchRootNode.cs +++ b/src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchRootNode.cs @@ -16,7 +16,7 @@ using ICSharpCode.SharpDevelop.Editor.Search; namespace SearchAndReplace { - sealed class SearchRootNode : SearchNode + public sealed class SearchRootNode : SearchNode { ObservableCollection resultNodes; ObservableCollection fileNodes; diff --git a/src/AddIns/Misc/SearchAndReplace/Project/SearchAndReplace.addin b/src/AddIns/Misc/SearchAndReplace/Project/SearchAndReplace.addin index b36b5c6963..2f315064a8 100644 --- a/src/AddIns/Misc/SearchAndReplace/Project/SearchAndReplace.addin +++ b/src/AddIns/Misc/SearchAndReplace/Project/SearchAndReplace.addin @@ -15,7 +15,7 @@