public static void RestoreApplication(DockPanel dockPanel, Stream stream, DockPanelExt.DeserializeDockContentDelegate deserializeDockContent) { if (dockPanel.Contents.Count != 0) { throw new InvalidOperationException("DockPanel is Already Initialized"); } var xmlIn = new XmlTextReader(stream) { WhitespaceHandling = WhitespaceHandling.None }; xmlIn.MoveToContent(); while (!xmlIn.Name.Equals("ApplicationDocks")) { if (!MoveToNextElement(xmlIn)) { throw new ArgumentException("Invalid Xml Format"); } } string formatVersion = xmlIn.GetAttribute("FormatVersion"); if (!IsFormatVersionValid(formatVersion)) { throw new ArgumentException("Invalid FormatVersion"); } MoveToNextElement(xmlIn); RestoreDockPanel(dockPanel, xmlIn, deserializeDockContent); }
public WorkSpaceForm(string tabText) { InitializeComponent(); this.Text = tabText; m_DeserializeItemContent = DeserializeItemContent; }
public MainForm() { InitializeComponent(); m_DeserializeDockContent = DeserializeDockContent; //m_MainTaskList.Show(MainDockPanel); //m_MainToolBox.Show(MainDockPanel); //m_WorkspacesDock.Show(MainDockPanel); }
private static ContentStruct[] LoadAndCreateContents(DockPanel dockPanel, XmlTextReader xmlIn, DockPanelExt.DeserializeDockContentDelegate deserializeDockContent) { int countOfContents = Convert.ToInt32(xmlIn.GetAttribute("Count"), CultureInfo.InvariantCulture); ContentStruct[] contents = new ContentStruct[countOfContents]; for (int i = 0; i < countOfContents; i++) { MoveToNextElement(xmlIn); int id = Convert.ToInt32(xmlIn.GetAttribute("ID"), CultureInfo.InvariantCulture); if (xmlIn.Name != "Content" || id != i) { throw new ArgumentException("Invalid Xml Format"); } contents[i].AutoHidePortion = Convert.ToDouble(xmlIn.GetAttribute("AutoHidePortion"), CultureInfo.InvariantCulture); contents[i].IsHidden = Convert.ToBoolean(xmlIn.GetAttribute("IsHidden"), CultureInfo.InvariantCulture); contents[i].IsFloat = Convert.ToBoolean(xmlIn.GetAttribute("IsFloat"), CultureInfo.InvariantCulture); MoveToNextElement(xmlIn); IDockContent content = deserializeDockContent(xmlIn.LocalName, xmlIn) ?? new DummyContent(); content.DockHandler.DockPanel = dockPanel; content.DockHandler.AutoHidePortion = contents[i].AutoHidePortion; content.DockHandler.IsHidden = true; content.DockHandler.IsFloat = contents[i].IsFloat; //MoveToNextElement(xmlIn); } return(contents); }
public static void RestoreDockPanel(DockPanel dockPanel, XmlTextReader xmlIn, DockPanelExt.DeserializeDockContentDelegate deserializeDockContent) { if (xmlIn.Name != "DockPanel") { throw new ArgumentException("Invalid Xml Format"); } var dockPanelStruct = new DockPanelStruct(); dockPanelStruct.DockLeftPortion = Convert.ToDouble(xmlIn.GetAttribute("DockLeftPortion"), CultureInfo.InvariantCulture); dockPanelStruct.DockRightPortion = Convert.ToDouble(xmlIn.GetAttribute("DockRightPortion"), CultureInfo.InvariantCulture); dockPanelStruct.DockTopPortion = Convert.ToDouble(xmlIn.GetAttribute("DockTopPortion"), CultureInfo.InvariantCulture); dockPanelStruct.DockBottomPortion = Convert.ToDouble(xmlIn.GetAttribute("DockBottomPortion"), CultureInfo.InvariantCulture); dockPanelStruct.IndexActiveDocumentPane = Convert.ToInt32(xmlIn.GetAttribute("ActiveDocumentPane"), CultureInfo.InvariantCulture); dockPanelStruct.IndexActivePane = Convert.ToInt32(xmlIn.GetAttribute("ActivePane"), CultureInfo.InvariantCulture); // Load Contents MoveToNextElement(xmlIn); if (xmlIn.Name != "Contents") { throw new ArgumentException("Invalid Xml Format"); } ContentStruct[] contents = LoadAndCreateContents(dockPanel, xmlIn, deserializeDockContent); // Load Panes MoveToNextElement(xmlIn); if (xmlIn.Name != "Panes") { throw new ArgumentException("Invalid Xml Format"); } PaneStruct[] panes = LoadPanes(xmlIn); // Load DockWindows MoveToNextElement(xmlIn); if (xmlIn.Name != "DockWindows") { throw new ArgumentException("Invalid Xml Format"); } DockWindowStruct[] dockWindows = LoadDockWindows(xmlIn, dockPanel); // Load FloatWindows MoveToNextElement(xmlIn); if (xmlIn.Name != "FloatWindows") { throw new ArgumentException("Invalid Xml Format"); } FloatWindowStruct[] floatWindows = LoadFloatWindows(xmlIn); dockPanel.SuspendLayout(true); dockPanel.DockLeftPortion = dockPanelStruct.DockLeftPortion; dockPanel.DockRightPortion = dockPanelStruct.DockRightPortion; dockPanel.DockTopPortion = dockPanelStruct.DockTopPortion; dockPanel.DockBottomPortion = dockPanelStruct.DockBottomPortion; // Set DockWindow ZOrders int prevMaxDockWindowZOrder = int.MaxValue; for (int i = 0; i < dockWindows.Length; i++) { int maxDockWindowZOrder = -1; int index = -1; for (int j = 0; j < dockWindows.Length; j++) { if (dockWindows[j].ZOrderIndex > maxDockWindowZOrder && dockWindows[j].ZOrderIndex < prevMaxDockWindowZOrder) { maxDockWindowZOrder = dockWindows[j].ZOrderIndex; index = j; } } dockPanel.DockWindows[dockWindows[index].DockState].BringToFront(); prevMaxDockWindowZOrder = maxDockWindowZOrder; } // Create panes foreach (PaneStruct t in panes) { DockPane pane = null; for (int j = 0; j < t.IndexContents.Length; j++) { IDockContent content = dockPanel.Contents[t.IndexContents[j]]; if (j == 0) { pane = dockPanel.DockPaneFactory.CreateDockPane(content, t.DockState, false); } else if (t.DockState == DockState.Float) { content.DockHandler.FloatPane = pane; } else { content.DockHandler.PanelPane = pane; } } } // Assign Panes to DockWindows foreach (DockWindowStruct t in dockWindows) { for (int j = 0; j < t.NestedPanes.Length; j++) { DockWindow dw = dockPanel.DockWindows[t.DockState]; int indexPane = t.NestedPanes[j].IndexPane; DockPane pane = dockPanel.Panes[indexPane]; int indexPrevPane = t.NestedPanes[j].IndexPrevPane; DockPane prevPane = (indexPrevPane == -1) ? dw.NestedPanes.GetDefaultPreviousPane(pane) : dockPanel.Panes[indexPrevPane]; DockAlignment alignment = t.NestedPanes[j].Alignment; double proportion = t.NestedPanes[j].Proportion; pane.DockTo(dw, prevPane, alignment, proportion); if (panes[indexPane].DockState == dw.DockState) { panes[indexPane].ZOrderIndex = t.ZOrderIndex; } } } // Create float windows foreach (FloatWindowStruct t in floatWindows) { FloatWindow fw = null; for (int j = 0; j < t.NestedPanes.Length; j++) { int indexPane = t.NestedPanes[j].IndexPane; DockPane pane = dockPanel.Panes[indexPane]; if (j == 0) { fw = dockPanel.FloatWindowFactory.CreateFloatWindow(dockPanel, pane, t.Bounds); } else { int indexPrevPane = t.NestedPanes[j].IndexPrevPane; DockPane prevPane = indexPrevPane == -1 ? null : dockPanel.Panes[indexPrevPane]; DockAlignment alignment = t.NestedPanes[j].Alignment; double proportion = t.NestedPanes[j].Proportion; pane.DockTo(fw, prevPane, alignment, proportion); } if (panes[indexPane].DockState == fw.DockState) { panes[indexPane].ZOrderIndex = t.ZOrderIndex; } } } // sort IDockContent by its Pane's ZOrder int[] sortedContents = null; if (contents.Length > 0) { sortedContents = new int[contents.Length]; for (int i = 0; i < contents.Length; i++) { sortedContents[i] = i; } int lastDocument = contents.Length; for (int i = 0; i < contents.Length - 1; i++) { for (int j = i + 1; j < contents.Length; j++) { DockPane pane1 = dockPanel.Contents[sortedContents[i]].DockHandler.Pane; int ZOrderIndex1 = pane1 == null ? 0 : panes[dockPanel.Panes.IndexOf(pane1)].ZOrderIndex; DockPane pane2 = dockPanel.Contents[sortedContents[j]].DockHandler.Pane; int ZOrderIndex2 = pane2 == null ? 0 : panes[dockPanel.Panes.IndexOf(pane2)].ZOrderIndex; if (ZOrderIndex1 > ZOrderIndex2) { int temp = sortedContents[i]; sortedContents[i] = sortedContents[j]; sortedContents[j] = temp; } } } } // show non-document IDockContent first to avoid screen flickers for (int i = 0; i < contents.Length; i++) { IDockContent content = dockPanel.Contents[sortedContents[i]]; if (content.DockHandler.Pane != null && content.DockHandler.Pane.DockState != DockState.Document) { content.DockHandler.IsHidden = contents[sortedContents[i]].IsHidden; } } // after all non-document IDockContent, show document IDockContent for (int i = 0; i < contents.Length; i++) { IDockContent content = dockPanel.Contents[sortedContents[i]]; if (content.DockHandler.Pane != null && content.DockHandler.Pane.DockState == DockState.Document) { content.DockHandler.IsHidden = contents[sortedContents[i]].IsHidden; } } for (int i = 0; i < panes.Length; i++) { dockPanel.Panes[i].ActiveContent = panes[i].IndexActiveContent == -1 ? null : dockPanel.Contents[panes[i].IndexActiveContent]; } if (dockPanelStruct.IndexActiveDocumentPane != -1) { dockPanel.Panes[dockPanelStruct.IndexActiveDocumentPane].Activate(); } if (dockPanelStruct.IndexActivePane != -1) { dockPanel.Panes[dockPanelStruct.IndexActivePane].Activate(); } for (int i = dockPanel.Contents.Count - 1; i >= 0; i--) { if (dockPanel.Contents[i] is DummyContent) { dockPanel.Contents[i].DockHandler.Form.Close(); } } dockPanel.ResumeLayout(true, true); }