diff --git a/ILSpy/Commands/DecompileInNewViewCommand.cs b/ILSpy/Commands/DecompileInNewViewCommand.cs index 92fdd7275..94e81d360 100644 --- a/ILSpy/Commands/DecompileInNewViewCommand.cs +++ b/ILSpy/Commands/DecompileInNewViewCommand.cs @@ -55,7 +55,7 @@ namespace ICSharpCode.ILSpy.Commands private static void DecompileNodes(params ILSpyTreeNode[] nodes) { var title = string.Join(", ", nodes.Select(x => x.ToString())); - DockWorkspace.Instance.Documents.Add(new ViewModels.DecompiledDocumentModel(title, title)); + DockWorkspace.Instance.Documents.Add(new ViewModels.DecompiledDocumentModel(title, title) { Language = MainWindow.Instance.CurrentLanguage, LanguageVersion = MainWindow.Instance.CurrentLanguageVersion }); DockWorkspace.Instance.ActiveDocument = DockWorkspace.Instance.Documents.Last(); MainWindow.Instance.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, (Action)delegate { DockWorkspace.Instance.GetTextView().DecompileAsync(MainWindow.Instance.CurrentLanguage, nodes, new DecompilationOptions()); diff --git a/ILSpy/Docking/DockWorkspace.cs b/ILSpy/Docking/DockWorkspace.cs index 1735507f7..a75ef21a2 100644 --- a/ILSpy/Docking/DockWorkspace.cs +++ b/ILSpy/Docking/DockWorkspace.cs @@ -1,6 +1,7 @@ using System; using System.Collections.ObjectModel; using System.ComponentModel; +using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; using ICSharpCode.AvalonEdit.Highlighting; @@ -11,6 +12,8 @@ namespace ICSharpCode.ILSpy.Docking { public class DockWorkspace : INotifyPropertyChanged { + private SessionSettings sessionSettings; + public event PropertyChangedEventHandler PropertyChanged; public static DockWorkspace Instance { get; } = new DockWorkspace(); @@ -37,12 +40,16 @@ namespace ICSharpCode.ILSpy.Docking set { if (_activeDocument != value) { _activeDocument = value; + if (value is DecompiledDocumentModel ddm) { + this.sessionSettings.FilterSettings.Language = ddm.Language; + this.sessionSettings.FilterSettings.LanguageVersion = ddm.LanguageVersion; + } RaisePropertyChanged(nameof(ActiveDocument)); } } } - protected void RaisePropertyChanged(string propertyName) + protected void RaisePropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } @@ -71,5 +78,21 @@ namespace ICSharpCode.ILSpy.Docking { GetTextView().ShowNodes(output, nodes, highlighting); } + + internal void LoadSettings(SessionSettings sessionSettings) + { + this.sessionSettings = sessionSettings; + sessionSettings.FilterSettings.PropertyChanged += FilterSettings_PropertyChanged; + } + + private void FilterSettings_PropertyChanged(object sender, PropertyChangedEventArgs e) + { + if (ActiveDocument is DecompiledDocumentModel ddm) { + if (e.PropertyName == "Language" || e.PropertyName == "LanguageVersion") { + ddm.Language = sessionSettings.FilterSettings.Language; + ddm.LanguageVersion = sessionSettings.FilterSettings.LanguageVersion; + } + } + } } } diff --git a/ILSpy/MainWindow.xaml.cs b/ILSpy/MainWindow.xaml.cs index 66053dfce..cf9c803c8 100644 --- a/ILSpy/MainWindow.xaml.cs +++ b/ILSpy/MainWindow.xaml.cs @@ -122,6 +122,8 @@ namespace ICSharpCode.ILSpy SessionSettings = sessionSettings }; + DockWorkspace.Instance.LoadSettings(sessionSettings); + InitializeComponent(); sessionSettings.DockLayout.Deserialize(new XmlLayoutSerializer(DockManager)); @@ -461,7 +463,7 @@ namespace ICSharpCode.ILSpy void MainWindow_Loaded(object sender, RoutedEventArgs e) { DockWorkspace.Instance.ToolPanes.Add(AssemblyListPaneModel.Instance); - DockWorkspace.Instance.Documents.Add(new DecompiledDocumentModel() { IsCloseable = false }); + DockWorkspace.Instance.Documents.Add(new DecompiledDocumentModel() { IsCloseable = false, Language = CurrentLanguage, LanguageVersion = CurrentLanguageVersion }); DockWorkspace.Instance.ActiveDocument = DockWorkspace.Instance.Documents.First(); ILSpySettings spySettings = this.spySettingsForMainWindow_Loaded; diff --git a/ILSpy/ViewModels/DocumentModel.cs b/ILSpy/ViewModels/DocumentModel.cs index 3e7fbeb8d..b3139f3d5 100644 --- a/ILSpy/ViewModels/DocumentModel.cs +++ b/ILSpy/ViewModels/DocumentModel.cs @@ -36,5 +36,27 @@ namespace ICSharpCode.ILSpy.ViewModels } } } + + private Language language; + public Language Language { + get => language; + set { + if (language != value) { + language = value; + RaisePropertyChanged(nameof(Language)); + } + } + } + + private LanguageVersion languageVersion; + public LanguageVersion LanguageVersion { + get => languageVersion; + set { + if (languageVersion != value) { + languageVersion = value; + RaisePropertyChanged(nameof(LanguageVersion)); + } + } + } } -} +} \ No newline at end of file