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

Commit 7a4599a

Browse files
Merge branch 'master' into sorting-reviews
2 parents 35fdd06 + 01afc6f commit 7a4599a

File tree

6 files changed

+79
-50
lines changed

6 files changed

+79
-50
lines changed
Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
using System;
22
using System.ComponentModel.Composition;
3+
using Microsoft.VisualStudio.Shell;
34
using Microsoft.VisualStudio.Utilities;
45
using Microsoft.VisualStudio.Text.Editor;
56
using Microsoft.VisualStudio.Text.Tagging;
67
using Microsoft.VisualStudio.Text.Classification;
7-
using GitHub.InlineReviews.Services;
88
using GitHub.Services;
9+
using GitHub.VisualStudio;
10+
using GitHub.InlineReviews.Services;
911

1012
namespace GitHub.InlineReviews.Margins
1113
{
@@ -17,28 +19,41 @@ namespace GitHub.InlineReviews.Margins
1719
[TextViewRole(PredefinedTextViewRoles.Interactive)]
1820
internal sealed class InlineCommentMarginProvider : IWpfTextViewMarginProvider
1921
{
20-
readonly IEditorFormatMapService editorFormatMapService;
21-
readonly IViewTagAggregatorFactoryService tagAggregatorFactory;
22-
readonly IInlineCommentPeekService peekService;
22+
readonly Lazy<IEditorFormatMapService> editorFormatMapService;
23+
readonly Lazy<IViewTagAggregatorFactoryService> tagAggregatorFactory;
24+
readonly Lazy<IInlineCommentPeekService> peekService;
2325
readonly Lazy<IPullRequestSessionManager> sessionManager;
26+
readonly UIContext uiContext;
2427

2528
[ImportingConstructor]
2629
public InlineCommentMarginProvider(
27-
IGitHubServiceProvider serviceProvider,
28-
IEditorFormatMapService editorFormatMapService,
29-
IViewTagAggregatorFactoryService tagAggregatorFactory,
30-
IInlineCommentPeekService peekService)
30+
Lazy<IPullRequestSessionManager> sessionManager,
31+
Lazy<IEditorFormatMapService> editorFormatMapService,
32+
Lazy<IViewTagAggregatorFactoryService> tagAggregatorFactory,
33+
Lazy<IInlineCommentPeekService> peekService)
3134
{
35+
this.sessionManager = sessionManager;
3236
this.editorFormatMapService = editorFormatMapService;
3337
this.tagAggregatorFactory = tagAggregatorFactory;
3438
this.peekService = peekService;
35-
sessionManager = new Lazy<IPullRequestSessionManager>(() => serviceProvider.GetService<IPullRequestSessionManager>());
39+
40+
uiContext = UIContext.FromUIContextGuid(new Guid(Guids.UIContext_Git));
3641
}
3742

3843
public IWpfTextViewMargin CreateMargin(IWpfTextViewHost wpfTextViewHost, IWpfTextViewMargin parent)
3944
{
45+
if (!uiContext.IsActive)
46+
{
47+
// Only create margin when in the context of a Git repository
48+
return null;
49+
}
50+
4051
return new InlineCommentMargin(
41-
wpfTextViewHost, peekService, editorFormatMapService, tagAggregatorFactory, sessionManager);
52+
wpfTextViewHost,
53+
peekService.Value,
54+
editorFormatMapService.Value,
55+
tagAggregatorFactory.Value,
56+
sessionManager);
4257
}
4358
}
4459
}

src/GitHub.InlineReviews/Margins/PullRequestFileMarginProvider.cs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using GitHub.Commands;
44
using GitHub.Services;
55
using GitHub.Settings;
6+
using GitHub.VisualStudio;
7+
using Microsoft.VisualStudio.Shell;
68
using Microsoft.VisualStudio.Utilities;
79
using Microsoft.VisualStudio.Text.Editor;
810

