Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
simplify Search*Nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
siegfriedpammer committed Oct 25, 2011
1 parent 943b193 commit 51642a5
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 81 deletions.
98 changes: 24 additions & 74 deletions src/AddIns/Misc/SearchAndReplace/Project/Gui/DefaultSearchResult.cs
Expand Up @@ -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)
{
Expand All @@ -42,9 +46,9 @@ public DefaultSearchResult(string title, IEnumerable<SearchResultMatch> matches)
}
}

static ResultsTreeView resultsTreeViewInstance;
protected static ResultsTreeView resultsTreeViewInstance;

public object GetControl()
public virtual object GetControl()
{
WorkbenchSingleton.AssertMainThread();
if (resultsTreeViewInstance == null)
Expand All @@ -57,9 +61,14 @@ public object GetControl()
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();
Expand Down Expand Up @@ -130,23 +139,18 @@ public ISearchResult CreateSearchResult(string title, IObservable<SearchedFile>
}
}

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)
Expand All @@ -156,50 +160,16 @@ public object GetControl()
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)
Expand All @@ -208,25 +178,6 @@ void StopButtonClick(object sender, RoutedEventArgs e)
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);
Expand All @@ -250,5 +201,4 @@ void IObserver<SearchedFile>.OnCompleted()
OnCompleted();
}
}

}
Expand Up @@ -122,7 +122,7 @@ void ReplaceAllButtonClicked(object sender, EventArgs e)
{
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);
Expand Down
Expand Up @@ -12,10 +12,9 @@

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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchNode.cs
Expand Up @@ -9,7 +9,7 @@

namespace SearchAndReplace
{
abstract class SearchNode : INotifyPropertyChanged
public abstract class SearchNode : INotifyPropertyChanged
{
bool isExpanded;

Expand Down
Expand Up @@ -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;
Expand Down
Expand Up @@ -16,7 +16,7 @@

namespace SearchAndReplace
{
sealed class SearchRootNode : SearchNode
public sealed class SearchRootNode : SearchNode
{
ObservableCollection<SearchResultNode> resultNodes;
ObservableCollection<SearchFileNode> fileNodes;
Expand Down
Expand Up @@ -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"
Expand Down

0 comments on commit 51642a5

Please sign in to comment.