Пример #1
0
        void buildTreeNodes()
        {
            ProjectNode        root  = new ProjectNode(this, ItemType.VirtualGroup, RootNamespace);
            List <ProjectItem> items = new List <ProjectItem> ();

            foreach (XmlNode i in nodesItems)
            {
                foreach (XmlNode f in i.ChildNodes)
                {
                    items.Add(new ProjectItem(this, f));
                }
            }

            flattenNodes = new List <ProjectNode> ();

            ProjectNode refs = new ProjectNode(this, ItemType.ReferenceGroup, "References");

            root.AddChild(refs);

            foreach (ProjectItem pn in items)
            {
                switch (pn.Type)
                {
                case ItemType.Reference:
                    refs.AddChild(pn);
                    flattenNodes.Add(pn);
                    break;

                case ItemType.ProjectReference:
                    ProjectReference pr = new ProjectReference(pn);
                    refs.AddChild(pr);
                    flattenNodes.Add(pr);
                    break;

                case ItemType.Compile:
                case ItemType.None:
                case ItemType.EmbeddedResource:
                    ProjectNode curNode = root;
                    string[]    folds   = pn.Path.Split('/');
                    for (int i = 0; i < folds.Length - 1; i++)
                    {
                        ProjectNode nextNode = curNode.ChildNodes.FirstOrDefault(n => n.DisplayName == folds [i] && n.Type == ItemType.VirtualGroup);
                        if (nextNode == null)
                        {
                            nextNode = new ProjectNode(this, ItemType.VirtualGroup, folds [i]);
                            curNode.AddChild(nextNode);
                        }
                        curNode = nextNode;
                    }
                    ProjectNode f = null;
                    switch (pn.Extension)
                    {
                    case ".crow":
                    case ".template":
                    case ".goml":
                    case ".itemp":
                    case ".imtl":
                        f = new ImlProjectItem(pn);
                        break;

                    case ".style":
                        f = new StyleProjectItem(pn);
                        break;

                    default:
                        f = new ProjectFile(pn);
                        break;
                    }
                    curNode.AddChild(f);
                    flattenNodes.Add(f);
                    break;
                }
            }
            root.SortChilds();

            rootItems = root.ChildNodes;
        }
Пример #2
0
        void populateTreeNodes()
        {
            ProjectNode root = new ProjectNode(this, ItemType.VirtualGroup, RootNamespace);
            ProjectNode refs = new ProjectNode(this, ItemType.ReferenceGroup, "References");

            root.AddChild(refs);

            /*Console.ForegroundColor = ConsoleColor.Green;
             * Console.WriteLine ($"Evaluated Globals properties for {DisplayName}");
             * foreach (ProjectProperty item in project.AllEvaluatedProperties.OrderBy(p=>p.Name)) {
             *      Console.ForegroundColor = ConsoleColor.White;
             *      Console.Write ($"\t{item.Name,-40} = ");
             *      Console.ForegroundColor = ConsoleColor.Gray;
             *      Console.WriteLine ($"{item.EvaluatedValue}");
             * }*/


            foreach (ProjectItem pn in project.AllEvaluatedItems)
            {
                switch (pn.ItemType)
                {
                case "ProjectReferenceTargets":
                    Commands.Add(new Crow.Command(new Action(() => Compile(pn.EvaluatedInclude)))
                    {
                        Caption = pn.EvaluatedInclude,
                    });
                    break;

                case "Reference":
                case "PackageReference":
                case "ProjectReference":
                    refs.AddChild(new ProjectItemNode(this, pn));
                    break;

                case "Compile":
                case "None":
                case "EmbeddedResource":
                    ProjectNode curNode = root;
                    try {
                        string file     = pn.EvaluatedInclude.Replace('\\', '/');
                        string treePath = file;
                        if (pn.HasMetadata("Link"))
                        {
                            treePath = project.ExpandString(pn.GetMetadataValue("Link"));
                        }
                        string [] folds = treePath.Split('/');
                        for (int i = 0; i < folds.Length - 1; i++)
                        {
                            ProjectNode nextNode = curNode.Childs.OfType <ProjectNode>().FirstOrDefault(n => n.DisplayName == folds [i] && n.Type == ItemType.VirtualGroup);
                            if (nextNode == null)
                            {
                                nextNode = new ProjectNode(this, ItemType.VirtualGroup, folds [i]);
                                curNode.AddChild(nextNode);
                            }
                            curNode = nextNode;
                        }
                        ProjectItemNode pi = new ProjectItemNode(this, pn);

                        switch (Path.GetExtension(file))
                        {
                        case ".cs":
                            pi = new CSProjectItem(pi);
                            break;

                        case ".crow":
                        case ".template":
                        case ".goml":
                        case ".itemp":
                        case ".imtl":
                            pi = new ImlProjectItem(pi);
                            break;

                        case ".style":
                            pi = new StyleProjectItem(pi);
                            break;

                        default:
                            pi = new ProjectFileNode(pi);
                            break;
                        }
                        curNode.AddChild(pi);
                    } catch (Exception ex) {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(ex);
                        Console.ResetColor();
                    }

                    break;
                }
            }
            root.SortChilds();
            foreach (var item in root.Childs)
            {
                Childs.Add(item);
                item.Parent = this;
            }


            IsLoaded = true;
        }