-
Notifications
You must be signed in to change notification settings - Fork 364
Expand file tree
/
Copy pathCleanupAllCodeCommand.cs
More file actions
91 lines (82 loc) · 3.52 KB
/
CleanupAllCodeCommand.cs
File metadata and controls
91 lines (82 loc) · 3.52 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using EnvDTE;
using SteveCadwallader.CodeMaid.Helpers;
using SteveCadwallader.CodeMaid.Logic.Cleaning;
using SteveCadwallader.CodeMaid.Properties;
using SteveCadwallader.CodeMaid.UI.Dialogs.CleanupProgress;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace SteveCadwallader.CodeMaid.Integration.Commands
{
/// <summary>
/// A command that provides for cleaning up code in all documents.
/// </summary>
internal sealed class CleanupAllCodeCommand : BaseCommand
{
/// <summary>
/// Initializes a new instance of the <see cref="CleanupAllCodeCommand" /> class.
/// </summary>
/// <param name="package">The hosting package.</param>
internal CleanupAllCodeCommand(CodeMaidPackage package)
: base(package, PackageGuids.GuidCodeMaidMenuSet, PackageIds.CmdIDCodeMaidCleanupAllCode)
{
CodeCleanupAvailabilityLogic = CodeCleanupAvailabilityLogic.GetInstance(Package);
}
/// <summary>
/// A singleton instance of this command.
/// </summary>
public static CleanupAllCodeCommand Instance { get; private set; }
/// <summary>
/// Gets the list of all project items.
/// </summary>
private IEnumerable<ProjectItem> AllProjectItems
=> SolutionHelper.GetAllItemsInSolution<ProjectItem>(Package.IDE.Solution).Where(x => CodeCleanupAvailabilityLogic.CanCleanupProjectItem(x));
/// <summary>
/// Gets or sets the code cleanup availability logic.
/// </summary>
private CodeCleanupAvailabilityLogic CodeCleanupAvailabilityLogic { get; set; }
/// <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 CleanupAllCodeCommand(package);
return package.SettingsMonitor.WatchAsync(s => s.Feature_CleanupAllCode, Instance.SwitchAsync);
}
/// <summary>
/// Called to update the current status of the command.
/// </summary>
protected override void OnBeforeQueryStatus()
{
Enabled = Package.IDE.Solution.IsOpen;
}
/// <summary>
/// Called to execute the command.
/// </summary>
protected override void OnExecute()
{
base.OnExecute();
if (!CodeCleanupAvailabilityLogic.IsCleanupEnvironmentAvailable())
{
MessageBox.Show(Resources.CleanupCannotRunWhileDebugging,
Resources.CodeMaidCleanupAllCode,
MessageBoxButton.OK, MessageBoxImage.Warning);
}
else if (MessageBox.Show(Resources.AreYouReadyForCodeMaidToCleanEverythingInTheSolution,
Resources.CodeMaidConfirmationForCleanupAllCode,
MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No)
== MessageBoxResult.Yes)
{
using (new ActiveDocumentRestorer(Package))
{
var viewModel = new CleanupProgressViewModel(Package, AllProjectItems);
var window = new CleanupProgressWindow { DataContext = viewModel };
window.ShowModal();
}
}
}
}
}