Browse Source

refactor DisplaySettings to MVVM model first design

pull/3274/head
tom-englert 1 year ago committed by tom-englert
parent
commit
7c9f377457
  1. 328
      ILSpy/Options/DisplaySettings.cs
  2. 73
      ILSpy/Options/DisplaySettingsPanel.xaml
  3. 166
      ILSpy/Options/DisplaySettingsPanel.xaml.cs
  4. 90
      ILSpy/Options/DisplaySettingsViewModel.cs
  5. 2
      ILSpy/Util/SettingsService.cs

328
ILSpy/Options/DisplaySettings.cs

@ -16,18 +16,20 @@ @@ -16,18 +16,20 @@
// 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;
using System.Windows.Media;
using System.Xml.Linq;
using ICSharpCode.ILSpy.Themes;
using ICSharpCode.ILSpyX.Settings;
using TomsToolbox.Wpf;
namespace ICSharpCode.ILSpy.Options
{
/// <summary>
/// Description of DisplaySettings.
/// </summary>
public class DisplaySettings : INotifyPropertyChanged
public class DisplaySettings : ObservableObject
{
public DisplaySettings()
{
@ -41,291 +43,151 @@ namespace ICSharpCode.ILSpy.Options @@ -41,291 +43,151 @@ namespace ICSharpCode.ILSpy.Options
this.highlightMatchingBraces = true;
}
#region INotifyPropertyChanged implementation
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
{
PropertyChanged?.Invoke(this, e);
}
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
}
#endregion
string theme;
public string Theme {
get { return theme; }
set {
if (theme != value)
{
theme = value;
OnPropertyChanged();
}
}
get => theme;
set => SetProperty(ref theme, value);
}
FontFamily selectedFont;
public FontFamily SelectedFont {
get { return selectedFont; }
set {
if (selectedFont != value)
{
selectedFont = value;
OnPropertyChanged();
}
}
get => selectedFont;
set => SetProperty(ref selectedFont, value);
}
double selectedFontSize;
public double SelectedFontSize {
get { return selectedFontSize; }
set {
if (selectedFontSize != value)
{
selectedFontSize = value;
OnPropertyChanged();
}
}
get => selectedFontSize;
set => SetProperty(ref selectedFontSize, value);
}
bool showLineNumbers;
public bool ShowLineNumbers {
get { return showLineNumbers; }
set {
if (showLineNumbers != value)
{
showLineNumbers = value;
OnPropertyChanged();
}
}
get => showLineNumbers;
set => SetProperty(ref showLineNumbers, value);
}
bool showMetadataTokens;
public bool ShowMetadataTokens {
get { return showMetadataTokens; }
set {
if (showMetadataTokens != value)
{
showMetadataTokens = value;
OnPropertyChanged();
}
}
get => showMetadataTokens;
set => SetProperty(ref showMetadataTokens, value);
}
bool showMetadataTokensInBase10;
public bool ShowMetadataTokensInBase10 {
get { return showMetadataTokensInBase10; }
set {
if (showMetadataTokensInBase10 != value)
{
showMetadataTokensInBase10 = value;
OnPropertyChanged();
}
}
get => showMetadataTokensInBase10;
set => SetProperty(ref showMetadataTokensInBase10, value);
}
bool enableWordWrap;
public bool EnableWordWrap {
get { return enableWordWrap; }
set {
if (enableWordWrap != value)
{
enableWordWrap = value;
OnPropertyChanged();
}
}
get => enableWordWrap;
set => SetProperty(ref enableWordWrap, value);
}
bool sortResults = true;
bool sortResults;
public bool SortResults {
get { return sortResults; }
set {
if (sortResults != value)
{
sortResults = value;
OnPropertyChanged();
}
}
get => sortResults;
set => SetProperty(ref sortResults, value);
}
bool foldBraces = false;
bool foldBraces;
public bool FoldBraces {
get { return foldBraces; }
set {
if (foldBraces != value)
{
foldBraces = value;
OnPropertyChanged();
}
}
get => foldBraces;
set => SetProperty(ref foldBraces, value);
}
bool expandMemberDefinitions = false;
bool expandMemberDefinitions;
public bool ExpandMemberDefinitions {
get { return expandMemberDefinitions; }
set {
if (expandMemberDefinitions != value)
{
expandMemberDefinitions = value;
OnPropertyChanged();
}
}
get => expandMemberDefinitions;
set => SetProperty(ref expandMemberDefinitions, value);
}
bool expandUsingDeclarations = false;
bool expandUsingDeclarations;
public bool ExpandUsingDeclarations {
get { return expandUsingDeclarations; }
set {
if (expandUsingDeclarations != value)
{
expandUsingDeclarations = value;
OnPropertyChanged();
}
}
get => expandUsingDeclarations;
set => SetProperty(ref expandUsingDeclarations, value);
}
bool showDebugInfo;
public bool ShowDebugInfo {
get { return showDebugInfo; }
set {
if (showDebugInfo != value)
{
showDebugInfo = value;
OnPropertyChanged();
}
}
get => showDebugInfo;
set => SetProperty(ref showDebugInfo, value);
}
bool indentationUseTabs = true;
bool indentationUseTabs;
public bool IndentationUseTabs {
get { return indentationUseTabs; }
set {
if (indentationUseTabs != value)
{
indentationUseTabs = value;
OnPropertyChanged();
}
}
get => indentationUseTabs;
set => SetProperty(ref indentationUseTabs, value);
}
int indentationTabSize = 4;
int indentationTabSize;
public int IndentationTabSize {
get { return indentationTabSize; }
set {
if (indentationTabSize != value)
{
indentationTabSize = value;
OnPropertyChanged();
}
}
get => indentationTabSize;
set => SetProperty(ref indentationTabSize, value);
}
int indentationSize = 4;
int indentationSize;
public int IndentationSize {
get { return indentationSize; }
set {
if (indentationSize != value)
{
indentationSize = value;
OnPropertyChanged();
}
}
get => indentationSize;
set => SetProperty(ref indentationSize, value);
}
bool highlightMatchingBraces = true;
bool highlightMatchingBraces;
public bool HighlightMatchingBraces {
get { return highlightMatchingBraces; }
set {
if (highlightMatchingBraces != value)
{
highlightMatchingBraces = value;
OnPropertyChanged();
}
}
get => highlightMatchingBraces;
set => SetProperty(ref highlightMatchingBraces, value);
}
bool highlightCurrentLine = false;
bool highlightCurrentLine;
public bool HighlightCurrentLine {
get { return highlightCurrentLine; }
set {
if (highlightCurrentLine != value)
{
highlightCurrentLine = value;
OnPropertyChanged();
}
}
get => highlightCurrentLine;
set => SetProperty(ref highlightCurrentLine, value);
}
bool hideEmptyMetadataTables = true;
bool hideEmptyMetadataTables;
public bool HideEmptyMetadataTables {
get { return hideEmptyMetadataTables; }
set {
if (hideEmptyMetadataTables != value)
{
hideEmptyMetadataTables = value;
OnPropertyChanged();
}
}
get => hideEmptyMetadataTables;
set => SetProperty(ref hideEmptyMetadataTables, value);
}
bool useNestedNamespaceNodes = true;
bool useNestedNamespaceNodes;
public bool UseNestedNamespaceNodes {
get { return useNestedNamespaceNodes; }
set {
if (useNestedNamespaceNodes != value)
{
useNestedNamespaceNodes = value;
OnPropertyChanged();
}
}
get => useNestedNamespaceNodes;
set => SetProperty(ref useNestedNamespaceNodes, value);
}
private bool styleWindowTitleBar;
public bool StyleWindowTitleBar {
get { return styleWindowTitleBar; }
set {
if (styleWindowTitleBar != value)
{
styleWindowTitleBar = value;
OnPropertyChanged();
}
}
get => styleWindowTitleBar;
set => SetProperty(ref styleWindowTitleBar, value);
}
private bool showRawOffsetsAndBytesBeforeInstruction;
public bool ShowRawOffsetsAndBytesBeforeInstruction {
get { return showRawOffsetsAndBytesBeforeInstruction; }
set {
if (showRawOffsetsAndBytesBeforeInstruction != value)
{
showRawOffsetsAndBytesBeforeInstruction = value;
OnPropertyChanged();
}
}
get => showRawOffsetsAndBytesBeforeInstruction;
set => SetProperty(ref showRawOffsetsAndBytesBeforeInstruction, value);
}
public void CopyValues(DisplaySettings s)
@ -352,5 +214,79 @@ namespace ICSharpCode.ILSpy.Options @@ -352,5 +214,79 @@ namespace ICSharpCode.ILSpy.Options
this.ShowRawOffsetsAndBytesBeforeInstruction = s.showRawOffsetsAndBytesBeforeInstruction;
this.StyleWindowTitleBar = s.styleWindowTitleBar;
}
public static DisplaySettings Load(ILSpySettings settings, SessionSettings sessionSettings = null)
{
XElement e = settings["DisplaySettings"];
var s = new DisplaySettings {
SelectedFont = new FontFamily((string)e.Attribute("Font") ?? "Consolas"),
SelectedFontSize = (double?)e.Attribute("FontSize") ?? 10.0 * 4 / 3,
ShowLineNumbers = (bool?)e.Attribute("ShowLineNumbers") ?? false,
ShowMetadataTokens = (bool?)e.Attribute("ShowMetadataTokens") ?? false,
ShowMetadataTokensInBase10 = (bool?)e.Attribute("ShowMetadataTokensInBase10") ?? false,
ShowDebugInfo = (bool?)e.Attribute("ShowDebugInfo") ?? false,
EnableWordWrap = (bool?)e.Attribute("EnableWordWrap") ?? false,
SortResults = (bool?)e.Attribute("SortResults") ?? true,
FoldBraces = (bool?)e.Attribute("FoldBraces") ?? false,
ExpandMemberDefinitions = (bool?)e.Attribute("ExpandMemberDefinitions") ?? false,
ExpandUsingDeclarations = (bool?)e.Attribute("ExpandUsingDeclarations") ?? false,
IndentationUseTabs = (bool?)e.Attribute("IndentationUseTabs") ?? true,
IndentationSize = (int?)e.Attribute("IndentationSize") ?? 4,
IndentationTabSize = (int?)e.Attribute("IndentationTabSize") ?? 4,
HighlightMatchingBraces = (bool?)e.Attribute("HighlightMatchingBraces") ?? true,
HighlightCurrentLine = (bool?)e.Attribute("HighlightCurrentLine") ?? false,
HideEmptyMetadataTables = (bool?)e.Attribute("HideEmptyMetadataTables") ?? true,
UseNestedNamespaceNodes = (bool?)e.Attribute("UseNestedNamespaceNodes") ?? false,
ShowRawOffsetsAndBytesBeforeInstruction = (bool?)e.Attribute("ShowRawOffsetsAndBytesBeforeInstruction") ?? false,
StyleWindowTitleBar = (bool?)e.Attribute("StyleWindowTitleBar") ?? false,
Theme = (sessionSettings ?? SettingsService.Instance.SessionSettings).Theme
};
return s;
}
public void Save(XElement root)
{
var s = this;
var section = new XElement("DisplaySettings");
section.SetAttributeValue("Font", s.SelectedFont.Source);
section.SetAttributeValue("FontSize", s.SelectedFontSize);
section.SetAttributeValue("ShowLineNumbers", s.ShowLineNumbers);
section.SetAttributeValue("ShowMetadataTokens", s.ShowMetadataTokens);
section.SetAttributeValue("ShowMetadataTokensInBase10", s.ShowMetadataTokensInBase10);
section.SetAttributeValue("ShowDebugInfo", s.ShowDebugInfo);
section.SetAttributeValue("EnableWordWrap", s.EnableWordWrap);
section.SetAttributeValue("SortResults", s.SortResults);
section.SetAttributeValue("FoldBraces", s.FoldBraces);
section.SetAttributeValue("ExpandMemberDefinitions", s.ExpandMemberDefinitions);
section.SetAttributeValue("ExpandUsingDeclarations", s.ExpandUsingDeclarations);
section.SetAttributeValue("IndentationUseTabs", s.IndentationUseTabs);
section.SetAttributeValue("IndentationSize", s.IndentationSize);
section.SetAttributeValue("IndentationTabSize", s.IndentationTabSize);
section.SetAttributeValue("HighlightMatchingBraces", s.HighlightMatchingBraces);
section.SetAttributeValue("HighlightCurrentLine", s.HighlightCurrentLine);
section.SetAttributeValue("HideEmptyMetadataTables", s.HideEmptyMetadataTables);
section.SetAttributeValue("UseNestedNamespaceNodes", s.UseNestedNamespaceNodes);
section.SetAttributeValue("ShowRawOffsetsAndBytesBeforeInstruction", s.ShowRawOffsetsAndBytesBeforeInstruction);
section.SetAttributeValue("StyleWindowTitleBar", s.StyleWindowTitleBar);
SettingsService.Instance.SessionSettings.Theme = s.Theme;
var sessionSettings = SettingsService.Instance.SessionSettings.ToXml();
SettingsService.Instance.DisplaySettings.CopyValues(s);
Update(section);
Update(sessionSettings);
void Update(XElement element)
{
var existingElement = root.Element(element.Name);
if (existingElement != null)
existingElement.ReplaceWith(element);
else
root.Add(element);
}
}
}
}

