private static void CollapseProjectHierarchyItems(Project project, ISet <VsHierarchyItem> ignoredHierarcyItems) { VsHierarchyItem projectHierarchyItem = GetHierarchyItemForProject(project); IVsUIHierarchyWindow solutionExplorerWindow = GetSolutionExplorerHierarchyWindow(); 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 projectHierarchyItem.WalkDepthFirst( fVisible: true, processCallback: (VsHierarchyItem currentHierarchyItem, object callerObject, out object newCallerObject) => { newCallerObject = null; if (!ignoredHierarcyItems.Contains(currentHierarchyItem)) { CollapseVsHierarchyItem(currentHierarchyItem, solutionExplorerWindow); } return(0); }, callerObject: null); }
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); }
private static ICollection <VsHierarchyItem> GetExpandedProjectHierarchyItems(EnvDTE.Project project) { VsHierarchyItem projectHierarchyItem = GetHierarchyItemForProject(project); IVsUIHierarchyWindow solutionExplorerWindow = GetSolutionExplorerHierarchyWindow(); if (solutionExplorerWindow == null) { // If the solution explorer is collapsed since opening VS, this value is null. In such a case, simply exit early. return(new VsHierarchyItem[0]); } var expandedItems = new List <VsHierarchyItem>(); // processCallback return values: // 0 continue, // 1 don't recurse into, // -1 stop projectHierarchyItem.WalkDepthFirst( fVisible: true, processCallback: (VsHierarchyItem vsItem, object callerObject, out object newCallerObject) => { newCallerObject = null; if (IsVsHierarchyItemExpanded(vsItem, solutionExplorerWindow)) { expandedItems.Add(vsItem); } return(0); }, callerObject: null); return(expandedItems); }
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); }
private static void CollapseVsHierarchyItem(VsHierarchyItem vsHierarchyItem, IVsUIHierarchyWindow vsHierarchyWindow) { if (vsHierarchyItem == null || vsHierarchyWindow == null) { return; } vsHierarchyWindow.ExpandItem(vsHierarchyItem.UIHierarchy(), vsHierarchyItem.VsItemID, EXPANDFLAGS.EXPF_CollapseFolder); }
private static void CollapseVsHierarchyItem(VsHierarchyItem vsHierarchyItem, IVsUIHierarchyWindow vsHierarchyWindow) { ThreadHelper.ThrowIfNotOnUIThread(); if (vsHierarchyItem == null || vsHierarchyWindow == null) { return; } vsHierarchyWindow.ExpandItem(AsVsUIHierarchy(vsHierarchyItem), vsHierarchyItem.VsItemID, EXPANDFLAGS.EXPF_CollapseFolder); }
private static async Task CollapseVsHierarchyItemAsync(VsHierarchyItem vsHierarchyItem, IVsUIHierarchyWindow vsHierarchyWindow) { if (vsHierarchyItem == null || vsHierarchyWindow == null) { return; } await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); vsHierarchyWindow.ExpandItem(AsVsUIHierarchy(vsHierarchyItem), vsHierarchyItem.VsItemID, EXPANDFLAGS.EXPF_CollapseFolder); }
private static bool IsVsHierarchyItemExpanded(VsHierarchyItem hierarchyItem, IVsUIHierarchyWindow uiWindow) { if (!hierarchyItem.IsExpandable()) { return(false); } const uint expandedStateMask = (uint)__VSHIERARCHYITEMSTATE.HIS_Expanded; uint itemState; uiWindow.GetItemState(hierarchyItem.UIHierarchy(), hierarchyItem.VsItemID, expandedStateMask, out itemState); return((__VSHIERARCHYITEMSTATE)itemState == __VSHIERARCHYITEMSTATE.HIS_Expanded); }
private static async Task <bool> IsVsHierarchyItemExpandedAsync(VsHierarchyItem hierarchyItem, IVsUIHierarchyWindow uiWindow) { if (!await hierarchyItem.IsExpandableAsync()) { return(false); } const uint expandedStateMask = (uint)__VSHIERARCHYITEMSTATE.HIS_Expanded; uint itemState; await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); uiWindow.GetItemState(AsVsUIHierarchy(hierarchyItem), hierarchyItem.VsItemID, expandedStateMask, out itemState); return((__VSHIERARCHYITEMSTATE)itemState == __VSHIERARCHYITEMSTATE.HIS_Expanded); }
private static IVsUIHierarchy AsVsUIHierarchy(VsHierarchyItem hierarchyItem) { ThreadHelper.ThrowIfNotOnUIThread(); return(hierarchyItem.VsHierarchy as IVsUIHierarchy); }