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

Commit d8256bd

Browse files
committed
Use InlineCommentMarginEnabled.Key not OptionName
By using Key we can take advantage of the option's type information.
1 parent ebc07b5 commit d8256bd

File tree

6 files changed

+25
-10
lines changed

6 files changed

+25
-10
lines changed

src/GitHub.InlineReviews/Commands/ToggleInlineCommentMarginCommand.cs

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

2828
readonly Lazy<IVsTextManager> textManager;
2929
readonly Lazy<IVsEditorAdaptersFactoryService> editorAdapter;
30+
readonly Lazy<InlineCommentMarginEnabled> inlineCommentMarginEnabled;
3031
readonly Lazy<IUsageTracker> usageTracker;
3132

3233
[ImportingConstructor]
3334
public ToggleInlineCommentMarginCommand(
3435
IGitHubServiceProvider serviceProvider,
3536
Lazy<IVsEditorAdaptersFactoryService> editorAdapter,
37+
Lazy<InlineCommentMarginEnabled> inlineCommentMarginEnabled,
3638
Lazy<IUsageTracker> usageTracker) : base(CommandSet, CommandId)
3739
{
3840
textManager = new Lazy<IVsTextManager>(() => serviceProvider.GetService<SVsTextManager, IVsTextManager>());
3941
this.editorAdapter = editorAdapter;
42+
this.inlineCommentMarginEnabled = inlineCommentMarginEnabled;
4043
this.usageTracker = usageTracker;
4144
}
4245

@@ -49,8 +52,8 @@ public override Task Execute()
4952
{
5053
var wpfTextView = editorAdapter.Value.GetWpfTextView(activeView);
5154
var options = wpfTextView.Options;
52-
var enabled = options.GetOptionValue<bool>(InlineCommentMarginEnabled.OptionName);
53-
options.SetOptionValue(InlineCommentMarginEnabled.OptionName, !enabled);
55+
var enabled = options.GetOptionValue(inlineCommentMarginEnabled.Value.Key);
56+
options.SetOptionValue(inlineCommentMarginEnabled.Value.Key, !enabled);
5457
}
5558

5659
return Task.CompletedTask;

src/GitHub.InlineReviews/Margins/InlineCommentMargin.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public sealed class InlineCommentMargin : IWpfTextViewMargin
2424

2525
readonly IWpfTextView textView;
2626
readonly IPullRequestSessionManager sessionManager;
27+
readonly InlineCommentMarginEnabled inlineCommentMarginEnabled;
2728
readonly Grid marginGrid;
2829

2930
GlyphMargin<InlineCommentTag> glyphMargin;
@@ -37,13 +38,15 @@ public InlineCommentMargin(
3738
IInlineCommentPeekService peekService,
3839
IEditorFormatMapService editorFormatMapService,
3940
IViewTagAggregatorFactoryService tagAggregatorFactory,
40-
Lazy<IPullRequestSessionManager> sessionManager)
41+
Lazy<IPullRequestSessionManager> sessionManager,
42+
InlineCommentMarginEnabled inlineCommentMarginEnabled)
4143
{
4244
textView = wpfTextViewHost.TextView;
4345
this.sessionManager = sessionManager.Value;
46+
this.inlineCommentMarginEnabled = inlineCommentMarginEnabled;
4447

4548
// Default to not show comment margin
46-
textView.Options.SetOptionValue(InlineCommentMarginEnabled.OptionName, false);
49+
textView.Options.SetOptionValue(inlineCommentMarginEnabled.Key, false);
4750

4851
marginGrid = new GlyphMarginGrid { Width = 17.0 };
4952
var glyphFactory = new InlineCommentGlyphFactory(peekService, textView);
@@ -135,7 +138,7 @@ void RefreshMarginVisibility()
135138

136139
bool IsMarginVisible()
137140
{
138-
var enabled = textView.Options.GetOptionValue<bool>(InlineCommentMarginEnabled.OptionName);
141+
var enabled = textView.Options.GetOptionValue(inlineCommentMarginEnabled.Key);
139142
return hasInfo || (enabled && hasChanges);
140143
}
141144
}

