Пример #1
0
        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);
        }
Пример #2
0
        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);
            }
        }
Пример #3
0
        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 = "";
            }
        }
Пример #4
0
        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();
            }
        }
Пример #5
0
        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();
            }
        }