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

8
ILSpy.ReadyToRun/ReadyToRunOptions.cs

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

2
ILSpy/Commands/BrowseBackCommand.cs

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

2
ILSpy/Commands/BrowseForwardCommand.cs

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

8
ILSpy/Commands/CommandWrapper.cs

@ -22,11 +22,11 @@ using System.Windows.Input; @@ -22,11 +22,11 @@ using System.Windows.Input;
namespace ICSharpCode.ILSpy
{
class CommandWrapper : ICommand
abstract class CommandWrapper : ICommand
{
private readonly ICommand wrappedCommand;
public CommandWrapper(ICommand wrappedCommand)
protected CommandWrapper(ICommand wrappedCommand)
{
this.wrappedCommand = wrappedCommand;
@ -56,9 +56,7 @@ namespace ICSharpCode.ILSpy @@ -56,9 +56,7 @@ namespace ICSharpCode.ILSpy
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)
{

2
ILSpy/Commands/OpenCommand.cs

@ -42,8 +42,6 @@ namespace ICSharpCode.ILSpy @@ -42,8 +42,6 @@ namespace ICSharpCode.ILSpy
protected override void OnExecute(object sender, ExecutedRoutedEventArgs e)
{
base.OnExecute(sender, e);
e.Handled = true;
OpenFileDialog dlg = new OpenFileDialog {
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 @@ -40,8 +40,6 @@ namespace ICSharpCode.ILSpy
protected override void OnExecute(object sender, ExecutedRoutedEventArgs e)
{
base.OnExecute(sender, e);
assemblyTreeModel.Refresh();
}
}

2
ILSpy/Commands/SaveCommand.cs

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

2
ILSpy/Languages/Languages.cs

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

14
ILSpy/Options/DecompilerSettings.cs

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

2
ILSpy/Options/DecompilerSettingsViewModel.cs

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

8
ILSpy/Options/DisplaySettings.cs

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

2
ILSpy/Options/DisplaySettingsViewModel.cs

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

8
ILSpy/Options/MiscSettings.cs

@ -40,16 +40,20 @@ namespace ICSharpCode.ILSpyX.Settings @@ -40,16 +40,20 @@ namespace ICSharpCode.ILSpyX.Settings
public XName SectionName => "MiscSettings";
public void LoadFromSection(XElement e)
public void LoadFromXml(XElement e)
{
AllowMultipleInstances = (bool?)e.Attribute(nameof(AllowMultipleInstances)) ?? false;
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(LoadPreviousAssemblies), LoadPreviousAssemblies);
return section;
}
}
}

2
ILSpy/Options/MiscSettingsViewModel.cs

@ -98,7 +98,7 @@ namespace ICSharpCode.ILSpy.Options @@ -98,7 +98,7 @@ namespace ICSharpCode.ILSpy.Options
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 @@ -550,8 +550,6 @@ namespace ICSharpCode.ILSpy.Search
protected override void OnExecute(object sender, ExecutedRoutedEventArgs e)
{
base.OnExecute(sender, e);
DockWorkspace.Instance.ShowToolPane(SearchPaneModel.PaneContentId);
}
}

8
ILSpy/SessionSettings.cs

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

12
ILSpy/Util/SettingsService.cs

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

11
TestPlugin/CustomOptionPage.xaml.cs

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