Пример #1
0
            public void WhenGettingParentForSolutionNode_ThenReturnsNull()
            {
                var solution  = ServiceProvider.GetService <IVsSolution>();
                var hierarchy = solution as IVsHierarchy;

                var node = new VsSolutionHierarchyNode(hierarchy, VSConstants.VSITEMID_ROOT);

                Assert.Null(node.Parent);
            }
            public void WhenIteratingSolutionFolder1_ThenGetsTwoNodes()
            {
                var solution  = ServiceProvider.GetService <IVsSolution>();
                var hierarchy = solution as IVsHierarchy;

                var solutionFolder1 = new VsSolutionHierarchyNode(hierarchy, VSConstants.VSITEMID_ROOT).Children
                                      .FirstOrDefault(n => n.VsHierarchy.Properties(n.ItemId).DisplayName == "SolutionFolder1");

                Assert.Equal(2, solutionFolder1.Children.Count());
            }
            public void WhenIteratingTopLevelNodes_ThenGetsTwoFolders()
            {
                var solution  = ServiceProvider.GetService <IVsSolution>();
                var hierarchy = solution as IVsHierarchy;

                var nodes = new VsSolutionHierarchyNode(hierarchy, VSConstants.VSITEMID_ROOT).Children.Select(n =>
                                                                                                              n.VsHierarchy.Properties(n.ItemId).DisplayName).ToList();

                Assert.Equal(2, nodes.Count);
            }
Пример #4
0
            public void WhenGettingParentForSolutionFolder1_ThenReturnsSolution()
            {
                var solution  = ServiceProvider.GetService <IVsSolution>();
                var hierarchy = solution as IVsHierarchy;

                var solutionFolder1 = new VsSolutionHierarchyNode(hierarchy, VSConstants.VSITEMID_ROOT).Children
                                      .FirstOrDefault(n => n.VsHierarchy.Properties(n.ItemId).DisplayName == "SolutionFolder1");

                Assert.NotNull(solutionFolder1.Parent);
                Assert.Equal("SampleSolution", solutionFolder1.Parent.VsHierarchy.Properties(solutionFolder1.ItemId).DisplayName);
            }
