Browse Source

Clean up MiscSettings and DisplaySettings

pull/863/head
Siegfried Pammer 8 years ago
parent
commit
a91bd2fb15
  1. 3
      ILSpy/App.xaml.cs
  2. 1
      ILSpy/ILSpy.csproj
  3. 26
      ILSpy/Options/DisplaySettings.cs
  4. 18
      ILSpy/Options/DisplaySettingsPanel.xaml.cs
  5. 40
      ILSpy/Options/MiscSettings.cs
  6. 47
      ILSpy/Options/MiscSettingsLoader.cs
  7. 47
      ILSpy/Options/MiscSettingsPanel.xaml.cs

3
ILSpy/App.xaml.cs

@ -58,9 +58,8 @@ namespace ICSharpCode.ILSpy
public App() public App()
{ {
var cmdArgs = Environment.GetCommandLineArgs().Skip(1); var cmdArgs = Environment.GetCommandLineArgs().Skip(1);
var allowMultipleInstance = MiscSettingsInstance.Current.LoadMiscSettings().AllowMultipleInstances;
App.CommandLineArguments = new CommandLineArguments(cmdArgs); App.CommandLineArguments = new CommandLineArguments(cmdArgs);
if ((App.CommandLineArguments.SingleInstance ?? true) && (!allowMultipleInstance)) { if ((App.CommandLineArguments.SingleInstance ?? true) && !MiscSettingsPanel.CurrentMiscSettings.AllowMultipleInstances) {
cmdArgs = cmdArgs.Select(FullyQualifyPath); cmdArgs = cmdArgs.Select(FullyQualifyPath);
string message = string.Join(Environment.NewLine, cmdArgs); string message = string.Join(Environment.NewLine, cmdArgs);
if (SendToPreviousInstance("ILSpy:\r\n" + message, !App.CommandLineArguments.NoActivate)) { if (SendToPreviousInstance("ILSpy:\r\n" + message, !App.CommandLineArguments.NoActivate)) {

1
ILSpy/ILSpy.csproj

@ -152,7 +152,6 @@
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Options\MiscSettings.cs" /> <Compile Include="Options\MiscSettings.cs" />
<Compile Include="Options\MiscSettingsLoader.cs" />
<Compile Include="Options\MiscSettingsPanel.xaml.cs"> <Compile Include="Options\MiscSettingsPanel.xaml.cs">
<DependentUpon>MiscSettingsPanel.xaml</DependentUpon> <DependentUpon>MiscSettingsPanel.xaml</DependentUpon>
</Compile> </Compile>

26
ILSpy/Options/DisplaySettings.cs

@ -17,6 +17,7 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System.ComponentModel; using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Media; using System.Windows.Media;
namespace ICSharpCode.ILSpy.Options namespace ICSharpCode.ILSpy.Options
@ -35,12 +36,10 @@ namespace ICSharpCode.ILSpy.Options
protected virtual void OnPropertyChanged(PropertyChangedEventArgs e) protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
{ {
if (PropertyChanged != null) { PropertyChanged?.Invoke(this, e);
PropertyChanged(this, e);
}
} }
protected void OnPropertyChanged(string propertyName) protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{ {
OnPropertyChanged(new PropertyChangedEventArgs(propertyName)); OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
} }
@ -53,7 +52,7 @@ namespace ICSharpCode.ILSpy.Options
set { set {
if (selectedFont != value) { if (selectedFont != value) {
selectedFont = value; selectedFont = value;
OnPropertyChanged("SelectedFont"); OnPropertyChanged();
} }
} }
} }
@ -65,7 +64,7 @@ namespace ICSharpCode.ILSpy.Options
set { set {
if (selectedFontSize != value) { if (selectedFontSize != value) {
selectedFontSize = value; selectedFontSize = value;
OnPropertyChanged("SelectedFontSize"); OnPropertyChanged();
} }
} }
} }
@ -77,7 +76,7 @@ namespace ICSharpCode.ILSpy.Options
set { set {
if (showLineNumbers != value) { if (showLineNumbers != value) {
showLineNumbers = value; showLineNumbers = value;
OnPropertyChanged("ShowLineNumbers"); OnPropertyChanged();
} }
} }
} }
@ -90,7 +89,7 @@ namespace ICSharpCode.ILSpy.Options
set { set {
if (showMetadataTokens != value) { if (showMetadataTokens != value) {
showMetadataTokens = value; showMetadataTokens = value;
OnPropertyChanged("ShowMetadataTokens"); OnPropertyChanged();
} }
} }
} }
@ -104,18 +103,9 @@ namespace ICSharpCode.ILSpy.Options
{ {
if (enableWordWrap != value) { if (enableWordWrap != value) {
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;
}
} }
} }

18
ILSpy/Options/DisplaySettingsPanel.xaml.cs

