internal VsSolutionHierarchyNode(IVsHierarchy hierarchy, uint itemId, Lazy<VsSolutionHierarchyNode> parent)
      {
         if (hierarchy == null)
            throw new ArgumentNullException(nameof(hierarchy), $"{nameof(hierarchy)} is null.");

         VsHierarchy = hierarchy;
         ItemId = itemId;

         IntPtr nestedHierarchyObj;
         uint nestedItemId;
         Guid hierGuid = typeof(IVsHierarchy).GUID;

         // Check first if this node has a nested hierarchy. If so, then there really are two 
         // identities for this node: 1. hierarchy/itemid 2. nestedHierarchy/nestedItemId.
         // We will recurse and call EnumHierarchyItems which will display this node using
         // the inner nestedHierarchy/nestedItemId identity.
         int hr = hierarchy.GetNestedHierarchy(itemId, ref hierGuid, out nestedHierarchyObj, out nestedItemId);
         if (hr == VSConstants.S_OK && nestedHierarchyObj != IntPtr.Zero)
         {
            IVsHierarchy nestedHierarchy = Marshal.GetObjectForIUnknown(nestedHierarchyObj) as IVsHierarchy;
            Marshal.Release(nestedHierarchyObj); // we are responsible to release the refcount on the out IntPtr parameter
            if (nestedHierarchy != null)
            {
               VsHierarchy = nestedHierarchy;
               ItemId = nestedItemId;
            }
         }
                  
         DisplayName = VsHierarchy.GetProperty<string>(__VSHPROPID.VSHPROPID_Name, ItemId);

         m_parent = parent ?? new Lazy<VsSolutionHierarchyNode>(() =>
         {
            if (VsHierarchy is IVsSolution)
               return null;

            var rootHierarchy = hierarchy.GetProperty<IVsHierarchy>(__VSHPROPID.VSHPROPID_ParentHierarchy, VSConstants.VSITEMID_ROOT);
            if (rootHierarchy == null)
               return null;

            var rootNode = new VsSolutionHierarchyNode(rootHierarchy, VSConstants.VSITEMID_ROOT);

            var parentNode = new VsSolutionHierarchyNode[] { rootNode }
                .Concat(rootNode.Children.BreadthFirstTraversal(node => node.Children))
                .FirstOrDefault(node => node.Children.Any(child => child.ItemId == ItemId));

            if (parentNode == null)
               return null;

            return new VsSolutionHierarchyNode(parentNode.VsHierarchy, parentNode.ItemId);
         });

         this.m_serviceProvider = new Lazy<IServiceProvider>(() =>
         {
            Microsoft.VisualStudio.OLE.Interop.IServiceProvider oleSp;
            hierarchy.GetSite(out oleSp);
            return oleSp != null ?
                new ServiceProvider(oleSp) :
                GlobalVsServiceProvider.Instance;
         });
      }
예제 #2
0
      public SolutionExplorerNode(SolutionExplorerNodeKind kind, VsSolutionHierarchyNode hierarchyNode, Lazy<ISolutionExplorerNode> parentNode, ISolutionExplorerNodeFactory nodeFactory)
      {
         if (nodeFactory == null)
            throw new ArgumentNullException(nameof(nodeFactory), $"{nameof(nodeFactory)} is null.");

         if (hierarchyNode == null)
            throw new ArgumentNullException(nameof(hierarchyNode), $"{nameof(hierarchyNode)} is null.");

         Kind = kind;
         NodeFactory = nodeFactory;
         m_hierarchyNode = hierarchyNode;
         m_window = new Lazy<IVsUIHierarchyWindow>(() => GetWindow(hierarchyNode.ServiceProvider));
         m_parent = parentNode ?? new Lazy<ISolutionExplorerNode>(() => null);

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

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

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

            return new SolutionNode(solutionHierarchy, NodeFactory);
         });
      }
예제 #3
0
      public ProjectNode(VsSolutionHierarchyNode hierarchyNode, Lazy<ISolutionExplorerNode> parentNode, ISolutionExplorerNodeFactory nodeFactory)
          : base(SolutionExplorerNodeKind.Project, hierarchyNode, parentNode, nodeFactory)
      {
         if (parentNode == null)
            throw new ArgumentNullException(nameof(parentNode), $"{nameof(parentNode)} is null.");

         m_project = new Lazy<EnvDTE.Project>(() => (EnvDTE.Project)hierarchyNode.ExtenderObject);
      }
예제 #4
0
      public bool CanCreateFrom(VsSolutionHierarchyNode hierarchy)
      {
         var extenderObject = hierarchy.ExtenderObject;
         var project = extenderObject as EnvDTE.Project;

         return (extenderObject != null && extenderObject.GetType().FullName == "Microsoft.VisualStudio.Project.Automation.OAProject") ||
          (project != null && !(project.Object is EnvDTE80.SolutionFolder));
      }