@@ -19,25 +21,28 @@ namespace GitHub.InlineReviews.Margins
1921
[TextViewRole(PredefinedTextViewRoles.Editable)]
2022
internal sealed class PullRequestFileMarginProvider : IWpfTextViewMarginProvider
2123
{
22-
readonly IPullRequestSessionManager sessionManager;
23-
readonly IToggleInlineCommentMarginCommand enableInlineCommentsCommand;
24-
readonly IGoToSolutionOrPullRequestFileCommand goToSolutionOrPullRequestFileCommand;
25-
readonly IPackageSettings packageSettings;
24+
readonly Lazy<IPullRequestSessionManager> sessionManager;
25+
readonly Lazy<IToggleInlineCommentMarginCommand> enableInlineCommentsCommand;
26+
readonly Lazy<IGoToSolutionOrPullRequestFileCommand> goToSolutionOrPullRequestFileCommand;
27+
readonly Lazy<IPackageSettings> packageSettings;
2628
readonly Lazy<IUsageTracker> usageTracker;
29+
readonly UIContext uiContext;
2730

2831
[ImportingConstructor]
2932
public PullRequestFileMarginProvider(
30-
IToggleInlineCommentMarginCommand enableInlineCommentsCommand,
31-
IGoToSolutionOrPullRequestFileCommand goToSolutionOrPullRequestFileCommand,
32-
IPullRequestSessionManager sessionManager,
33-
IPackageSettings packageSettings,
33+
Lazy<IToggleInlineCommentMarginCommand> enableInlineCommentsCommand,
34+
Lazy<IGoToSolutionOrPullRequestFileCommand> goToSolutionOrPullRequestFileCommand,
35+
Lazy<IPullRequestSessionManager> sessionManager,
36+
Lazy<IPackageSettings> packageSettings,
3437
Lazy<IUsageTracker> usageTracker)
3538
{
3639
this.enableInlineCommentsCommand = enableInlineCommentsCommand;
3740
this.goToSolutionOrPullRequestFileCommand = goToSolutionOrPullRequestFileCommand;
3841
this.sessionManager = sessionManager;
3942
this.packageSettings = packageSettings;
4043
this.usageTracker = usageTracker;
44+
45+
uiContext = UIContext.FromUIContextGuid(new Guid(Guids.UIContext_Git));
4146
}
4247

4348
/// <summary>
@@ -50,8 +55,14 @@ public PullRequestFileMarginProvider(
5055
/// </returns>
5156
public IWpfTextViewMargin CreateMargin(IWpfTextViewHost wpfTextViewHost, IWpfTextViewMargin marginContainer)
5257
{
58+
if (!uiContext.IsActive)
59+
{
60+
// Only create margin when in the context of a Git repository
61+
return null;
62+
}
63+
5364
// Comments in the editor feature flag
54-
if (!packageSettings.EditorComments)
65+
if (!packageSettings.Value.EditorComments)
5566
{
5667
return null;
5768
}
@@ -63,7 +74,11 @@ public IWpfTextViewMargin CreateMargin(IWpfTextViewHost wpfTextViewHost, IWpfTex
6374
}
6475

6576
return new PullRequestFileMargin(
66-
wpfTextViewHost.TextView, enableInlineCommentsCommand, goToSolutionOrPullRequestFileCommand, sessionManager, usageTracker);
77+
wpfTextViewHost.TextView,
78+
enableInlineCommentsCommand.Value,
79+
goToSolutionOrPullRequestFileCommand.Value,
80+
sessionManager.Value,
81+
usageTracker);
6782
}
6883

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

src/GitHub.TeamFoundation.14/Services/VSGitExt.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using Microsoft.VisualStudio.Threading;
1313
using Microsoft.VisualStudio.TeamFoundation.Git.Extensibility;
1414
using Task = System.Threading.Tasks.Task;
15+
using static Microsoft.VisualStudio.VSConstants;
1516

1617
namespace GitHub.VisualStudio.Base
1718
{
@@ -51,9 +52,8 @@ public VSGitExt(IAsyncServiceProvider asyncServiceProvider, IVSUIContextFactory
5152
// Start with empty array until we have a chance to initialize.
5253
ActiveRepositories = Array.Empty<ILocalRepositoryModel>();
5354

54-
// The IGitExt service isn't available when a TFS based solution is opened directly.
55-
// It will become available when moving to a Git based solution (and cause a UIContext event to fire).
56-
var context = factory.GetUIContext(new Guid(Guids.GitSccProviderId));
55+
// Initialize when we enter the context of a Git repository
56+
var context = factory.GetUIContext(UICONTEXT.RepositoryOpen_guid);
5757
context.WhenActivated(() => JoinableTaskFactory.RunAsync(InitializeAsync).Task.Forget(log));
5858
}
5959

src/GitHub.VisualStudio/GitContextPackage.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,28 @@
22
using System.Threading;
33
using System.Runtime.InteropServices;
44
using GitHub.Exports;
5-
using GitHub.Logging;
65
using GitHub.Services;
76
using Microsoft.VisualStudio.Shell;
8-
using Serilog;
97
using Task = System.Threading.Tasks.Task;
8+
using static Microsoft.VisualStudio.VSConstants;
109

1110
namespace GitHub.VisualStudio
1211
{
1312
/// <summary>
1413
/// This package creates a custom UIContext <see cref="Guids.UIContext_Git"/> that is activated when a
15-
/// repository is active in <see cref="IVSGitExt"/>.
14+
/// repository is active in <see cref="IVSGitExt"/> and the current process is Visual Studio (not Blend).
1615
/// </summary>
1716
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
1817
[Guid(Guids.UIContext_Git)]
19-
// this is the Git service GUID, so we load whenever it loads
20-
[ProvideAutoLoad(Guids.GitSccProviderId, PackageAutoLoadFlags.BackgroundLoad)]
18+
// Initialize when we enter the context of a Git repository
19+
[ProvideAutoLoad(UICONTEXT.RepositoryOpen_string, PackageAutoLoadFlags.BackgroundLoad)]
2120
public class GitContextPackage : AsyncPackage
2221
{
23-
static readonly ILogger log = LogManager.ForContext<GitContextPackage>();
24-
2522
protected async override Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
2623
{
2724
if (!ExportForVisualStudioProcessAttribute.IsVisualStudioProcess())
2825
{
29-
log.Warning("Don't activate 'UIContext_Git' for non-Visual Studio process");
26+
// Don't activate 'UIContext_Git' for non-Visual Studio process
3027
return;
3128
}
3229

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
<Viewbox xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2-
Width="1024" Height="1024">
1+
<Viewbox
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
5+
Width="1024" Height="1024">
6+
7+
<Viewbox.Resources>
8+
<ResourceDictionary>
9+
<Color x:Key="GitHubContextMenuIconColor">#424242</Color>
10+
<SolidColorBrush x:Key="GitHubContextMenuIconBrush" Color="{StaticResource GitHubContextMenuIconColor}" PresentationOptions:Freeze="true" />
11+
</ResourceDictionary>
12+
</Viewbox.Resources>
13+
314
<Border BorderBrush="Transparent" BorderThickness="1">
4-
<ghfvs:OcticonImage xmlns:ghfvs="https://github.com/github/VisualStudio"
5-
Foreground="{DynamicResource GitHubContextMenuIconBrush}"
6-
Icon="mark_github">
7-
<ghfvs:OcticonImage.Resources>
8-
<ResourceDictionary>
9-
<ResourceDictionary.MergedDictionaries>
10-
<ghfvs:SharedDictionaryManager Source="pack://application:,,,/GitHub.VisualStudio.UI;component/SharedDictionary.xaml" />
11-
<ghfvs:SharedDictionaryManager Source="pack://application:,,,/GitHub.UI;component/SharedDictionary.xaml" />
12-
</ResourceDictionary.MergedDictionaries>
13-
</ResourceDictionary>
14-
</ghfvs:OcticonImage.Resources>
15-
</ghfvs:OcticonImage>
15+
<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Width="16" Height="16">
16+
<Path xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Fill="{StaticResource GitHubContextMenuIconBrush}" Data="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"/>
17+
</Canvas>
1618
</Border>
1719
</Viewbox>

test/GitHub.TeamFoundation.UnitTests/VSGitExtTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
using Microsoft.VisualStudio.Shell;
1414
using Microsoft.VisualStudio.Threading;
1515
using Task = System.Threading.Tasks.Task;
16+
using static Microsoft.VisualStudio.VSConstants;
1617

1718
public class VSGitExtTests
1819
{
1920
public class TheConstructor : TestBaseClass
2021
{
2122
[TestCase(true, 1)]
2223
[TestCase(false, 0)]
23-
public void GetServiceIGitExt_WhenSccProviderContextIsActive(bool isActive, int expectCalls)
24+
public void GetServiceIGitExt_WhenRepositoryOpenIsActive(bool isActive, int expectCalls)
2425
{
2526
var context = CreateVSUIContext(isActive);
2627
var sp = Substitute.For<IAsyncServiceProvider>();
@@ -135,7 +136,7 @@ public void WhenUIContextChanged_FiredUsingThreadPoolThread()
135136
public class TheActiveRepositoriesProperty : TestBaseClass
136137
{
137138
[Test]
138-
public void SccProviderContextNotActive_IsEmpty()
139+
public void RepositoryOpenContextNotActive_IsEmpty()
139140
{
140141
var context = CreateVSUIContext(false);
141142
var target = CreateVSGitExt(context);
@@ -144,7 +145,7 @@ public void SccProviderContextNotActive_IsEmpty()
144145
}
145146

146147
[Test]
147-
public void SccProviderContextIsActive_InitializeWithActiveRepositories()
148+
public void RepositoryOpenIsActive_InitializeWithActiveRepositories()
148149
{
149150
var repoPath = "repoPath";
150151
var repoFactory = Substitute.For<ILocalRepositoryModelFactory>();
@@ -217,8 +218,7 @@ static VSGitExt CreateVSGitExt(IVSUIContext context = null, IGitExt gitExt = nul
217218
repoFactory = repoFactory ?? Substitute.For<ILocalRepositoryModelFactory>();
218219
joinableTaskContext = joinableTaskContext ?? new JoinableTaskContext();
219220
var factory = Substitute.For<IVSUIContextFactory>();
220-
var contextGuid = new Guid(Guids.GitSccProviderId);
221-
factory.GetUIContext(contextGuid).Returns(context);
221+
factory.GetUIContext(UICONTEXT.RepositoryOpen_guid).Returns(context);
222222
sp.GetServiceAsync(typeof(IGitExt)).Returns(gitExt);
223223
var vsGitExt = new VSGitExt(sp, factory, repoFactory, joinableTaskContext);
224224
vsGitExt.JoinTillEmpty();

0 commit comments

Comments
 (0)