@ -87,16 +87,16 @@ namespace ICSharpCode.ILSpy.Options
static FontFamily[] FontLoader() static FontFamily[] FontLoader()
{ {
return Fonts.SystemFontFamilies return (from ff in Fonts.SystemFontFamilies
.Where(ff => !IsSymbolFont(ff)) where !IsSymbolFont(ff)
.OrderBy(ff => ff.Source) orderby ff.Source
.ToArray(); select ff).ToArray();
} }
public static DisplaySettings LoadDisplaySettings(ILSpySettings settings) public static DisplaySettings LoadDisplaySettings(ILSpySettings settings)
{ {
XElement e = settings["DisplaySettings"]; XElement e = settings["DisplaySettings"];
DisplaySettings s = new DisplaySettings(); var s = new DisplaySettings();
s.SelectedFont = new FontFamily((string)e.Attribute("Font") ?? "Consolas"); s.SelectedFont = new FontFamily((string)e.Attribute("Font") ?? "Consolas");
s.SelectedFontSize = (double?)e.Attribute("FontSize") ?? 10.0 * 4 / 3; s.SelectedFontSize = (double?)e.Attribute("FontSize") ?? 10.0 * 4 / 3;
s.ShowLineNumbers = (bool?)e.Attribute("ShowLineNumbers") ?? false; s.ShowLineNumbers = (bool?)e.Attribute("ShowLineNumbers") ?? false;
@ -108,11 +108,9 @@ namespace ICSharpCode.ILSpy.Options
public void Save(XElement root) public void Save(XElement root)
{ {
DisplaySettings s = (DisplaySettings)this.DataContext; var s = (DisplaySettings)this.DataContext;
currentDisplaySettings.CopyValues(s); var section = new XElement("DisplaySettings");
XElement section = new XElement("DisplaySettings");
section.SetAttributeValue("Font", s.SelectedFont.Source); section.SetAttributeValue("Font", s.SelectedFont.Source);
section.SetAttributeValue("FontSize", s.SelectedFontSize); section.SetAttributeValue("FontSize", s.SelectedFontSize);
section.SetAttributeValue("ShowLineNumbers", s.ShowLineNumbers); section.SetAttributeValue("ShowLineNumbers", s.ShowLineNumbers);
@ -124,6 +122,8 @@ namespace ICSharpCode.ILSpy.Options
existingElement.ReplaceWith(section); existingElement.ReplaceWith(section);
else else
root.Add(section); root.Add(section);
currentDisplaySettings = null; // invalidate cached settings
} }
} }

40
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 namespace ICSharpCode.ILSpy.Options
{ {
public class MiscSettings : INotifyPropertyChanged public class MiscSettings : INotifyPropertyChanged
{ {
bool allowMultipleInstances = false; bool allowMultipleInstances;
/// <summary> /// <summary>
/// Decompile anonymous methods/lambdas. /// Allow multiple instances.
/// </summary> /// </summary>
public bool AllowMultipleInstances public bool AllowMultipleInstances
{ {
get get { return allowMultipleInstances; }
{ set {
return allowMultipleInstances; if (allowMultipleInstances != value) {
}
set
{
if (allowMultipleInstances != value)
{
allowMultipleInstances = value; allowMultipleInstances = value;
OnPropertyChanged("AllowMultipleInstance"); OnPropertyChanged();
} }
} }
} }
@ -34,7 +48,7 @@ namespace ICSharpCode.ILSpy.Options
PropertyChanged?.Invoke(this, e); PropertyChanged?.Invoke(this, e);
} }
protected void OnPropertyChanged(string propertyName) protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{ {
OnPropertyChanged(new PropertyChangedEventArgs(propertyName)); OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
} }

47
ILSpy/Options/MiscSettingsLoader.cs

@ -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;
}
}
}
}

47
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; using System.Xml.Linq;
namespace ICSharpCode.ILSpy.Options namespace ICSharpCode.ILSpy.Options
@ -16,20 +34,39 @@ namespace ICSharpCode.ILSpy.Options
public void Load(ILSpySettings settings) 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) public void Save(XElement root)
{ {
MiscSettings s = (MiscSettings)this.DataContext; var s = (MiscSettings)this.DataContext;
XElement section = new XElement("MiscSettings");
section.SetAttributeValue("allowMultipleInstance", s.AllowMultipleInstances); var section = new XElement("MiscSettings");
section.SetAttributeValue("AllowMultipleInstances", s.AllowMultipleInstances);
XElement existingElement = root.Element("MiscSettings"); XElement existingElement = root.Element("MiscSettings");
if (existingElement != null) if (existingElement != null)
existingElement.ReplaceWith(section); existingElement.ReplaceWith(section);
else else
root.Add(section); root.Add(section);
currentMiscSettings = null; // invalidate cached settings
} }
} }
} }

Loading…
Cancel
Save