Beispiel #1
0
        private static Thread populateTreeViewUsingViewMode_byFunctionSignature(IEnumerable <string> lsList,
                                                                                TreeView targetTreeView,
                                                                                int namespaceDepthValue, string textFilter, int iMaxItemsToShow)
        {
            return(O2Thread.mtaThread(
                       () =>
            {
                targetTreeView.invokeOnThread(() => targetTreeView.Visible = false);
                try
                {
                    var dItemsParsed = new Dictionary <String, FilteredSignature>();
                    foreach (String sItem in lsList)
                    {
                        //if (false == dItemsParsed.ContainsKey(sItem))
                        {
                            if (textFilter == "" || RegEx.findStringInString(sItem, textFilter))
                            {
                                dItemsParsed.Add(sItem, new FilteredSignature(sItem));
                            }
                        }
                        //else
                        //    PublicDI.log.error("Something's wrong in showListOnTreeView, lsList had repeated key:{0}", sItem);
                    }
                    var dItemsBrokenByClassDepth = new Dictionary <String, List <FilteredSignature> >();

                    foreach (String sItem in lsList)
                    {
                        if (namespaceDepthValue == -1)
                        {
                            if (textFilter == "" || RegEx.findStringInString(sItem, textFilter))
                            {
                                if (dItemsParsed.ContainsKey(sItem))
                                {
                                    // add node ASync and on the correct thread
                                    O2Forms.addNodeToTreeNodeCollection(targetTreeView, targetTreeView.Nodes,
                                                                        O2Forms.newTreeNode(
                                                                            dItemsParsed[sItem].sSignature, sItem,
                                                                            3, dItemsParsed[sItem]), iMaxItemsToShow);
                                }
                            }
                        }
                        else
                        {
                            if (dItemsParsed.ContainsKey(sItem))
                            {
                                String sClassNameToShow =
                                    dItemsParsed[sItem].getClassName_Rev(namespaceDepthValue);
                                if (sClassNameToShow == "")
                                {
                                    sClassNameToShow = dItemsParsed[sItem].sFunctionClass;
                                }

                                /*  var sClassNameToConsolidate = (sClassNameToShow == "")
                                 *                           ? dItemsParsed[sItem].sFunctionClass
                                 *                           : dItemsParsed[sItem].sFunctionClass.Replace(
                                 *                                 sClassNameToShow, "");*/
                                if (false == dItemsBrokenByClassDepth.ContainsKey(sClassNameToShow))
                                {
                                    dItemsBrokenByClassDepth.Add(sClassNameToShow, new List <FilteredSignature>());
                                }
                                //String sSignatureToShow = sClassNameToConsolidate + "__" + dItemsParsed[sItem].sFunctionNameAndParams;
                                dItemsBrokenByClassDepth[sClassNameToShow].Add(dItemsParsed[sItem]);
                            }
                        }

                        // add calculated results
                        //     TreeNodeCollection tncToAddFunction_ = targetTreeView.Nodes;
                    }
                    foreach (String sClass in dItemsBrokenByClassDepth.Keys)
                    {
                        var filteredSignatures = dItemsBrokenByClassDepth[sClass];
                        TreeNode tnNewTreeNode = O2Forms.newTreeNode(sClass, sClass, 0,
                                                                     filteredSignatures);
                        if (filteredSignatures.Count > 0)
                        {
                            tnNewTreeNode.Nodes.Add("DummyNode");
                        }
                        // add node ASync and on the correct thread
                        O2Forms.addNodeToTreeNodeCollection(targetTreeView, targetTreeView.Nodes, tnNewTreeNode, iMaxItemsToShow);
                        //tncToAddFunction.Add(tnNewTreeNode);
                    }


                    // remove empty nodes

                    /*       if (false && bRemoveEmptyRootNodes && NamespaceDepthValue > -1)
                     * {
                     * var tnTreeNodesToRemove = new List<TreeNode>();
                     * foreach (TreeNode tnTreeNode in tvTempTreeView.Nodes)
                     * if (tnTreeNode.Nodes.Count == 0)
                     *  tnTreeNodesToRemove.Add(tnTreeNode);
                     * foreach (TreeNode tnTreeNode in tnTreeNodesToRemove)
                     * tvTempTreeView.Nodes.Remove(tnTreeNode);
                     * }*/


                    var numberOfUniqueStrings = lsList.Count();
                    if (numberOfUniqueStrings > iMaxItemsToShow)
                    {
                        var message = "This view has more items that the current MaxToView. only showing the first {0} out of {1}".format(iMaxItemsToShow, numberOfUniqueStrings);
                        PublicDI.log.error(message);
                        targetTreeView.add_Node(message);
                    }
                }
                catch (Exception ex)
                {
                    PublicDI.log.error("in populateTreeViewUsingViewMode_byFunctionSignature: {0}", ex.Message);
                }

                targetTreeView.invokeOnThread(
                    () =>
                {
                    targetTreeView.Visible = true;
                    // the code below tries to solve a weird GUI problem that happens when there is only one child Node (which is invible until the user clicks on it))
                    if (targetTreeView.Nodes.Count == 1)
                    {
                        targetTreeView.Nodes[0].Expand();
                        //                                    targetTreeView.SelectedNode = targetTreeView.Nodes[0];
                        //var dummyNode = targetTreeView.Nodes.Add("dUMMYN node");
                        //targetTreeView.Nodes.Remove(dummyNode);
                    }
                });
            }));
        }