Пример #5
0
            public void WhenGettingAncestorSolutionFolder2_ThenReturnsNull()
            {
                var solution  = ServiceProvider.GetService <IVsSolution>();
                var hierarchy = solution as IVsHierarchy;

                var solutionFolder1 = new VsSolutionHierarchyNode(hierarchy, VSConstants.VSITEMID_ROOT).Children
                                      .FirstOrDefault(n => n.VsHierarchy.Properties(n.ItemId).DisplayName == "SolutionFolder1");
                var solutionFolder2 = solutionFolder1.Children
                                      .FirstOrDefault(n => n.VsHierarchy.Properties(n.ItemId).DisplayName == "SolutionFolder2");

                Assert.Null(solutionFolder2.Parent.Parent.Parent);
            }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProjectItemNode"/> class.
 /// </summary>
 /// <param name="kind">The kind of project node.</param>
 /// <param name="hierarchyNode">The underlying hierarchy represented by this node.</param>
 /// <param name="parentNode">The parent node accessor.</param>
 /// <param name="nodeFactory">The factory for child nodes.</param>
 /// <param name="adapter">The adapter service that implements the smart cast <see cref="ITreeNode.As{T}"/>.</param>
 public ProjectItemNode(
     SolutionNodeKind kind,
     IVsSolutionHierarchyNode hierarchyNode,
     Lazy <ITreeNode> parentNode,
     ITreeNodeFactory <IVsSolutionHierarchyNode> nodeFactory,
     IAdapterService adapter)
     : base(kind, hierarchyNode, parentNode, nodeFactory, adapter)
 {
     this.nodeFactory   = nodeFactory;
     this.owningProject = new Lazy <IProjectNode>(() =>
     {
         var owningHierarchy = new VsSolutionHierarchyNode(hierarchyNode.VsHierarchy, VSConstants.VSITEMID_ROOT);
         return(this.nodeFactory.CreateNode(GetParent(owningHierarchy), owningHierarchy) as IProjectNode);
     });
 }
        public void WhenGettingIdFromExtension_ThenAlwaysReturnsSameValue()
        {
            var solution  = ServiceProvider.GetService <IVsSolution>();
            var hierarchy = solution as IVsHierarchy;

            var solutionFolder1 = new VsSolutionHierarchyNode(hierarchy, VSConstants.VSITEMID_ROOT).Children.FirstOrDefault(n =>
                                                                                                                            n.VsHierarchy.Properties(n.ItemId).DisplayName == "SolutionFolder1");

            Assert.Equal(solutionFolder1.ItemId, solutionFolder1.VsHierarchy.Properties(solutionFolder1.ItemId).ItemId);

            var solutionFolder2 = solutionFolder1.Children.FirstOrDefault(n => n.VsHierarchy.Properties(n.ItemId).DisplayName == "SolutionFolder2");
            var project         = solutionFolder2.Children.FirstOrDefault(n => n.VsHierarchy.Properties(n.ItemId).DisplayName == "ClassLibrary");

            Assert.Equal(solutionFolder2.ItemId, solutionFolder2.VsHierarchy.Properties(solutionFolder2.ItemId).ItemId);
            Assert.Equal(project.ItemId, project.VsHierarchy.Properties(project.ItemId).ItemId);
        }
            public void WhenIteratingClassLibraryProject_ThenGetsFourNodes()
            {
                var solution  = ServiceProvider.GetService <IVsSolution>();
                var hierarchy = solution as IVsHierarchy;

                var solutionFolder1 = new VsSolutionHierarchyNode(hierarchy, VSConstants.VSITEMID_ROOT).Children
                                      .FirstOrDefault(n => n.VsHierarchy.Properties(n.ItemId).DisplayName == "SolutionFolder1");
                var solutionFolder2 = solutionFolder1.Children
                                      .FirstOrDefault(n => n.VsHierarchy.Properties(n.ItemId).DisplayName == "SolutionFolder2");
                var project = solutionFolder2.Children
                              .FirstOrDefault(n => n.VsHierarchy.Properties(n.ItemId).DisplayName == "ClassLibrary");

                var count = project.Children.Count();

                Assert.Equal(4, count, "Expected 4 child nodes for project, but instead got {0}: {1}", count,
                             string.Join(", ", project.Children.Select(x => x.DisplayName).ToArray()));
            }
            public void WhenIteratingClassLibraryProjectFolderFolder_ThenGetsOneNode()
            {
                var solution  = ServiceProvider.GetService <IVsSolution>();
                var hierarchy = solution as IVsHierarchy;

                var solutionFolder1 = new VsSolutionHierarchyNode(hierarchy, VSConstants.VSITEMID_ROOT).Children
                                      .FirstOrDefault(n => n.VsHierarchy.Properties(n.ItemId).DisplayName == "SolutionFolder1");
                var solutionFolder2 = solutionFolder1.Children
                                      .FirstOrDefault(n => n.VsHierarchy.Properties(n.ItemId).DisplayName == "SolutionFolder2");
                var project = solutionFolder2.Children
                              .FirstOrDefault(n => n.VsHierarchy.Properties(n.ItemId).DisplayName == "ClassLibrary");

                var folder = project.Children.FirstOrDefault(n => n.VsHierarchy.Properties(n.ItemId).DisplayName == "Folder");

                folder = folder.Children.FirstOrDefault(n => n.VsHierarchy.Properties(n.ItemId).DisplayName == "Folder");

                Assert.Equal(1, folder.Children.Count());
            }
Пример #10
0
            public void WhenGettingOwningHierarchyForItem_ThenReturnsProject()
            {
                var solution  = ServiceProvider.GetService <IVsSolution>();
                var hierarchy = solution as IVsHierarchy;

                var item = new VsSolutionHierarchyNode(hierarchy, VSConstants.VSITEMID_ROOT)
                           .Children
                           .Traverse(TraverseKind.DepthFirst, node => node.Children)
                           .First(node => node.DisplayName == "SolutionItem.txt");

                Assert.NotNull(item);

                Console.WriteLine("Owning hierarchy is project? {0}", (item.VsHierarchy is IVsProject));
                Console.WriteLine("Parent display name: {0}", item.Parent.DisplayName);
                Console.WriteLine("Owning hierarchy project kind: {0}", ((EnvDTE.Project)item.Parent.ExtensibilityObject).Kind);

                Console.WriteLine("Owning hierarchy is solution folder? {0}",
                                  ((EnvDTE.Project)item.Parent.ExtensibilityObject).Kind.Equals(EnvDTE80.ProjectKinds.vsProjectKindSolutionFolder, StringComparison.OrdinalIgnoreCase));
            }
