/// <summary> /// Internal main restore layout method /// </summary> /// <param name="doc">Document Xml from which restore layout</param> void RestoreLayout(XmlDocument doc) { if (!_isControlLoaded) throw new InvalidOperationException("Unable to deserialize a docking layout while DockingManager control is unloaded"); if (doc.DocumentElement == null || doc.DocumentElement.Name != "DockingManager") { 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 != "DocumentPane") || doc.DocumentElement.ChildNodes[1].Name != "Hidden" || doc.DocumentElement.ChildNodes[2].Name != "Windows") { Debug.Assert(false, "Layout file hasn't a valid structure!"); throw new InvalidOperationException("Layout file hasn't a valid structure!"); } //Hide temp windows HideFlyoutWindow(); HideNavigatorWindow(); //HideDocumentNavigatorWindow(); RestoringLayout = true; //show all auto hidden panes var panesAutoHidden = DockableContents.Where(c => c.State == DockableContentState.AutoHide).Select(c => c.ContainerPane).Distinct(); foreach (DockablePane pane in panesAutoHidden) pane.ToggleAutoHide(); DockableContent[] actualContents = DockableContents.ToArray(); DocumentContent[] actualDocuments = Documents.ToArray(); //first detach all my actual contents this.Content = null; this.ActiveContent = null; this.ActiveDocument = null; //restore main panel XmlElement rootElement = doc.DocumentElement.ChildNodes[0] as XmlElement; DocumentPane mainDocumentPane = null; this.Content = RestoreLayout(rootElement, actualContents, actualDocuments, ref mainDocumentPane); MainDocumentPane = mainDocumentPane; //restore hidden contents foreach (XmlElement hiddenContentElement in doc.DocumentElement.ChildNodes[1].ChildNodes) { var hiddenContentName = hiddenContentElement.GetAttribute("Name"); var hiddenContent = actualContents.FirstOrDefault(c => c.Name == hiddenContentName && c.State != DockableContentState.Hidden); if (hiddenContent != null) { Hide(hiddenContent); hiddenContent.RestoreLayout(hiddenContentElement); } } //restore floating windows foreach (XmlElement flWindowElement in doc.DocumentElement.ChildNodes[2].ChildNodes) { if (flWindowElement.ChildNodes.Count != 1) continue;//handles invalid layouts structures bool isDockableWindow = XmlConvert.ToBoolean(flWindowElement.GetAttribute("IsDockableWindow")); Point location = new Point(XmlConvert.ToDouble(flWindowElement.GetAttribute("Left")), XmlConvert.ToDouble(flWindowElement.GetAttribute("Top"))); Size size = new Size(XmlConvert.ToDouble(flWindowElement.GetAttribute("Width")), XmlConvert.ToDouble(flWindowElement.GetAttribute("Height"))); XmlElement paneElement = flWindowElement.ChildNodes[0] as XmlElement; DockablePane paneForFloatingWindow = new DockablePane(); if (paneElement.HasAttribute("ResizingWidth")) ResizingPanel.SetResizeWidth(paneForFloatingWindow, (GridLength)GLConverter.ConvertFromInvariantString(paneElement.GetAttribute("ResizeWidth"))); if (paneElement.HasAttribute("ResizingHeight")) ResizingPanel.SetResizeHeight(paneForFloatingWindow, (GridLength)GLConverter.ConvertFromInvariantString(paneElement.GetAttribute("ResizeHeight"))); paneForFloatingWindow.Anchor = (AnchorStyle)Enum.Parse(typeof(AnchorStyle), paneElement.GetAttribute("Anchor")); DockableContent contentToTransfer = null; foreach (XmlElement contentElement in paneElement.ChildNodes) { #region Find the content to transfer string contentToFindName = contentElement.GetAttribute("Name"); contentToTransfer = actualContents.FirstOrDefault(c => c.Name == contentToFindName); if (contentToTransfer == null && DeserializationCallback != null) { DeserializationCallbackEventArgs e = new DeserializationCallbackEventArgs(contentToFindName); DeserializationCallback(this, e); contentToTransfer = e.Content as DockableContent; } #endregion if (contentToTransfer != null) { DetachContentFromDockingManager(contentToTransfer); paneForFloatingWindow.Items.Add(contentToTransfer); contentToTransfer.RestoreLayout(contentElement); } } if (paneForFloatingWindow.Items.Count > 0) { var flWindow = new DockableFloatingWindow(this); flWindow.Content = paneForFloatingWindow; flWindow.Left = location.X; flWindow.Top = location.Y; flWindow.Width = size.Width; flWindow.Height = size.Height; flWindow.Owner = Window.GetWindow(this); flWindow.IsDockableWindow = isDockableWindow; flWindow.ShowActivated = false; flWindow.ApplyTemplate(); flWindow.Show(); } } ClearEmptyPanels(Content as ResizingPanel); //get documents that are not present in last layout and must be included //in the new one var documentsNotTransferred = actualDocuments.Where(d => d.ContainerPane == null || d.ContainerPane.GetManager() != this).ToArray(); Debug.Assert(MainDocumentPane != null && MainDocumentPane.GetManager() == this); if (MainDocumentPane != null && documentsNotTransferred.Count() > 0) { documentsNotTransferred.ForEach(d => MainDocumentPane.Items.Add(d.DetachFromContainerPane())); } //get contents that are not present in the new layout and hide them var contentsNotTransferred = actualContents.Where(c => c.ContainerPane == null || c.ContainerPane.GetManager() != this).ToArray(); contentsNotTransferred.ForEach(c => { Hide(c); }); RestoringLayout = false; ClearEmptyPanes(); RefreshContents(); if (ActiveDocument != null && (ActiveDocument.ContainerPane == null || ActiveDocument.ContainerPane.GetManager() != this)) { if (Documents.Count > 0) ActiveDocument = Documents[0]; else ActiveDocument = null; } ActiveContent = ActiveDocument; }
///// <summary> ///// Restore from xml a document pane ///// </summary> ///// <param name="childElement"></param> ///// <param name="mainExistingDocumentPane"></param> ///// <param name="existingDocumentPanel"></param> ///// <param name="dockableContents"></param> //void RestoreDocumentPaneLayout(XmlElement childElement, out DocumentPane mainExistingDocumentPane, out DocumentPaneResizingPanel existingDocumentPanel, DockableContent[] dockableContents) //{ // mainExistingDocumentPane = (Content is DocumentPane) ? Content as DocumentPane : GetMainDocumentPane(Content as ResizingPanel); // if (mainExistingDocumentPane != null) // { // existingDocumentPanel = mainExistingDocumentPane.GetParentDocumentPaneResizingPanel(); // } // else // { // existingDocumentPanel = null; // } // if (existingDocumentPanel != null) // { // if (existingDocumentPanel.Parent is ResizingPanel) // { // ((ResizingPanel)existingDocumentPanel.Parent).RemoveChild(existingDocumentPanel); // } // else if (existingDocumentPanel.Parent is DockingManager) // { // ((DockingManager)existingDocumentPanel.Parent).Content = null; // } // } // else if (mainExistingDocumentPane != null) // { // if (mainExistingDocumentPane.Parent is ResizingPanel) // { // ((ResizingPanel)mainExistingDocumentPane.Parent).RemoveChild(mainExistingDocumentPane); // } // else if (mainExistingDocumentPane.Parent is DockingManager) // { // ((DockingManager)mainExistingDocumentPane.Parent).Content = null; // } // } // foreach (XmlElement contentElement in childElement.ChildNodes) // { // if (contentElement.HasAttribute("Name")) // { // DockableContent foundContent = null; // string contentName = contentElement.GetAttribute("Name"); // foreach (DockableContent content in dockableContents) // { // if (content.Name == contentName) // { // foundContent = content; // break; // } // } // if (foundContent == null && // DeserializationCallback != null) // { // DeserializationCallbackEventArgs e = new DeserializationCallbackEventArgs(contentName); // DeserializationCallback(this, e); // foundContent = e.Content as DockableContent; // } // if (foundContent != null) // { // DetachContentFromDockingManager(foundContent); // mainExistingDocumentPane.Items.Add(foundContent); // foundContent.SetStateToDocument(); // //call custom layout persistence method // foundContent.RestoreLayout(contentElement); // } // } // } //} DocumentPane RestoreDocumentPaneLayout(XmlElement mainElement, DockableContent[] actualContents, DocumentContent[] actualDocuments) { var documentPane = new DocumentPane(); if (mainElement.HasAttribute("ResizeWidth")) ResizingPanel.SetResizeWidth(documentPane, (GridLength)GLConverter.ConvertFromInvariantString(mainElement.GetAttribute("ResizeWidth"))); if (mainElement.HasAttribute("ResizeHeight")) ResizingPanel.SetResizeHeight(documentPane, (GridLength)GLConverter.ConvertFromInvariantString(mainElement.GetAttribute("ResizeHeight"))); if (mainElement.HasAttribute("EffectiveSize")) ResizingPanel.SetEffectiveSize(documentPane, (Size)(new SizeConverter()).ConvertFromInvariantString(mainElement.GetAttribute("EffectiveSize"))); foreach (XmlElement contentElement in mainElement.ChildNodes) { if (contentElement.Name == "DockableContent" && contentElement.HasAttribute("Name")) { DockableContent foundContent = null; string contentName = contentElement.GetAttribute("Name"); foundContent = actualContents.FirstOrDefault(c => c.Name == contentName); if (foundContent == null && DeserializationCallback != null) { DeserializationCallbackEventArgs e = new DeserializationCallbackEventArgs(contentName); DeserializationCallback(this, e); foundContent = e.Content as DockableContent; } if (foundContent != null) { DetachContentFromDockingManager(foundContent); documentPane.Items.Add(foundContent); foundContent.SetStateToDocument(); //call custom layout persistence method foundContent.RestoreLayout(contentElement); } } else if (contentElement.Name == "DocumentContent" && contentElement.HasAttribute("Name")) { DocumentContent foundDocument = null; string contentName = contentElement.GetAttribute("Name"); foundDocument = actualDocuments.FirstOrDefault(c => c.Name == contentName); if (foundDocument == null && DeserializationCallback != null) { DeserializationCallbackEventArgs e = new DeserializationCallbackEventArgs(contentName); DeserializationCallback(this, e); foundDocument = e.Content as DocumentContent; } if (foundDocument != null) { foundDocument.DetachFromContainerPane(); documentPane.Items.Add(foundDocument); } } } if (mainElement.HasAttribute("SelectedIndex")) documentPane.SelectedIndex = XmlConvert.ToInt32(mainElement.GetAttribute("SelectedIndex")); return documentPane; }
private void DeserializationCallback(object _sender, DeserializationCallbackEventArgs _deserializationCallbackEventArgs) { var rootToolDescriptor = UiManager.GetRootToolDescriptor(_deserializationCallbackEventArgs.Name); if (rootToolDescriptor != null) { _deserializationCallbackEventArgs.Content = new AlphaRootTool(rootToolDescriptor); } else { EAlphaToolKind kind; if (Enum.TryParse(_deserializationCallbackEventArgs.Name, out kind)) { var descriptor = UiManager.GetDescriptor(kind); _deserializationCallbackEventArgs.Content = new AlphaTool(descriptor); } } }
DockablePane RestoreDockablePaneLayout(XmlElement mainElement, DockableContent[] actualContents, DocumentContent[] actualDocuments) { DockablePane pane = new DockablePane(); if (mainElement.HasAttribute("Anchor")) pane.Anchor = (AnchorStyle)Enum.Parse(typeof(AnchorStyle), mainElement.GetAttribute("Anchor")); if (mainElement.HasAttribute("ResizeWidth")) ResizingPanel.SetResizeWidth(pane, (GridLength)GLConverter.ConvertFromInvariantString(mainElement.GetAttribute("ResizeWidth"))); if (mainElement.HasAttribute("ResizeHeight")) ResizingPanel.SetResizeHeight(pane, (GridLength)GLConverter.ConvertFromInvariantString(mainElement.GetAttribute("ResizeHeight"))); if (mainElement.HasAttribute("EffectiveSize")) ResizingPanel.SetEffectiveSize(pane, (Size)(new SizeConverter()).ConvertFromInvariantString(mainElement.GetAttribute("EffectiveSize"))); if (mainElement.HasAttribute("ID")) pane.ID = new Guid(mainElement.GetAttribute("ID")); bool toggleAutoHide = false; if (mainElement.HasAttribute("IsAutoHidden")) toggleAutoHide = XmlConvert.ToBoolean(mainElement.GetAttribute("IsAutoHidden")); foreach (XmlElement contentElement in mainElement.ChildNodes) { if (contentElement.HasAttribute("Name")) { DockableContent foundContent = null; string contentName = contentElement.GetAttribute("Name"); foundContent = actualContents.FirstOrDefault(c => c.Name == contentName); if (foundContent == null && DeserializationCallback != null) { DeserializationCallbackEventArgs e = new DeserializationCallbackEventArgs(contentName); DeserializationCallback(this, e); foundContent = e.Content as DockableContent; } if (foundContent != null) { DetachContentFromDockingManager(foundContent); pane.Items.Add(foundContent); foundContent.SetStateToDock(); //call custom layout persistence method foundContent.RestoreLayout(contentElement); } } } if (toggleAutoHide && pane.Items.Count > 0) ToggleAutoHide(pane); if (mainElement.HasAttribute("SelectedIndex")) pane.SelectedIndex = XmlConvert.ToInt32(mainElement.GetAttribute("SelectedIndex")); return pane; }
private void DSPane(object sender, DeserializationCallbackEventArgs e) { e.Content=GetContent(e.Name); if(e.Content==null) { Log.Warning("{0} not restored", e.Name); } }