private void filesTree_AfterLabelEdit(object sender, NodeLabelEditEventArgs e) { filesTree.LabelEdit = false; EntryTreeNode entryItem = e.Node as EntryTreeNode; // copy-paste sadly if (e.Label == null || e.Label == "") { // invalid name, don't create message box e.CancelEdit = true; //entryItem.Update(); } else if (e.Label == entryItem.Entry.Name) { // do nothing } else if (entryItem.Entry.Parent.GetEntries().Any(entry => entry.Name == e.Label)) { MessageBox.Show("Name already used."); e.CancelEdit = true; } else { entryItem.Entry.Parent.RenameEntry(entryItem.Entry, e.Label); } if (!e.CancelEdit) { e.Node.Text = e.Label; filesTree.Sort(); e.CancelEdit = true; } }
private void UpdateGUIEntiresNodes(EntryTreeNode node, string path) { node.Entry = this.File.Root.GetEntry(path) as DirectoryEntry; if (node.Entry == null) { throw new Exception("Failed to update GUI with new file"); } node.Entry.Node = node; foreach (TreeNode cnode in node.Nodes) { UpdateGUIEntiresNodes(cnode as EntryTreeNode, path + "/" + cnode.Text); } }
private void UpdateGUIEntries() { // Update tree UpdateGUIEntiresNodes(filesTree.Nodes[0] as EntryTreeNode, ""); filesTree.Nodes[0].Text = this.File.Filename; foreach (TreeNode node in filesTree.Nodes) { EntryTreeNode enode = node as EntryTreeNode; if (enode.Parent == null) { // root entry enode.Entry = this.File.Root; this.File.Root.Node = enode; } else { string path = enode.Text; EntryTreeNode currentNode = enode; while ((currentNode = currentNode.Parent as EntryTreeNode).Parent != null) { path = currentNode.Text + "/" + path; } } } if (filesTree.SelectedNode != null) { EntryTreeNode enode = filesTree.SelectedNode as EntryTreeNode; // Update list foreach (ListViewItem item in filesList.Items) { EntryListViewItem eitem = item as EntryListViewItem; eitem.Entry = enode.Entry.GetEntry(eitem.Text) as FileEntry; if (eitem.Entry == null) { throw new Exception("Failed to update GUI with new file"); } eitem.Entry.ViewItem = eitem; } } }