public static Project Open(string fileName) { if (File.Exists(fileName) == false) { ExceptionHandler.HandledException(new FileNotFoundException(string.Format(Localization.Exception_ProjectFileNotFound, fileName), fileName)); return null; } if (Loading != null) { ProjectEventArgs e = new ProjectEventArgs(Path.GetFileNameWithoutExtension(fileName), Path.GetDirectoryName(fileName)); Loading(null, e); if (e.Handled == true) { return null; } } Project result = new Project(fileName); Workspace.Project = result; using (XmlTextReader xmlReader = new XmlTextReader(fileName)) { string activeFile = string.Empty; while (xmlReader.Read()) { switch (xmlReader.Name.ToString()) { case "File": { bool wasActive = Convert.ToBoolean(xmlReader.GetAttribute("Active")); // Get the attribute first. string filePath = xmlReader.ReadString(); if (File.Exists(filePath) == true) { Workspace.OpenFile(filePath, true); if (wasActive == true) { activeFile = filePath; } } else { Logger.Write(new FileNotFoundException(string.Format(Localization.Exception_FileNotFound, filePath), filePath)); } break; } } } if (string.IsNullOrEmpty(activeFile) == false) { Workspace.SetActiveEditor(activeFile, true); } } if (Loaded != null) { Loaded(null, new ProjectEventArgs(result.Name, result.BaseDirectory)); } return result; }
public bool Close() { if (Closing != null) { ProjectEventArgs e = new ProjectEventArgs(this.Name, this.BaseDirectory); Closing(this, e); if (e.Handled == true) { return true; } } bool result = false; try { XmlDocument xmlFile = new XmlDocument(); xmlFile.LoadXml(File.ReadAllText(this.FileName)); 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; // Create a list of editors, we will delete from it later. List<Editor> editors = new List<Editor>(); // Push to list our project files. foreach (Editor editor in Workspace.GetEditors().Values) { if (editor.HasProject == true) { editors.Add(editor); } } // Save files and close them. foreach (Editor editor in editors.ToList()) { xmlElement = xmlFile.CreateElement("File"); xmlElement.InnerText = editor.FileName; if (editor == Workspace.CurrentEditor) { XmlNode xmlAttribute = xmlFile.CreateNode(XmlNodeType.Attribute, "Active", string.Empty); xmlAttribute.Value = "true"; xmlElement.Attributes.SetNamedItem(xmlAttribute); } xmlDocument.AppendChild(xmlElement); } // All done, let's save the XML. xmlFile.Save(this.FileName); Workspace.Project = null; result = Workspace.CloseAllFiles(true); if (Closed != null) { Closed(this, new ProjectEventArgs(this.Name, this.BaseDirectory)); } } catch (Exception ex) { ExceptionHandler.HandledException(ex); } return result; }
private void event_ProjectLoaded(object sender, ProjectEventArgs e) { this.projectFiles.BeginUpdate(); this.projectFiles.Nodes.Clear(); TreeNode treeNode = new TreeNode(Workspace.Project.Name, 0, 0); treeNode.Tag = TreeNodeType.Root; this.projectFiles.Nodes.Add(treeNode); foreach (string directoryPath in Workspace.Project.Directories) { this.Add(TreeNodeType.Directory, directoryPath, false); } foreach (string filePath in Workspace.Project.Files) { this.Add(TreeNodeType.File, filePath, false); } this.projectFiles.Nodes[0].Expand(); this.projectFiles.EndUpdate(); }
private void event_ProjectLoaded(object sender, ProjectEventArgs e) { MessageBox.Show(string.Format("Project \"{0}\" loaded.", e.Name), this.Name, MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void event_ProjectClosed(object sender, ProjectEventArgs e) { this.projectFiles.Nodes.Clear(); }