diff --git a/ILSpy/App.xaml.cs b/ILSpy/App.xaml.cs index f938fc5e4..a09fa4a9d 100644 --- a/ILSpy/App.xaml.cs +++ b/ILSpy/App.xaml.cs @@ -58,9 +58,8 @@ namespace ICSharpCode.ILSpy public App() { var cmdArgs = Environment.GetCommandLineArgs().Skip(1); - var allowMultipleInstance = MiscSettingsInstance.Current.LoadMiscSettings().AllowMultipleInstances; App.CommandLineArguments = new CommandLineArguments(cmdArgs); - if ((App.CommandLineArguments.SingleInstance ?? true) && (!allowMultipleInstance)) { + if ((App.CommandLineArguments.SingleInstance ?? true) && !MiscSettingsPanel.CurrentMiscSettings.AllowMultipleInstances) { cmdArgs = cmdArgs.Select(FullyQualifyPath); string message = string.Join(Environment.NewLine, cmdArgs); if (SendToPreviousInstance("ILSpy:\r\n" + message, !App.CommandLineArguments.NoActivate)) { diff --git a/ILSpy/ILSpy.csproj b/ILSpy/ILSpy.csproj index 9c2c2b215..8aefd0401 100644 --- a/ILSpy/ILSpy.csproj +++ b/ILSpy/ILSpy.csproj @@ -152,7 +152,6 @@ Code - MiscSettingsPanel.xaml diff --git a/ILSpy/Options/DisplaySettings.cs b/ILSpy/Options/DisplaySettings.cs index 806f7eac6..0ecd46676 100644 --- a/ILSpy/Options/DisplaySettings.cs +++ b/ILSpy/Options/DisplaySettings.cs @@ -17,6 +17,7 @@ // DEALINGS IN THE SOFTWARE. using System.ComponentModel; +using System.Runtime.CompilerServices; using System.Windows.Media; namespace ICSharpCode.ILSpy.Options @@ -35,12 +36,10 @@ namespace ICSharpCode.ILSpy.Options protected virtual void OnPropertyChanged(PropertyChangedEventArgs e) { - if (PropertyChanged != null) { - PropertyChanged(this, e); - } + PropertyChanged?.Invoke(this, e); } - protected void OnPropertyChanged(string propertyName) + protected void OnPropertyChanged([CallerMemberName] string propertyName = null) { OnPropertyChanged(new PropertyChangedEventArgs(propertyName)); } @@ -53,7 +52,7 @@ namespace ICSharpCode.ILSpy.Options set { if (selectedFont != value) { selectedFont = value; - OnPropertyChanged("SelectedFont"); + OnPropertyChanged(); } } } @@ -65,7 +64,7 @@ namespace ICSharpCode.ILSpy.Options set { if (selectedFontSize != value) { selectedFontSize = value; - OnPropertyChanged("SelectedFontSize"); + OnPropertyChanged(); } } } @@ -77,7 +76,7 @@ namespace ICSharpCode.ILSpy.Options set { if (showLineNumbers != value) { showLineNumbers = value; - OnPropertyChanged("ShowLineNumbers"); + OnPropertyChanged(); } } } @@ -90,7 +89,7 @@ namespace ICSharpCode.ILSpy.Options set { if (showMetadataTokens != value) { showMetadataTokens = value; - OnPropertyChanged("ShowMetadataTokens"); + OnPropertyChanged(); } } } @@ -104,18 +103,9 @@ namespace ICSharpCode.ILSpy.Options { if (enableWordWrap != value) { enableWordWrap = value; - OnPropertyChanged("EnableWordWrap"); + OnPropertyChanged(); } } } - - public void CopyValues(DisplaySettings s) - { - this.SelectedFont = s.selectedFont; - this.SelectedFontSize = s.selectedFontSize; - this.ShowLineNumbers = s.showLineNumbers; - this.ShowMetadataTokens = s.showMetadataTokens; - this.EnableWordWrap = s.enableWordWrap; - } } } diff --git a/ILSpy/Options/DisplaySettingsPanel.xaml.cs b/ILSpy/Options/DisplaySettingsPanel.xaml.cs index 5ca096e7b..cce85daa7 100644 --- a/ILSpy/Options/DisplaySettingsPanel.xaml.cs +++ b/ILSpy/Options/DisplaySettingsPanel.xaml.cs @@ -87,16 +87,16 @@ namespace ICSharpCode.ILSpy.Options static FontFamily[] FontLoader() { - return Fonts.SystemFontFamilies - .Where(ff => !IsSymbolFont(ff)) - .OrderBy(ff => ff.Source) - .ToArray(); + return (from ff in Fonts.SystemFontFamilies + where !IsSymbolFont(ff) + orderby ff.Source + select ff).ToArray(); } public static DisplaySettings LoadDisplaySettings(ILSpySettings settings) { XElement e = settings["DisplaySettings"]; - DisplaySettings s = new DisplaySettings(); + 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; @@ -108,11 +108,9 @@ namespace ICSharpCode.ILSpy.Options public void Save(XElement root) { - DisplaySettings s = (DisplaySettings)this.DataContext; + var s = (DisplaySettings)this.DataContext; - currentDisplaySettings.CopyValues(s); - - XElement section = new XElement("DisplaySettings"); + var section = new XElement("DisplaySettings"); section.SetAttributeValue("Font", s.SelectedFont.Source); section.SetAttributeValue("FontSize", s.SelectedFontSize); section.SetAttributeValue("ShowLineNumbers", s.ShowLineNumbers); @@ -124,6 +122,8 @@ namespace ICSharpCode.ILSpy.Options existingElement.ReplaceWith(section); else root.Add(section); + + currentDisplaySettings = null; // invalidate cached settings } } diff --git a/ILSpy/Options/MiscSettings.cs b/ILSpy/Options/MiscSettings.cs index e56516ee4..2df04770d 100644 --- a/ILSpy/Options/MiscSettings.cs +++ b/ILSpy/Options/MiscSettings.cs @@ -1,26 +1,40 @@ -using System.ComponentModel; +// Copyright (c) 2017 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.ComponentModel; +using System.Runtime.CompilerServices; namespace ICSharpCode.ILSpy.Options { public class MiscSettings : INotifyPropertyChanged { - bool allowMultipleInstances = false; + bool allowMultipleInstances; /// - /// Decompile anonymous methods/lambdas. + /// Allow multiple instances. /// public bool AllowMultipleInstances { - get - { - return allowMultipleInstances; - } - set - { - if (allowMultipleInstances != value) - { + get { return allowMultipleInstances; } + set { + if (allowMultipleInstances != value) { allowMultipleInstances = value; - OnPropertyChanged("AllowMultipleInstance"); + OnPropertyChanged(); } } } @@ -34,7 +48,7 @@ namespace ICSharpCode.ILSpy.Options PropertyChanged?.Invoke(this, e); } - protected void OnPropertyChanged(string propertyName) + protected void OnPropertyChanged([CallerMemberName] string propertyName = null) { OnPropertyChanged(new PropertyChangedEventArgs(propertyName)); } diff --git a/ILSpy/Options/MiscSettingsLoader.cs b/ILSpy/Options/MiscSettingsLoader.cs deleted file mode 100644 index dd6f260a5..000000000 --- a/ILSpy/Options/MiscSettingsLoader.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System.Xml.Linq; - -namespace ICSharpCode.ILSpy.Options -{ - public interface IMiscSettingsLoader - { - MiscSettings LoadMiscSettings(); - MiscSettings LoadMiscSettings(ILSpySettings settings); - } - - public class MiscSettingsLoader : IMiscSettingsLoader - { - private ILSpySettings settings; - - public MiscSettingsLoader() - { - settings = ILSpySettings.Load(); - } - - public MiscSettings LoadMiscSettings() - { - return LoadMiscSettings(settings); - } - - public MiscSettings LoadMiscSettings(ILSpySettings settings) - { - XElement e = settings["MiscSettings"]; - MiscSettings s = new MiscSettings(); - s.AllowMultipleInstances = (bool?)e.Attribute("allowMultipleInstance") ?? s.AllowMultipleInstances; - return s; - } - } - - public static class MiscSettingsInstance - { - private static MiscSettingsLoader current; - - public static MiscSettingsLoader Current - { - get - { - current = current ?? new MiscSettingsLoader(); - return current; - } - } - } -} diff --git a/ILSpy/Options/MiscSettingsPanel.xaml.cs b/ILSpy/Options/MiscSettingsPanel.xaml.cs index 361532dcf..538652633 100644 --- a/ILSpy/Options/MiscSettingsPanel.xaml.cs +++ b/ILSpy/Options/MiscSettingsPanel.xaml.cs @@ -1,4 +1,22 @@ -using System.Windows.Controls; +// Copyright (c) 2017 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.Windows.Controls; using System.Xml.Linq; namespace ICSharpCode.ILSpy.Options @@ -16,20 +34,39 @@ namespace ICSharpCode.ILSpy.Options public void Load(ILSpySettings settings) { - this.DataContext = MiscSettingsInstance.Current.LoadMiscSettings(settings); + this.DataContext = LoadMiscSettings(settings); + } + + static MiscSettings currentMiscSettings; + + public static MiscSettings CurrentMiscSettings { + get { + return currentMiscSettings ?? (currentMiscSettings = LoadMiscSettings(ILSpySettings.Load())); + } + } + + public static MiscSettings LoadMiscSettings(ILSpySettings settings) + { + XElement e = settings["MiscSettings"]; + var s = new MiscSettings(); + s.AllowMultipleInstances = (bool?)e.Attribute("AllowMultipleInstances") ?? false; + return s; } public void Save(XElement root) { - MiscSettings s = (MiscSettings)this.DataContext; - XElement section = new XElement("MiscSettings"); - section.SetAttributeValue("allowMultipleInstance", s.AllowMultipleInstances); + var s = (MiscSettings)this.DataContext; + + var section = new XElement("MiscSettings"); + section.SetAttributeValue("AllowMultipleInstances", s.AllowMultipleInstances); XElement existingElement = root.Element("MiscSettings"); if (existingElement != null) existingElement.ReplaceWith(section); else root.Add(section); + + currentMiscSettings = null; // invalidate cached settings } } }