private TreeNode GetSnippetNode(List <TreeNode> nodes, string snippetInternalName) { foreach (TreeNode node in nodes) { SnippetTreeEntry entry = node.Tag as SnippetTreeEntry; if (entry.InternalName == snippetInternalName) { return(node); } } return(null); }
private void SnippetTreeView_KeyDown(object sender, KeyEventArgs e) { TreeNode node = SnippetTreeView.SelectedNode; if (node == null) { return; } if (e.KeyCode == Keys.Delete) { SnippetTreeEntry entry = node.Tag as SnippetTreeEntry; DeleteSnippet(entry); } }
private void SnippetTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { SnippetTreeEntry snippet = e.Node.Tag as SnippetTreeEntry; TxtName.Text = snippet.InternalName; if (!string.IsNullOrEmpty(snippet.Path)) { TxtContents.Text = File.ReadAllText(snippet.Path); if (BtnCopyPasteOnClick.Checked) { PasteToApplication(); } } else { TxtContents.Text = ""; } }
private void DeleteSnippet(SnippetTreeEntry entry) { if (entry.IsCategory) { MessageBox.Show("Categories are automatically deleted when it contains no snippets", "Can't delete category", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } DialogResult result = MessageBox.Show("Delete the snippet " + entry.InternalName, "Confirm", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (result == DialogResult.OK) { File.Delete(entry.Path); TreeLoader.Load(); } }
public void Load() { List <SnippetTreeEntry> treeDefinition = LoadTreeDefinition(); List <TreeNode> nodes = new List <TreeNode>(); // Add categories foreach (SnippetTreeEntry entry in treeDefinition) { if (GetCategoryNode(nodes, entry.Category) == null) { TreeNode categoryNode = new TreeNode(entry.Category, FolderIcon, FolderIcon); categoryNode.Tag = new SnippetTreeEntry(entry.Category); nodes.Add(categoryNode); } } // Add snippets to categories foreach (SnippetTreeEntry entry in treeDefinition) { TreeNode categoryNode = GetCategoryNode(nodes, entry.Category); TreeNode snippetNode = new TreeNode(entry.SnippetName, SnippetIcon, SnippetIcon); snippetNode.Tag = entry; categoryNode.Nodes.Add(snippetNode); } TreeNode categoryNodeToExpand = null; TreeNode selectedNode = TreeView.SelectedNode; if (selectedNode != null && selectedNode.Parent != null) { SnippetTreeEntry selectedEntry = selectedNode.Tag as SnippetTreeEntry; categoryNodeToExpand = GetCategoryNode(nodes, selectedEntry.Category); } TreeView.Nodes.Clear(); TreeView.Nodes.AddRange(nodes.ToArray()); TreeView.Refresh(); if (categoryNodeToExpand != null) { categoryNodeToExpand.Expand(); } }