diff --git a/ICSharpCode.ILSpyX/Search/AbstractSearchStrategy.cs b/ICSharpCode.ILSpyX/Search/AbstractSearchStrategy.cs index 61de7b714..76c3c4d4f 100644 --- a/ICSharpCode.ILSpyX/Search/AbstractSearchStrategy.cs +++ b/ICSharpCode.ILSpyX/Search/AbstractSearchStrategy.cs @@ -52,7 +52,7 @@ namespace ICSharpCode.ILSpyX.Search public AssemblySearchKind AssemblySearchKind; public MemberSearchKind MemberSearchKind; public string[] Keywords; - public Regex RegEx; + public Regex? RegEx; public bool FullNameSearch; public bool OmitGenerics; public string InNamespace; @@ -62,7 +62,7 @@ namespace ICSharpCode.ILSpyX.Search public abstract class AbstractSearchStrategy { protected readonly string[] searchTerm; - protected readonly Regex regex; + protected readonly Regex? regex; protected readonly bool fullNameSearch; protected readonly bool omitGenerics; protected readonly SearchRequest searchRequest; diff --git a/ILSpy/Commands/ScopeSearchToAssembly.cs b/ILSpy/Commands/ScopeSearchToAssembly.cs index 3d8a10397..27f3c79f4 100644 --- a/ILSpy/Commands/ScopeSearchToAssembly.cs +++ b/ILSpy/Commands/ScopeSearchToAssembly.cs @@ -23,6 +23,7 @@ using System.ComponentModel.Composition; using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.ILSpy.AppEnv; using ICSharpCode.ILSpy.Properties; +using ICSharpCode.ILSpy.Search; using ICSharpCode.ILSpy.TreeNodes; namespace ICSharpCode.ILSpy @@ -31,11 +32,19 @@ namespace ICSharpCode.ILSpy [PartCreationPolicy(CreationPolicy.Shared)] public class ScopeSearchToAssembly : IContextMenuEntry { + private readonly SearchPaneModel searchPane; + + [ImportingConstructor] + public ScopeSearchToAssembly(SearchPaneModel searchPane) + { + this.searchPane = searchPane; + } + public void Execute(TextViewContext context) { // asmName cannot be null here, because Execute is only called if IsEnabled/IsVisible return true. string asmName = GetAssembly(context)!; - string searchTerm = MainWindow.Instance.SearchPane.SearchTerm; + string searchTerm = searchPane.SearchTerm; string[] args = CommandLineTools.CommandLineToArgumentArray(searchTerm); bool replaced = false; for (int i = 0; i < args.Length; i++) @@ -55,7 +64,7 @@ namespace ICSharpCode.ILSpy { searchTerm = CommandLineTools.ArgumentArrayToCommandLine(args); } - MainWindow.Instance.SearchPane.SearchTerm = searchTerm; + searchPane.SearchTerm = searchTerm; } public bool IsEnabled(TextViewContext context) diff --git a/ILSpy/Commands/ScopeSearchToNamespace.cs b/ILSpy/Commands/ScopeSearchToNamespace.cs index c6be0a9db..645f9d425 100644 --- a/ILSpy/Commands/ScopeSearchToNamespace.cs +++ b/ILSpy/Commands/ScopeSearchToNamespace.cs @@ -21,6 +21,7 @@ using System.ComponentModel.Composition; using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.ILSpy.AppEnv; using ICSharpCode.ILSpy.Properties; +using ICSharpCode.ILSpy.Search; using ICSharpCode.ILSpy.TreeNodes; namespace ICSharpCode.ILSpy @@ -29,10 +30,18 @@ namespace ICSharpCode.ILSpy [PartCreationPolicy(CreationPolicy.Shared)] public class ScopeSearchToNamespace : IContextMenuEntry { + private readonly SearchPaneModel searchPane; + + [ImportingConstructor] + public ScopeSearchToNamespace(SearchPaneModel searchPane) + { + this.searchPane = searchPane; + } + public void Execute(TextViewContext context) { string ns = GetNamespace(context); - string searchTerm = MainWindow.Instance.SearchPane.SearchTerm; + string searchTerm = searchPane.SearchTerm; string[] args = CommandLineTools.CommandLineToArgumentArray(searchTerm); bool replaced = false; for (int i = 0; i < args.Length; i++) @@ -52,7 +61,8 @@ namespace ICSharpCode.ILSpy { searchTerm = CommandLineTools.ArgumentArrayToCommandLine(args); } - MainWindow.Instance.SearchPane.SearchTerm = searchTerm; + + searchPane.SearchTerm = searchTerm; } public bool IsEnabled(TextViewContext context) diff --git a/ILSpy/Controls/CultureSelectionConverter.cs b/ILSpy/Controls/CultureSelectionConverter.cs index 0e79cf105..74c38993e 100644 --- a/ILSpy/Controls/CultureSelectionConverter.cs +++ b/ILSpy/Controls/CultureSelectionConverter.cs @@ -19,10 +19,11 @@ using System; using System.Globalization; using System.Windows.Data; +using System.Windows.Markup; namespace ICSharpCode.ILSpy.Controls { - public class CultureSelectionConverter : IValueConverter + public class CultureSelectionConverter : MarkupExtension, IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { @@ -37,5 +38,10 @@ namespace ICSharpCode.ILSpy.Controls return parameter; return Binding.DoNothing; } + + public override object ProvideValue(IServiceProvider serviceProvider) + { + return this; + } } } diff --git a/ILSpy/Controls/TreeView/Converters.cs b/ILSpy/Controls/TreeView/Converters.cs deleted file mode 100644 index 401d9026c..000000000 --- a/ILSpy/Controls/TreeView/Converters.cs +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) 2020 AlphaSierraPapa for the SharpDevelop Team -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this -// software and associated documentation files (the "Software"), to deal in the Software -// without restriction, including without limitation the rights to use, copy, modify, merge, -// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons -// to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or -// substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, -// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR -// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE -// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -using System; -using System.Globalization; -using System.Windows; -using System.Windows.Data; -using System.Windows.Markup; - -namespace ICSharpCode.ILSpy.Controls.TreeView -{ - public class CollapsedWhenFalse : MarkupExtension, IValueConverter - { - public static CollapsedWhenFalse Instance = new CollapsedWhenFalse(); - - public override object ProvideValue(IServiceProvider serviceProvider) - { - return Instance; - } - - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - return (bool)value ? Visibility.Visible : Visibility.Collapsed; - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - throw new NotImplementedException(); - } - } -} diff --git a/ILSpy/Controls/TreeView/SharpTreeView.xaml b/ILSpy/Controls/TreeView/SharpTreeView.xaml index 6e87b9e67..562f4bc51 100644 --- a/ILSpy/Controls/TreeView/SharpTreeView.xaml +++ b/ILSpy/Controls/TreeView/SharpTreeView.xaml @@ -1,7 +1,8 @@ + xmlns:styles="urn:TomsToolbox.Wpf.Styles" + xmlns:toms="urn:TomsToolbox"> @@ -279,4 +291,4 @@ - + \ No newline at end of file diff --git a/ILSpy/MainWindow.xaml.cs b/ILSpy/MainWindow.xaml.cs index d87bd31ff..235594f7a 100644 --- a/ILSpy/MainWindow.xaml.cs +++ b/ILSpy/MainWindow.xaml.cs @@ -89,12 +89,6 @@ namespace ICSharpCode.ILSpy } } - public SearchPane SearchPane { - get { - return App.ExportProvider.GetExportedValue(); - } - } - public DecompilationOptions CreateDecompilationOptions() { var decompilerView = DockWorkspace.Instance.ActiveTabPage.Content as IProgress; @@ -123,10 +117,10 @@ namespace ICSharpCode.ILSpy } InitializeComponent(); InitToolPanes(); - DockWorkspace.Instance.InitializeLayout(DockManager); + DockWorkspace.Instance.InitializeLayout(dockManager); MessageBus.Subscribers += (sender, e) => SessionSettings_PropertyChanged(sender, e); - MessageBus.Subscribers += (sender, e) => filterSettings_PropertyChanged(sender, e); + MessageBus.Subscribers += (sender, e) => LanguageSettings_PropertyChanged(sender, e); MessageBus.Subscribers += DockWorkspace_ActiveTabPageChanged; InitMainMenu(); @@ -647,8 +641,10 @@ namespace ICSharpCode.ILSpy NavigateOnLaunch(args.NavigateTo, sessionSettings.ActiveTreeViewPath, spySettings, relevantAssemblies); if (args.Search != null) { - SearchPane.SearchTerm = args.Search; - SearchPane.Show(); + var searchPane = App.ExportProvider.GetExportedValue(); + + searchPane.SearchTerm = args.Search; + searchPane.Show(); } } @@ -1004,20 +1000,14 @@ namespace ICSharpCode.ILSpy assemblyList.OpenAssembly(asm.Location); } - void filterSettings_PropertyChanged(object sender, PropertyChangedEventArgs e) + void LanguageSettings_PropertyChanged(object sender, PropertyChangedEventArgs e) { - RefreshTreeViewFilter(); if (e.PropertyName == "Language" || e.PropertyName == "LanguageVersion") { DecompileSelectedNodes(recordHistory: false); } } - public void RefreshTreeViewFilter() - { - SearchPane.UpdateFilter(); - } - internal AssemblyListTreeNode AssemblyListTreeNode { get { return assemblyListTreeNode; } } @@ -1592,7 +1582,7 @@ namespace ICSharpCode.ILSpy sessionSettings.ActiveTreeViewPath = GetPathForNode(AssemblyTreeView.SelectedItem as SharpTreeNode); sessionSettings.ActiveAutoLoadedAssembly = GetAutoLoadedAssemblyNode(AssemblyTreeView.SelectedItem as SharpTreeNode); sessionSettings.WindowBounds = this.RestoreBounds; - sessionSettings.DockLayout.Serialize(new XmlLayoutSerializer(DockManager)); + sessionSettings.DockLayout.Serialize(new XmlLayoutSerializer(dockManager)); sessionSettings.Save(); } @@ -1622,8 +1612,8 @@ namespace ICSharpCode.ILSpy { if (this.statusBar.Visibility == Visibility.Collapsed) this.statusBar.Visibility = Visibility.Visible; - this.StatusLabel.Foreground = foreground; - this.StatusLabel.Text = status; + this.statusLabel.Foreground = foreground; + this.statusLabel.Text = status; } public ItemCollection GetMainMenuItems() diff --git a/ILSpy/Options/DisplaySettingsViewModel.cs b/ILSpy/Options/DisplaySettings.cs similarity index 98% rename from ILSpy/Options/DisplaySettingsViewModel.cs rename to ILSpy/Options/DisplaySettings.cs index 15b54ebe5..f59c31a95 100644 --- a/ILSpy/Options/DisplaySettingsViewModel.cs +++ b/ILSpy/Options/DisplaySettings.cs @@ -27,9 +27,9 @@ namespace ICSharpCode.ILSpy.Options /// /// Description of DisplaySettings. /// - public class DisplaySettingsViewModel : INotifyPropertyChanged + public class DisplaySettings : INotifyPropertyChanged { - public DisplaySettingsViewModel() + public DisplaySettings() { this.theme = ThemeManager.Current.DefaultTheme; this.selectedFont = new FontFamily("Consolas"); @@ -328,7 +328,7 @@ namespace ICSharpCode.ILSpy.Options } } - public void CopyValues(DisplaySettingsViewModel s) + public void CopyValues(DisplaySettings s) { this.Theme = s.Theme; this.SelectedFont = s.selectedFont; diff --git a/ILSpy/Options/DisplaySettingsPanel.xaml b/ILSpy/Options/DisplaySettingsPanel.xaml index 52f5c3ab1..1170a8f5b 100644 --- a/ILSpy/Options/DisplaySettingsPanel.xaml +++ b/ILSpy/Options/DisplaySettingsPanel.xaml @@ -7,7 +7,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:themes="clr-namespace:ICSharpCode.ILSpy.Themes" - d:DataContext="{d:DesignInstance local:DisplaySettingsViewModel}"> + d:DataContext="{d:DesignInstance local:DisplaySettings}"> diff --git a/ILSpy/Options/DisplaySettingsPanel.xaml.cs b/ILSpy/Options/DisplaySettingsPanel.xaml.cs index 8358a3cf5..9645dacc7 100644 --- a/ILSpy/Options/DisplaySettingsPanel.xaml.cs +++ b/ILSpy/Options/DisplaySettingsPanel.xaml.cs @@ -99,10 +99,10 @@ namespace ICSharpCode.ILSpy.Options select ff).ToArray(); } - public static DisplaySettingsViewModel LoadDisplaySettings(ILSpySettings settings, SessionSettings sessionSettings = null) + public static DisplaySettings LoadDisplaySettings(ILSpySettings settings, SessionSettings sessionSettings = null) { XElement e = settings["DisplaySettings"]; - var s = new DisplaySettingsViewModel(); + var s = new DisplaySettings(); s.SelectedFont = new FontFamily((string)e.Attribute("Font") ?? "Consolas"); s.SelectedFontSize = (double?)e.Attribute("FontSize") ?? 10.0 * 4 / 3; s.ShowLineNumbers = (bool?)e.Attribute("ShowLineNumbers") ?? false; @@ -131,7 +131,7 @@ namespace ICSharpCode.ILSpy.Options public void Save(XElement root) { - var s = (DisplaySettingsViewModel)this.DataContext; + var s = (DisplaySettings)this.DataContext; var section = new XElement("DisplaySettings"); section.SetAttributeValue("Font", s.SelectedFont.Source); @@ -190,7 +190,7 @@ namespace ICSharpCode.ILSpy.Options public void LoadDefaults() { - SettingsService.Instance.DisplaySettings.CopyValues(new DisplaySettingsViewModel()); + SettingsService.Instance.DisplaySettings.CopyValues(new DisplaySettings()); this.DataContext = SettingsService.Instance.DisplaySettings; } } diff --git a/ILSpy/Search/SearchPane.xaml b/ILSpy/Search/SearchPane.xaml index f08a8d014..518f87e76 100644 --- a/ILSpy/Search/SearchPane.xaml +++ b/ILSpy/Search/SearchPane.xaml @@ -2,10 +2,14 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="clr-namespace:ICSharpCode.ILSpy.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:properties="clr-namespace:ICSharpCode.ILSpy.Properties" + xmlns:properties="clr-namespace:ICSharpCode.ILSpy.Properties" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" x:Name="self" mc:Ignorable="d" xmlns:toms="urn:TomsToolbox" - d:DesignHeight="300" d:DesignWidth="300"> + xmlns:search="clr-namespace:ICSharpCode.ILSpy.Search" + xmlns:spyX="clr-namespace:ICSharpCode.ILSpyX.Search;assembly=ICSharpCode.ILSpyX" + xmlns:viewModels="clr-namespace:ICSharpCode.ILSpy.ViewModels" + d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance search:SearchPaneModel}" + viewModels:Pane.IsActive="{Binding IsActive}"> @@ -20,15 +24,19 @@