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

Commit 3d7d1c5

Browse files
committed
Store keys in InlineCommentTextViewOptions
Use InlineCommentTextViewOptions for typed editor option keys.
1 parent 41ba0bf commit 3d7d1c5

11 files changed

+31
-47
lines changed

src/GitHub.InlineReviews/Commands/ToggleInlineCommentMarginCommand.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,16 @@ public class ToggleInlineCommentMarginCommand : VsCommand, IToggleInlineCommentM
2727

2828
readonly Lazy<IVsTextManager> textManager;
2929
readonly Lazy<IVsEditorAdaptersFactoryService> editorAdapter;
30-
readonly Lazy<InlineCommentMarginEnabled> inlineCommentMarginEnabled;
3130
readonly Lazy<IUsageTracker> usageTracker;
3231

3332
[ImportingConstructor]
3433
public ToggleInlineCommentMarginCommand(
3534
IGitHubServiceProvider serviceProvider,
3635
Lazy<IVsEditorAdaptersFactoryService> editorAdapter,
37-
Lazy<InlineCommentMarginEnabled> inlineCommentMarginEnabled,
3836
Lazy<IUsageTracker> usageTracker) : base(CommandSet, CommandId)
3937
{
4038
textManager = new Lazy<IVsTextManager>(() => serviceProvider.GetService<SVsTextManager, IVsTextManager>());
4139
this.editorAdapter = editorAdapter;
42-
this.inlineCommentMarginEnabled = inlineCommentMarginEnabled;
4340
this.usageTracker = usageTracker;
4441
}
4542

@@ -52,8 +49,8 @@ public override Task Execute()
5249
{
5350
var wpfTextView = editorAdapter.Value.GetWpfTextView(activeView);
5451
var options = wpfTextView.Options;
55-
var enabled = options.GetOptionValue(inlineCommentMarginEnabled.Value.Key);
56-
options.SetOptionValue(inlineCommentMarginEnabled.Value.Key, !enabled);
52+
var enabled = options.GetOptionValue(InlineCommentTextViewOptions.MarginEnabledId);
53+
options.SetOptionValue(InlineCommentTextViewOptions.MarginEnabledId, !enabled);
5754
}
5855

5956
return Task.CompletedTask;

src/GitHub.InlineReviews/GitHub.InlineReviews.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
<Compile Include="Commands\InlineCommentNavigationCommand.cs" />
7474
<Compile Include="Commands\PreviousInlineCommentCommand.cs" />
7575
<Compile Include="Commands\NextInlineCommentCommand.cs" />
76+
<Compile Include="Margins\InlineCommentTextViewOptions.cs" />
7677
<Compile Include="Margins\PullRequestFileMargin.cs" />
7778
<Compile Include="Margins\PullRequestFileMarginProvider.cs" />
7879
<Compile Include="Glyph\GlyphData.cs" />

src/GitHub.InlineReviews/Margins/InlineCommentMargin.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Threading.Tasks;
55
using GitHub.Models;
66
using GitHub.Services;
7-
using GitHub.Settings;
87
using GitHub.Extensions;
98
using GitHub.InlineReviews.Tags;
109
using GitHub.InlineReviews.Views;
@@ -24,7 +23,6 @@ public sealed class InlineCommentMargin : IWpfTextViewMargin
2423

2524
readonly IWpfTextView textView;
2625
readonly IPullRequestSessionManager sessionManager;
27-
readonly InlineCommentMarginEnabled inlineCommentMarginEnabled;
2826
readonly Grid marginGrid;
2927

3028
GlyphMargin<InlineCommentTag> glyphMargin;
@@ -38,15 +36,13 @@ public InlineCommentMargin(
3836
IInlineCommentPeekService peekService,
3937
IEditorFormatMapService editorFormatMapService,
4038
IViewTagAggregatorFactoryService tagAggregatorFactory,
41-
Lazy<IPullRequestSessionManager> sessionManager,
42-
InlineCommentMarginEnabled inlineCommentMarginEnabled)
39+
Lazy<IPullRequestSessionManager> sessionManager)
4340
{
4441
textView = wpfTextViewHost.TextView;
4542
this.sessionManager = sessionManager.Value;
46-
this.inlineCommentMarginEnabled = inlineCommentMarginEnabled;
4743

4844
// Default to not show comment margin
49-
textView.Options.SetOptionValue(inlineCommentMarginEnabled.Key, false);
45+
textView.Options.SetOptionValue(InlineCommentTextViewOptions.MarginEnabledId, false);
5046

5147
marginGrid = new GlyphMarginGrid { Width = 17.0 };
5248
var glyphFactory = new InlineCommentGlyphFactory(peekService, textView);
@@ -64,7 +60,7 @@ public InlineCommentMargin(
6460
.Subscribe(x => RefreshCurrentSession().Forget());
6561

6662
visibleSubscription = marginGrid.WhenAnyValue(x => x.IsVisible)
67-
.Subscribe(x => textView.Options.SetOptionValue(InlineCommentMarginVisible.OptionName, x));
63+
.Subscribe(x => textView.Options.SetOptionValue(InlineCommentTextViewOptions.MarginVisibleId, x));
6864

6965
textView.Options.OptionChanged += (s, e) => RefreshMarginVisibility();
7066
}
@@ -138,7 +134,7 @@ void RefreshMarginVisibility()
138134

139135
bool IsMarginVisible()
140136
{
141-
var enabled = textView.Options.GetOptionValue(inlineCommentMarginEnabled.Key);
137+
var enabled = textView.Options.GetOptionValue(InlineCommentTextViewOptions.MarginEnabledId);
142138
return hasInfo || (enabled && hasChanges);
143139
}
144140
}
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
using System;
2-
using System.ComponentModel.Composition;
3-
using Microsoft.VisualStudio.Utilities;
1+
using System.ComponentModel.Composition;
42
using Microsoft.VisualStudio.Text.Editor;
53