73
ILSpy/Options/DisplaySettingsPanel.xaml

@ -7,15 +7,12 @@ @@ -7,15 +7,12 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:themes="clr-namespace:ICSharpCode.ILSpy.Themes"
d:DataContext="{d:DesignInstance local:DisplaySettings}">
<UserControl.Resources>
<local:FontSizeConverter x:Key="fontSizeConv" />
</UserControl.Resources>
d:DataContext="{d:DesignInstance local:DisplaySettingsViewModel}">
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<StackPanel Orientation="Vertical">
<DockPanel>
<Label DockPanel.Dock="Left" Content="{x:Static properties:Resources.DisplaySettingsPanel_Theme}" />
<ComboBox ItemsSource="{x:Static themes:ThemeManager.AllThemes}" SelectedItem="{Binding Theme}" VerticalContentAlignment="Center" Margin="0,0,8,0" />
<ComboBox ItemsSource="{x:Static themes:ThemeManager.AllThemes}" SelectedItem="{Binding Settings.Theme}" VerticalContentAlignment="Center" Margin="0,0,8,0" />
</DockPanel>
<GroupBox Header="{x:Static properties:Resources.Font}">
<Grid>
@ -30,78 +27,58 @@ @@ -30,78 +27,58 @@
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<Label Margin="3,0" Content="{x:Static properties:Resources.DisplaySettingsPanel_Font}"></Label>
<ComboBox x:Name="fontSelector" VerticalContentAlignment="Center" SelectedItem="{Binding SelectedFont}" Grid.Column="1">
<ComboBox Grid.Row="0" ItemsSource="{Binding FontFamilies}" VerticalContentAlignment="Center" SelectedItem="{Binding Settings.SelectedFont}" Grid.Column="1">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Source}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<Label Grid.Column="2" Margin="3,0" Content="{x:Static properties:Resources.Size}"></Label>
<ComboBox Grid.Column="3" Text="{Binding SelectedFontSize, Converter={StaticResource fontSizeConv}}" IsEditable="True" Margin="3,0">
<system:Int32>6</system:Int32>
<system:Int32>7</system:Int32>
<system:Int32>8</system:Int32>
<system:Int32>9</system:Int32>
<system:Int32>10</system:Int32>
<system:Int32>11</system:Int32>
<system:Int32>12</system:Int32>
<system:Int32>13</system:Int32>
<system:Int32>14</system:Int32>
<system:Int32>15</system:Int32>
<system:Int32>16</system:Int32>
<system:Int32>17</system:Int32>
<system:Int32>18</system:Int32>
<system:Int32>19</system:Int32>
<system:Int32>20</system:Int32>
<system:Int32>21</system:Int32>
<system:Int32>22</system:Int32>
<system:Int32>23</system:Int32>
<system:Int32>24</system:Int32>
</ComboBox>
<Border Grid.Row="1" Grid.ColumnSpan="4" BorderBrush="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" BorderThickness="1" Margin="3,5">
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="AaBbCcXxYyZz" FontFamily="{Binding SelectedFont}" FontSize="{Binding SelectedFontSize}" />
<Label Grid.Row="0" Grid.Column="2" Margin="3,0" Content="{x:Static properties:Resources.Size}"></Label>
<ComboBox Grid.Row="0" Grid.Column="3" ItemsSource="{Binding FontSizes}" Text="{Binding Settings.SelectedFontSize, Converter={local:FontSizeConverter}}" IsEditable="True" Margin="3,0" />
<Border Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="4" BorderBrush="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" BorderThickness="1" Margin="3,5">
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="AaBbCcXxYyZz" FontFamily="{Binding Settings.SelectedFont}" FontSize="{Binding Settings.SelectedFontSize}" />
</Border>
</Grid>
</GroupBox>
<GroupBox Header="{x:Static properties:Resources.Indentation}">
<StackPanel Margin="3">
<CheckBox IsChecked="{Binding IndentationUseTabs}" Content="{x:Static properties:Resources.UseTabsInsteadOfSpaces}"></CheckBox>
<CheckBox IsChecked="{Binding Settings.IndentationUseTabs}" Content="{x:Static properties:Resources.UseTabsInsteadOfSpaces}"></CheckBox>
<StackPanel Orientation="Horizontal">
<Label Content="{x:Static properties:Resources.TabSize}"></Label>
<TextBox x:Name="tabSizeTextBox" Width="50" Margin="3" Text="{Binding IndentationTabSize}" PreviewTextInput="TextBox_PreviewTextInput" />
<TextBox x:Name="tabSizeTextBox" Width="50" Margin="3" Text="{Binding Settings.IndentationTabSize}" PreviewTextInput="TextBox_PreviewTextInput" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Content="{x:Static properties:Resources.IndentSize}"></Label>
<TextBox x:Name="indentSizeTextBox" Width="50" Margin="3" Text="{Binding IndentationSize}" PreviewTextInput="TextBox_PreviewTextInput" />
<TextBox x:Name="indentSizeTextBox" Width="50" Margin="3" Text="{Binding Settings.IndentationSize}" PreviewTextInput="TextBox_PreviewTextInput" />
</StackPanel>
</StackPanel>
</GroupBox>
<GroupBox Header="{x:Static properties:Resources.DecompilationViewOptions}">
<StackPanel Margin="3">
<CheckBox IsChecked="{Binding ShowLineNumbers}" Content="{x:Static properties:Resources.ShowLineNumbers}"></CheckBox>
<CheckBox IsChecked="{Binding EnableWordWrap}" Content="{x:Static properties:Resources.EnableWordWrap}"></CheckBox>
<CheckBox IsChecked="{Binding FoldBraces}" Content="{x:Static properties:Resources.EnableFoldingBlocksBraces}"></CheckBox>
<CheckBox IsChecked="{Binding HighlightMatchingBraces}" Content="{x:Static properties:Resources.HighlightMatchingBraces}"></CheckBox>
<CheckBox IsChecked="{Binding HighlightCurrentLine}" Content="{x:Static properties:Resources.HighlightCurrentLine}"></CheckBox>
<CheckBox IsChecked="{Binding ExpandMemberDefinitions}" Content="{x:Static properties:Resources.ExpandMemberDefinitionsAfterDecompilation}"></CheckBox>
<CheckBox IsChecked="{Binding ExpandUsingDeclarations}" Content="{x:Static properties:Resources.ExpandUsingDeclarationsAfterDecompilation}"></CheckBox>
<CheckBox IsChecked="{Binding ShowDebugInfo}" Content="{x:Static properties:Resources.ShowInfoFromDebugSymbolsAvailable}"></CheckBox>
<CheckBox IsChecked="{Binding ShowRawOffsetsAndBytesBeforeInstruction}" Content="{x:Static properties:Resources.ShowRawOffsetsAndBytesBeforeInstruction}"></CheckBox>
<CheckBox IsChecked="{Binding Settings.ShowLineNumbers}" Content="{x:Static properties:Resources.ShowLineNumbers}"></CheckBox>
<CheckBox IsChecked="{Binding Settings.EnableWordWrap}" Content="{x:Static properties:Resources.EnableWordWrap}"></CheckBox>
<CheckBox IsChecked="{Binding Settings.FoldBraces}" Content="{x:Static properties:Resources.EnableFoldingBlocksBraces}"></CheckBox>
<CheckBox IsChecked="{Binding Settings.HighlightMatchingBraces}" Content="{x:Static properties:Resources.HighlightMatchingBraces}"></CheckBox>
<CheckBox IsChecked="{Binding Settings.HighlightCurrentLine}" Content="{x:Static properties:Resources.HighlightCurrentLine}"></CheckBox>
<CheckBox IsChecked="{Binding Settings.ExpandMemberDefinitions}" Content="{x:Static properties:Resources.ExpandMemberDefinitionsAfterDecompilation}"></CheckBox>
<CheckBox IsChecked="{Binding Settings.ExpandUsingDeclarations}" Content="{x:Static properties:Resources.ExpandUsingDeclarationsAfterDecompilation}"></CheckBox>
<CheckBox IsChecked="{Binding Settings.ShowDebugInfo}" Content="{x:Static properties:Resources.ShowInfoFromDebugSymbolsAvailable}"></CheckBox>
<CheckBox IsChecked="{Binding Settings.ShowRawOffsetsAndBytesBeforeInstruction}" Content="{x:Static properties:Resources.ShowRawOffsetsAndBytesBeforeInstruction}"></CheckBox>
</StackPanel>
</GroupBox>
<GroupBox Header="{x:Static properties:Resources.TreeViewOptions}">
<StackPanel Margin="3">
<CheckBox IsChecked="{Binding ShowMetadataTokens}" Content="{x:Static properties:Resources.ShowMetadataTokens}"></CheckBox>
<CheckBox IsChecked="{Binding ShowMetadataTokensInBase10}" Content="{x:Static properties:Resources.ShowMetadataTokensInBase10}"></CheckBox>
<CheckBox IsChecked="{Binding HideEmptyMetadataTables}" Content="{x:Static properties:Resources.HideEmptyMetadataTables}"></CheckBox>
<CheckBox IsChecked="{Binding UseNestedNamespaceNodes}" Content="{x:Static properties:Resources.UseNestedNamespaceNodes}"></CheckBox>
<CheckBox IsChecked="{Binding Settings.ShowMetadataTokens}" Content="{x:Static properties:Resources.ShowMetadataTokens}"></CheckBox>
<CheckBox IsChecked="{Binding Settings.ShowMetadataTokensInBase10}" Content="{x:Static properties:Resources.ShowMetadataTokensInBase10}"></CheckBox>
<CheckBox IsChecked="{Binding Settings.HideEmptyMetadataTables}" Content="{x:Static properties:Resources.HideEmptyMetadataTables}"></CheckBox>
<CheckBox IsChecked="{Binding Settings.UseNestedNamespaceNodes}" Content="{x:Static properties:Resources.UseNestedNamespaceNodes}"></CheckBox>
</StackPanel>
</GroupBox>
<GroupBox Header="{x:Static properties:Resources.OtherOptions}">
<StackPanel Margin="3">
<CheckBox IsChecked="{Binding SortResults}" Content="{x:Static properties:Resources.SortResultsFitness}"></CheckBox>
<CheckBox IsChecked="{Binding StyleWindowTitleBar}" Content="{x:Static properties:Resources.StyleTheWindowTitleBar}"></CheckBox>
<CheckBox IsChecked="{Binding Settings.SortResults}" Content="{x:Static properties:Resources.SortResultsFitness}"></CheckBox>
<CheckBox IsChecked="{Binding Settings.StyleWindowTitleBar}" Content="{x:Static properties:Resources.StyleTheWindowTitleBar}"></CheckBox>
</StackPanel>
</GroupBox>
</StackPanel>

