Пример #1
0
        private static async Task CollapseProjectHierarchyItemsAsync(EnvDTE.Project project, ISet <VsHierarchyItem> ignoredHierarcyItems)
        {
            var projectHierarchyItem = await VsHierarchyItem.FromDteProjectAsync(project);

            var solutionExplorerWindow = await GetSolutionExplorerHierarchyWindowAsync();

            if (solutionExplorerWindow == null)
            {
                // If the solution explorer is collapsed since opening VS, this value is null. In such a case, simply exit early.
                return;
            }

            // processCallback return values:
            //     0   continue,
            //     1   don't recurse into,
            //    -1   stop
            await projectHierarchyItem.WalkDepthFirstAsync(
                fVisible : true,
                processCallbackAsync :
                async(VsHierarchyItem currentHierarchyItem, object callerObject) =>
            {
                if (!ignoredHierarcyItems.Contains(currentHierarchyItem))
                {
                    await CollapseVsHierarchyItemAsync(currentHierarchyItem, solutionExplorerWindow);
                }
                return(0, null);
            },
                callerObject : null);
        }
Пример #2
0
        private static async Task <ICollection <VsHierarchyItem> > GetExpandedProjectHierarchyItemsAsync(EnvDTE.Project project)
        {
            var projectHierarchyItem = await VsHierarchyItem.FromDteProjectAsync(project);

            var solutionExplorerWindow = await GetSolutionExplorerHierarchyWindowAsync();

            if (solutionExplorerWindow == null)
            {
                // If the solution explorer is collapsed since opening VS, this value is null. In such a case, simply exit early.
                return(Array.Empty <VsHierarchyItem>());
            }

            var expandedItems = new List <VsHierarchyItem>();

            await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            // processCallback return values:
            //     0   continue,
            //     1   don't recurse into,
            //    -1   stop
            await projectHierarchyItem.WalkDepthFirstAsync(
                fVisible : true,
                processCallbackAsync :
                async(VsHierarchyItem vsItem, object callerObject) =>
            {
                if (await IsVsHierarchyItemExpandedAsync(vsItem, solutionExplorerWindow))
                {
                    expandedItems.Add(vsItem);
                }
                return(0, null);
            },
                callerObject : null);

            return(expandedItems);
        }