/// <summary> /// Expands the specified items. /// </summary> /// <param name="items">The items to expand.</param> /// <param name="mode">Specifies how the items will be expanded.</param> public void Expand(IEnumerable <SolutionItem> items, SolutionItemExpansionMode mode = SolutionItemExpansionMode.Single) { if (items is null) { throw new ArgumentNullException(nameof(items)); } ThreadHelper.ThrowIfNotOnUIThread(); // Although the `EXPANDFLAGS` has the `[Flags]` attribute, the values // cannot actually be combined because the values are sequential. // We need to make multiple calls for each mode that is set. if ((mode & SolutionItemExpansionMode.Ancestors) == SolutionItemExpansionMode.Ancestors) { Expand(items, EXPANDFLAGS.EXPF_ExpandParentsToShowItem); } // Expanding recursively will also expand the given items, so if we // expand recurisvely, then we don't need to check for the `Single` mode. if ((mode & SolutionItemExpansionMode.Recursive) == SolutionItemExpansionMode.Recursive) { Expand(items, EXPANDFLAGS.EXPF_ExpandFolderRecursively); } else if ((mode & SolutionItemExpansionMode.Single) == SolutionItemExpansionMode.Single) { Expand(items, EXPANDFLAGS.EXPF_ExpandFolder); } }
/// <summary> /// Expands the specified item. /// </summary> /// <param name="item">The item to expand.</param> /// <param name="mode">Specifies how the item will be expanded.</param> public void Expand(SolutionItem item, SolutionItemExpansionMode mode = SolutionItemExpansionMode.Single) { if (item is null) { throw new ArgumentNullException(nameof(item)); } ThreadHelper.ThrowIfNotOnUIThread(); Expand(new[] { item }, mode); }
protected override async Task ExecuteAsync(OleMenuCmdEventArgs e) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); SolutionExplorerWindow solutionExplorer = await VS.Windows.GetSolutionExplorerWindowAsync(); if (solutionExplorer != null) { IEnumerable <SolutionItem> items = await solutionExplorer.GetSelectionAsync(); SolutionItemExpansionMode mode = SolutionItemExpansionMode.None; ModifierKeys modifiers = Keyboard.Modifiers; if (modifiers == ModifierKeys.None) { mode = SolutionItemExpansionMode.Single; } else { if ((modifiers & ModifierKeys.Control) == ModifierKeys.Control) { mode |= SolutionItemExpansionMode.Recursive; } if ((modifiers & ModifierKeys.Shift) == ModifierKeys.Shift) { // To expand to the selected items, theose items and their ancestors // all need to be collapsed, so collapse them first, then pause for a // moment so that you can see that we start from a collapsed state. foreach (SolutionItem item in items) { CollapseRecursively(solutionExplorer, item); } await Task.Delay(2000); mode |= SolutionItemExpansionMode.Ancestors; } } solutionExplorer.Expand(items, mode); } }