64
namespace GitHub.InlineReviews.Margins
75
{
8-
[Export(typeof(InlineCommentMarginEnabled))]
9-
[Export(typeof(EditorOptionDefinition)), Name(OptionName)]
6+
[Export(typeof(EditorOptionDefinition))]
107
public class InlineCommentMarginEnabled : ViewOptionDefinition<bool>
118
{
12-
const string OptionName = "TextViewHost/InlineCommentMarginEnabled";
13-
149
public override bool Default => false;
1510

16-
public override EditorOptionKey<bool> Key => new EditorOptionKey<bool>(OptionName);
11+
public override EditorOptionKey<bool> Key => InlineCommentTextViewOptions.MarginEnabledId;
1712
}
1813
}

src/GitHub.InlineReviews/Margins/InlineCommentMarginProvider.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using Microsoft.VisualStudio.Text.Classification;
77
using GitHub.InlineReviews.Services;
88
using GitHub.Services;
9-
using GitHub.Settings;
109

1110
namespace GitHub.InlineReviews.Margins
1211
{
@@ -22,28 +21,24 @@ internal sealed class InlineCommentMarginProvider : IWpfTextViewMarginProvider
2221
readonly IViewTagAggregatorFactoryService tagAggregatorFactory;
2322
readonly IInlineCommentPeekService peekService;
2423
readonly Lazy<IPullRequestSessionManager> sessionManager;
25-
readonly InlineCommentMarginEnabled inlineCommentMarginEnabled;
2624

2725
[ImportingConstructor]
2826
public InlineCommentMarginProvider(
29-
Lazy<IPullRequestSessionManager> sessionManager,
27+
IGitHubServiceProvider serviceProvider,
3028
IEditorFormatMapService editorFormatMapService,
3129
IViewTagAggregatorFactoryService tagAggregatorFactory,
32-
IInlineCommentPeekService peekService,
33-
InlineCommentMarginEnabled inlineCommentMarginEnabled)
30+
IInlineCommentPeekService peekService)
3431
{
3532
this.editorFormatMapService = editorFormatMapService;
3633
this.tagAggregatorFactory = tagAggregatorFactory;
3734
this.peekService = peekService;
38-
this.sessionManager = sessionManager;
39-
this.inlineCommentMarginEnabled = inlineCommentMarginEnabled;
35+
sessionManager = new Lazy<IPullRequestSessionManager>(() => serviceProvider.GetService<IPullRequestSessionManager>());
4036
}
4137

4238
public IWpfTextViewMargin CreateMargin(IWpfTextViewHost wpfTextViewHost, IWpfTextViewMargin parent)
4339
{
4440
return new InlineCommentMargin(
45-
wpfTextViewHost, peekService, editorFormatMapService, tagAggregatorFactory, sessionManager,
46-
inlineCommentMarginEnabled);
41+
wpfTextViewHost, peekService, editorFormatMapService, tagAggregatorFactory, sessionManager);
4742
}
4843
}
4944
}
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
using System;
2-
using System.ComponentModel.Composition;
3-
using Microsoft.VisualStudio.Utilities;
1+
using System.ComponentModel.Composition;
42
using Microsoft.VisualStudio.Text.Editor;
53