Пример #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SolutionTreeNode"/> class.
        /// </summary>
        /// <param name="nodeKind">Kind of the node.</param>
        /// <param name="hierarchyNode">The underlying hierarchy represented by this node.</param>
        /// <param name="parentNode">The parent node accessor.</param>
        /// <param name="nodeFactory">The factory for child nodes.</param>
        /// <param name="adapter">The adapter service that implements the smart cast <see cref="ITreeNode.As{T}"/>.</param>
        protected SolutionTreeNode(
            SolutionNodeKind nodeKind,
            IVsSolutionHierarchyNode hierarchyNode,
            Lazy <ITreeNode> parentNode,
            ITreeNodeFactory <IVsSolutionHierarchyNode> nodeFactory,
            IAdapterService adapter)
        {
            Guard.NotNull(() => hierarchyNode, hierarchyNode);
            Guard.NotNull(() => nodeFactory, nodeFactory);
            Guard.NotNull(() => adapter, adapter);

            this.hierarchyNode = hierarchyNode;
            this.factory       = nodeFactory;
            this.adapter       = adapter;
            this.window        = new Lazy <IVsUIHierarchyWindow>(() => GetWindow(this.hierarchyNode.ServiceProvider));
            this.parent        = parentNode ?? new Lazy <ITreeNode>(() => null);
            this.DisplayName   = this.hierarchyNode.VsHierarchy.Properties(hierarchyNode.ItemId).DisplayName;
            this.Kind          = nodeKind;

            Func <bool> getHiddenProperty = () => GetProperty <bool?>(
                this.hierarchyNode.VsHierarchy,
                __VSHPROPID.VSHPROPID_IsHiddenItem,
                this.hierarchyNode.ItemId).GetValueOrDefault();

            this.isHidden = parentNode != null ?
                            new Lazy <bool>(() => getHiddenProperty() || parentNode.Value.IsHidden) :
                            new Lazy <bool>(() => getHiddenProperty());

            if (System.Diagnostics.Debugger.IsAttached)
            {
                this.debuggerDisplay = BuildDebuggerDisplay();
            }

            this.solutionNode = new Lazy <ISolutionNode>(() =>
            {
                var solutionHierarchy = new VsSolutionHierarchyNode(
                    (IVsHierarchy)this.hierarchyNode.ServiceProvider.GetService <SVsSolution, IVsSolution>(),
                    VSConstants.VSITEMID_ROOT);

                return((ISolutionNode)this.factory.CreateNode(null, solutionHierarchy));
            });
        }
Пример #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SolutionItemNode"/> class.
        /// </summary>
        /// <param name="hierarchyNode">The underlying hierarchy represented by this node.</param>
        /// <param name="parentNode">The parent node accessor.</param>
        /// <param name="nodeFactory">The factory for child nodes.</param>
        /// <param name="adapter">The adapter service that implements the smart cast <see cref="ITreeNode.As{T}"/>.</param>
        public SolutionItemNode(
            IVsSolutionHierarchyNode hierarchyNode,
            Lazy <ITreeNode> parentNode,
            ITreeNodeFactory <IVsSolutionHierarchyNode> nodeFactory,
            IAdapterService adapter)
            : base(SolutionNodeKind.SolutionItem, hierarchyNode, parentNode, nodeFactory, adapter)
        {
            Guard.NotNull(() => parentNode, parentNode);

            this.nodeFactory = nodeFactory;

            this.Item = new Lazy <EnvDTE.ProjectItem>(
                () => (EnvDTE.ProjectItem)hierarchyNode.VsHierarchy.Properties(hierarchyNode.ItemId).ExtenderObject);

            this.owningFolder = new Lazy <ISolutionFolderNode>(() =>
            {
                var owningHierarchy = new VsSolutionHierarchyNode(hierarchyNode.VsHierarchy, VSConstants.VSITEMID_ROOT);
                return(this.nodeFactory.CreateNode(GetParent(owningHierarchy), owningHierarchy) as ISolutionFolderNode);
            });
        }
Пример #13
0
        int IVsSolutionEvents.OnBeforeCloseProject(IVsHierarchy pHierarchy, int fRemoved)
        {
            // Quickly exit if there are no subscribers.
            if (this.ProjectClosing == null)
            {
                return(VSConstants.S_OK);
            }

            var project = GetProject(pHierarchy);

            //This event is also fired when a solution folder is added/loaded
            if (project != null && !(project.Object is SolutionFolder))
            {
                var node = new VsSolutionHierarchyNode(pHierarchy, VSConstants.VSITEMID_ROOT);
                if (this.nodeFactory.Value.Supports(node))
                {
                    this.ProjectClosing(this,
                                        new ProjectEventArgs(new Lazy <IProjectNode>(() =>
                                                                                     GetNode(node).As <IProjectNode>())));
                }
            }

            return(VSConstants.S_OK);
        }
Пример #14
0
        private ISolutionExplorerNode CreateNode(IVsHierarchy from)
        {
            var node = new VsSolutionHierarchyNode(from, VSConstants.VSITEMID_ROOT);

            return(this.nodeFactory.Create(node));
        }