Пример #1
0
 public void AddNode(TreeNodes target)
 {
     lock ((_syncLock))
     {
         _nodes.Add(target);
     }
 }
Пример #2
0
        private TreeNodes SearchNodes(TreeNodes targetNodes, string namePath)
        {
            var       targetPath  = namePath.Split('.');
            bool      validPath   = false;
            TreeNodes existsNodes = null;

            var validNode = targetNodes.Nodes.Where(x => x.Name.ToLower() == targetPath[0].ToLower());

            if ((validNode != null) && (validNode.Count() > 0))
            {
                existsNodes = validNode.FirstOrDefault();
                validPath   = true;
            }

            if (!validPath)
            {
                return(targetNodes);
            }

            var nextPath = namePath.Substring(targetPath[0].Length, namePath.Length - targetPath[0].Length);

            if (nextPath.StartsWith("."))
            {
                nextPath = nextPath.Substring(1, nextPath.Length - 1);
            }
            if (nextPath.Trim() == "")
            {
                return(existsNodes);
            }
            return(this.SearchNodes(existsNodes, nextPath));
        }
Пример #3
0
        private TreeNodes SearchNodes(TreeNodes targetNodes, string namePath)
        {
            var       targetPath  = namePath.Split('.');
            bool      validPath   = false;
            TreeNodes existsNodes = null;

            foreach (var childNode in targetNodes.Nodes)
            {
                if (childNode.Name.ToLower() != targetPath[0].ToLower())
                {
                    continue;
                }
                validPath   = true;
                existsNodes = childNode;
                break;                 // TODO: might not be correct. Was : Exit For
            }
            if (!validPath)
            {
                return(targetNodes);
            }

            var nextPath = namePath.Substring(targetPath[0].Length, namePath.Length - targetPath[0].Length);

            if (nextPath.StartsWith("."))
            {
                nextPath = nextPath.Substring(1, nextPath.Length - 1);
            }
            if (nextPath == null || string.IsNullOrEmpty(nextPath.Trim()))
            {
                return(existsNodes);
            }
            return(this.SearchNodes(existsNodes, nextPath));
        }
Пример #4
0
 private void SortNodes(TreeNodes targetNodes)
 {
     targetNodes.Nodes.Sort(new ComparerName());
     foreach (var childNode in targetNodes.Nodes)
     {
         this.SortNodes(childNode);
     }
 }
Пример #5
0
        private void AddNode(TreeNodes targetNodes, string namePath, bool isNamespace)
        {
            var       targetPath  = namePath.Split('.');
            bool      validPath   = false;
            TreeNodes existsNodes = null;

            var validNode = targetNodes.Nodes.Where(x => x.Name.ToLower() == targetPath[0].ToLower());

            if ((validNode != null) && (validNode.Count() > 0))
            {
                existsNodes = validNode.FirstOrDefault();
                validPath   = true;
            }

            if (!validPath)
            {
                TreeNodes childNodes = new TreeNodes
                {
                    Name        = targetPath[0],
                    AddStrings  = targetPath[0],
                    ItemType    = isNamespace ? TreeNodes.NodeTypes.Namespace : TreeNodes.NodeTypes.Primitive,
                    Parent      = targetNodes,
                    Description = isNamespace ? string.Format("Namespace {0}", targetPath[0]) : ""
                };
                targetNodes.AddNode(childNodes);

                if (isNamespace)
                {
                    string nextPath = namePath.Substring(targetPath[0].Length, namePath.Length - targetPath[0].Length);
                    if (nextPath.StartsWith("."))
                    {
                        nextPath = nextPath.Substring(1, nextPath.Length - 1);
                    }
                    if (nextPath.Trim() != "")
                    {
                        this.AddNode(childNodes, nextPath);
                    }
                }
            }
            else
            {
                if (isNamespace)
                {
                    string nextPath = namePath.Substring(targetPath[0].Length, namePath.Length - targetPath[0].Length);
                    if (nextPath.StartsWith("."))
                    {
                        nextPath = nextPath.Substring(1, nextPath.Length - 1);
                    }
                    if (nextPath.Trim() != "")
                    {
                        this.AddNode(existsNodes, nextPath);
                    }
                }
            }
        }
Пример #6
0
        private void CommitIntellisenseItem(TreeNodes selectedNodes)
        {
            var inputText = _startText;

            inputText += selectedNodes.Name;

            editor.Text           = inputText;
            editor.SelectionStart = editor.Text.Length;
            editor.UpdateLayout();
            this.UnInitializePopup();
        }
Пример #7
0
        private void AddNestedTypeNode(TreeNodes targetNodes, Type target)
        {
            System.Threading.Tasks.Parallel.ForEach(target.GetNestedTypes(BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance), targetmember =>
            {
                TreeNodes memberNodes = new TreeNodes
                {
                    Name       = targetmember.Name,
                    AddStrings = targetmember.Name,
                    ItemType   = TreeNodes.NodeTypes.Method,
                    Parent     = targetNodes
                };

                targetNodes.AddNode(memberNodes);
            });
        }
Пример #8
0
        private void AddEventNode(TreeNodes targetNodes, Type target)
        {
            System.Threading.Tasks.Parallel.ForEach(target.GetEvents(BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance), targetmember =>
            {
                TreeNodes memberNodes = new TreeNodes
                {
                    Name        = targetmember.Name,
                    AddStrings  = targetmember.Name,
                    ItemType    = TreeNodes.NodeTypes.Event,
                    Parent      = targetNodes,
                    Description = CreateEventDescription(targetmember)
                };

                targetNodes.AddNode(memberNodes);
            });
        }
