Browse Source

simplify Search*Nodes

pull/23/head
Siegfried Pammer 14 years ago
parent
commit
51642a5f37
  1. 98
      src/AddIns/Misc/SearchAndReplace/Project/Gui/DefaultSearchResult.cs
  2. 2
      src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchAndReplacePanel.cs
  3. 3
      src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchFileNode.cs
  4. 2
      src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchNode.cs
  5. 2
      src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchResultNode.cs
  6. 2
      src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchRootNode.cs
  7. 2
      src/AddIns/Misc/SearchAndReplace/Project/SearchAndReplace.addin

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

@ -24,7 +24,11 @@ namespace SearchAndReplace @@ -24,7 +24,11 @@ namespace SearchAndReplace
public class DefaultSearchResult : ISearchResult
{
IList<SearchResultMatch> matches;
SearchRootNode rootNode;
protected SearchRootNode rootNode;
protected DefaultSearchResult()
{
}
public DefaultSearchResult(string title, IEnumerable<SearchResultMatch> matches)
{
@ -42,9 +46,9 @@ namespace SearchAndReplace @@ -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 @@ -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<object>();
DropDownButton perFileDropDown = new DropDownButton();
@ -130,23 +139,18 @@ namespace SearchAndReplace @@ -130,23 +139,18 @@ namespace SearchAndReplace
}
}
public class ObserverSearchResult : ISearchResult, IObserver<SearchedFile>
public class ObserverSearchResult : DefaultSearchResult, IObserver<SearchedFile>
{
static Button stopButton;
SearchRootNode rootNode;
Button stopButton;
public ObserverSearchResult(string title)
{
Text = title;
rootNode = new SearchRootNode(title, new List<SearchResultMatch>());
}
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 @@ -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<object>();
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 @@ -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<SearchNode>().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<SearchRootNode>()) {
node.GroupResultsByFile(perFile);
}
}
}
void IObserver<SearchedFile>.OnNext(SearchedFile value)
{
rootNode.Add(value);
@ -250,5 +201,4 @@ namespace SearchAndReplace @@ -250,5 +201,4 @@ namespace SearchAndReplace
OnCompleted();
}
}
}

2
src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchAndReplacePanel.cs

@ -122,7 +122,7 @@ namespace SearchAndReplace @@ -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);

3
src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchFileNode.cs

@ -12,10 +12,9 @@ using ICSharpCode.SharpDevelop.Editor.Search; @@ -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<SearchResultNode> resultNodes)
{

2
src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchNode.cs

@ -9,7 +9,7 @@ using System.Windows.Media; @@ -9,7 +9,7 @@ using System.Windows.Media;
namespace SearchAndReplace
{
abstract class SearchNode : INotifyPropertyChanged
public abstract class SearchNode : INotifyPropertyChanged
{
bool isExpanded;

2
src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchResultNode.cs

@ -19,7 +19,7 @@ namespace SearchAndReplace @@ -19,7 +19,7 @@ namespace SearchAndReplace
/// <summary>
/// Represents a search result.
/// </summary>
sealed class SearchResultNode : SearchNode
public sealed class SearchResultNode : SearchNode
{
SearchResultMatch result;
PermanentAnchor anchor;

2
src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchRootNode.cs

@ -16,7 +16,7 @@ using ICSharpCode.SharpDevelop.Editor.Search; @@ -16,7 +16,7 @@ using ICSharpCode.SharpDevelop.Editor.Search;
namespace SearchAndReplace
{
sealed class SearchRootNode : SearchNode
public sealed class SearchRootNode : SearchNode
{
ObservableCollection<SearchResultNode> resultNodes;
ObservableCollection<SearchFileNode> fileNodes;

2
src/AddIns/Misc/SearchAndReplace/Project/SearchAndReplace.addin

@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
<MenuItem id = "Find"
label = "${res:XML.MainMenu.SearchMenu.Find}"
icon = "Icons.16x16.FindIcon"
shortcut = "Control|F"
shortcut = "Control|Shift|F"
class = "SearchAndReplace.Find"/>
<MenuItem id = "FindNext"
insertafter = "Find"

Loading…
Cancel
Save