From db5f09dfd4e60fd4c8180c3454a28d085db57314 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Wed, 4 Nov 2009 19:21:04 +0000 Subject: [PATCH] Add version info to layout files to avoid exception when AvalonDock version has changed. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5212 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- data/layouts/Debug.xml | 2 +- data/layouts/Default.xml | 2 +- data/layouts/Plain.xml | 2 +- src/Libraries/AvalonDock/DockingManager.cs | 6 +++++ .../Gui/Workbench/Layouts/AvalonDockLayout.cs | 23 ++++++++++++++----- 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/data/layouts/Debug.xml b/data/layouts/Debug.xml index 265d9b43a5..1ed42b231a 100644 --- a/data/layouts/Debug.xml +++ b/data/layouts/Debug.xml @@ -1,4 +1,4 @@ - + diff --git a/data/layouts/Default.xml b/data/layouts/Default.xml index 4620cbe1f1..988fb426ab 100644 --- a/data/layouts/Default.xml +++ b/data/layouts/Default.xml @@ -1,4 +1,4 @@ - + diff --git a/data/layouts/Plain.xml b/data/layouts/Plain.xml index 2fec23db83..da1deb0774 100644 --- a/data/layouts/Plain.xml +++ b/data/layouts/Plain.xml @@ -1,4 +1,4 @@ - + diff --git a/src/Libraries/AvalonDock/DockingManager.cs b/src/Libraries/AvalonDock/DockingManager.cs index d0a39e60d9..30e4a7807e 100644 --- a/src/Libraries/AvalonDock/DockingManager.cs +++ b/src/Libraries/AvalonDock/DockingManager.cs @@ -2714,6 +2714,8 @@ namespace AvalonDock SaveLayout(stream); } + const string layoutFileVersion = "1.2.1"; + /// /// Send layout configuration to a object /// @@ -2725,6 +2727,7 @@ namespace AvalonDock throw new InvalidOperationException("Unable to serialize docking layout while DockingManager control is unloaded"); sw.WriteStartElement("DockingManager"); + sw.WriteAttributeString("version", layoutFileVersion); if (Content is ResizingPanel) SaveLayout(sw, Content as ResizingPanel); @@ -3032,6 +3035,9 @@ namespace AvalonDock Debug.Assert(false, "Layout file hasn't a valid structure!"); throw new InvalidOperationException("Layout file had not a valid structure!"); } + + if (doc.DocumentElement.GetAttribute("version") != layoutFileVersion) + throw new FileFormatException("Unsupported layout file version"); if (doc.DocumentElement.ChildNodes.Count != 3 || (doc.DocumentElement.ChildNodes[0].Name != "ResizingPanel" && doc.DocumentElement.ChildNodes[0].Name != "DocumentPanePlaceHolder") || diff --git a/src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonDockLayout.cs b/src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonDockLayout.cs index 39d144b613..dae8ae44c9 100644 --- a/src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonDockLayout.cs +++ b/src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonDockLayout.cs @@ -204,12 +204,7 @@ namespace ICSharpCode.SharpDevelop.Gui return; Busy = true; try { - bool isPlainLayout = LayoutConfiguration.CurrentLayoutName == "Plain"; - if (File.Exists(LayoutConfiguration.CurrentLayoutFileName)) { - LoadLayout(LayoutConfiguration.CurrentLayoutFileName, isPlainLayout); - } else if (File.Exists(LayoutConfiguration.CurrentLayoutTemplateFileName)) { - LoadLayout(LayoutConfiguration.CurrentLayoutTemplateFileName, isPlainLayout); - } + TryLoadConfiguration(); } catch (Exception ex) { MessageService.ShowException(ex); // ignore errors loading configuration @@ -221,6 +216,22 @@ namespace ICSharpCode.SharpDevelop.Gui } } + void TryLoadConfiguration() + { + bool isPlainLayout = LayoutConfiguration.CurrentLayoutName == "Plain"; + if (File.Exists(LayoutConfiguration.CurrentLayoutFileName)) { + try { + LoadLayout(LayoutConfiguration.CurrentLayoutFileName, isPlainLayout); + return; + } catch (FileFormatException) { + // error when version of AvalonDock has changed: ignore and load template instead + } + } + if (File.Exists(LayoutConfiguration.CurrentLayoutTemplateFileName)) { + LoadLayout(LayoutConfiguration.CurrentLayoutTemplateFileName, isPlainLayout); + } + } + void LoadLayout(string fileName, bool hideAllLostPads) { LoggingService.Info("Loading layout file: " + fileName + ", hideAllLostPads=" + hideAllLostPads);