private ISet <Guid> GetIncludedProjectIds(ISolutionHierarchyItem item, HashSet <Guid> ids, bool isParentIncluded)
        {
            bool value;
            bool?itemInclusionState;

            if (m_projects.TryGetValue(item.Id, out value))
            {
                itemInclusionState = value;
            }
            else
            {
                itemInclusionState = null;
            }

            bool isItemIncluded = isParentIncluded && itemInclusionState == null || itemInclusionState == true;

            if (isItemIncluded)
            {
                ids.Add(item.Id);
            }

            ISolutionHierarchyContainerItem container = item as ISolutionHierarchyContainerItem;

            if (container != null)
            {
                foreach (ISolutionHierarchyItem child in container.Children)
                {
                    GetIncludedProjectIds(child, ids, isItemIncluded);
                }
            }

            return(ids);
        }
Beispiel #2
0
        public static ProjectSetNodeViewModel CreateFrom(ProjectSetViewModel owner, ISolutionHierarchyItem node, ProjectSetContainerNodeViewModel parent)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node", "node is null.");
            }


            if (parent == null && node.ItemType != SolutionHierarchyItemType.Solution)
            {
                throw new ArgumentNullException("parent", "parent is null.");
            }

            switch (node.ItemType)
            {
            case SolutionHierarchyItemType.Solution:
                return(new ProjectSetSolutionRootNodeViewModel(owner, (ISolutionHierarchyContainerItem)node));

            case SolutionHierarchyItemType.SolutionFolder:
                return(new ProjectSetSolutionFolderNodeViewModel(owner, (ISolutionHierarchyContainerItem)node, parent));

            case SolutionHierarchyItemType.Project:
            case SolutionHierarchyItemType.UnloadedProject:
                return(new ProjectSetProjectNodeViewModel(owner, node, parent));

            default:
                throw new NotSupportedException(String.Format("Unknown project set node type {0}", node.ItemType));
            }
        }
        private ISolutionHierarchyItem PopulateHierarchy(IVsHierarchy hierarchy, uint itemId, bool visibleNodesOnly, ISolutionHierarchyContainerItem solutionNode, ISolutionHierarchyItem thisNode)
        {
            Dispatcher.CurrentDispatcher.VerifyAccess();

            ISolutionHierarchyContainerItem container = thisNode as ISolutionHierarchyContainerItem;

            if (container != null)
            {
                if (solutionNode == null)
                {
                    solutionNode = container;
                }

                IEnumerable <uint> childIds = EnumerateChildIds(hierarchy, itemId, visibleNodesOnly);

                List <ISolutionHierarchyItem> list = new List <ISolutionHierarchyItem>();

                foreach (uint childId in childIds)
                {
                    ISolutionHierarchyItem childItem = CreateSolutionHierarchyItem(hierarchy, childId);
                    if (childItem != null)
                    {
                        container.Children.Add(childItem);
                        list.Add(childItem);

                        // Due to a bug in VS, enumerating the solution node actually returns all projects within the solution, at any depth,
                        // so we need to remove them here if found.
                        if (container != solutionNode)
                        {
                            solutionNode.Children.Remove(childItem.Id);
                        }
                    }
                }

                foreach (var childItem in list.OfType <ISolutionHierarchyContainerItem>())
                {
                    if (container.Children.Contains(childItem.Id)) // On SolutionNode the child may actually have been removed (see below)
                    {
                        PopulateHierarchy(childItem.VsHierarchy, childItem.HierarchyItemId, visibleNodesOnly, solutionNode, childItem);
                    }
                }
            }
            return(thisNode);
        }
            public StateItem(ISolutionHierarchyItem item)
            {
                m_item = item;

                ISolutionHierarchyContainerItem container = item as ISolutionHierarchyContainerItem;

                if (container == null)
                {
                    m_children = new List <StateItem>();
                    State      = item.ItemType != SolutionHierarchyItemType.UnloadedProject;
                }
                else
                {
                    m_children = container.Children.Select(c => new StateItem(c)).ToList();

                    int inclusionCount = m_children.Count(c => c.State == true);
                    int exclusionCount = m_children.Count - inclusionCount;

                    if (exclusionCount == 0)
                    {
                        m_children.ForEach(si => si.State = null);
                        State = true;
                    }
                    else if (inclusionCount == 0)
                    {
                        m_children.ForEach(si => si.State = null);
                        State = false;
                    }
                    else if (inclusionCount == exclusionCount && item.ItemType != SolutionHierarchyItemType.Solution || inclusionCount > exclusionCount)
                    {
                        State = true;
                        m_children.ForEach(si => si.State = si.State == true ? (bool?)null : si.State);
                    }
                    else
                    {
                        State = false;
                        m_children.ForEach(si => si.State = si.State == false ? (bool?)null : si.State);
                    }
                }
            }
Beispiel #5
0
 public ProjectSetProjectNodeViewModel(ProjectSetViewModel owner, ISolutionHierarchyItem node, ProjectSetContainerNodeViewModel parent)
     : base(owner, node, parent)
 {
 }
Beispiel #6
0
 public ProjectSetNodeViewModel(ProjectSetViewModel owner, ISolutionHierarchyItem projectSetNode, ProjectSetContainerNodeViewModel parent)
 {
     m_owner          = owner;
     m_parent         = parent;
     m_projectSetNode = projectSetNode;
 }
        private ISolutionHierarchyItem GetSolutionHierarchy(IVsHierarchy hierarchy, uint itemId, bool visibleNodesOnly, ISolutionHierarchyContainerItem solutionNode)
        {
            Dispatcher.CurrentDispatcher.VerifyAccess();

            int    hr;
            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.
            hr = hierarchy.GetNestedHierarchy(itemId, ref hierGuid, out nestedHierarchyObj, out nestedItemId);
            if (VSConstants.S_OK == hr && IntPtr.Zero != nestedHierarchyObj)
            {
                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)
                {
                    // Display name and type of the node in the Output Window
                    return(GetSolutionHierarchy(nestedHierarchy, nestedItemId, visibleNodesOnly, solutionNode));
                }

                return(null);
            }
            else
            {
                ISolutionHierarchyItem          item      = CreateSolutionHierarchyItemDirect(hierarchy, itemId);
                ISolutionHierarchyContainerItem container = item as ISolutionHierarchyContainerItem;

                if (container != null)
                {
                    if (solutionNode == null)
                    {
                        solutionNode = container;
                    }

                    IEnumerable <uint> childIds = EnumerateChildIds(hierarchy, itemId, visibleNodesOnly);

                    if (container == solutionNode && solutionNode != null)
                    {
                        childIds = childIds.OrderBy(id => IsSolutionFolder(hierarchy, id) ? 1 : 0);
                    }

                    foreach (uint childId in childIds)
                    {
                        ISolutionHierarchyItem childItem = GetSolutionHierarchy(hierarchy, childId, visibleNodesOnly, solutionNode);
                        if (childItem != null)
                        {
                            container.Children.Add(childItem);

                            // Due to a bug in VS, enumerating the solution node actually returns all projects within the solution, at any depth,
                            // so we need to remove them here if found.
                            if (container != solutionNode)
                            {
                                solutionNode.Children.Remove(childItem.Id);
                            }
                        }
                    }
                }

                return(item);
            }
        }