private void UpdateAttachmentNode_Click(object sender, RoutedEventArgs e) { if (tvAttachments.SelectedItem != null) { AttachmentNode selectedNode = (AttachmentNode)tvAttachments.SelectedItem; if (selectedNode.IsFile) { AttachmentNoteWindow dlg = new AttachmentNoteWindow(this) { Note = selectedNode.Attachment.Note }; if (dlg.ShowDialog() ?? false) { selectedNode.UpdateNote(dlg.Note); attachments.RemoveAll(x => x.Path == selectedNode.Attachment.Path); attachments.Add(new Attachment() { Path = selectedNode.Attachment.Path, Note = dlg.Note }); } } } }
private void RemoveAttachment_Click(object sender, RoutedEventArgs e) { if (tvAttachments.SelectedItem != null) { AttachmentNode selectedNode = (AttachmentNode)tvAttachments.SelectedItem; ((ItemsControl)selectedNode.Parent).Items.Remove(selectedNode); attachments.RemoveAll(x => x.Path.StartsWith(selectedNode.FullPath)); } }
private void CreateAttachmentNode(ItemsControl parentNode, string[] path, int level, Attachment attachment) { if (path.Length > level) { if (parentNode.Items.SortDescriptions.Count == 0) { parentNode.Items.SortDescriptions.Add(new SortDescription("IsFile", ListSortDirection.Ascending)); parentNode.Items.SortDescriptions.Add(new SortDescription("NodeName", ListSortDirection.Ascending)); } string nodeName = path[level]; AttachmentNode node = parentNode.Items.OfType <AttachmentNode>().FirstOrDefault(x => x.NodeName == nodeName); if (node == null) { node = new AttachmentNode(attachment, nodeName, string.Join(@"\", path.Take(level + 1)), path.Length == level + 1); parentNode.Items.Add(node); parentNode.Items.Refresh(); } CreateAttachmentNode(node, path, level + 1, attachment); node.ExpandSubtree(); } }