예제 #1
0
 public void TestFixtureTearDown()
 {
     _unitUnderTest = null;
 }
예제 #2
0
 public void TestFixtureSetUp()
 {
     _unitUnderTest = new MainWindow();
 }
예제 #3
0
 /// <summary>
 /// Set the status of window.
 /// </summary>
 /// <param name="window"></param>
 /// <param name="windowState"></param>
 private static void SetWindowStatus(MainWindow window, WindowStateStruct windowState)
 {
     window.WindowState = windowState.WindowState;
     window.Left = windowState.Left;
     window.Top = windowState.Top;
     window.Width = windowState.Width;
     window.Height = windowState.Height;
     NormalizeFormScreen(window, windowState.Screen);
 }
예제 #4
0
        /// <summary>
        /// Load ECell window settings.
        /// </summary>
        /// <param name="window">MainWindow.</param>
        /// <param name="filename">the file path.</param>
        /// <param name="initializeWindow">whether this window is the initial window.</param>
        public static void LoadFromXML(MainWindow window, string filename, bool initializeWindow, bool isSimulation)
        {
            DockPanel dockPanel = window.DockPanel;
            FileStream fs = null;
            XmlTextReader xmlIn = null;
            try
            {
                // Load XML file
                fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
                xmlIn = new XmlTextReader(fs);
                xmlIn.WhitespaceHandling = WhitespaceHandling.None;
                xmlIn.MoveToContent();

                // Check XML file
                CheckFileStatus(xmlIn);

                // load window settings
                WindowStateStruct windowState = LoadWindowState(xmlIn);
                // Load DockPanelStruct
                DockPanelStruct dockPanelStruct = LoadDockPanelStruct(xmlIn);
                // Load Contents
                ContentStruct[] contents = LoadContents(xmlIn);
                // Load Panes
                PaneStruct[] panes = LoadPanes(xmlIn);
                // Load DockWindows
                DockWindowStruct[] dockWindows = LoadDockWindows(xmlIn, dockPanel);
                // Load FloatWindows
                FloatWindowStruct[] floatWindows = LoadFloatWindows(xmlIn);
                // close file
                xmlIn.Close();
                dockPanel.SuspendLayout(true);
                // Close windows.
                CloseWindows(dockPanel);
                // Set WindowSetting
                if(initializeWindow)
                    SetWindowStatus(window, windowState);

                // Set DockPanelLayout
                dockPanel.DockTopPortion = dockPanelStruct.DockTopPortion;
                dockPanel.DockBottomPortion = dockPanelStruct.DockBottomPortion;
                dockPanel.DockLeftPortion = dockPanelStruct.DockLeftPortion;
                dockPanel.DockRightPortion = dockPanelStruct.DockRightPortion;

                // Set DockWindow ZOrders
                SetDockWindowZOrder(dockPanel, dockWindows);

                // Create Contents
                List<DockContent> contentList = CreateContents(dockPanel, contents);

                // Create panes
                List<DockPane> paneList = CreatePanes(dockPanel, panes, contentList);

                // Assign Panes to DockWindows
                AssignPanes(dockPanel, panes, dockWindows, paneList);

                // Create float windows
                CreateFloatWindows(dockPanel, panes, floatWindows, paneList);

                // Create float windows for unrecorded contents
                if(isSimulation)
                    CreateFloatWindowForUnrecordedContents(dockPanel, contentList, paneList);

                // sort IDockContent by its Pane's ZOrder
                int[] sortedContents = SortContents(dockPanel, contents, panes);

                // show non-document IDockContent first to avoid screen flickers
                for (int i = 0; i < contents.Length; i++)
                {
                    IDockContent content = contentList[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 = contentList[sortedContents[i]];
                    if (content.DockHandler.Pane != null && content.DockHandler.Pane.DockState == DockState.Document)
                        content.DockHandler.IsHidden = contents[sortedContents[i]].IsHidden;
                }

                // Activate the Contents, Panes and DockWindows.
                for (int i = 0; i < panes.Length; i++)
                    if (panes[i].IndexActiveContent < 0 || panes[i].IndexActiveContent >= contentList.Count)
                        paneList[i].ActiveContent = null;
                    else
                        paneList[i].ActiveContent = contentList[panes[i].IndexActiveContent];
                if (dockPanelStruct.IndexActiveDocumentPane != -1)
                    paneList[dockPanelStruct.IndexActiveDocumentPane].Activate();
                if (dockPanelStruct.IndexActivePane != -1)
                    paneList[dockPanelStruct.IndexActivePane].Activate();
                dockPanel.ResumeLayout(true, true);

                CloseUnloadedWindows(dockPanel);
            }
            catch (Exception e)
            {
                foreach (DockContent content in dockPanel.Contents)
                {
                }

                Debug.Print(e.StackTrace);
                throw new EcellException("Failed to load file: " + filename, e);
            }
            finally
            {
                if (xmlIn != null) xmlIn.Close();
                if (fs != null) fs.Close();
            }
        }
예제 #5
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();
            }
        }
예제 #6
0
 public void SetUp()
 {
     _window = new MainWindow();
     _unitUnderTest = new DockWindowSerializer();
 }