166
ILSpy/Options/DisplaySettingsPanel.xaml.cs

@ -29,14 +29,17 @@ using System.Xml.Linq; @@ -29,14 +29,17 @@ using System.Xml.Linq;
using ICSharpCode.ILSpyX.Settings;
using TomsToolbox.Wpf.Composition.Mef;
using TomsToolbox.Wpf.Converters;
namespace ICSharpCode.ILSpy.Options
{
/// <summary>
/// Interaction logic for DisplaySettingsPanel.xaml
/// </summary>
[ExportOptionPage(Order = 20)]
[PartCreationPolicy(CreationPolicy.NonShared)]
public partial class DisplaySettingsPanel : UserControl, IOptionPage
[DataTemplate(typeof(DisplaySettingsViewModel))]
public partial class DisplaySettingsPanel
{
public DisplaySettingsPanel()
{
@ -44,134 +47,6 @@ namespace ICSharpCode.ILSpy.Options @@ -44,134 +47,6 @@ namespace ICSharpCode.ILSpy.Options
DataObject.AddPastingHandler(tabSizeTextBox, OnPaste);
DataObject.AddPastingHandler(indentSizeTextBox, OnPaste);
Task<FontFamily[]> task = new Task<FontFamily[]>(FontLoader);
task.Start();
task.ContinueWith(
delegate (Task continuation) {
App.Current.Dispatcher.Invoke(
DispatcherPriority.Normal,
(Action)(
() => {
fontSelector.ItemsSource = task.Result;
if (continuation.Exception != null)
{
foreach (var ex in continuation.Exception.InnerExceptions)
{
MessageBox.Show(ex.ToString());
}
}
})
);
}
);
}
public string Title => Properties.Resources.Display;
public void Load(ILSpySettings spySettings)
{
this.DataContext = LoadDisplaySettings(spySettings);
}
static bool IsSymbolFont(FontFamily fontFamily)
{
foreach (var tf in fontFamily.GetTypefaces())
{
GlyphTypeface glyph;
try
{
if (tf.TryGetGlyphTypeface(out glyph))
return glyph.Symbol;
}
catch (Exception)
{
return true;
}
}
return false;
}
static FontFamily[] FontLoader()
{
return (from ff in Fonts.SystemFontFamilies
where !IsSymbolFont(ff)
orderby ff.Source
select ff).ToArray();
}
public static DisplaySettings LoadDisplaySettings(ILSpySettings settings, SessionSettings sessionSettings = null)
{
XElement e = settings["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;
s.ShowMetadataTokens = (bool?)e.Attribute("ShowMetadataTokens") ?? false;
s.ShowMetadataTokensInBase10 = (bool?)e.Attribute("ShowMetadataTokensInBase10") ?? false;
s.ShowDebugInfo = (bool?)e.Attribute("ShowDebugInfo") ?? false;
s.EnableWordWrap = (bool?)e.Attribute("EnableWordWrap") ?? false;
s.SortResults = (bool?)e.Attribute("SortResults") ?? true;
s.FoldBraces = (bool?)e.Attribute("FoldBraces") ?? false;
s.ExpandMemberDefinitions = (bool?)e.Attribute("ExpandMemberDefinitions") ?? false;
s.ExpandUsingDeclarations = (bool?)e.Attribute("ExpandUsingDeclarations") ?? false;
s.IndentationUseTabs = (bool?)e.Attribute("IndentationUseTabs") ?? true;
s.IndentationSize = (int?)e.Attribute("IndentationSize") ?? 4;
s.IndentationTabSize = (int?)e.Attribute("IndentationTabSize") ?? 4;
s.HighlightMatchingBraces = (bool?)e.Attribute("HighlightMatchingBraces") ?? true;
s.HighlightCurrentLine = (bool?)e.Attribute("HighlightCurrentLine") ?? false;
s.HideEmptyMetadataTables = (bool?)e.Attribute("HideEmptyMetadataTables") ?? true;
s.UseNestedNamespaceNodes = (bool?)e.Attribute("UseNestedNamespaceNodes") ?? false;
s.ShowRawOffsetsAndBytesBeforeInstruction = (bool?)e.Attribute("ShowRawOffsetsAndBytesBeforeInstruction") ?? false;
s.StyleWindowTitleBar = (bool?)e.Attribute("StyleWindowTitleBar") ?? false;
s.Theme = (sessionSettings ?? SettingsService.Instance.SessionSettings).Theme;
return s;
}
public void Save(XElement root)
{
var s = (DisplaySettings)this.DataContext;
var section = new XElement("DisplaySettings");
section.SetAttributeValue("Font", s.SelectedFont.Source);
section.SetAttributeValue("FontSize", s.SelectedFontSize);
section.SetAttributeValue("ShowLineNumbers", s.ShowLineNumbers);
section.SetAttributeValue("ShowMetadataTokens", s.ShowMetadataTokens);
section.SetAttributeValue("ShowMetadataTokensInBase10", s.ShowMetadataTokensInBase10);
section.SetAttributeValue("ShowDebugInfo", s.ShowDebugInfo);
section.SetAttributeValue("EnableWordWrap", s.EnableWordWrap);
section.SetAttributeValue("SortResults", s.SortResults);
section.SetAttributeValue("FoldBraces", s.FoldBraces);
section.SetAttributeValue("ExpandMemberDefinitions", s.ExpandMemberDefinitions);
section.SetAttributeValue("ExpandUsingDeclarations", s.ExpandUsingDeclarations);
section.SetAttributeValue("IndentationUseTabs", s.IndentationUseTabs);
section.SetAttributeValue("IndentationSize", s.IndentationSize);
section.SetAttributeValue("IndentationTabSize", s.IndentationTabSize);
section.SetAttributeValue("HighlightMatchingBraces", s.HighlightMatchingBraces);
section.SetAttributeValue("HighlightCurrentLine", s.HighlightCurrentLine);
section.SetAttributeValue("HideEmptyMetadataTables", s.HideEmptyMetadataTables);
section.SetAttributeValue("UseNestedNamespaceNodes", s.UseNestedNamespaceNodes);
section.SetAttributeValue("ShowRawOffsetsAndBytesBeforeInstruction", s.ShowRawOffsetsAndBytesBeforeInstruction);
section.SetAttributeValue("StyleWindowTitleBar", s.StyleWindowTitleBar);
SettingsService.Instance.SessionSettings.Theme = s.Theme;
var sessionSettings = SettingsService.Instance.SessionSettings.ToXml();
SettingsService.Instance.DisplaySettings.CopyValues(s);
Update(section);
Update(sessionSettings);
void Update(XElement element)
{
var existingElement = root.Element(element.Name);
if (existingElement != null)
existingElement.ReplaceWith(element);
else
root.Add(element);
}
}
private void TextBox_PreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e)
@ -180,44 +55,39 @@ namespace ICSharpCode.ILSpy.Options @@ -180,44 +55,39 @@ namespace ICSharpCode.ILSpy.Options
e.Handled = true;
}
private void OnPaste(object sender, DataObjectPastingEventArgs e)
private static void OnPaste(object sender, DataObjectPastingEventArgs e)
{
if (!e.SourceDataObject.GetDataPresent(DataFormats.UnicodeText, true))
return;
var text = (string)e.SourceDataObject.GetData(DataFormats.UnicodeText, true) ?? string.Empty;
if (!text.All(char.IsDigit))
e.CancelCommand();
}
public void LoadDefaults()
{
SettingsService.Instance.DisplaySettings.CopyValues(new DisplaySettings());
this.DataContext = SettingsService.Instance.DisplaySettings;
}
}
public class FontSizeConverter : IValueConverter
public sealed class FontSizeConverter : ValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
protected override object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is double d)
{
return Math.Round(d / 4 * 3);
}
throw new NotImplementedException();
return DependencyProperty.UnsetValue;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
protected override object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is string s)
{
if (double.TryParse(s, out double d))
return d * 4 / 3;
return 11.0 * 4 / 3;
}
if (value is not string s)
return DependencyProperty.UnsetValue;
if (double.TryParse(s, out double d))
return d * 4 / 3;
throw new NotImplementedException();
return 11.0 * 4 / 3;
}
}
}

