-
Notifications
You must be signed in to change notification settings - Fork 363
Expand file tree
/
Copy pathCollapseSelectedSolutionExplorerCommand.cs
More file actions
65 lines (58 loc) · 2.37 KB
/
CollapseSelectedSolutionExplorerCommand.cs
File metadata and controls
65 lines (58 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using EnvDTE;
using SteveCadwallader.CodeMaid.Helpers;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace SteveCadwallader.CodeMaid.Integration.Commands
{
/// <summary>
/// A command that provides for collapsing selected nodes in the solution explorer tool window.
/// </summary>
internal sealed class CollapseSelectedSolutionExplorerCommand : BaseCommand
{
/// <summary>
/// Initializes a new instance of the <see cref="CollapseSelectedSolutionExplorerCommand" /> class.
/// </summary>
/// <param name="package">The hosting package.</param>
internal CollapseSelectedSolutionExplorerCommand(CodeMaidPackage package)
: base(package, PackageGuids.GuidCodeMaidMenuSet, PackageIds.CmdIDCodeMaidCollapseSelectedSolutionExplorer)
{
}
/// <summary>
/// A singleton instance of this command.
/// </summary>
public static CollapseSelectedSolutionExplorerCommand Instance { get; private set; }
/// <summary>
/// Gets an enumerable collection of the selected UI hierarchy items.
/// </summary>
private IEnumerable<UIHierarchyItem> SelectedUIHierarchyItems => UIHierarchyHelper.GetSelectedUIHierarchyItems(Package);
/// <summary>
/// Initializes a singleton instance of this command.
/// </summary>
/// <param name="package">The hosting package.</param>
/// <returns>A task.</returns>
public static Task InitializeAsync(CodeMaidPackage package)
{
Instance = new CollapseSelectedSolutionExplorerCommand(package);
return package.SettingsMonitor.WatchAsync(s => s.Feature_CollapseSelectedSolutionExplorer, Instance.SwitchAsync);
}
/// <summary>
/// Called to update the current status of the command.
/// </summary>
protected override void OnBeforeQueryStatus()
{
Enabled = SelectedUIHierarchyItems.Any(x => x.UIHierarchyItems.Expanded);
}
/// <summary>
/// Called to execute the command.
/// </summary>
protected override void OnExecute()
{
base.OnExecute();
foreach (UIHierarchyItem item in SelectedUIHierarchyItems)
{
UIHierarchyHelper.CollapseRecursively(item);
}
}
}
}