コード例 #1
0
ファイル: Main.cs プロジェクト: BroneKot/PawnPlus
 private void saveAllToolStripMenuItem_Click(object sender, EventArgs e)
 {
     foreach (Editor editor in CEManager.ToList().Values)
     {
         editor.Save();
     }
 }
コード例 #2
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);
        }