// Builds the Treeview recursively protected void BuildTreeView(IFileSystemComponent fsc, TreeNodeCollection nodes) { //Checks if its a document if (fsc.FileType == SliceOfPie.DocType.Document) { // Makes a new TreeNode with the correct title and adds it to nodes TreeNode n = new TreeNode(fsc.Title); nodes.Add(n); n.Value = ((DocumentStruct)fsc).Id; } // else its a folder else { TreeNode n = new TreeNode(fsc.Title); nodes.Add(n); if (fsc.FileType == DocType.Project) { // We save the value of the id for later use n.Value = ((Project)fsc).Id; } // We make the folder object and check its children recursively SliceOfPie.Folder folder = (SliceOfPie.Folder)fsc; foreach (SliceOfPie.IFileSystemComponent f in (folder.Children)) { BuildTreeView(f, n.ChildNodes); } } }
public void Add(IFileSystemComponent component) { if (component == null) { throw new ArgumentNullException(nameof(component)); } _components.Add(component); }
/** * Called when something is selected, expanded or collapsed in the treeview * Sets the selected folder/document here */ private void treeView_AfterSelect(object sender, TreeViewEventArgs e) { IFileSystemComponent fsc = (IFileSystemComponent)e.Node.Tag; if (fsc.FileType == DocType.Document) // If it's a document { isDocument = true; selectedDocument = (DocumentStruct)fsc; selectedFolder = (Folder)e.Node.Parent.Tag; } else // else, if it's a folder { isDocument = false; selectedFolder = (Folder)e.Node.Tag; } // If a document was not selected, grey out the button if (isDocument) { openButton.Enabled = true; } else { openButton.Enabled = false; } // You can't rename, move or delete projects in the offline client if (selectedFolder.FileType == DocType.Project && !isDocument) { renameButton.Enabled = false; moveButton.Enabled = false; deleteButton.Enabled = false; } else { renameButton.Enabled = true; moveButton.Enabled = true; deleteButton.Enabled = true; } createDocumentButton.Enabled = true; }
/** * Recursive function, * filling out the treeView with folders and documents * 'tag' is a property referencing the object itself. * * Don't add the document to the tree if it is marked for deletion. */ private void BuildDocumentTree(TreeNodeCollection nodes, IFileSystemComponent fsc) { if (fsc.FileType == SliceOfPie.DocType.Document) // If it's a document { if (!((DocumentStruct)fsc).Deleted) { TreeNode n = new TreeNode(fsc.Title); n.Tag = fsc; nodes.Add(n); } } else // else, if it's a folder { TreeNode n = new TreeNode(fsc.Title); n.Tag = fsc; nodes.Add(n); SliceOfPie.Folder folder = (SliceOfPie.Folder)fsc; foreach (IFileSystemComponent f in (folder.Children)) { BuildDocumentTree(n.Nodes, f); } } }
/** * Recursively visit all children in a folder and change their path */ private void RenameFolderChildren(IFileSystemComponent fsc, string oldpath, string newpath) { if (fsc.FileType == DocType.Document) { Document doc = Controller.OpenDocument(selectedProject.Id, ((DocumentStruct)fsc).Id); //Debug.Print("Old doc path: {0}", doc.Path); doc.Path = newpath + doc.Path.Substring(oldpath.Count()); //Debug.Print("New doc path: {0}", doc.Path); //Debug.Print("---"); Controller.SaveDocument(selectedProject, doc, activeUser); } else if (fsc.FileType == DocType.Folder) { foreach (IFileSystemComponent f in ((Folder)fsc).Children) { RenameFolderChildren(f, oldpath, newpath); } } }
public void RemoveChild(IFileSystemComponent child) { children.Remove(child); }
public void AddChild(IFileSystemComponent doc) { children.Add(doc); }
public void Remove(IFileSystemComponent component) { this._fsComponents.Remove(component); }
public void Add(IFileSystemComponent component) { this._fsComponents.Add(component); }