Пример #9
0
        private void EditorTextChanged(object sender, EventArgs e)
        {
            this.Text = editor.Text;

            if ((isPopup == null))
            {
                return;
            }

            string    inpText    = this.GetInputingText();
            TreeNodes targetNode = this.SearchNodes(IntellisenseList, inpText);

            if (targetNode == null)
            {
                targetNode = IntellisenseList;
            }

            string targetText = inpText.ToLower();

            if (targetText.EndsWith("."))
            {
                targetText = targetText.Substring(0, targetText.Length - 1);
            }
            var searchList = targetNode.Nodes.Where(x => x.GetFullPath().ToLower().Contains(targetText));

            if (IsVarOrArg(targetText))
            {
                TreeNodes itemNode = this.SearchNodes(IntellisenseList, targetText);
                if (itemNode != null)
                {
                    TreeNodes itemTypeNode = this.SearchNodes(IntellisenseList, itemNode.SystemType.FullName);
                    if ((itemTypeNode != null) && (itemTypeNode.Nodes.Count > 0))
                    {
                        searchList = searchList.Union(itemTypeNode.Nodes);
                    }
                }
            }

            if ((searchList == null) || (searchList.Count() <= 0))
            {
                this.UnInitializePopup();
                return;
            }

            isPopup.DataContext = null;
            isPopup.DataContext = searchList;
        }
Пример #10
0
        private TreeNodes CreateUpdatedIntellisense(List <ModelItem> vars)
        {
            TreeNodes result = IntellisenseData;

            lock (_intellisenseLock)
            {
                foreach (var vs in vars)
                {
                    ModelProperty vsProp = vs.Properties["Name"];
                    if (vsProp == null)
                    {
                        continue;
                    }
                    string varName = (string)vsProp.ComputedValue;
                    IEnumerable <TreeNodes> res = result.Nodes.Where(x => x.Name == varName);

                    if (res.FirstOrDefault() == null)
                    {
                        Type          sysType     = null;
                        ModelProperty sysTypeProp = vs.Properties["Type"];
                        if (sysTypeProp != null)
                        {
                            sysType = (Type)sysTypeProp.ComputedValue;
                        }
                        TreeNodes newVar = new TreeNodes
                        {
                            Name        = varName,
                            ItemType    = TreeNodes.NodeTypes.Primitive,
                            SystemType  = sysType,
                            Description = ""
                        };
                        result.Nodes.Add(newVar);
                    }
                }
            }
            return(result);
        }
Пример #11
0
        private void AddTypeNode(TreeNodes targetNodes, Type target)
        {
            if (target.IsAbstract || !target.IsVisible)
            {
                return;
            }

            var typeNamespace = target.Namespace;
            var typeName      = target.Name;

            var       parentNode = this.SearchNodes(targetNodes, typeNamespace);
            TreeNodes newNodes   = new TreeNodes
            {
                Name       = typeName,
                AddStrings = typeName,
                Parent     = parentNode,
                SystemType = target
            };
            string nodesName = typeName;

            if (target.IsGenericType)
            {
                newNodes.ItemType = TreeNodes.NodeTypes.Class;
                if (typeName.Contains("`"))
                {
                    nodesName           = typeName.Substring(0, typeName.LastIndexOf("`"));
                    newNodes.AddStrings = nodesName;
                }
                System.Text.StringBuilder paramStrings = new System.Text.StringBuilder();
                int count = 0;
                foreach (var childArg in target.GetGenericArguments())
                {
                    if (count > 0)
                    {
                        paramStrings.Append(", ");
                    }
                    paramStrings.Append(childArg.Name);
                    count += 1;
                }

                nodesName           += "(" + paramStrings.ToString() + ")";
                newNodes.Name        = nodesName;
                newNodes.Description = string.Format("Class {0}", newNodes.AddStrings);
            }
            else if (target.IsClass)
            {
                newNodes.ItemType    = TreeNodes.NodeTypes.Class;
                newNodes.Description = string.Format("Class {0}", newNodes.AddStrings);
            }
            else if (target.IsEnum)
            {
                newNodes.ItemType    = TreeNodes.NodeTypes.Enum;
                newNodes.Description = string.Format("Enum {0}", newNodes.AddStrings);
            }
            else if (target.IsInterface)
            {
                newNodes.ItemType    = TreeNodes.NodeTypes.Interface;
                newNodes.Description = string.Format("Interface {0}", newNodes.AddStrings);
            }
            else if (target.IsPrimitive)
            {
                newNodes.ItemType    = TreeNodes.NodeTypes.Primitive;
                newNodes.Description = string.Format("{0}", newNodes.AddStrings);
            }
            else if (target.IsValueType)
            {
                newNodes.ItemType    = TreeNodes.NodeTypes.ValueType;
                newNodes.Description = string.Format("{0}", newNodes.AddStrings);
            }
            else
            {
                return;
            }
            if (parentNode == null)
            {
                targetNodes.AddNode(newNodes);
            }
            else
            {
                parentNode.AddNode(newNodes);
            }
            this.AddMethodNode(newNodes, target);
            this.AddPropertyNode(newNodes, target);
            this.AddFieldNode(newNodes, target);
            this.AddEventNode(newNodes, target);
            this.AddNestedTypeNode(newNodes, target);
        }