Browse Source

Save and load AvalonDock layout

pull/1736/head
Andreas Weizel 7 years ago
parent
commit
aadad76d52
  1. 50
      ILSpy/Docking/DockLayoutSettings.cs
  2. 1
      ILSpy/ILSpy.csproj
  3. 15
      ILSpy/MainWindow.xaml.cs
  4. 13
      ILSpy/SessionSettings.cs

50
ILSpy/Docking/DockLayoutSettings.cs

@ -0,0 +1,50 @@ @@ -0,0 +1,50 @@
using System;
using System.IO;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using Xceed.Wpf.AvalonDock.Layout.Serialization;
namespace ICSharpCode.ILSpy.Docking
{
public class DockLayoutSettings
{
private string rawSettings;
public bool Valid => rawSettings != null;
public DockLayoutSettings(XElement element)
{
if ((element != null) && element.HasElements) {
rawSettings = element.Elements().FirstOrDefault()?.ToString();
}
}
public XElement SaveAsXml()
{
try {
return XElement.Parse(rawSettings);
} catch (Exception) {
return null;
}
}
public void Deserialize(XmlLayoutSerializer serializer)
{
if (!Valid)
return;
using (StringReader reader = new StringReader(rawSettings)) {
serializer.Deserialize(reader);
}
}
public void Serialize(XmlLayoutSerializer serializer)
{
using (StringWriter fs = new StringWriter()) {
serializer.Serialize(fs);
rawSettings = fs.ToString();
}
}
}
}

1
ILSpy/ILSpy.csproj

@ -139,6 +139,7 @@ @@ -139,6 +139,7 @@
<DependentUpon>DebugSteps.xaml</DependentUpon>
</Compile>
<Compile Include="Docking\DockingHelper.cs" />
<Compile Include="Docking\DockLayoutSettings.cs" />
<Compile Include="ILSpyTraceListener.cs" />
<Compile Include="DecompilationOptions.cs" />
<Compile Include="ExtensionMethods.cs" />

15
ILSpy/MainWindow.xaml.cs

@ -45,6 +45,7 @@ using ICSharpCode.TreeView; @@ -45,6 +45,7 @@ using ICSharpCode.TreeView;
using Microsoft.Win32;
using OSVersionHelper;
using Xceed.Wpf.AvalonDock.Layout;
using Xceed.Wpf.AvalonDock.Layout.Serialization;
namespace ICSharpCode.ILSpy
{
@ -91,11 +92,8 @@ namespace ICSharpCode.ILSpy @@ -91,11 +92,8 @@ namespace ICSharpCode.ILSpy
decompilerTextView = App.ExportProvider.GetExportedValue<DecompilerTextView>();
mainPane.Content = decompilerTextView;
//todo
//if (sessionSettings.SplitterPosition > 0 && sessionSettings.SplitterPosition < 1) {
// leftColumn.Width = new GridLength(sessionSettings.SplitterPosition, GridUnitType.Star);
// rightColumn.Width = new GridLength(1 - sessionSettings.SplitterPosition, GridUnitType.Star);
//}
sessionSettings.DockLayout.Deserialize(new XmlLayoutSerializer(DockManager));
sessionSettings.FilterSettings.PropertyChanged += filterSettings_PropertyChanged;
InitMainMenu();
@ -1017,12 +1015,7 @@ namespace ICSharpCode.ILSpy @@ -1017,12 +1015,7 @@ namespace ICSharpCode.ILSpy
sessionSettings.ActiveTreeViewPath = GetPathForNode(treeView.SelectedItem as SharpTreeNode);
sessionSettings.ActiveAutoLoadedAssembly = GetAutoLoadedAssemblyNode(treeView.SelectedItem as SharpTreeNode);
sessionSettings.WindowBounds = this.RestoreBounds;
//todo
//sessionSettings.SplitterPosition = leftColumn.Width.Value / (leftColumn.Width.Value + rightColumn.Width.Value);
//if (topPane.Visibility == Visibility.Visible)
// sessionSettings.TopPaneSplitterPosition = topPaneRow.Height.Value / (topPaneRow.Height.Value + textViewRow.Height.Value);
//if (bottomPane.Visibility == Visibility.Visible)
// sessionSettings.BottomPaneSplitterPosition = bottomPaneRow.Height.Value / (bottomPaneRow.Height.Value + textViewRow.Height.Value);
sessionSettings.DockLayout.Serialize(new XmlLayoutSerializer(DockManager));
sessionSettings.Save();
}

13
ILSpy/SessionSettings.cs

@ -24,6 +24,7 @@ using System.Text; @@ -24,6 +24,7 @@ using System.Text;
using System.Text.RegularExpressions;
using System.Windows;
using System.Xml.Linq;
using ICSharpCode.ILSpy.Docking;
namespace ICSharpCode.ILSpy
{
@ -56,6 +57,8 @@ namespace ICSharpCode.ILSpy @@ -56,6 +57,8 @@ namespace ICSharpCode.ILSpy
this.TopPaneSplitterPosition = FromString((string)doc.Element("TopPaneSplitterPosition"), 0.3);
this.BottomPaneSplitterPosition = FromString((string)doc.Element("BottomPaneSplitterPosition"), 0.3);
this.SelectedSearchMode = FromString((string)doc.Element("SelectedSearchMode"), SearchMode.TypeAndMember);
this.DockLayout = new DockLayoutSettings(doc.Element("DockLayout"));
}
public event PropertyChangedEventHandler PropertyChanged;
@ -76,13 +79,15 @@ namespace ICSharpCode.ILSpy @@ -76,13 +79,15 @@ namespace ICSharpCode.ILSpy
public WindowState WindowState = WindowState.Normal;
public Rect WindowBounds;
internal static Rect DefaultWindowBounds = new Rect(10, 10, 750, 550);
internal static Rect DefaultWindowBounds = new Rect(10, 10, 750, 550);
/// <summary>
/// position of the left/right splitter
/// </summary>
public double SplitterPosition;
public double TopPaneSplitterPosition, BottomPaneSplitterPosition;
public DockLayoutSettings DockLayout { get; private set; }
public void Save()
{
XElement doc = new XElement("SessionSettings");
@ -103,6 +108,12 @@ namespace ICSharpCode.ILSpy @@ -103,6 +108,12 @@ namespace ICSharpCode.ILSpy
doc.Add(new XElement("BottomPaneSplitterPosition", ToString(this.BottomPaneSplitterPosition)));
doc.Add(new XElement("SelectedSearchMode", ToString(this.SelectedSearchMode)));
var dockLayoutElement = new XElement("DockLayout");
if (DockLayout.Valid) {
dockLayoutElement.Add(DockLayout.SaveAsXml());
}
doc.Add(dockLayoutElement);
ILSpySettings.SaveSettings(doc);
}

Loading…
Cancel
Save