-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeStatsForVSPackage.cs
More file actions
91 lines (77 loc) · 3.57 KB
/
Copy pathCodeStatsForVSPackage.cs
File metadata and controls
91 lines (77 loc) · 3.57 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
global using System;
global using Community.VisualStudio.Toolkit;
global using Microsoft.VisualStudio.Shell;
global using Task = System.Threading.Tasks.Task;
using System.ComponentModel.Composition;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Editor;
using Microsoft.VisualStudio.OLE.Interop;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.TextManager.Interop;
using Microsoft.VisualStudio.Utilities;
namespace CodeStatsForVS
{
/// <summary>
/// Класс инициализации пакета.
/// </summary>
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
[InstalledProductRegistration(Vsix.Name, Vsix.Description, Vsix.Version)]
[ProvideMenuResource("Menus.ctmenu", 1)]
[Guid(PackageGuids.CodeStatsForVSString)]
[ProvideOptionPage(typeof(OptionsProvider.GeneralOptions), "CodeStats", "General", 0, 0, true)]
[ProvideProfile(typeof(OptionsProvider.GeneralOptions), "CodeStats", "General", 0, 0, true)]
[Export(typeof(IVsTextViewCreationListener))]
[ContentType("text")]
[TextViewRole(PredefinedTextViewRoles.Editable)]
public sealed class CodeStatsForVSPackage : ToolkitPackage, IVsTextViewCreationListener
{
[Export(typeof(AdornmentLayerDefinition))]
[Name("CodeStatsClientLayer")]
[TextViewRole(PredefinedTextViewRoles.Editable)]
internal AdornmentLayerDefinition m_multieditAdornmentLayer = null;
[Import(typeof(IVsEditorAdaptersFactoryService))]
internal IVsEditorAdaptersFactoryService editorFactory = null;
/// <summary>
/// Вызывается, когда адаптер <see cref="IVsTextView"/> был создан и инициализирован.
/// </summary>
/// <param name="textViewAdapter">Недавно созданный и инициализированный адаптер текстового представления.</param>
public void VsTextViewCreated(IVsTextView textViewAdapter)
{
IWpfTextView textView = editorFactory.GetWpfTextView(textViewAdapter);
if (textView == null)
return;
AddCommandFilter(textViewAdapter, new CommandFilter(textView));
}
/// <summary>
/// Добавляет <see cref="CommandFilter"/> к <see cref="IVsTextView"/>.
/// </summary>
/// <param name="viewAdapter">Ссылка на <see cref="IVsTextView"/>.</param>
/// <param name="commandFilter">Ссылка на <see cref="CommandFilter"/>.</param>
private void AddCommandFilter(IVsTextView viewAdapter, CommandFilter commandFilter)
{
if (commandFilter.Added)
{
return;
}
int hr = viewAdapter.AddCommandFilter(commandFilter, out IOleCommandTarget next);
if (hr == VSConstants.S_OK)
{
commandFilter.Added = true;
if (next != null)
commandFilter.NextTarget = next;
}
}
/// <summary>
/// Инициализация данного пакета.
/// </summary>
/// <param name="cancellationToken"></param>
/// <param name="progress"></param>
/// <returns></returns>
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
}
}
}