64
namespace GitHub.InlineReviews.Margins
75
{
86
[Export(typeof(EditorOptionDefinition))]
9-
[Name(OptionName)]
107
public class InlineCommentMarginVisible : ViewOptionDefinition<bool>
118
{
12-
public const string OptionName = "TextViewHost/InlineCommentMarginVisible";
13-
149
public override bool Default => false;
1510

16-
public override EditorOptionKey<bool> Key => new EditorOptionKey<bool>(OptionName);
11+
public override EditorOptionKey<bool> Key => InlineCommentTextViewOptions.MarginVisibleId;
1712
}
1813
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Microsoft.VisualStudio.Text.Editor;
2+
3+
namespace GitHub.InlineReviews.Margins
4+
{
5+
public static class InlineCommentTextViewOptions
6+
{
7+
public static EditorOptionKey<bool> MarginVisibleId = new EditorOptionKey<bool>("TextViewHost/InlineCommentMarginVisible");
8+
9+
public static EditorOptionKey<bool> MarginEnabledId = new EditorOptionKey<bool>("TextViewHost/InlineCommentMarginEnabled");
10+
}
11+
}

src/GitHub.InlineReviews/Margins/PullRequestFileMargin.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public PullRequestFileMargin(
3838
IToggleInlineCommentMarginCommand toggleInlineCommentMarginCommand,
3939
IGoToSolutionOrPullRequestFileCommand goToSolutionOrPullRequestFileCommand,
4040
IPullRequestSessionManager sessionManager,
41-
InlineCommentMarginEnabled inlineCommentMarginEnabled,
4241
Lazy<IUsageTracker> usageTracker)
4342
{
4443
this.textView = textView;
@@ -54,7 +53,7 @@ public PullRequestFileMargin(
5453

5554
optionChangedSubscription = Observable.FromEventPattern(textView.Options, nameof(textView.Options.OptionChanged)).Subscribe(_ =>
5655
{
57-
viewModel.MarginEnabled = textView.Options.GetOptionValue(inlineCommentMarginEnabled.Key);
56+
viewModel.MarginEnabled = textView.Options.GetOptionValue(InlineCommentTextViewOptions.MarginEnabledId);
5857
});
5958

6059
currentSessionSubscription = sessionManager.WhenAnyValue(x => x.CurrentSession)

src/GitHub.InlineReviews/Margins/PullRequestFileMarginProvider.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ internal sealed class PullRequestFileMarginProvider : IWpfTextViewMarginProvider
2323
readonly IToggleInlineCommentMarginCommand enableInlineCommentsCommand;
2424
readonly IGoToSolutionOrPullRequestFileCommand goToSolutionOrPullRequestFileCommand;
2525
readonly IPackageSettings packageSettings;
26-
readonly InlineCommentMarginEnabled inlineCommentMarginEnabled;
2726
readonly Lazy<IUsageTracker> usageTracker;
2827

2928
[ImportingConstructor]
@@ -32,14 +31,12 @@ public PullRequestFileMarginProvider(
3231
IGoToSolutionOrPullRequestFileCommand goToSolutionOrPullRequestFileCommand,
3332
IPullRequestSessionManager sessionManager,
3433
IPackageSettings packageSettings,
35-
InlineCommentMarginEnabled inlineCommentMarginEnabled,
3634
Lazy<IUsageTracker> usageTracker)
3735
{
3836
this.enableInlineCommentsCommand = enableInlineCommentsCommand;
3937
this.goToSolutionOrPullRequestFileCommand = goToSolutionOrPullRequestFileCommand;
4038
this.sessionManager = sessionManager;
4139
this.packageSettings = packageSettings;
42-
this.inlineCommentMarginEnabled = inlineCommentMarginEnabled;
4340
this.usageTracker = usageTracker;
4441
}
4542

@@ -66,8 +63,7 @@ public IWpfTextViewMargin CreateMargin(IWpfTextViewHost wpfTextViewHost, IWpfTex
6663
}
6764

6865
return new PullRequestFileMargin(
69-
wpfTextViewHost.TextView, enableInlineCommentsCommand, goToSolutionOrPullRequestFileCommand,
70-
sessionManager, inlineCommentMarginEnabled, usageTracker);
66+
wpfTextViewHost.TextView, enableInlineCommentsCommand, goToSolutionOrPullRequestFileCommand, sessionManager, usageTracker);
7167
}
7268

7369
bool IsDiffView(ITextView textView) => textView.Roles.Contains("DIFF");

src/GitHub.InlineReviews/Tags/InlineCommentTagger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ async Task InitializeLiveFile()
175175
Observable.FromEventPattern<EditorOptionChangedEventArgs>(options, nameof(options.OptionChanged))
176176
.Select(_ => Unit.Default)
177177
.StartWith(Unit.Default)
178-
.Select(x => options.GetOptionValue<bool>(InlineCommentMarginVisible.OptionName))
178+
.Select(x => options.GetOptionValue(InlineCommentTextViewOptions.MarginVisibleId))
179179
.DistinctUntilChanged()
180180
.Subscribe(VisibleChanged);
181181
}

0 commit comments

Comments
 (0)