예제 #5
0
 public ProjectItemNode(SolutionExplorerNodeKind kind, VsSolutionHierarchyNode hierarchyNode, Lazy<ISolutionExplorerNode> parent, ISolutionExplorerNodeFactory nodeFactory)
    : base(kind, hierarchyNode, parent, nodeFactory)
 {
    m_parentProject = new Lazy<IProjectNode>(() =>
    {
       VsSolutionHierarchyNode parentProjectHierarchy = new VsSolutionHierarchyNode(hierarchyNode.VsHierarchy, VSConstants.VSITEMID_ROOT);
       return NodeFactory.Create(parentProjectHierarchy, GetParent(parentProjectHierarchy)) as IProjectNode;
    });
 }
예제 #6
0
      public ISolutionExplorerNode Create(VsSolutionHierarchyNode hierarchy, Lazy<ISolutionExplorerNode> parent)
      {
         if (hierarchy == null)
            throw new ArgumentNullException(nameof(hierarchy), $"{nameof(hierarchy)} is null.");

         if (parent != null)
            throw new ArgumentException($"{nameof(parent)} must be null for {nameof(SolutionNode)} creation.");

         return CanCreateFrom(hierarchy) ? new SolutionNode(hierarchy, m_nodeFactory.Value) : null;
      }
예제 #7
0
      public ISolutionExplorerNode Create(VsSolutionHierarchyNode hierarchy, Lazy<ISolutionExplorerNode> parent)
      {
         if (hierarchy == null)
            throw new ArgumentNullException(nameof(hierarchy), $"{nameof(hierarchy)} is null.");

         if (parent == null)
            throw new ArgumentNullException(nameof(parent), $"{nameof(parent)} is null.");

         return CanCreateFrom(hierarchy) ? new ProjectNode(hierarchy, parent, m_nodeFactory.Value) : null;
      }
      public bool CanCreateFrom(VsSolutionHierarchyNode hierarchy)
      {
         if (hierarchy.Parent == null)
            return false;

         var item = hierarchy.ExtenderObject as EnvDTE.ProjectItem;
         var project = hierarchy.Parent.ExtenderObject as EnvDTE.Project;

         return project != null && item != null && project.Object is EnvDTE80.SolutionFolder;
      }
예제 #9
0
      public SolutionItemNode(VsSolutionHierarchyNode hierarchyNode, Lazy<ISolutionExplorerNode> parentNode, ISolutionExplorerNodeFactory nodeFactory)
          : base(SolutionExplorerNodeKind.SolutionItem, hierarchyNode, parentNode, nodeFactory)
      {
         m_dteItem = new Lazy<EnvDTE.ProjectItem>(() => (EnvDTE.ProjectItem)hierarchyNode.ExtenderObject);

         owningFolder = new Lazy<ISolutionFolderNode>(() =>
         {
            var owningHierarchy = new VsSolutionHierarchyNode(hierarchyNode.VsHierarchy, VSConstants.VSITEMID_ROOT);
            return NodeFactory.Create(owningHierarchy, GetParent(owningHierarchy)) as ISolutionFolderNode;
         });
      }
예제 #10
0
      public bool CanCreateFrom(VsSolutionHierarchyNode hierarchy)
      {
         var projectItem = hierarchy.ExtenderObject as EnvDTE.ProjectItem;

         return projectItem != null && projectItem.Kind == EnvDTE.Constants.vsProjectItemKindPhysicalFile && !(projectItem.ContainingProject.Object is EnvDTE80.SolutionFolder);
      }
예제 #11
0
 private Lazy<ISolutionExplorerNode> GetParent(VsSolutionHierarchyNode hierarchy)
 {
    return hierarchy.Parent == null ? null : new Lazy<ISolutionExplorerNode>(() => NodeFactory.Create(hierarchy.Parent, GetParent(hierarchy.Parent)));
 }
예제 #12
0
 public SolutionNode(VsSolutionHierarchyNode hierarchyNode, ISolutionExplorerNodeFactory nodeFactory)
    : base(SolutionExplorerNodeKind.Solution, hierarchyNode, null, nodeFactory)
 {
 }
예제 #13
0
 public bool CanCreateFrom(VsSolutionHierarchyNode hierarchyNode)
 {
    return hierarchyNode.ExtenderObject is VSLangProj.Reference;
 }
 public bool CanCreateFrom(VsSolutionHierarchyNode hierarchyNode)
 {
    // Can we do something better here?
    return hierarchyNode.ExtenderObject == null && hierarchyNode.DisplayName == "References";
 }