90
ILSpy/Options/DisplaySettingsViewModel.cs

@ -0,0 +1,90 @@ @@ -0,0 +1,90 @@
using ICSharpCode.ILSpyX.Settings;
using System.Windows.Media;
using System.Xml.Linq;
using System;
using System.ComponentModel.Composition;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using TomsToolbox.Wpf;
namespace ICSharpCode.ILSpy.Options
{
[ExportOptionPage(Order = 20)]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class DisplaySettingsViewModel : ObservableObject, IOptionPage
{
private DisplaySettings settings = new();
private FontFamily[] fontFamilies;
public DisplaySettingsViewModel()
{
fontFamilies = [settings.SelectedFont];
Task.Run(FontLoader).ContinueWith(continuation => {
FontFamilies = continuation.Result;
if (continuation.Exception == null)
return;
foreach (var ex in continuation.Exception.InnerExceptions)
{
MessageBox.Show(ex.ToString());
}
});
}
public string Title => Properties.Resources.Display;
public DisplaySettings Settings {
get => settings;
set => SetProperty(ref settings, value);
}
public FontFamily[] FontFamilies {
get => fontFamilies;
set => SetProperty(ref fontFamilies, value);
}
public int[] FontSizes { get; } = Enumerable.Range(6, 24 - 6 + 1).ToArray();
public void Load(ILSpySettings spySettings)
{
Settings = DisplaySettings.Load(spySettings);
}
static bool IsSymbolFont(FontFamily fontFamily)
{
foreach (var tf in fontFamily.GetTypefaces())
{
try
{
if (tf.TryGetGlyphTypeface(out GlyphTypeface glyph))
return glyph.Symbol;
}
catch (Exception)
{
return true;
}
}
return false;
}
static FontFamily[] FontLoader()
{
return Fonts.SystemFontFamilies
.Where(ff => !IsSymbolFont(ff))
.OrderBy(ff => ff.Source)
.ToArray();
}
public void Save(XElement root)
{
Settings.Save(root);
}
public void LoadDefaults()
{
Settings = new();
}
}
}

2
ILSpy/Util/SettingsService.cs

@ -17,7 +17,7 @@ namespace ICSharpCode.ILSpy.Util @@ -17,7 +17,7 @@ namespace ICSharpCode.ILSpy.Util
SpySettings = ILSpySettings.Load();
SessionSettings = new(SpySettings);
DecompilerSettings = ISettingsProvider.LoadDecompilerSettings(SpySettings);
DisplaySettings = DisplaySettingsPanel.LoadDisplaySettings(SpySettings, SessionSettings);
DisplaySettings = DisplaySettings.Load(SpySettings, SessionSettings);
MiscSettings = MiscSettings.Load(SpySettings);
AssemblyListManager = new(SpySettings) {
ApplyWinRTProjections = DecompilerSettings.ApplyWindowsRuntimeProjections,

Loading…
Cancel
Save