mirror of https://github.com/icsharpcode/ILSpy.git
8 changed files with 120 additions and 93 deletions
@ -1,35 +1,43 @@ |
|||||||
<Window x:Class="ICSharpCode.ILSpy.Options.OptionsDialog" |
<Window x:Class="ICSharpCode.ILSpy.Options.OptionsDialog" |
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||||
xmlns:properties="clr-namespace:ICSharpCode.ILSpy.Properties" |
xmlns:properties="clr-namespace:ICSharpCode.ILSpy.Properties" |
||||||
xmlns:options="clr-namespace:ICSharpCode.ILSpy.Options" |
xmlns:options="clr-namespace:ICSharpCode.ILSpy.Options" |
||||||
Style="{DynamicResource DialogWindow}" |
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" |
WindowStartupLocation="CenterOwner" |
||||||
ResizeMode="CanResizeWithGrip" |
ResizeMode="CanResizeWithGrip" |
||||||
Title="{x:Static properties:Resources.Options}" Height="500" Width="600"> |
Title="{x:Static properties:Resources.Options}" Height="500" Width="600"> |
||||||
<Grid> |
<DockPanel> |
||||||
<Grid.RowDefinitions> |
<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Right" Margin="12,8"> |
||||||
<RowDefinition |
<Button Margin="2,0" |
||||||
Height="1*" /> |
Command="{Binding ResetDefaultsCommand}" |
||||||
<RowDefinition |
Content="{x:Static properties:Resources.ResetToDefaults}" /> |
||||||
Height="Auto" /> |
<Button IsDefault="True" Margin="2,0" |
||||||
</Grid.RowDefinitions> |
toms:Button.DialogResult="true" |
||||||
<TabControl Name="tabControl" SelectedValuePath="Content"> |
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> |
<TabControl.ItemTemplate> |
||||||
<DataTemplate DataType="options:TabItemViewModel"> |
<DataTemplate DataType="options:OptionsItemViewModel"> |
||||||
<TextBlock Text="{Binding Header}" /> |
<TextBlock Text="{Binding Title}" /> |
||||||
</DataTemplate> |
</DataTemplate> |
||||||
</TabControl.ItemTemplate> |
</TabControl.ItemTemplate> |
||||||
<TabControl.ContentTemplate> |
<TabControl.ContentTemplate> |
||||||
<DataTemplate DataType="options:TabItemViewModel"> |
<DataTemplate DataType="options:OptionsItemViewModel"> |
||||||
<ContentPresenter Content="{Binding Content}" /> |
<ContentPresenter Content="{Binding Content}" /> |
||||||
</DataTemplate> |
</DataTemplate> |
||||||
</TabControl.ContentTemplate> |
</TabControl.ContentTemplate> |
||||||
</TabControl> |
</TabControl> |
||||||
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right" Margin="12,8"> |
</DockPanel> |
||||||
<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> |
|
||||||
</Window> |
</Window> |
||||||
@ -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