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. 17
      ILSpy/MainWindow.xaml.cs
  4. 49
      ILSpy/SessionSettings.cs

50
ILSpy/Docking/DockLayoutSettings.cs

@ -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 @@
<DependentUpon>DebugSteps.xaml</DependentUpon> <DependentUpon>DebugSteps.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="Docking\DockingHelper.cs" /> <Compile Include="Docking\DockingHelper.cs" />
<Compile Include="Docking\DockLayoutSettings.cs" />
<Compile Include="ILSpyTraceListener.cs" /> <Compile Include="ILSpyTraceListener.cs" />
<Compile Include="DecompilationOptions.cs" /> <Compile Include="DecompilationOptions.cs" />
<Compile Include="ExtensionMethods.cs" /> <Compile Include="ExtensionMethods.cs" />

17
ILSpy/MainWindow.xaml.cs

@ -45,6 +45,7 @@ using ICSharpCode.TreeView;
using Microsoft.Win32; using Microsoft.Win32;
using OSVersionHelper; using OSVersionHelper;
using Xceed.Wpf.AvalonDock.Layout; using Xceed.Wpf.AvalonDock.Layout;
using Xceed.Wpf.AvalonDock.Layout.Serialization;
namespace ICSharpCode.ILSpy namespace ICSharpCode.ILSpy
{ {
@ -91,11 +92,8 @@ namespace ICSharpCode.ILSpy
decompilerTextView = App.ExportProvider.GetExportedValue<DecompilerTextView>(); decompilerTextView = App.ExportProvider.GetExportedValue<DecompilerTextView>();
mainPane.Content = decompilerTextView; mainPane.Content = decompilerTextView;
//todo sessionSettings.DockLayout.Deserialize(new XmlLayoutSerializer(DockManager));
//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.FilterSettings.PropertyChanged += filterSettings_PropertyChanged; sessionSettings.FilterSettings.PropertyChanged += filterSettings_PropertyChanged;
InitMainMenu(); InitMainMenu();
@ -514,7 +512,7 @@ namespace ICSharpCode.ILSpy
} else { } else {
downloadUrl = await AboutPage.CheckForUpdatesIfEnabledAsync(spySettings); downloadUrl = await AboutPage.CheckForUpdatesIfEnabledAsync(spySettings);
} }
AdjustUpdateUIAfterCheck(downloadUrl, forceCheck); AdjustUpdateUIAfterCheck(downloadUrl, forceCheck);
} }
@ -1017,12 +1015,7 @@ namespace ICSharpCode.ILSpy
sessionSettings.ActiveTreeViewPath = GetPathForNode(treeView.SelectedItem as SharpTreeNode); sessionSettings.ActiveTreeViewPath = GetPathForNode(treeView.SelectedItem as SharpTreeNode);
sessionSettings.ActiveAutoLoadedAssembly = GetAutoLoadedAssemblyNode(treeView.SelectedItem as SharpTreeNode); sessionSettings.ActiveAutoLoadedAssembly = GetAutoLoadedAssemblyNode(treeView.SelectedItem as SharpTreeNode);
sessionSettings.WindowBounds = this.RestoreBounds; sessionSettings.WindowBounds = this.RestoreBounds;
//todo sessionSettings.DockLayout.Serialize(new XmlLayoutSerializer(DockManager));
//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.Save(); sessionSettings.Save();
} }

49
ILSpy/SessionSettings.cs