src/GitHub.InlineReviews/Margins/InlineCommentMarginEnabled.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace GitHub.InlineReviews.Margins
99
[Name(OptionName)]
1010
public class InlineCommentMarginEnabled : ViewOptionDefinition<bool>
1111
{
12-
public const string OptionName = "TextViewHost/InlineCommentMarginEnabled";
12+
const string OptionName = "TextViewHost/InlineCommentMarginEnabled";
1313

1414
public override bool Default => false;
1515

src/GitHub.InlineReviews/Margins/InlineCommentMarginProvider.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,28 @@ internal sealed class InlineCommentMarginProvider : IWpfTextViewMarginProvider
2222
readonly IViewTagAggregatorFactoryService tagAggregatorFactory;
2323
readonly IInlineCommentPeekService peekService;
2424
readonly Lazy<IPullRequestSessionManager> sessionManager;
25+
readonly InlineCommentMarginEnabled inlineCommentMarginEnabled;
2526

2627
[ImportingConstructor]
2728
public InlineCommentMarginProvider(
2829
IGitHubServiceProvider serviceProvider,
2930
IEditorFormatMapService editorFormatMapService,
3031
IViewTagAggregatorFactoryService tagAggregatorFactory,
31-
IInlineCommentPeekService peekService)
32+
IInlineCommentPeekService peekService,
33+
InlineCommentMarginEnabled inlineCommentMarginEnabled)
3234
{
3335
this.editorFormatMapService = editorFormatMapService;
3436
this.tagAggregatorFactory = tagAggregatorFactory;
3537
this.peekService = peekService;
3638
sessionManager = new Lazy<IPullRequestSessionManager>(() => serviceProvider.GetService<IPullRequestSessionManager>());
39+
this.inlineCommentMarginEnabled = inlineCommentMarginEnabled;
3740
}
3841

3942
public IWpfTextViewMargin CreateMargin(IWpfTextViewHost wpfTextViewHost, IWpfTextViewMargin parent)
4043
{
4144
return new InlineCommentMargin(
42-
wpfTextViewHost, peekService, editorFormatMapService, tagAggregatorFactory, sessionManager);
45+
wpfTextViewHost, peekService, editorFormatMapService, tagAggregatorFactory, sessionManager,
46+
inlineCommentMarginEnabled);
4347
}
4448
}
4549
}

src/GitHub.InlineReviews/Margins/PullRequestFileMargin.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public PullRequestFileMargin(
3838
IToggleInlineCommentMarginCommand toggleInlineCommentMarginCommand,
3939
IGoToSolutionOrPullRequestFileCommand goToSolutionOrPullRequestFileCommand,
4040
IPullRequestSessionManager sessionManager,
41+
InlineCommentMarginEnabled inlineCommentMarginEnabled,
4142
Lazy<IUsageTracker> usageTracker)
4243
{
4344
this.textView = textView;
@@ -53,7 +54,7 @@ public PullRequestFileMargin(
5354

5455
optionChangedSubscription = Observable.FromEventPattern(textView.Options, nameof(textView.Options.OptionChanged)).Subscribe(_ =>
5556
{
56-
viewModel.MarginEnabled = textView.Options.GetOptionValue<bool>(InlineCommentMarginEnabled.OptionName);
57+
viewModel.MarginEnabled = textView.Options.GetOptionValue(inlineCommentMarginEnabled.Key);
5758
});
5859

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

src/GitHub.InlineReviews/Margins/PullRequestFileMarginProvider.cs

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

2829
[ImportingConstructor]
@@ -31,12 +32,14 @@ public PullRequestFileMarginProvider(
3132
IGoToSolutionOrPullRequestFileCommand goToSolutionOrPullRequestFileCommand,
3233
IPullRequestSessionManager sessionManager,
3334
IPackageSettings packageSettings,
35+
InlineCommentMarginEnabled inlineCommentMarginEnabled,
3436
Lazy<IUsageTracker> usageTracker)
3537
{
3638
this.enableInlineCommentsCommand = enableInlineCommentsCommand;
3739
this.goToSolutionOrPullRequestFileCommand = goToSolutionOrPullRequestFileCommand;
3840
this.sessionManager = sessionManager;
3941
this.packageSettings = packageSettings;
42+
this.inlineCommentMarginEnabled = inlineCommentMarginEnabled;
4043
this.usageTracker = usageTracker;
4144
}
4245

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

6568
return new PullRequestFileMargin(
66-
wpfTextViewHost.TextView, enableInlineCommentsCommand, goToSolutionOrPullRequestFileCommand, sessionManager, usageTracker);
69+
wpfTextViewHost.TextView, enableInlineCommentsCommand, goToSolutionOrPullRequestFileCommand,
70+
sessionManager, inlineCommentMarginEnabled, usageTracker);
6771
}
6872

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

0 commit comments

Comments
 (0)