Exemplo n.º 1
0
        public void RefreshTree(CSnippetter.CodeEntryCollection codecoll)
        {
            // Clear the nodes and set the update flag so we don't redraw the control all the time.
            this.tvSnippets.Nodes.Clear();
            this.tvSnippets.BeginUpdate();

            // Loop through all the code snippets and gather a list of categories
            ArrayList cats = new ArrayList();

            foreach (CSnippetter.CodeEntry entry in codecoll)
            {
                if (!cats.Contains(entry.CodeCategory))
                {
                    cats.Add(entry.CodeCategory);
                }
            }

            // Add the categories to the snippetter
            foreach (string entry in cats)
            {
                TreeNode node = new TreeNode(entry, 0, 0);
                this.tvSnippets.Nodes.Add(node);
            }

            // Run a second pass on all the code snippets and add them to the select
            // categories
            foreach (CSnippetter.CodeEntry entry in codecoll)
            {
                TreeNode parent = GetCategory(entry.CodeCategory);

                if (parent == null)                                             // This should never happen
                {
                    continue;
                }

                TreeNode node = new TreeNode(entry.CodeTitle, 6, 6);
                node.Tag = entry;

                parent.Nodes.Add(node);
            }

            // Allow updates to the treeview and expand all nodes
            this.tvSnippets.ExpandAll();
            this.tvSnippets.EndUpdate();

            // Sort the TV
            this.tvSnippets.Sorted = true;
        }
Exemplo n.º 2
0
        private void cmdSearch_Click(object sender, System.EventArgs e)
        {
            if (txtSearch.Text == "" || cmdSearch.Text == "Clear")
            {
                RefreshTree();
                txtSearch.Enabled = true;
                cmdSearch.Text    = "Search";
                return;
            }

            CSnippetter.CodeEntryCollection coll = frmMain.stc_Snippets.CodeSnippets.Search(txtSearch.Text.Split(' '));

            if (coll.Count == 0)
            {
                MessageBox.Show(this, "Could not find search keywords.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            RefreshTree(coll);
            cmdSearch.Text    = "Clear";
            txtSearch.Enabled = false;
        }