/// <summary> /// Removes a file from the project, either by removing it directory /// or asking subfolders to remove it. /// </summary> /// <param name="file">The file to remove.</param> public void PerformRemove(Management.File file) { if (this.p_Files.Contains(file)) { this.p_Files.Remove(file); if (file is Management.Folder) { Management.Folder ff = file as Management.Folder; ff.FileAdded -= new EventHandler(ff_FileAdded); ff.FileRemoved -= new EventHandler(ff_FileRemoved); } if (this.FileRemoved != null) { this.FileRemoved(this, new EventArgs()); } } else { foreach (Management.File f in this.p_Files.ToList()) { if (f is Management.Folder) { // Request the subfolder to remove the file if they // have it. (f as Management.Folder).Remove(file); } } } }
/// <summary> /// Adds a file to the project. /// </summary> /// <param name="f">The file to add.</param> public void AddFile(Management.File f) { this.p_Files.Add(f); if (f is Management.Folder) { Management.Folder ff = f as Management.Folder; ff.FileAdded += new EventHandler(ff_FileAdded); ff.FileRemoved += new EventHandler(ff_FileRemoved); } if (this.FileAdded != null) { this.FileAdded(this, new EventArgs()); } }
/// <summary> /// Gets the File object based on the relative path provided. The specified path must /// be a file that is included in the project. /// </summary> /// <param name="path">The relative path to the file from the project file.</param> /// <returns>The File object that represents this path, or null if not found.</returns> public Management.File GetByPath(string path) { string[] parts = path.Split(Path.DirectorySeparatorChar); Management.File f = this.p_Files.Find(a => a.FileInfo.Name == parts[0]); for (int i = 1; i < parts.Length; i++) { if (f is Management.Folder) { Management.Folder ff = f as Management.Folder; f = ff.Files.ToList().Find(a => a.FileInfo.Name == parts[i]); } else { return(null); } } return(f); }
/// <summary> /// Adds a file interactively to the project (i.e. prompts the user). /// </summary> /// <param name="f">The folder to place the file in, or null for the project root.</param> public void AddFileInteractive(string preselected, Management.Folder f) { FileCreationData fcd = Central.Platform.UI.PickNewFile(); fcd.Template.Create(fcd.Name, this, f); }
/// <summary> /// Adds a file interactively to the project (i.e. prompts the user). /// </summary> public void AddFileInteractive(Management.Folder f) { this.AddFileInteractive(null, f); }
/// <summary> /// Loads the project data from the specified XML document. /// </summary> /// <param name="file">The XML document represented as a FileInfo object.</param> private void LoadFromXml(FileInfo file) { // Import the XML document using the Tree collection. Tree t = null; using (XmlReader reader = XmlReader.Create(file.FullName)) { t = Tree.FromXml(reader); } Node p = t.GetChildElement("project"); if (p == null) { return; } List <Node> childs = p.GetChildElements("file"); if (childs != null) { foreach (Node f in childs) { List <string> sf = f.Attributes["Include"].Split(new char[] { '\\', '/' }).ToList(); string fn = sf[sf.Count - 1]; sf.RemoveAt(sf.Count - 1); Management.Folder ff = null; // Loop through until we get the parent directory // if needed. string path = ""; foreach (string s in sf) { path += s + Path.DirectorySeparatorChar; bool handled = false; if (ff == null) { foreach (Management.File f2 in this.p_Files) { if (f2 is Management.Folder && (f2 as Management.Folder).FolderInfo.Name == s) { ff = f2 as Management.Folder; handled = true; break; } } if (!handled) { Management.Folder newf = new Folder(this, file.Directory.FullName, path.Substring(0, path.Length - 1)); newf.FileAdded += new EventHandler(ff_FileAdded); newf.FileRemoved += new EventHandler(ff_FileRemoved); this.p_Files.Add(newf); ff = newf; } } else { foreach (Management.File f2 in ff.Files) { if (f2 is Management.Folder && (f2 as Management.Folder).FolderInfo.Name == s) { ff = f2 as Management.Folder; handled = true; break; } } if (!handled) { Management.Folder newf = new Folder(this, file.Directory.FullName, path.Substring(0, path.Length - 1)); newf.FileAdded += new EventHandler(ff_FileAdded); newf.FileRemoved += new EventHandler(ff_FileRemoved); ff.AddWithoutEvent(newf); ff = newf; } } } // Skip the file if it doesn't exist on disk. if (!System.IO.File.Exists(Path.Combine(file.Directory.FullName, f.Attributes["Include"]))) { continue; } // Now associate the file with the directory or project, // depending on whether or not we have a parent directory. if (ff == null) { this.p_Files.Add(new File(this, file.Directory.FullName, f.Attributes["Include"])); } else { ff.AddWithoutEvent(new File(this, file.Directory.FullName, f.Attributes["Include"])); } } } }