Browse Source

Fix some minor design flaws in new code.

pull/3274/head
tom-englert 9 months ago
parent
commit
da0117680b
  1. 2
      ILSpy.ReadyToRun/ReadyToRunOptionPage.xaml.cs
  2. 8
      ILSpy.ReadyToRun/ReadyToRunOptions.cs
  3. 2
      ILSpy/Commands/BrowseBackCommand.cs
  4. 2
      ILSpy/Commands/BrowseForwardCommand.cs
  5. 8
      ILSpy/Commands/CommandWrapper.cs
  6. 2
      ILSpy/Commands/OpenCommand.cs
  7. 2
      ILSpy/Commands/RefreshCommand.cs
  8. 2
      ILSpy/Commands/SaveCommand.cs
  9. 2
      ILSpy/Languages/Languages.cs
  10. 14
      ILSpy/Options/DecompilerSettings.cs
  11. 2
      ILSpy/Options/DecompilerSettingsViewModel.cs
  12. 8
      ILSpy/Options/DisplaySettings.cs
  13. 2
      ILSpy/Options/DisplaySettingsViewModel.cs
  14. 8
      ILSpy/Options/MiscSettings.cs
  15. 2
      ILSpy/Options/MiscSettingsViewModel.cs
  16. 2
      ILSpy/Search/SearchPane.xaml.cs
  17. 8
      ILSpy/SessionSettings.cs
  18. 12
      ILSpy/Util/SettingsService.cs
  19. 11
      TestPlugin/CustomOptionPage.xaml.cs

2
ILSpy.ReadyToRun/ReadyToRunOptionPage.xaml.cs

@ -56,7 +56,7 @@ namespace ICSharpCode.ILSpy.ReadyToRun
public void LoadDefaults() public void LoadDefaults()
{ {
Options.LoadFromSection(new("empty")); Options.LoadFromXml(new("empty"));
} }
} }
} }

8
ILSpy.ReadyToRun/ReadyToRunOptions.cs

@ -64,7 +64,7 @@ namespace ICSharpCode.ILSpy.ReadyToRun
public XName SectionName { get; } = ns + "ReadyToRunOptions"; public XName SectionName { get; } = ns + "ReadyToRunOptions";
public void LoadFromSection(XElement e) public void LoadFromXml(XElement e)
{ {
XAttribute format = e.Attribute("DisassemblyFormat"); XAttribute format = e.Attribute("DisassemblyFormat");
DisassemblyFormat = format == null ? intel : (string)format; DisassemblyFormat = format == null ? intel : (string)format;
@ -79,12 +79,16 @@ namespace ICSharpCode.ILSpy.ReadyToRun
IsShowGCInfo = showGc != null && (bool)showGc; IsShowGCInfo = showGc != null && (bool)showGc;
} }
public void SaveToSection(XElement section) public XElement SaveToXml()
{ {
var section = new XElement(SectionName);
section.SetAttributeValue("DisassemblyFormat", disassemblyFormat); section.SetAttributeValue("DisassemblyFormat", disassemblyFormat);
section.SetAttributeValue("IsShowUnwindInfo", isShowUnwindInfo); section.SetAttributeValue("IsShowUnwindInfo", isShowUnwindInfo);
section.SetAttributeValue("IsShowDebugInfo", isShowDebugInfo); section.SetAttributeValue("IsShowDebugInfo", isShowDebugInfo);
section.SetAttributeValue("IsShowGCInfo", isShowGCInfo); section.SetAttributeValue("IsShowGCInfo", isShowGCInfo);
return section;
} }
} }
} }

2
ILSpy/Commands/BrowseBackCommand.cs

