mirror of https://github.com/icsharpcode/ILSpy.git
8 changed files with 120 additions and 93 deletions
@ -1,35 +1,43 @@
@@ -1,35 +1,43 @@
|
||||
<Window x:Class="ICSharpCode.ILSpy.Options.OptionsDialog" |
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
xmlns:properties="clr-namespace:ICSharpCode.ILSpy.Properties" |
||||
xmlns:options="clr-namespace:ICSharpCode.ILSpy.Options" |
||||
Style="{DynamicResource DialogWindow}" |
||||
xmlns:properties="clr-namespace:ICSharpCode.ILSpy.Properties" |
||||
xmlns:options="clr-namespace:ICSharpCode.ILSpy.Options" |
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
||||
xmlns:toms="urn:TomsToolbox" |
||||
mc:Ignorable="d" |
||||
d:DataContext="{d:DesignInstance options:OptionsDialogViewModel}" |
||||
Style="{StaticResource DialogWindow}" |
||||
WindowStartupLocation="CenterOwner" |
||||
ResizeMode="CanResizeWithGrip" |
||||
Title="{x:Static properties:Resources.Options}" Height="500" Width="600"> |
||||
<Grid> |
||||
<Grid.RowDefinitions> |
||||
<RowDefinition |
||||
Height="1*" /> |
||||
<RowDefinition |
||||
Height="Auto" /> |
||||
</Grid.RowDefinitions> |
||||
<TabControl Name="tabControl" SelectedValuePath="Content"> |
||||
<DockPanel> |
||||
<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Right" Margin="12,8"> |
||||
<Button Margin="2,0" |
||||
Command="{Binding ResetDefaultsCommand}" |
||||
Content="{x:Static properties:Resources.ResetToDefaults}" /> |
||||
<Button IsDefault="True" Margin="2,0" |
||||
toms:Button.DialogResult="true" |
||||
Command="{Binding CommitCommand}" |
||||
Content="{x:Static properties:Resources.OK}" /> |
||||
<Button IsCancel="True" Margin="2,0" |
||||
Content="{x:Static properties:Resources.Cancel}" /> |
||||
</StackPanel> |
||||
<TabControl ItemsSource="{Binding OptionPages}" |
||||
SelectedIndex="0" |
||||
SelectedValuePath="Content" |
||||
SelectedValue="{Binding SelectedPage}"> |
||||
<TabControl.ItemTemplate> |
||||
<DataTemplate DataType="options:TabItemViewModel"> |
||||
<TextBlock Text="{Binding Header}" /> |
||||
<DataTemplate DataType="options:OptionsItemViewModel"> |
||||
<TextBlock Text="{Binding Title}" /> |
||||
</DataTemplate> |
||||
</TabControl.ItemTemplate> |
||||
<TabControl.ContentTemplate> |
||||
<DataTemplate DataType="options:TabItemViewModel"> |
||||
<DataTemplate DataType="options:OptionsItemViewModel"> |
||||
<ContentPresenter Content="{Binding Content}" /> |
||||
</DataTemplate> |
||||
</TabControl.ContentTemplate> |
||||
</TabControl> |
||||
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right" Margin="12,8"> |
||||
<Button Margin="2,0" Name="defaultsButton" Click="DefaultsButton_Click" Content="{x:Static properties:Resources.ResetToDefaults}" /> |
||||
<Button IsDefault="True" Margin="2,0" Name="okButton" Click="OKButton_Click" Content="{x:Static properties:Resources.OK}" /> |
||||
<Button IsCancel="True" Margin="2,0" Content="{x:Static properties:Resources.Cancel}" /> |
||||
</StackPanel> |
||||
</Grid> |
||||
</DockPanel> |
||||
</Window> |
@ -0,0 +1,71 @@
@@ -0,0 +1,71 @@
|
||||
using System.Linq; |
||||
using System.Windows; |
||||
using System.Windows.Input; |
||||
|
||||
using TomsToolbox.Essentials; |
||||
using TomsToolbox.Wpf; |
||||
|
||||
#nullable enable |
||||
|
||||
namespace ICSharpCode.ILSpy.Options |
||||
{ |
||||
public class OptionsItemViewModel(IOptionPage content) : ObservableObject |
||||
{ |
||||
public string Title { get; } = content.Title; |
||||
|
||||
public IOptionPage Content { get; } = content; |
||||
} |
||||
|
||||
public class OptionsDialogViewModel : ObservableObject |
||||
{ |
||||
private IOptionPage? selectedPage; |
||||
|
||||
private readonly IOptionPage[] optionPages = App.ExportProvider.GetExports<IOptionPage, IOptionsMetadata>("OptionPages") |
||||
.OrderBy(page => page.Metadata?.Order) |
||||
.Select(item => item.Value) |
||||
.ExceptNullItems() |
||||
.ToArray(); |
||||
|
||||
public OptionsDialogViewModel() |
||||
{ |
||||
var settings = SettingsService.Instance.SpySettings; |
||||
|
||||
foreach (var optionPage in optionPages) |
||||
{ |
||||
optionPage.Load(settings); |
||||
} |
||||
|
||||
OptionPages = optionPages.Select(page => new OptionsItemViewModel(page)).ToArray(); |
||||
SelectedPage = optionPages.FirstOrDefault(); |
||||
} |
||||
|
||||
public OptionsItemViewModel[] OptionPages { get; } |
||||
|
||||
public IOptionPage? SelectedPage { |
||||
get => selectedPage; |
||||
set => SetProperty(ref selectedPage, value); |
||||
} |
||||
|
||||
public ICommand CommitCommand => new DelegateCommand(Commit); |
||||
|
||||
public ICommand ResetDefaultsCommand => new DelegateCommand(ResetDefaults); |
||||
|
||||
private void ResetDefaults() |
||||
{ |
||||
if (MessageBox.Show(Properties.Resources.ResetToDefaultsConfirmationMessage, "ILSpy", MessageBoxButton.YesNo) == MessageBoxResult.Yes) |
||||
{ |
||||
SelectedPage?.LoadDefaults(); |
||||
} |
||||
} |
||||
|
||||
private void Commit() |
||||
{ |
||||
SettingsService.Instance.SpySettings.Update(root => { |
||||
foreach (var optionPage in optionPages) |
||||
{ |
||||
optionPage.Save(root); |
||||
} |
||||
}); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue