Skip to content

Commit 10c3773

Browse files
Move more of the settings infrastructure to ILSpyX for reuse.
1 parent fa4108e commit 10c3773

File tree

11 files changed

+90
-61
lines changed

11 files changed

+90
-61
lines changed

ILSpy/Options/DecompilerSettings.cs renamed to ICSharpCode.ILSpyX/Settings/DecompilerSettings.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2024 Tom Englert for the SharpDevelop Team
1+
// Copyright (c) 2024 Tom Englert
22
//
33
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
44
// software and associated documentation files (the "Software"), to deal in the Software
@@ -21,9 +21,7 @@
2121
using System.Reflection;
2222
using System.Xml.Linq;
2323

24-
#nullable enable
25-
26-
namespace ICSharpCode.ILSpy.Options
24+
namespace ICSharpCode.ILSpyX.Settings
2725
{
2826
public class DecompilerSettings : Decompiler.DecompilerSettings, ISettingsSection
2927
{
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright (c) 2024 Tom Englert
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4+
// software and associated documentation files (the "Software"), to deal in the Software
5+
// without restriction, including without limitation the rights to use, copy, modify, merge,
6+
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7+
// to whom the Software is furnished to do so, subject to the following conditions:
8+
//
9+
// The above copyright notice and this permission notice shall be included in all copies or
10+
// substantial portions of the Software.
11+
//
12+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14+
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15+
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17+
// DEALINGS IN THE SOFTWARE.
18+
19+
using System;
20+
using System.Collections.Concurrent;
21+
using System.ComponentModel;
22+
using System.Xml.Linq;
23+
24+
namespace ICSharpCode.ILSpyX.Settings
25+
{
26+
public interface IChildSettings
27+
{
28+
ISettingsSection Parent { get; }
29+
}
30+
31+
public interface ISettingsSection : INotifyPropertyChanged
32+
{
33+
XName SectionName { get; }
34+
35+
void LoadFromXml(XElement section);
36+
37+
XElement SaveToXml();
38+
}
39+
40+
public class SettingsServiceBase(ISettingsProvider spySettings)
41+
{
42+
protected readonly ConcurrentDictionary<Type, ISettingsSection> sections = new();
43+
44+
protected ISettingsProvider SpySettings { get; set; } = spySettings;
45+
46+
public T GetSettings<T>() where T : ISettingsSection, new()
47+
{
48+
return (T)sections.GetOrAdd(typeof(T), _ => {
49+
T section = new T();
50+
51+
var sectionElement = SpySettings[section.SectionName];
52+
53+
section.LoadFromXml(sectionElement);
54+
section.PropertyChanged += Section_PropertyChanged;
55+
56+
return section;
57+
});
58+
}
59+
60+
protected static void SaveSection(ISettingsSection section, XElement root)
61+
{
62+
var element = section.SaveToXml();
63+
64+
var existingElement = root.Element(section.SectionName);
65+
if (existingElement != null)
66+
existingElement.ReplaceWith(element);
67+
else
68+
root.Add(element);
69+
}
70+
71+
protected virtual void Section_PropertyChanged(object? sender, PropertyChangedEventArgs e)
72+
{
73+
}
74+
}
75+
}

ILSpy.ReadyToRun/ReadyToRunOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
using System.Xml.Linq;
2020

21-
using ICSharpCode.ILSpy.Util;
21+
using ICSharpCode.ILSpyX.Settings;
2222

2323
using TomsToolbox.Wpf;
2424

ILSpy/DecompilationOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
using ICSharpCode.ILSpy.Options;
2424
using ICSharpCode.ILSpyX;
2525

26-
using DecompilerSettings = ICSharpCode.ILSpy.Options.DecompilerSettings;
26+
using DecompilerSettings = ICSharpCode.ILSpyX.Settings.DecompilerSettings;
2727

2828
namespace ICSharpCode.ILSpy
2929
{

ILSpy/LanguageSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using System.Xml.Linq;
2121

2222
using ICSharpCode.ILSpyX;
23+
using ICSharpCode.ILSpyX.Settings;
2324

2425
using TomsToolbox.Wpf;
2526

ILSpy/Options/DecompilerSettingsViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
using ICSharpCode.ILSpy.Properties;
2626
using ICSharpCode.ILSpy.TreeNodes;
27+
using ICSharpCode.ILSpyX.Settings;
2728

2829
using TomsToolbox.Wpf;
2930

ILSpy/Options/DisplaySettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
using System.Windows.Media;
2020
using System.Xml.Linq;
2121

22+
using ICSharpCode.ILSpyX.Settings;
23+
2224
using TomsToolbox.Wpf;
2325

2426
namespace ICSharpCode.ILSpy.Options

ILSpy/SessionSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
using ICSharpCode.ILSpy.Docking;
3131
using ICSharpCode.ILSpy.Themes;
3232
using ICSharpCode.ILSpyX.Search;
33+
using ICSharpCode.ILSpyX.Settings;
3334

3435
namespace ICSharpCode.ILSpy
3536
{

ILSpy/Updates/UpdateSettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
using System;
2020
using System.Xml.Linq;
2121

22+
using ICSharpCode.ILSpyX.Settings;
23+
2224
using TomsToolbox.Wpf;
2325

2426
namespace ICSharpCode.ILSpy.Updates

ILSpy/Util/SettingsService.cs

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -16,71 +16,18 @@
1616
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1717
// DEALINGS IN THE SOFTWARE.
1818

19-
using System;
20-
using System.Collections.Concurrent;
2119
using System.ComponentModel;
22-
using System.Xml.Linq;
2320

2421
using ICSharpCode.ILSpy.Options;
2522
using ICSharpCode.ILSpyX;
2623
using ICSharpCode.ILSpyX.Settings;
2724

28-
using DecompilerSettings = ICSharpCode.ILSpy.Options.DecompilerSettings;
25+
using DecompilerSettings = ICSharpCode.ILSpyX.Settings.DecompilerSettings;
2926

3027
#nullable enable
3128

3229
namespace ICSharpCode.ILSpy.Util
3330
{
34-
public interface IChildSettings
35-
{
36-
ISettingsSection Parent { get; }
37-
}
38-
39-
public interface ISettingsSection : INotifyPropertyChanged
40-
{
41-
XName SectionName { get; }
42-
43-
void LoadFromXml(XElement section);
44-
45-
XElement SaveToXml();
46-
}
47-
48-
public abstract class SettingsServiceBase(ISettingsProvider spySettings)
49-
{
50-
protected readonly ConcurrentDictionary<Type, ISettingsSection> sections = new();
51-
52-
protected ISettingsProvider SpySettings { get; set; } = spySettings;
53-
54-
public T GetSettings<T>() where T : ISettingsSection, new()
55-
{
56-
return (T)sections.GetOrAdd(typeof(T), _ => {
57-
T section = new T();
58-
59-
var sectionElement = SpySettings[section.SectionName];
60-
61-
section.LoadFromXml(sectionElement);
62-
section.PropertyChanged += Section_PropertyChanged;
63-
64-
return section;
65-
});
66-
}
67-
68-
protected static void SaveSection(ISettingsSection section, XElement root)
69-
{
70-
var element = section.SaveToXml();
71-
72-
var existingElement = root.Element(section.SectionName);
73-
if (existingElement != null)
74-
existingElement.ReplaceWith(element);
75-
else
76-
root.Add(element);
77-
}
78-
79-
protected virtual void Section_PropertyChanged(object? sender, PropertyChangedEventArgs e)
80-
{
81-
}
82-
}
83-
8431
public class SettingsSnapshot(SettingsService parent, ISettingsProvider spySettings) : SettingsServiceBase(spySettings)
8532
{
8633
public void Save()
@@ -173,7 +120,8 @@ protected override void Section_PropertyChanged(object? sender, PropertyChangedE
173120
SpySettings.Update(root => {
174121
SaveSection(section, root);
175122
});
176-
};
123+
}
124+
;
177125
}
178126

179127
if (sender is DecompilerSettings decompilerSettings && assemblyListManager != null)

0 commit comments

Comments
 (0)