Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit acb8a94

Browse files
committed
Prototype toggle margin using GlyphMargin
This toggles the GlyphMargin on and off. It will be changed to toggle the comments margin.
1 parent 93c6738 commit acb8a94

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/GitHub.InlineReviews/Commands/EnableInlineCommentsCommand.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
using GitHub.VisualStudio;
44
using GitHub.Services.Vssdk.Commands;
55
using System.ComponentModel.Composition;
6+
using Microsoft.VisualStudio.TextManager.Interop;
7+
using Microsoft.VisualStudio;
8+
using Microsoft.VisualStudio.Editor;
9+
using GitHub.Services;
610

711
namespace GitHub.InlineReviews.Commands
812
{
@@ -19,13 +23,31 @@ public class EnableInlineCommentsCommand : VsCommand, IEnableInlineCommentsComma
1923
/// </summary>
2024
public const int CommandId = PkgCmdIDList.EnableInlineCommentsId;
2125

22-
public EnableInlineCommentsCommand() : base(CommandSet, CommandId)
26+
const string optionName = "TextViewHost/GlyphMargin";
27+
28+
readonly Lazy<IVsTextManager> textManager;
29+
readonly Lazy<IVsEditorAdaptersFactoryService> editorAdapter;
30+
31+
[ImportingConstructor]
32+
public EnableInlineCommentsCommand(
33+
IGitHubServiceProvider serviceProvider,
34+
Lazy<IVsEditorAdaptersFactoryService> editorAdapter) : base(CommandSet, CommandId)
2335
{
36+
textManager = new Lazy<IVsTextManager>(() => serviceProvider.GetService<SVsTextManager, IVsTextManager>());
37+
this.editorAdapter = editorAdapter;
2438
}
2539

2640
public override Task Execute()
2741
{
28-
System.Diagnostics.Trace.WriteLine("EnableInlineComments");
42+
IVsTextView activeView = null;
43+
if (textManager.Value.GetActiveView(1, null, out activeView) == VSConstants.S_OK)
44+
{
45+
var wpfTextView = editorAdapter.Value.GetWpfTextView(activeView);
46+
var options = wpfTextView.Options;
47+
var enabled = options.GetOptionValue<bool>(optionName);
48+
options.SetOptionValue(optionName, !enabled);
49+
}
50+
2951
return Task.CompletedTask;
3052
}
3153
}

0 commit comments

Comments
 (0)