How to sort list of functions alphabetically

Sep 25, 2012 at 8:03 PM

At present you could make right click on script outline window and see 

Sort --> Alphabetically

             By Declaration

but the the first option was not realized. To get it working change function BuildSortedTree() as the following:

   private void BuildSortedTree()
        {

            //define root;
            XmlNode root = ScriptStructure.DocumentElement;
            XmlNodeList ScriptInfoNodes = root.ChildNodes;
            XmlNodeList FunctionInfoNodes = null;
            string FunctionName = "";
            string LineIndex = "";

            string ScriptName = "";

            //clear treeview
            trvScript.Nodes.Clear();
            //create root of treeview
            TreeNode TreeRoot = new TreeNode(_FileFullName);

            trvScript.Nodes.Add(TreeRoot);
            TreeRoot.ImageIndex = 0;
            TreeNode FunctionNode = null;
            TreeNode BlockNode = null;
            foreach (XmlNode ScriptInfoNode in ScriptInfoNodes)
            {
                if (ScriptInfoNode.ChildNodes.Count == 0)
                {
                    ScriptName = ScriptInfoNode.Attributes["language"].InnerText;
                    LineIndex = ScriptInfoNode.Attributes["line"].InnerText;
                    BlockNode = new TreeNode(ScriptName);
                    BlockNode.ImageIndex = 2;
                    BlockNode.Tag = LineIndex;
                    BlockNode.SelectedImageIndex = 2;
                    TreeRoot.Nodes.Add(BlockNode);

                }
                else //Script Block has functions
                {
                    ScriptName = ScriptInfoNode.Attributes["language"].InnerText;
                    LineIndex = ScriptInfoNode.Attributes["line"].InnerText;

                    FunctionInfoNodes = ScriptInfoNode.ChildNodes;

                    BlockNode = new TreeNode(ScriptName);
                    BlockNode.ImageIndex = 2;
                    BlockNode.Tag = LineIndex;
                    BlockNode.SelectedImageIndex = 2;
                    TreeRoot.Nodes.Add(BlockNode);
                    SortedDictionary dict = new SortedDictionary();
                    foreach (XmlNode FunctionInfoNode in FunctionInfoNodes)
                    {
                        FunctionName = FunctionInfoNode.InnerText;
                        if (!dict.ContainsKey(FunctionName))
                            dict[FunctionName] = FunctionInfoNode;
                        else
                        {
                            string tempFunctionName = FunctionName;
                            while (dict.ContainsKey(tempFunctionName))
                            {
                                tempFunctionName += "_";
                            }
                            dict[tempFunctionName] = FunctionInfoNode;
                        }

                    }
                    foreach (string key in dict.Keys)
                    {
                        XmlNode FunctionInfoNode = dict[key];
                        FunctionName = FunctionInfoNode.InnerText;
                        LineIndex = FunctionInfoNode.Attributes.GetNamedItem("line").InnerText;
                        FunctionNode = new TreeNode(FunctionName);
                        BlockNode.Nodes.Add(FunctionNode);
                        FunctionNode.ImageIndex = 2;
                        FunctionNode.SelectedImageIndex = 2;
                        FunctionNode.Tag = LineIndex;

                    }
                   
                }
            }

            TreeNodeCollection children = trvScript.Nodes;
            foreach (TreeNode node in children)
            {
                node.Expand();
            }
        }