예제 #15
0
 public ReferenceNode(VsSolutionHierarchyNode hierarchyNode, Lazy<ISolutionExplorerNode> parentNode, ISolutionExplorerNodeFactory nodeFactory)
     : base(SolutionExplorerNodeKind.Reference, hierarchyNode, parentNode, nodeFactory)
 {      
    m_dteReference = new Lazy<VSLangProj.Reference>(() => (VSLangProj.Reference)hierarchyNode.ExtenderObject);         
 }
예제 #16
0
 public FolderNode(VsSolutionHierarchyNode hierarchyNode, Lazy<ISolutionExplorerNode> parentNode, ISolutionExplorerNodeFactory nodeFactory)
     : base(SolutionExplorerNodeKind.Folder, hierarchyNode, parentNode, nodeFactory)
 {
    m_dteItem = new Lazy<EnvDTE.ProjectItem>(() => (EnvDTE.ProjectItem)hierarchyNode.ExtenderObject);
 }
예제 #17
0
 public bool CanCreateFrom(VsSolutionHierarchyNode hierarchyNode)
 {
    EnvDTE.ProjectItem projectItem = hierarchyNode.ExtenderObject as EnvDTE.ProjectItem;
    return projectItem != null && projectItem.Kind == EnvDTE.Constants.vsProjectItemKindPhysicalFolder;
 }
 public ISolutionExplorerNode Create(VsSolutionHierarchyNode hierarchy, Lazy<ISolutionExplorerNode> parent)
 {
    return m_factories.FirstOrDefault(factory => factory.CanCreateFrom(hierarchy))?.Create(hierarchy, parent);
 }
예제 #19
0
 public bool CanCreateFrom(VsSolutionHierarchyNode hierarchyNode)
 {
    return hierarchyNode.VsHierarchy is IVsSolution;
 }
예제 #20
0
 public ItemNode(VsSolutionHierarchyNode hierarchyNode, Lazy<ISolutionExplorerNode> parentNode, ISolutionExplorerNodeFactory nodeFactory)
     : base(SolutionExplorerNodeKind.Item, hierarchyNode, parentNode, nodeFactory)
 {
     m_dteProjectItem = new Lazy<EnvDTE.ProjectItem>(() => (EnvDTE.ProjectItem)hierarchyNode.ExtenderObject);
      Properties = new ItemProperties(this);
 }
 public bool CanCreateFrom(VsSolutionHierarchyNode hierarchyNode)
 {
    return m_factories.Any(factory => factory.CanCreateFrom(hierarchyNode));
 }
 public bool CanCreateFrom(VsSolutionHierarchyNode hierarchyNode)
 {
    var project = hierarchyNode.ExtenderObject as EnvDTE.Project;
    return project != null && project.Object is EnvDTE80.SolutionFolder;
 }
예제 #23
0
 public ReferencesFolderNode(VsSolutionHierarchyNode hierarchyNode, Lazy<ISolutionExplorerNode> parentNode, ISolutionExplorerNodeFactory nodeFactory)
     : base(SolutionExplorerNodeKind.ReferencesFolder, hierarchyNode, parentNode, nodeFactory)
 {
    m_dteReferences = new Lazy<VSLangProj.References>(() => ((VSLangProj.VSProject)((EnvDTE.Project)hierarchyNode.VsHierarchy.GetProperty<object>(Microsoft.VisualStudio.Shell.Interop.__VSHPROPID.VSHPROPID_ExtObject, VSConstants.VSITEMID_ROOT)).Object).References);
 }
예제 #24
0
 protected virtual ISolutionExplorerNode CreateChildNode(VsSolutionHierarchyNode hierarchy)
 {
    return NodeFactory.Create(hierarchy, new Lazy<ISolutionExplorerNode>(() => this));
 }
예제 #25
0
 public ISolutionExplorerNode Create(VsSolutionHierarchyNode hierarchy, Lazy<ISolutionExplorerNode> parent)
 {
    return CanCreateFrom(hierarchy) ? new FolderNode(hierarchy, parent, m_nodeFactory.Value) : null;
 }
예제 #26
0
 public SolutionFolderNode(VsSolutionHierarchyNode hierarchyNode, Lazy<ISolutionExplorerNode> parent, ISolutionExplorerNodeFactory nodeFactory)
    : base(SolutionExplorerNodeKind.SolutionFolder, hierarchyNode, parent, nodeFactory)
 {
    m_dteSolutionFolder = new Lazy<EnvDTE80.SolutionFolder>(() => (EnvDTE80.SolutionFolder)((EnvDTE.Project)hierarchyNode.ExtenderObject).Object);
 }