-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
TestExtensionPackage.cs
110 lines (94 loc) · 4.85 KB
/
TestExtensionPackage.cs
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using System;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using Community.VisualStudio.Toolkit;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;
using TestExtension;
using Task = System.Threading.Tasks.Task;
namespace VSSDK.TestExtension
{
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
[Guid(PackageGuids.TestExtensionString)]
[ProvideOptionPage(typeof(OptionsProvider.GeneralOptions), nameof(TestExtension), "General", 0, 0, true)]
[ProvideProfile(typeof(OptionsProvider.GeneralOptions), nameof(TestExtension), "General", 0, 0, true)]
[ProvideToolWindow(typeof(RunnerWindow.Pane), Style = VsDockStyle.Float, Window = WindowGuids.SolutionExplorer)]
[ProvideToolWindowVisibility(typeof(RunnerWindow.Pane), VSConstants.UICONTEXT.NoSolution_string)]
[ProvideToolWindow(typeof(ThemeWindow.Pane))]
[ProvideFileIcon(".abc", "KnownMonikers.Reference")]
[ProvideToolWindow(typeof(MultiInstanceWindow.Pane))]
[ProvideMenuResource("Menus.ctmenu", 1)]
[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionExists_string, PackageAutoLoadFlags.BackgroundLoad)]
[ProvideService(typeof(RunnerWindowMessenger), IsAsyncQueryable = true)]
public sealed class TestExtensionPackage : ToolkitPackage
{
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
AddService(typeof(RunnerWindowMessenger), (_, _, _) => Task.FromResult<object>(new RunnerWindowMessenger()));
// Tool windows
this.RegisterToolWindows();
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
// Commands
await this.RegisterCommandsAsync();
VS.Events.DocumentEvents.AfterDocumentWindowHide += DocumentEvents_AfterDocumentWindowHide;
VS.Events.DocumentEvents.Opened += DocumentEvents_Opened;
VS.Events.DocumentEvents.Closed += DocumentEvents_Closed;
VS.Events.DocumentEvents.BeforeDocumentWindowShow += DocumentEvents_BeforeDocumentWindowShow;
VS.Events.ProjectItemsEvents.AfterRenameProjectItems += ProjectItemsEvents_AfterRenameProjectItems;
VS.Events.ProjectItemsEvents.AfterRemoveProjectItems += ProjectItemsEvents_AfterRemoveProjectItems;
VS.Events.SolutionEvents.OnAfterOpenProject += SolutionEvents_OnAfterOpenProject;
VS.Events.SolutionEvents.OnBeforeOpenProject += SolutionEvents_OnBeforeOpenProject;
VS.Events.BuildEvents.ProjectConfigurationChanged += BuildEvents_ProjectConfigurationChanged;
VS.Events.BuildEvents.SolutionConfigurationChanged += BuildEvents_SolutionConfigurationChanged;
}
private void DocumentEvents_Closed(string obj)
{
VS.StatusBar.ShowMessageAsync("Closed document " + obj ?? "no name").FireAndForget();
}
private void DocumentEvents_Opened(string obj)
{
VS.StatusBar.ShowMessageAsync("Opened document " + obj ?? "no name").FireAndForget();
}
private void BuildEvents_SolutionConfigurationChanged()
{
VS.StatusBar.ShowMessageAsync("Solution configuration changed").FireAndForget();
}
private void BuildEvents_ProjectConfigurationChanged(Project? obj)
{
if (obj != null)
{
VS.StatusBar.ShowMessageAsync($"Configuration for project {obj.Name} changed").FireAndForget();
}
}
private void SolutionEvents_OnBeforeOpenProject(string obj)
{
VS.StatusBar.ShowMessageAsync("About to open " + obj).FireAndForget();
}
private void SolutionEvents_OnAfterOpenProject(Project obj)
{
if (obj != null)
{
VS.StatusBar.ShowMessageAsync("Opened project " + obj.Name).FireAndForget();
}
}
private void ProjectItemsEvents_AfterRemoveProjectItems(AfterRemoveProjectItemEventArgs obj)
{
string info = string.Join(",", obj.ProjectItemRemoves.Select(x => $"{x.Project.Name}:{x.RemovedItemName}"));
VS.MessageBox.ShowConfirm(info);
}
private void ProjectItemsEvents_AfterRenameProjectItems(AfterRenameProjectItemEventArgs obj)
{
string info = string.Join(",", obj.ProjectItemRenames.Select(x => $"{x.SolutionItem.Name}:{x.OldName}"));
VS.MessageBox.ShowConfirm(info);
}
private void DocumentEvents_BeforeDocumentWindowShow(DocumentView obj)
{
VS.StatusBar.ShowMessageAsync(obj.Document?.FilePath ?? "").FireAndForget();
}
private void DocumentEvents_AfterDocumentWindowHide(DocumentView obj)
{
VS.StatusBar.ShowMessageAsync(obj.Document?.FilePath ?? "").FireAndForget();
}
}
}