From a416566091768d6057940ce9462bd846ba71ebe9 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 20 Nov 2019 01:21:18 +0100 Subject: [PATCH] Properly restore all open panes. --- ILSpy/Docking/DockLayoutSettings.cs | 12 +++++++-- ILSpy/Docking/DockWorkspace.cs | 35 +++++++++++++++++++++++++++ ILSpy/Docking/PaneTemplateSelector.cs | 4 +++ ILSpy/MainWindow.xaml.cs | 15 +++++++++--- 4 files changed, 61 insertions(+), 5 deletions(-) diff --git a/ILSpy/Docking/DockLayoutSettings.cs b/ILSpy/Docking/DockLayoutSettings.cs index 23588db97..de5f96a1c 100644 --- a/ILSpy/Docking/DockLayoutSettings.cs +++ b/ILSpy/Docking/DockLayoutSettings.cs @@ -51,9 +51,17 @@ namespace ICSharpCode.ILSpy.Docking { if (!Valid) rawSettings = ""; + try { + Deserialize(rawSettings); + } catch (Exception) { + Deserialize(""); + } - using (StringReader reader = new StringReader(rawSettings)) { - serializer.Deserialize(reader); + void Deserialize(string settings) + { + using (StringReader reader = new StringReader(settings)) { + serializer.Deserialize(reader); + } } } diff --git a/ILSpy/Docking/DockWorkspace.cs b/ILSpy/Docking/DockWorkspace.cs index aec46085a..6b6f86661 100644 --- a/ILSpy/Docking/DockWorkspace.cs +++ b/ILSpy/Docking/DockWorkspace.cs @@ -25,6 +25,8 @@ using System.Threading.Tasks; using ICSharpCode.AvalonEdit.Highlighting; using ICSharpCode.ILSpy.TextView; using ICSharpCode.ILSpy.ViewModels; +using Xceed.Wpf.AvalonDock.Layout; +using Xceed.Wpf.AvalonDock.Layout.Serialization; namespace ICSharpCode.ILSpy.Docking { @@ -67,6 +69,39 @@ namespace ICSharpCode.ILSpy.Docking } } + internal void LayoutSerializationCallback(object sender, LayoutSerializationCallbackEventArgs e) + { + switch (e.Model) { + case LayoutAnchorable la: + switch (la.ContentId) { + case AssemblyListPaneModel.PaneContentId: + e.Content = AssemblyListPaneModel.Instance; + break; + case SearchPaneModel.PaneContentId: + e.Content = SearchPaneModel.Instance; + break; + case AnalyzerPaneModel.PaneContentId: + e.Content = AnalyzerPaneModel.Instance; + break; +#if DEBUG + case DebugStepsPaneModel.PaneContentId: + e.Content = DebugStepsPaneModel.Instance; + break; +#endif + default: + e.Cancel = true; + break; + } + if (!e.Cancel) { + ToolPanes.Add((ToolPaneModel)e.Content); + } + break; + default: + e.Cancel = true; + break; + } + } + protected void RaisePropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); diff --git a/ILSpy/Docking/PaneTemplateSelector.cs b/ILSpy/Docking/PaneTemplateSelector.cs index 06b299b8e..0bfecd642 100644 --- a/ILSpy/Docking/PaneTemplateSelector.cs +++ b/ILSpy/Docking/PaneTemplateSelector.cs @@ -36,6 +36,10 @@ namespace ICSharpCode.ILSpy.Docking public override DataTemplate SelectTemplate(object item, DependencyObject container) { + if (item == null) { + return base.SelectTemplate(item, container); + } + return Mappings.FirstOrDefault(m => m.Type == item.GetType())?.Template ?? base.SelectTemplate(item, container); } diff --git a/ILSpy/MainWindow.xaml.cs b/ILSpy/MainWindow.xaml.cs index 64f787a5a..394243f80 100644 --- a/ILSpy/MainWindow.xaml.cs +++ b/ILSpy/MainWindow.xaml.cs @@ -126,7 +126,13 @@ namespace ICSharpCode.ILSpy InitializeComponent(); - sessionSettings.DockLayout.Deserialize(new XmlLayoutSerializer(DockManager)); + XmlLayoutSerializer serializer = new XmlLayoutSerializer(DockManager); + serializer.LayoutSerializationCallback += DockWorkspace.Instance.LayoutSerializationCallback; + try { + sessionSettings.DockLayout.Deserialize(serializer); + } finally { + serializer.LayoutSerializationCallback -= DockWorkspace.Instance.LayoutSerializationCallback; + } sessionSettings.FilterSettings.PropertyChanged += filterSettings_PropertyChanged; @@ -462,8 +468,11 @@ namespace ICSharpCode.ILSpy void MainWindow_Loaded(object sender, RoutedEventArgs e) { - DockWorkspace.Instance.ToolPanes.Add(AssemblyListPaneModel.Instance); - DockWorkspace.Instance.Documents.Add(new DecompiledDocumentModel() { IsCloseable = false, Language = CurrentLanguage, LanguageVersion = CurrentLanguageVersion }); + DockWorkspace.Instance.Documents.Add(new DecompiledDocumentModel() { + IsCloseable = false, + Language = CurrentLanguage, + LanguageVersion = CurrentLanguageVersion + }); DockWorkspace.Instance.ActiveDocument = DockWorkspace.Instance.Documents.First(); ILSpySettings spySettings = this.spySettingsForMainWindow_Loaded;