@ -24,6 +24,7 @@ using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Windows; using System.Windows;
using System.Xml.Linq; using System.Xml.Linq;
using ICSharpCode.ILSpy.Docking;
namespace ICSharpCode.ILSpy namespace ICSharpCode.ILSpy
{ {
@ -36,53 +37,57 @@ namespace ICSharpCode.ILSpy
public SessionSettings(ILSpySettings spySettings) public SessionSettings(ILSpySettings spySettings)
{ {
XElement doc = spySettings["SessionSettings"]; XElement doc = spySettings["SessionSettings"];
XElement filterSettings = doc.Element("FilterSettings"); XElement filterSettings = doc.Element("FilterSettings");
if (filterSettings == null) filterSettings = new XElement("FilterSettings"); if (filterSettings == null) filterSettings = new XElement("FilterSettings");
this.FilterSettings = new FilterSettings(filterSettings); this.FilterSettings = new FilterSettings(filterSettings);
this.ActiveAssemblyList = (string)doc.Element("ActiveAssemblyList"); this.ActiveAssemblyList = (string)doc.Element("ActiveAssemblyList");
XElement activeTreeViewPath = doc.Element("ActiveTreeViewPath"); XElement activeTreeViewPath = doc.Element("ActiveTreeViewPath");
if (activeTreeViewPath != null) { if (activeTreeViewPath != null) {
this.ActiveTreeViewPath = activeTreeViewPath.Elements().Select(e => Unescape((string)e)).ToArray(); this.ActiveTreeViewPath = activeTreeViewPath.Elements().Select(e => Unescape((string)e)).ToArray();
} }
this.ActiveAutoLoadedAssembly = (string)doc.Element("ActiveAutoLoadedAssembly"); this.ActiveAutoLoadedAssembly = (string)doc.Element("ActiveAutoLoadedAssembly");
this.WindowState = FromString((string)doc.Element("WindowState"), WindowState.Normal); this.WindowState = FromString((string)doc.Element("WindowState"), WindowState.Normal);
this.WindowBounds = FromString((string)doc.Element("WindowBounds"), DefaultWindowBounds); this.WindowBounds = FromString((string)doc.Element("WindowBounds"), DefaultWindowBounds);
this.SplitterPosition = FromString((string)doc.Element("SplitterPosition"), 0.4); this.SplitterPosition = FromString((string)doc.Element("SplitterPosition"), 0.4);
this.TopPaneSplitterPosition = FromString((string)doc.Element("TopPaneSplitterPosition"), 0.3); this.TopPaneSplitterPosition = FromString((string)doc.Element("TopPaneSplitterPosition"), 0.3);
this.BottomPaneSplitterPosition = FromString((string)doc.Element("BottomPaneSplitterPosition"), 0.3); this.BottomPaneSplitterPosition = FromString((string)doc.Element("BottomPaneSplitterPosition"), 0.3);
this.SelectedSearchMode = FromString((string)doc.Element("SelectedSearchMode"), SearchMode.TypeAndMember); this.SelectedSearchMode = FromString((string)doc.Element("SelectedSearchMode"), SearchMode.TypeAndMember);
this.DockLayout = new DockLayoutSettings(doc.Element("DockLayout"));
} }
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
void OnPropertyChanged(string propertyName) void OnPropertyChanged(string propertyName)
{ {
if (PropertyChanged != null) if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
} }
public FilterSettings FilterSettings { get; private set; } public FilterSettings FilterSettings { get; private set; }
public SearchMode SelectedSearchMode { get; set; } public SearchMode SelectedSearchMode { get; set; }
public string[] ActiveTreeViewPath; public string[] ActiveTreeViewPath;
public string ActiveAutoLoadedAssembly; public string ActiveAutoLoadedAssembly;
public string ActiveAssemblyList; public string ActiveAssemblyList;
public WindowState WindowState = WindowState.Normal; public WindowState WindowState = WindowState.Normal;
public Rect WindowBounds; public Rect WindowBounds;
internal static Rect DefaultWindowBounds = new Rect(10, 10, 750, 550); internal static Rect DefaultWindowBounds = new Rect(10, 10, 750, 550);
/// <summary> /// <summary>
/// position of the left/right splitter /// position of the left/right splitter
/// </summary> /// </summary>
public double SplitterPosition; public double SplitterPosition;
public double TopPaneSplitterPosition, BottomPaneSplitterPosition; public double TopPaneSplitterPosition, BottomPaneSplitterPosition;
public DockLayoutSettings DockLayout { get; private set; }
public void Save() public void Save()
{ {
XElement doc = new XElement("SessionSettings"); XElement doc = new XElement("SessionSettings");
@ -102,12 +107,18 @@ namespace ICSharpCode.ILSpy
doc.Add(new XElement("TopPaneSplitterPosition", ToString(this.TopPaneSplitterPosition))); doc.Add(new XElement("TopPaneSplitterPosition", ToString(this.TopPaneSplitterPosition)));
doc.Add(new XElement("BottomPaneSplitterPosition", ToString(this.BottomPaneSplitterPosition))); doc.Add(new XElement("BottomPaneSplitterPosition", ToString(this.BottomPaneSplitterPosition)));
doc.Add(new XElement("SelectedSearchMode", ToString(this.SelectedSearchMode))); 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); ILSpySettings.SaveSettings(doc);
} }
static Regex regex = new Regex("\\\\x(?<num>[0-9A-f]{4})"); static Regex regex = new Regex("\\\\x(?<num>[0-9A-f]{4})");
static string Escape(string p) static string Escape(string p)
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@ -119,12 +130,12 @@ namespace ICSharpCode.ILSpy
} }
return sb.ToString(); return sb.ToString();
} }
static string Unescape(string p) static string Unescape(string p)
{ {
return regex.Replace(p, m => ((char)int.Parse(m.Groups["num"].Value, NumberStyles.HexNumber)).ToString()); return regex.Replace(p, m => ((char)int.Parse(m.Groups["num"].Value, NumberStyles.HexNumber)).ToString());
} }
static T FromString<T>(string s, T defaultValue) static T FromString<T>(string s, T defaultValue)
{ {
if (s == null) if (s == null)
@ -136,7 +147,7 @@ namespace ICSharpCode.ILSpy
return defaultValue; return defaultValue;
} }
} }
static string ToString<T>(T obj) static string ToString<T>(T obj)
{ {
TypeConverter c = TypeDescriptor.GetConverter(typeof(T)); TypeConverter c = TypeDescriptor.GetConverter(typeof(T));

Loading…
Cancel
Save