Пример #1
0
            public static void SaveAsXml(DockPanel dockPanel, Stream stream, Encoding encoding, bool upstream)
            {
                XmlTextWriter xmlOut = new XmlTextWriter(stream, encoding);

                // Use indenting for readability
                xmlOut.Formatting = Formatting.Indented;

                if (!upstream)
                    xmlOut.WriteStartDocument();

                // Always begin file with identification and warning
                xmlOut.WriteComment(Strings.DockPanel_Persistor_XmlFileComment1);
                xmlOut.WriteComment(Strings.DockPanel_Persistor_XmlFileComment2);

                // Associate a version number with the root element so that future version of the code
                // will be able to be backwards compatible or at least recognise out of date versions
                xmlOut.WriteStartElement("DockPanel");
                xmlOut.WriteAttributeString("FormatVersion", ConfigFileVersion);
                xmlOut.WriteAttributeString("DockLeftPortion", dockPanel.DockLeftPortion.ToString(CultureInfo.InvariantCulture));
                xmlOut.WriteAttributeString("DockRightPortion", dockPanel.DockRightPortion.ToString(CultureInfo.InvariantCulture));
                xmlOut.WriteAttributeString("DockTopPortion", dockPanel.DockTopPortion.ToString(CultureInfo.InvariantCulture));
                xmlOut.WriteAttributeString("DockBottomPortion", dockPanel.DockBottomPortion.ToString(CultureInfo.InvariantCulture));

                if (!Win32Helper.IsRunningOnMono)
                {
                    xmlOut.WriteAttributeString("ActiveDocumentPane", dockPanel.Panes.IndexOf(dockPanel.ActiveDocumentPane).ToString(CultureInfo.InvariantCulture));
                    xmlOut.WriteAttributeString("ActivePane", dockPanel.Panes.IndexOf(dockPanel.ActivePane).ToString(CultureInfo.InvariantCulture));
                }                

                // Contents
                xmlOut.WriteStartElement("Contents");
                xmlOut.WriteAttributeString("Count", dockPanel.Contents.Count.ToString(CultureInfo.InvariantCulture));
                foreach (IDockContent content in dockPanel.Contents)
                {
                    xmlOut.WriteStartElement("Content");
                    xmlOut.WriteAttributeString("ID", dockPanel.Contents.IndexOf(content).ToString(CultureInfo.InvariantCulture));
                    xmlOut.WriteAttributeString("PersistString", content.DockHandler.PersistString);
                    xmlOut.WriteAttributeString("AutoHidePortion", content.DockHandler.AutoHidePortion.ToString(CultureInfo.InvariantCulture));
                    xmlOut.WriteAttributeString("IsHidden", content.DockHandler.IsHidden.ToString(CultureInfo.InvariantCulture));
                    xmlOut.WriteAttributeString("IsFloat", content.DockHandler.IsFloat.ToString(CultureInfo.InvariantCulture));
                    xmlOut.WriteEndElement();
                }
                xmlOut.WriteEndElement();

                // Panes
                xmlOut.WriteStartElement("Panes");
                xmlOut.WriteAttributeString("Count", dockPanel.Panes.Count.ToString(CultureInfo.InvariantCulture));
                foreach (DockPane pane in dockPanel.Panes)
                {
                    xmlOut.WriteStartElement("Pane");
                    xmlOut.WriteAttributeString("ID", dockPanel.Panes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
                    xmlOut.WriteAttributeString("DockState", pane.DockState.ToString());
                    xmlOut.WriteAttributeString("ActiveContent", dockPanel.Contents.IndexOf(pane.ActiveContent).ToString(CultureInfo.InvariantCulture));
                    xmlOut.WriteStartElement("Contents");
                    xmlOut.WriteAttributeString("Count", pane.Contents.Count.ToString(CultureInfo.InvariantCulture));
                    foreach (IDockContent content in pane.Contents)
                    {
                        xmlOut.WriteStartElement("Content");
                        xmlOut.WriteAttributeString("ID", pane.Contents.IndexOf(content).ToString(CultureInfo.InvariantCulture));
                        xmlOut.WriteAttributeString("RefID", dockPanel.Contents.IndexOf(content).ToString(CultureInfo.InvariantCulture));
                        xmlOut.WriteEndElement();
                    }
                    xmlOut.WriteEndElement();
                    xmlOut.WriteEndElement();
                }
                xmlOut.WriteEndElement();

                // DockWindows
                xmlOut.WriteStartElement("DockWindows");
                int dockWindowId = 0;
                foreach (DockWindow dw in dockPanel.DockWindows)
                {
                    xmlOut.WriteStartElement("DockWindow");
                    xmlOut.WriteAttributeString("ID", dockWindowId.ToString(CultureInfo.InvariantCulture));
                    dockWindowId++;
                    xmlOut.WriteAttributeString("DockState", dw.DockState.ToString());
                    xmlOut.WriteAttributeString("ZOrderIndex", dockPanel.Controls.IndexOf(dw).ToString(CultureInfo.InvariantCulture));
                    xmlOut.WriteStartElement("NestedPanes");
                    xmlOut.WriteAttributeString("Count", dw.NestedPanes.Count.ToString(CultureInfo.InvariantCulture));
                    foreach (DockPane pane in dw.NestedPanes)
                    {
                        xmlOut.WriteStartElement("Pane");
                        xmlOut.WriteAttributeString("ID", dw.NestedPanes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
                        xmlOut.WriteAttributeString("RefID", dockPanel.Panes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
                        NestedDockingStatus status = pane.NestedDockingStatus;
                        xmlOut.WriteAttributeString("PrevPane", dockPanel.Panes.IndexOf(status.PreviousPane).ToString(CultureInfo.InvariantCulture));
                        xmlOut.WriteAttributeString("Alignment", status.Alignment.ToString());
                        xmlOut.WriteAttributeString("Proportion", status.Proportion.ToString(CultureInfo.InvariantCulture));
                        xmlOut.WriteEndElement();
                    }
                    xmlOut.WriteEndElement();
                    xmlOut.WriteEndElement();
                }
                xmlOut.WriteEndElement();

                // FloatWindows
                RectangleConverter rectConverter = new RectangleConverter();
                xmlOut.WriteStartElement("FloatWindows");
                xmlOut.WriteAttributeString("Count", dockPanel.FloatWindows.Count.ToString(CultureInfo.InvariantCulture));
                foreach (FloatWindow fw in dockPanel.FloatWindows)
                {
                    xmlOut.WriteStartElement("FloatWindow");
                    xmlOut.WriteAttributeString("ID", dockPanel.FloatWindows.IndexOf(fw).ToString(CultureInfo.InvariantCulture));
                    xmlOut.WriteAttributeString("Bounds", rectConverter.ConvertToInvariantString(fw.Bounds));
                    xmlOut.WriteAttributeString("ZOrderIndex", fw.DockPanel.FloatWindows.IndexOf(fw).ToString(CultureInfo.InvariantCulture));
                    xmlOut.WriteStartElement("NestedPanes");
                    xmlOut.WriteAttributeString("Count", fw.NestedPanes.Count.ToString(CultureInfo.InvariantCulture));
                    foreach (DockPane pane in fw.NestedPanes)
                    {
                        xmlOut.WriteStartElement("Pane");
                        xmlOut.WriteAttributeString("ID", fw.NestedPanes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
                        xmlOut.WriteAttributeString("RefID", dockPanel.Panes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
                        NestedDockingStatus status = pane.NestedDockingStatus;
                        xmlOut.WriteAttributeString("PrevPane", dockPanel.Panes.IndexOf(status.PreviousPane).ToString(CultureInfo.InvariantCulture));
                        xmlOut.WriteAttributeString("Alignment", status.Alignment.ToString());
                        xmlOut.WriteAttributeString("Proportion", status.Proportion.ToString(CultureInfo.InvariantCulture));
                        xmlOut.WriteEndElement();
                    }
                    xmlOut.WriteEndElement();
                    xmlOut.WriteEndElement();
                }
                xmlOut.WriteEndElement();	//	</FloatWindows>

                xmlOut.WriteEndElement();

                if (!upstream)
                {
                    xmlOut.WriteEndDocument();
                    xmlOut.Close();
                }
                else
                    xmlOut.Flush();
            }
Пример #2
0
        /// <summary>
        /// Save ECell window settings.
        /// </summary>
        /// <param name="window">MainWindow object.</param>
        /// <param name="filename">the file name.</param>
        /// <param name="isClosing">whether this file is closed.</param>
        public static void SaveAsXML(MainWindow window, string filename, bool isClosing)
        {
            DockPanel dockPanel = window.DockPanel;
            CheckUnsavableWindows(dockPanel, isClosing);
            CheckFilePath(filename);
            FileStream fs = null;
            XmlTextWriter xmlOut = null;
            try
            {
                // Create xml file
                fs = new FileStream(filename, FileMode.Create);
                xmlOut = new XmlTextWriter(fs, Encoding.UTF8);

                // Use indenting for readability
                xmlOut.Formatting = Formatting.Indented;
                xmlOut.WriteStartDocument();

                // Always begin file with identification and warning
                xmlOut.WriteComment(Constants.xPathFileHeader1);
                xmlOut.WriteComment(Constants.xPathFileHeader2);

                // Application settings
                xmlOut.WriteStartElement("Application");
                xmlOut.WriteAttributeString("Name", Application.ProductName);
                xmlOut.WriteAttributeString("Version", Application.ProductVersion);
                xmlOut.WriteAttributeString("ConfigFileVersion", ConfigFileVersion);

                // Form settings
                xmlOut.WriteStartElement("Form");
                xmlOut.WriteAttributeString("WindowState", window.WindowState.ToString());
                xmlOut.WriteAttributeString("Screen", GetScreenNum(window) );
                if (window.WindowState == FormWindowState.Maximized)
                {
                    xmlOut.WriteAttributeString("Top", window.RestoreBounds.Top.ToString());
                    xmlOut.WriteAttributeString("Left", window.RestoreBounds.Left.ToString());
                    xmlOut.WriteAttributeString("Height", window.RestoreBounds.Height.ToString());
                    xmlOut.WriteAttributeString("Width", window.RestoreBounds.Width.ToString());
                }
                else
                {
                    xmlOut.WriteAttributeString("Top", window.DesktopBounds.Top.ToString());
                    xmlOut.WriteAttributeString("Left", window.DesktopBounds.Left.ToString());
                    xmlOut.WriteAttributeString("Height", window.DesktopBounds.Height.ToString());
                    xmlOut.WriteAttributeString("Width", window.DesktopBounds.Width.ToString());
                }
                xmlOut.WriteEndElement();   //</Form>

                // DockPanel settings
                xmlOut.WriteStartElement("DockPanel");//	<DockPanel>
                xmlOut.WriteAttributeString("DockLeftPortion", dockPanel.DockLeftPortion.ToString());
                xmlOut.WriteAttributeString("DockRightPortion", dockPanel.DockRightPortion.ToString());
                xmlOut.WriteAttributeString("DockTopPortion", dockPanel.DockTopPortion.ToString());
                xmlOut.WriteAttributeString("DockBottomPortion", dockPanel.DockBottomPortion.ToString());
                xmlOut.WriteAttributeString("ActiveDocumentPane", dockPanel.Panes.IndexOf(dockPanel.ActiveDocumentPane).ToString());
                xmlOut.WriteAttributeString("ActivePane", dockPanel.Panes.IndexOf(dockPanel.ActivePane).ToString());

                // Contents
                xmlOut.WriteStartElement("Contents");//	<Contents>
                xmlOut.WriteAttributeString("Count", dockPanel.Contents.Count.ToString());
                foreach (DockContent content in dockPanel.Contents)
                {
                    xmlOut.WriteStartElement("Content");
                    xmlOut.WriteAttributeString("ID", dockPanel.Contents.IndexOf(content).ToString());
                    xmlOut.WriteAttributeString("Name", content.Name.ToString());
                    xmlOut.WriteAttributeString("AutoHidePortion", content.DockHandler.AutoHidePortion.ToString());
                    xmlOut.WriteAttributeString("IsHidden", content.DockHandler.IsHidden.ToString());
                    xmlOut.WriteAttributeString("IsFloat", content.DockHandler.IsFloat.ToString());
                    xmlOut.WriteEndElement();
                }
                xmlOut.WriteEndElement();//	</Contents>

                // Panes
                xmlOut.WriteStartElement("Panes");//	<Panes>
                xmlOut.WriteAttributeString("Count", dockPanel.Panes.Count.ToString());
                foreach (DockPane pane in dockPanel.Panes)
                {
                    xmlOut.WriteStartElement("Pane");//	<Panes>
                    xmlOut.WriteAttributeString("ID", dockPanel.Panes.IndexOf(pane).ToString());
                    xmlOut.WriteAttributeString("DockState", pane.DockState.ToString());
                    xmlOut.WriteAttributeString("ActiveContent", dockPanel.Contents.IndexOf(pane.ActiveContent).ToString());
                    xmlOut.WriteStartElement("Contents");//	<Contents>
                    xmlOut.WriteAttributeString("Count", pane.Contents.Count.ToString());
                    foreach (DockContent content in pane.Contents)
                    {
                        xmlOut.WriteStartElement("Content");//	<Content>
                        xmlOut.WriteAttributeString("ID", pane.Contents.IndexOf(content).ToString());
                        xmlOut.WriteAttributeString("Name", content.Name);
                        xmlOut.WriteAttributeString("RefID", dockPanel.Contents.IndexOf(content).ToString());
                        xmlOut.WriteEndElement();//	</Content>
                    }
                    xmlOut.WriteEndElement();//	</Contents>
                    xmlOut.WriteEndElement();//	</Pane>
                }
                xmlOut.WriteEndElement();//	</Panes>

                // DockWindows
                xmlOut.WriteStartElement("DockWindows");
                int dockWindowId = 0;
                foreach (DockWindow dw in dockPanel.DockWindows)
                {
                    xmlOut.WriteStartElement("DockWindow");
                    xmlOut.WriteAttributeString("ID", dockWindowId.ToString());
                    dockWindowId++;
                    xmlOut.WriteAttributeString("DockState", dw.DockState.ToString());
                    xmlOut.WriteAttributeString("ZOrderIndex", dockPanel.Controls.IndexOf(dw).ToString());
                    xmlOut.WriteStartElement("NestedPanes");
                    xmlOut.WriteAttributeString("Count", dw.NestedPanes.Count.ToString());
                    foreach (DockPane pane in dw.NestedPanes)
                    {
                        xmlOut.WriteStartElement("Pane");
                        xmlOut.WriteAttributeString("ID", dw.NestedPanes.IndexOf(pane).ToString());
                        xmlOut.WriteAttributeString("RefID", dockPanel.Panes.IndexOf(pane).ToString());
                        NestedDockingStatus status = pane.NestedDockingStatus;
                        xmlOut.WriteAttributeString("PrevPane", dockPanel.Panes.IndexOf(status.PreviousPane).ToString());
                        xmlOut.WriteAttributeString("Alignment", status.Alignment.ToString());
                        xmlOut.WriteAttributeString("Proportion", status.Proportion.ToString());
                        xmlOut.WriteEndElement();
                    }
                    xmlOut.WriteEndElement();//	</NestedPanes>
                    xmlOut.WriteEndElement();//	</DockWindow>
                }
                xmlOut.WriteEndElement();//	</DockWindows>

                // FloatWindows
                RectangleConverter rectConverter = new RectangleConverter();
                xmlOut.WriteStartElement("FloatWindows");
                xmlOut.WriteAttributeString("Count", dockPanel.FloatWindows.Count.ToString());
                foreach (FloatWindow fw in dockPanel.FloatWindows)
                {
                    xmlOut.WriteStartElement("FloatWindow");
                    xmlOut.WriteAttributeString("ID", dockPanel.FloatWindows.IndexOf(fw).ToString());
                    xmlOut.WriteAttributeString("Bounds", rectConverter.ConvertToInvariantString(fw.Bounds));
                    xmlOut.WriteAttributeString("ZOrderIndex", fw.DockPanel.FloatWindows.IndexOf(fw).ToString());
                    xmlOut.WriteAttributeString("Screen", GetScreenNum(fw));
                    xmlOut.WriteStartElement("NestedPanes");
                    xmlOut.WriteAttributeString("Count", fw.NestedPanes.Count.ToString());
                    foreach (DockPane pane in fw.NestedPanes)
                    {
                        xmlOut.WriteStartElement("Pane");
                        xmlOut.WriteAttributeString("ID", fw.NestedPanes.IndexOf(pane).ToString());
                        xmlOut.WriteAttributeString("RefID", dockPanel.Panes.IndexOf(pane).ToString());
                        NestedDockingStatus status = pane.NestedDockingStatus;
                        xmlOut.WriteAttributeString("PrevPane", dockPanel.Panes.IndexOf(status.PreviousPane).ToString());
                        xmlOut.WriteAttributeString("Alignment", status.Alignment.ToString());
                        xmlOut.WriteAttributeString("Proportion", status.Proportion.ToString());
                        xmlOut.WriteEndElement();
                    }
                    xmlOut.WriteEndElement();//	</NestedPanes>
                    xmlOut.WriteEndElement();//	</FloatWindow>
                }
                xmlOut.WriteEndElement();	//	</FloatWindows>

                xmlOut.WriteEndElement();   //	</DockPanel>
                xmlOut.WriteEndElement();   //	</Application>

                //xmlOut.WriteEndDocument();
                xmlOut.WriteEndDocument();
            }
            finally
            {
                if (xmlOut != null) xmlOut.Close();
                if (fs != null) fs.Close();
            }
        }
Пример #3
0
		public static void SaveAsXml(DockPanel dockPanel, Stream stream, Encoding encoding)
		{
			XmlTextWriter xmlOut = new XmlTextWriter(stream, encoding); 

			// Use indenting for readability
			xmlOut.Formatting = Formatting.Indented;
			
			// Always begin file with identification and warning
			xmlOut.WriteStartDocument();
			xmlOut.WriteComment(" DockPanel configuration file. Author: Weifen Luo, all rights reserved. ");
			xmlOut.WriteComment(" !!! AUTOMATICALLY GENERATED FILE. DO NOT MODIFY !!! ");

			// Associate a version number with the root element so that future version of the code
			// will be able to be backwards compatible or at least recognise out of date versions
			xmlOut.WriteStartElement("DockPanel");
			xmlOut.WriteAttributeString("FormatVersion", ConfigFileVersion);
			xmlOut.WriteAttributeString("DockLeftPortion", dockPanel.DockLeftPortion.ToString(CultureInfo.InvariantCulture));
			xmlOut.WriteAttributeString("DockRightPortion", dockPanel.DockRightPortion.ToString(CultureInfo.InvariantCulture));
			xmlOut.WriteAttributeString("DockTopPortion", dockPanel.DockTopPortion.ToString(CultureInfo.InvariantCulture));
			xmlOut.WriteAttributeString("DockBottomPortion", dockPanel.DockBottomPortion.ToString(CultureInfo.InvariantCulture));
			xmlOut.WriteAttributeString("ActiveDocumentPane", dockPanel.Panes.IndexOf(dockPanel.ActiveDocumentPane).ToString());
			xmlOut.WriteAttributeString("ActivePane", dockPanel.Panes.IndexOf(dockPanel.ActivePane).ToString());

			// Contents
			xmlOut.WriteStartElement("Contents");
			xmlOut.WriteAttributeString("Count", dockPanel.Contents.Count.ToString());
			foreach (DockContent content in dockPanel.Contents)
			{
				xmlOut.WriteStartElement("Content");
				xmlOut.WriteAttributeString("ID", dockPanel.Contents.IndexOf(content).ToString());
				xmlOut.WriteAttributeString("PersistString", content.PersistString);
				xmlOut.WriteAttributeString("AutoHidePortion", content.AutoHidePortion.ToString(CultureInfo.InvariantCulture));
				xmlOut.WriteAttributeString("IsHidden", content.IsHidden.ToString());
				xmlOut.WriteAttributeString("IsFloat", content.IsFloat.ToString());
				xmlOut.WriteEndElement();
			}
			xmlOut.WriteEndElement();

			// Panes
			xmlOut.WriteStartElement("Panes");
			xmlOut.WriteAttributeString("Count", dockPanel.Panes.Count.ToString());
			foreach (DockPane pane in dockPanel.Panes)
			{
				xmlOut.WriteStartElement("Pane");
				xmlOut.WriteAttributeString("ID", dockPanel.Panes.IndexOf(pane).ToString());
				xmlOut.WriteAttributeString("DockState", pane.DockState.ToString());
				xmlOut.WriteAttributeString("ActiveContent", dockPanel.Contents.IndexOf(pane.ActiveContent).ToString());
				xmlOut.WriteStartElement("Contents");
				xmlOut.WriteAttributeString("Count", pane.Contents.Count.ToString());
				foreach (DockContent content in pane.Contents)
				{
					xmlOut.WriteStartElement("Content");
					xmlOut.WriteAttributeString("ID", pane.Contents.IndexOf(content).ToString());
					xmlOut.WriteAttributeString("RefID", dockPanel.Contents.IndexOf(content).ToString());
					xmlOut.WriteEndElement();
				}
				xmlOut.WriteEndElement();
				xmlOut.WriteEndElement();
			}
			xmlOut.WriteEndElement();

			// DockWindows
			xmlOut.WriteStartElement("DockWindows");
			int count = 0;
			foreach (DockWindow dw in dockPanel.DockWindows)
				if (dw.DockList.Count > 0)
					count++;
			xmlOut.WriteAttributeString("Count", count.ToString());
			int i = 0;
			foreach (DockWindow dw in dockPanel.DockWindows)
			{
				if (dw.DockList.Count == 0)
					continue;
				xmlOut.WriteStartElement("DockWindow");
				xmlOut.WriteAttributeString("ID", i.ToString());
				xmlOut.WriteAttributeString("DockState", dw.DockState.ToString());
				xmlOut.WriteAttributeString("ZOrderIndex", dockPanel.Controls.IndexOf(dw).ToString());
				xmlOut.WriteStartElement("DockList");
				xmlOut.WriteAttributeString("Count", dw.DockList.Count.ToString());
				foreach (DockPane pane in dw.DockList)
				{
					xmlOut.WriteStartElement("Pane");
					xmlOut.WriteAttributeString("ID", dw.DockList.IndexOf(pane).ToString());
					xmlOut.WriteAttributeString("RefID", dockPanel.Panes.IndexOf(pane).ToString());
					NestedDockingStatus status = pane.NestedDockingStatus;
					xmlOut.WriteAttributeString("PrevPane", dockPanel.Panes.IndexOf(status.PrevPane).ToString());
					xmlOut.WriteAttributeString("Alignment", status.Alignment.ToString());
					xmlOut.WriteAttributeString("Proportion", status.Proportion.ToString(CultureInfo.InvariantCulture));
					xmlOut.WriteEndElement();
				}
				xmlOut.WriteEndElement();
				xmlOut.WriteEndElement();
				i++;
			}
			xmlOut.WriteEndElement();

			// FloatWindows
			RectangleConverter rectConverter = new RectangleConverter();
			xmlOut.WriteStartElement("FloatWindows");
			xmlOut.WriteAttributeString("Count", dockPanel.FloatWindows.Count.ToString());
			foreach (FloatWindow fw in dockPanel.FloatWindows)
			{
				xmlOut.WriteStartElement("FloatWindow");
				xmlOut.WriteAttributeString("ID", dockPanel.FloatWindows.IndexOf(fw).ToString());
				xmlOut.WriteAttributeString("Bounds", rectConverter.ConvertToInvariantString(fw.Bounds));
				xmlOut.WriteAttributeString("AllowRedocking", fw.AllowRedocking.ToString());
				xmlOut.WriteAttributeString("ZOrderIndex", fw.DockPanel.FloatWindows.IndexOf(fw).ToString());
				xmlOut.WriteStartElement("DockList");
				xmlOut.WriteAttributeString("Count", fw.DockList.Count.ToString());
				foreach (DockPane pane in fw.DockList)
				{
					xmlOut.WriteStartElement("Pane");
					xmlOut.WriteAttributeString("ID", fw.DockList.IndexOf(pane).ToString());
					xmlOut.WriteAttributeString("RefID", dockPanel.Panes.IndexOf(pane).ToString());
					NestedDockingStatus status = pane.NestedDockingStatus;
					xmlOut.WriteAttributeString("PrevPane", dockPanel.Panes.IndexOf(status.PrevPane).ToString());
					xmlOut.WriteAttributeString("Alignment", status.Alignment.ToString());
					xmlOut.WriteAttributeString("Proportion", status.Proportion.ToString(CultureInfo.InvariantCulture));
					xmlOut.WriteEndElement();
				}
				xmlOut.WriteEndElement();
				xmlOut.WriteEndElement();
			}
			xmlOut.WriteEndElement();	//	</FloatWindows>
			
			xmlOut.WriteEndElement();
			xmlOut.WriteEndDocument();

			// This should flush all actions and close the file
			xmlOut.Close();
		}
Пример #4
0
        public static void SaveApplication(DockPanel dockPanel, XmlTextWriter xmlWriter)
        {
            // Associate a version number with the root element so that future version of the code
            // will be able to be backwards compatible or at least recognise out of date versions
            xmlWriter.WriteStartElement("DockPanel");
            xmlWriter.WriteAttributeString("DockLeftPortion", dockPanel.DockLeftPortion.ToString(CultureInfo.InvariantCulture));
            xmlWriter.WriteAttributeString("DockRightPortion", dockPanel.DockRightPortion.ToString(CultureInfo.InvariantCulture));
            xmlWriter.WriteAttributeString("DockTopPortion", dockPanel.DockTopPortion.ToString(CultureInfo.InvariantCulture));
            xmlWriter.WriteAttributeString("DockBottomPortion", dockPanel.DockBottomPortion.ToString(CultureInfo.InvariantCulture));

            if (!Win32Helper.IsRunningOnMono)
            {
                xmlWriter.WriteAttributeString("ActiveDocumentPane", dockPanel.Panes.IndexOf(dockPanel.ActiveDocumentPane).ToString(CultureInfo.InvariantCulture));
                xmlWriter.WriteAttributeString("ActivePane", dockPanel.Panes.IndexOf(dockPanel.ActivePane).ToString(CultureInfo.InvariantCulture));
            }

            // Contents
            xmlWriter.WriteStartElement("Contents");
            xmlWriter.WriteAttributeString("Count", dockPanel.Contents.Count.ToString(CultureInfo.InvariantCulture));
            foreach (WorkItemDockContent content in dockPanel.Contents)
            {
                xmlWriter.WriteStartElement("Content");
                xmlWriter.WriteAttributeString("ID", dockPanel.Contents.IndexOf(content).ToString(CultureInfo.InvariantCulture));
                xmlWriter.WriteAttributeString("AutoHidePortion", content.DockHandler.AutoHidePortion.ToString(CultureInfo.InvariantCulture));
                xmlWriter.WriteAttributeString("IsHidden", content.DockHandler.IsHidden.ToString(CultureInfo.InvariantCulture));
                xmlWriter.WriteAttributeString("IsFloat", content.DockHandler.IsFloat.ToString(CultureInfo.InvariantCulture));

                content.Save(xmlWriter);

                xmlWriter.WriteEndElement();
            }
            xmlWriter.WriteEndElement();

            // Panes
            xmlWriter.WriteStartElement("Panes");
            xmlWriter.WriteAttributeString("Count", dockPanel.Panes.Count.ToString(CultureInfo.InvariantCulture));
            foreach (DockPane pane in dockPanel.Panes)
            {
                xmlWriter.WriteStartElement("Pane");
                xmlWriter.WriteAttributeString("ID", dockPanel.Panes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
                xmlWriter.WriteAttributeString("DockState", pane.DockState.ToString());
                xmlWriter.WriteAttributeString("ActiveContent", dockPanel.Contents.IndexOf(pane.ActiveContent).ToString(CultureInfo.InvariantCulture));
                xmlWriter.WriteStartElement("Contents");
                xmlWriter.WriteAttributeString("Count", pane.Contents.Count.ToString(CultureInfo.InvariantCulture));
                foreach (IDockContent content in pane.Contents)
                {
                    xmlWriter.WriteStartElement("Content");
                    xmlWriter.WriteAttributeString("ID", pane.Contents.IndexOf(content).ToString(CultureInfo.InvariantCulture));
                    xmlWriter.WriteAttributeString("RefID", dockPanel.Contents.IndexOf(content).ToString(CultureInfo.InvariantCulture));
                    xmlWriter.WriteEndElement();
                }
                xmlWriter.WriteEndElement();
                xmlWriter.WriteEndElement();
            }
            xmlWriter.WriteEndElement();

            // DockWindows
            xmlWriter.WriteStartElement("DockWindows");
            int dockWindowId = 0;
            foreach (DockWindow dw in dockPanel.DockWindows)
            {
                xmlWriter.WriteStartElement("DockWindow");
                xmlWriter.WriteAttributeString("ID", dockWindowId.ToString(CultureInfo.InvariantCulture));
                dockWindowId++;
                xmlWriter.WriteAttributeString("DockState", dw.DockState.ToString());
                xmlWriter.WriteAttributeString("ZOrderIndex", dockPanel.Controls.IndexOf(dw).ToString(CultureInfo.InvariantCulture));
                xmlWriter.WriteStartElement("NestedPanes");
                xmlWriter.WriteAttributeString("Count", dw.NestedPanes.Count.ToString(CultureInfo.InvariantCulture));
                foreach (DockPane pane in dw.NestedPanes)
                {
                    xmlWriter.WriteStartElement("Pane");
                    xmlWriter.WriteAttributeString("ID", dw.NestedPanes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
                    xmlWriter.WriteAttributeString("RefID", dockPanel.Panes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
                    NestedDockingStatus status = pane.NestedDockingStatus;
                    xmlWriter.WriteAttributeString("PrevPane", dockPanel.Panes.IndexOf(status.PreviousPane).ToString(CultureInfo.InvariantCulture));
                    xmlWriter.WriteAttributeString("Alignment", status.Alignment.ToString());
                    xmlWriter.WriteAttributeString("Proportion", status.Proportion.ToString(CultureInfo.InvariantCulture));
                    xmlWriter.WriteEndElement();
                }
                xmlWriter.WriteEndElement();
                xmlWriter.WriteEndElement();
            }
            xmlWriter.WriteEndElement();

            // FloatWindows
            var rectConverter = new RectangleConverter();
            xmlWriter.WriteStartElement("FloatWindows");
            xmlWriter.WriteAttributeString("Count", dockPanel.FloatWindows.Count.ToString(CultureInfo.InvariantCulture));
            foreach (FloatWindow fw in dockPanel.FloatWindows)
            {
                xmlWriter.WriteStartElement("FloatWindow");
                xmlWriter.WriteAttributeString("ID", dockPanel.FloatWindows.IndexOf(fw).ToString(CultureInfo.InvariantCulture));
                xmlWriter.WriteAttributeString("Bounds", rectConverter.ConvertToInvariantString(fw.Bounds));
                xmlWriter.WriteAttributeString("ZOrderIndex", fw.DockPanel.FloatWindows.IndexOf(fw).ToString(CultureInfo.InvariantCulture));
                xmlWriter.WriteStartElement("NestedPanes");
                xmlWriter.WriteAttributeString("Count", fw.NestedPanes.Count.ToString(CultureInfo.InvariantCulture));
                foreach (DockPane pane in fw.NestedPanes)
                {
                    xmlWriter.WriteStartElement("Pane");
                    xmlWriter.WriteAttributeString("ID", fw.NestedPanes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
                    xmlWriter.WriteAttributeString("RefID", dockPanel.Panes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
                    NestedDockingStatus status = pane.NestedDockingStatus;
                    xmlWriter.WriteAttributeString("PrevPane", dockPanel.Panes.IndexOf(status.PreviousPane).ToString(CultureInfo.InvariantCulture));
                    xmlWriter.WriteAttributeString("Alignment", status.Alignment.ToString());
                    xmlWriter.WriteAttributeString("Proportion", status.Proportion.ToString(CultureInfo.InvariantCulture));
                    xmlWriter.WriteEndElement();
                }
                xmlWriter.WriteEndElement();
                xmlWriter.WriteEndElement();
            }
            xmlWriter.WriteEndElement();	//	</FloatWindows>

            xmlWriter.WriteEndElement();
        }