@ -47,8 +47,6 @@ namespace ICSharpCode.ILSpy
protected override void OnExecute(object sender, ExecutedRoutedEventArgs e) protected override void OnExecute(object sender, ExecutedRoutedEventArgs e)
{ {
base.OnExecute(sender, e);
if (assemblyTreeModel.CanNavigateBack) if (assemblyTreeModel.CanNavigateBack)
{ {
e.Handled = true; e.Handled = true;

2
ILSpy/Commands/BrowseForwardCommand.cs

@ -47,8 +47,6 @@ namespace ICSharpCode.ILSpy
protected override void OnExecute(object sender, ExecutedRoutedEventArgs e) protected override void OnExecute(object sender, ExecutedRoutedEventArgs e)
{ {
base.OnExecute(sender, e);
if (assemblyTreeModel.CanNavigateForward) if (assemblyTreeModel.CanNavigateForward)
{ {
e.Handled = true; e.Handled = true;

8
ILSpy/Commands/CommandWrapper.cs

@ -22,11 +22,11 @@ using System.Windows.Input;
namespace ICSharpCode.ILSpy namespace ICSharpCode.ILSpy
{ {
class CommandWrapper : ICommand abstract class CommandWrapper : ICommand
{ {
private readonly ICommand wrappedCommand; private readonly ICommand wrappedCommand;
public CommandWrapper(ICommand wrappedCommand) protected CommandWrapper(ICommand wrappedCommand)
{ {
this.wrappedCommand = wrappedCommand; this.wrappedCommand = wrappedCommand;
@ -56,9 +56,7 @@ namespace ICSharpCode.ILSpy
return wrappedCommand.CanExecute(parameter); return wrappedCommand.CanExecute(parameter);
} }
protected virtual void OnExecute(object sender, ExecutedRoutedEventArgs e) protected abstract void OnExecute(object sender, ExecutedRoutedEventArgs e);
{
}
protected virtual void OnCanExecute(object sender, CanExecuteRoutedEventArgs e) protected virtual void OnCanExecute(object sender, CanExecuteRoutedEventArgs e)
{ {

2
ILSpy/Commands/OpenCommand.cs

@ -42,8 +42,6 @@ namespace ICSharpCode.ILSpy
protected override void OnExecute(object sender, ExecutedRoutedEventArgs e) protected override void OnExecute(object sender, ExecutedRoutedEventArgs e)
{ {
base.OnExecute(sender, e);
e.Handled = true; e.Handled = true;
OpenFileDialog dlg = new OpenFileDialog { OpenFileDialog dlg = new OpenFileDialog {
Filter = ".NET assemblies|*.dll;*.exe;*.winmd;*.wasm|Nuget Packages (*.nupkg)|*.nupkg|Portable Program Database (*.pdb)|*.pdb|All files|*.*", Filter = ".NET assemblies|*.dll;*.exe;*.winmd;*.wasm|Nuget Packages (*.nupkg)|*.nupkg|Portable Program Database (*.pdb)|*.pdb|All files|*.*",

2
ILSpy/Commands/RefreshCommand.cs

@ -40,8 +40,6 @@ namespace ICSharpCode.ILSpy
protected override void OnExecute(object sender, ExecutedRoutedEventArgs e) protected override void OnExecute(object sender, ExecutedRoutedEventArgs e)
{ {
base.OnExecute(sender, e);
assemblyTreeModel.Refresh(); assemblyTreeModel.Refresh();
} }
} }

2
ILSpy/Commands/SaveCommand.cs

@ -47,8 +47,6 @@ namespace ICSharpCode.ILSpy
protected override void OnExecute(object sender, ExecutedRoutedEventArgs e) protected override void OnExecute(object sender, ExecutedRoutedEventArgs e)
{ {
base.OnExecute(sender, e);
SaveCodeContextMenuEntry.Execute(assemblyTreeModel.SelectedNodes.ToList()); SaveCodeContextMenuEntry.Execute(assemblyTreeModel.SelectedNodes.ToList());
} }
} }

2
ILSpy/Languages/Languages.cs

@ -54,7 +54,7 @@ namespace ICSharpCode.ILSpy
return AllLanguages.FirstOrDefault(l => l.Name == name) ?? AllLanguages.First(); return AllLanguages.FirstOrDefault(l => l.Name == name) ?? AllLanguages.First();
} }
static ILLanguage ilLanguage; static ILLanguage? ilLanguage;
public static ILLanguage ILLanguage { public static ILLanguage ILLanguage {
get { get {

14
ILSpy/Options/DecompilerSettings.cs

@ -17,15 +17,19 @@ namespace ICSharpCode.ILSpy.Options
public XName SectionName => "DecompilerSettings"; public XName SectionName => "DecompilerSettings";
public void SaveToSection(XElement section) public XElement SaveToXml()
{ {
var section = new XElement(SectionName);
foreach (var p in properties) foreach (var p in properties)
{ {
section.SetAttributeValue(p.Name, p.GetValue(this)); section.SetAttributeValue(p.Name, p.GetValue(this));
} }
return section;
} }
public void LoadFromSection(XElement section) public void LoadFromXml(XElement section)
{ {
foreach (var p in properties) foreach (var p in properties)
{ {
@ -37,10 +41,10 @@ namespace ICSharpCode.ILSpy.Options
public new DecompilerSettings Clone() public new DecompilerSettings Clone()
{ {
var section = new XElement("DecompilerSettings"); var section = SaveToXml();
SaveToSection(section);
var newSettings = new DecompilerSettings(); var newSettings = new DecompilerSettings();
newSettings.LoadFromSection(section); newSettings.LoadFromXml(section);
return newSettings; return newSettings;
} }

2
ILSpy/Options/DecompilerSettingsViewModel.cs

@ -138,7 +138,7 @@ namespace ICSharpCode.ILSpy.Options
{ {
private bool isEnabled = property.GetValue(decompilerSettings) is true; private bool isEnabled = property.GetValue(decompilerSettings) is true;
public PropertyInfo Property { get; } = property; public PropertyInfo Property => property;
public bool IsEnabled { public bool IsEnabled {
get => isEnabled; get => isEnabled;

8
ILSpy/Options/DisplaySettings.cs

@ -150,7 +150,7 @@ namespace ICSharpCode.ILSpy.Options
public XName SectionName => "DisplaySettings"; public XName SectionName => "DisplaySettings";
public void LoadFromSection(XElement section) public void LoadFromXml(XElement section)
{ {
SelectedFont = new FontFamily((string)section.Attribute("Font") ?? "Consolas"); SelectedFont = new FontFamily((string)section.Attribute("Font") ?? "Consolas");
SelectedFontSize = (double?)section.Attribute("FontSize") ?? 10.0 * 4 / 3; SelectedFontSize = (double?)section.Attribute("FontSize") ?? 10.0 * 4 / 3;
@ -174,8 +174,10 @@ namespace ICSharpCode.ILSpy.Options
StyleWindowTitleBar = (bool?)section.Attribute("StyleWindowTitleBar") ?? false; StyleWindowTitleBar = (bool?)section.Attribute("StyleWindowTitleBar") ?? false;
} }
public void SaveToSection(XElement section) public XElement SaveToXml()
{ {
var section = new XElement(SectionName);
section.SetAttributeValue("Font", SelectedFont.Source); section.SetAttributeValue("Font", SelectedFont.Source);
section.SetAttributeValue("FontSize", SelectedFontSize); section.SetAttributeValue("FontSize", SelectedFontSize);
section.SetAttributeValue("ShowLineNumbers", ShowLineNumbers); section.SetAttributeValue("ShowLineNumbers", ShowLineNumbers);
@ -196,6 +198,8 @@ namespace ICSharpCode.ILSpy.Options
section.SetAttributeValue("UseNestedNamespaceNodes", UseNestedNamespaceNodes); section.SetAttributeValue("UseNestedNamespaceNodes", UseNestedNamespaceNodes);
section.SetAttributeValue("ShowRawOffsetsAndBytesBeforeInstruction", ShowRawOffsetsAndBytesBeforeInstruction); section.SetAttributeValue("ShowRawOffsetsAndBytesBeforeInstruction", ShowRawOffsetsAndBytesBeforeInstruction);
section.SetAttributeValue("StyleWindowTitleBar", StyleWindowTitleBar); section.SetAttributeValue("StyleWindowTitleBar", StyleWindowTitleBar);
return section;
} }
} }
} }

2
ILSpy/Options/DisplaySettingsViewModel.cs

@ -87,7 +87,7 @@ namespace ICSharpCode.ILSpy.Options
public void LoadDefaults() public void LoadDefaults()
{ {
Settings.LoadFromSection(new XElement("empty")); Settings.LoadFromXml(new XElement("empty"));
SessionSettings.Theme = ThemeManager.Current.DefaultTheme; SessionSettings.Theme = ThemeManager.Current.DefaultTheme;
} }
} }

8
ILSpy/Options/MiscSettings.cs

@ -40,16 +40,20 @@ namespace ICSharpCode.ILSpyX.Settings
public XName SectionName => "MiscSettings"; public XName SectionName => "MiscSettings";
public void LoadFromSection(XElement e) public void LoadFromXml(XElement e)
{ {
AllowMultipleInstances = (bool?)e.Attribute(nameof(AllowMultipleInstances)) ?? false; AllowMultipleInstances = (bool?)e.Attribute(nameof(AllowMultipleInstances)) ?? false;
LoadPreviousAssemblies = (bool?)e.Attribute(nameof(LoadPreviousAssemblies)) ?? true; LoadPreviousAssemblies = (bool?)e.Attribute(nameof(LoadPreviousAssemblies)) ?? true;
} }
public void SaveToSection(XElement section) public XElement SaveToXml()
{ {
var section = new XElement(SectionName);
section.SetAttributeValue(nameof(AllowMultipleInstances), AllowMultipleInstances); section.SetAttributeValue(nameof(AllowMultipleInstances), AllowMultipleInstances);
section.SetAttributeValue(nameof(LoadPreviousAssemblies), LoadPreviousAssemblies); section.SetAttributeValue(nameof(LoadPreviousAssemblies), LoadPreviousAssemblies);
return section;
} }
} }
} }

2
ILSpy/Options/MiscSettingsViewModel.cs

@ -98,7 +98,7 @@ namespace ICSharpCode.ILSpy.Options
public void LoadDefaults() public void LoadDefaults()
{ {
Settings.LoadFromSection(new XElement("dummy")); Settings.LoadFromXml(new XElement("dummy"));
} }
} }
} }

2
ILSpy/Search/SearchPane.xaml.cs

@ -550,8 +550,6 @@ namespace ICSharpCode.ILSpy.Search
protected override void OnExecute(object sender, ExecutedRoutedEventArgs e) protected override void OnExecute(object sender, ExecutedRoutedEventArgs e)
{ {
base.OnExecute(sender, e);
DockWorkspace.Instance.ShowToolPane(SearchPaneModel.PaneContentId); DockWorkspace.Instance.ShowToolPane(SearchPaneModel.PaneContentId);
} }
} }

8
ILSpy/SessionSettings.cs

@ -41,7 +41,7 @@ namespace ICSharpCode.ILSpy
{ {
public XName SectionName => "SessionSettings"; public XName SectionName => "SessionSettings";
public void LoadFromSection(XElement section) public void LoadFromXml(XElement section)
{ {
XElement filterSettings = section.Element("FilterSettings") ?? new XElement("FilterSettings"); XElement filterSettings = section.Element("FilterSettings") ?? new XElement("FilterSettings");
@ -103,9 +103,9 @@ namespace ICSharpCode.ILSpy
public DockLayoutSettings DockLayout { get; set; } public DockLayoutSettings DockLayout { get; set; }
public void SaveToSection(XElement section) public XElement SaveToXml()
{ {
section.RemoveAll(); var section = new XElement(SectionName);
section.Add(this.LanguageSettings.SaveAsXml()); section.Add(this.LanguageSettings.SaveAsXml());
if (this.ActiveAssemblyList != null) if (this.ActiveAssemblyList != null)
@ -134,6 +134,8 @@ namespace ICSharpCode.ILSpy
dockLayoutElement.Add(DockLayout.SaveAsXml()); dockLayoutElement.Add(DockLayout.SaveAsXml());
} }
section.Add(dockLayoutElement); section.Add(dockLayoutElement);
return section;
} }
static Regex regex = new("\\\\x(?<num>[0-9A-f]{4})"); static Regex regex = new("\\\\x(?<num>[0-9A-f]{4})");

12
ILSpy/Util/SettingsService.cs

@ -24,9 +24,9 @@ namespace ICSharpCode.ILSpy.Util
{ {
XName SectionName { get; } XName SectionName { get; }
void LoadFromSection(XElement section); void LoadFromXml(XElement section);
void SaveToSection(XElement section); XElement SaveToXml();
} }
public abstract class SettingsServiceBase public abstract class SettingsServiceBase
@ -47,7 +47,7 @@ namespace ICSharpCode.ILSpy.Util
var sectionElement = SpySettings[section.SectionName]; var sectionElement = SpySettings[section.SectionName];
section.LoadFromSection(sectionElement); section.LoadFromXml(sectionElement);
section.PropertyChanged += Section_PropertyChanged; section.PropertyChanged += Section_PropertyChanged;
return section; return section;
@ -56,9 +56,7 @@ namespace ICSharpCode.ILSpy.Util
protected void SaveSection(ISettingsSection section, XElement root) protected void SaveSection(ISettingsSection section, XElement root)
{ {
var element = SpySettings[section.SectionName]; var element = section.SaveToXml();
section.SaveToSection(element);
var existingElement = root.Element(section.SectionName); var existingElement = root.Element(section.SectionName);
if (existingElement != null) if (existingElement != null)
@ -150,7 +148,7 @@ namespace ICSharpCode.ILSpy.Util
{ {
var element = SpySettings[section.SectionName]; var element = SpySettings[section.SectionName];
section.LoadFromSection(element); section.LoadFromXml(element);
} }
} }
finally finally

11
TestPlugin/CustomOptionPage.xaml.cs

@ -23,6 +23,7 @@ namespace TestPlugin
} }
[ExportOptionPage(Order = 0)] [ExportOptionPage(Order = 0)]
[PartCreationPolicy(CreationPolicy.NonShared)]
class CustomOptionsViewModel : ObservableObject, IOptionPage class CustomOptionsViewModel : ObservableObject, IOptionPage
{ {
private Options options; private Options options;
@ -41,7 +42,7 @@ namespace TestPlugin
public void LoadDefaults() public void LoadDefaults()
{ {
Options.LoadFromSection(new XElement("dummy")); Options.LoadFromXml(new XElement("dummy"));
} }
} }
@ -65,16 +66,20 @@ namespace TestPlugin
public XName SectionName { get; } = ns + "CustomOptions"; public XName SectionName { get; } = ns + "CustomOptions";
public void LoadFromSection(XElement e) public void LoadFromXml(XElement e)
{ {
UselessOption1 = (bool?)e.Attribute("useless1") ?? false; UselessOption1 = (bool?)e.Attribute("useless1") ?? false;
UselessOption2 = (double?)e.Attribute("useless2") ?? 50.0; UselessOption2 = (double?)e.Attribute("useless2") ?? 50.0;
} }
public void SaveToSection(XElement section) public XElement SaveToXml()
{ {
var section = new XElement(SectionName);
section.SetAttributeValue("useless1", UselessOption1); section.SetAttributeValue("useless1", UselessOption1);
section.SetAttributeValue("useless2", UselessOption2); section.SetAttributeValue("useless2", UselessOption2);
return section;
} }
} }
} }
Loading…
Cancel
Save