예제 #1
0
        /// <summary>
        /// Close all project files.
        /// </summary>
        /// <returns>Returns <c>true</c> if cancel button is not pressed, <c>false</c> otherwise.</returns>
        public static bool Close()
        {
            bool cancelPressed = CEManager.CloseAll(true);

            if (cancelPressed == false)
            {
                try
                {
                    treeView.Nodes.Clear();

                    XmlDocument xmlFile = new XmlDocument();
                    xmlFile.LoadXml(File.ReadAllText(xmlPath));

                    XmlNode xmlDocument = xmlFile.DocumentElement;

                    // Let's delete the old 'File' nodes.
                    XmlNodeList xmlNodes = xmlFile.SelectNodes("//File");

                    foreach (XmlNode xmlNode in xmlNodes)
                    {
                        xmlDocument.RemoveChild(xmlNode);
                    }

                    // Let's create new 'File' nodes.
                    XmlNode xmlElement;

                    foreach (Editor editor in CEManager.ToList().Values)
                    {
                        xmlElement           = xmlFile.CreateElement("File");
                        xmlElement.InnerText = editor.FilePath;

                        if (editor == CEManager.ActiveDocument)
                        {
                            XmlNode xmlAttribute = xmlFile.CreateNode(XmlNodeType.Attribute, "Active", string.Empty);
                            xmlAttribute.Value = "1";

                            xmlElement.Attributes.SetNamedItem(xmlAttribute);
                        }

                        xmlDocument.AppendChild(xmlElement);
                    }

                    // All done, let's save the XML.
                    xmlFile.Save(xmlPath);
                }
                catch (Exception)
                {
                    // TODO: Write the exception to log file.
                }

                IsOpen = false;
            }

            return(cancelPressed);
        }
예제 #2
0
파일: Main.cs 프로젝트: BroneKot/PawnPlus
        private void Main_FormClosing(object sender, FormClosingEventArgs e)
        {
            // Let's check if project is open and let's close files from project. After that let's close all files.
            if ((ProjectManager.IsOpen == true && ProjectManager.Close() == true) || (ProjectManager.IsOpen == false && CEManager.CloseAll(false) == true))
            {
                e.Cancel = true;
                return;
            }

            if (Directory.Exists(Path.GetDirectoryName(this.layoutPath)) == false) // Check if path exist, if not create it.
            {
                Directory.CreateDirectory(Path.GetDirectoryName(this.layoutPath));
            }

            if (File.Exists(this.layoutPath) == true) // Check if the "Layout.xml" already exist, if it exist let's delete it.
            {
                File.Delete(this.layoutPath);
            }

            dockPanel.SaveAsXml(this.layoutPath);

            Application.ExitThread(); // Close the entire application.
        }