Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Change from using IVSGitExt to ITeamExplorerContext
TeamExplorerContext uses IVSGitExt and ITeamExplorerServiceHolder to expose all status change events.
  • Loading branch information
jcansdale committed Jan 5, 2018
commit c4b80e55856b8e8db583791a87606c4f20d2572d
1 change: 1 addition & 0 deletions src/GitHub.App/GitHub.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
<Compile Include="Models\PullRequestReviewCommentModel.cs" />
<Compile Include="Models\PullRequestDetailArgument.cs" />
<Compile Include="Services\GlobalConnection.cs" />
<Compile Include="Services\TeamExplorerContext.cs" />
<Compile Include="ViewModels\Dialog\GistCreationViewModel.cs" />
<Compile Include="ViewModels\Dialog\GitHubDialogWindowViewModel.cs" />
<Compile Include="ViewModels\Dialog\LoginCredentialsViewModel.cs" />
Expand Down
42 changes: 42 additions & 0 deletions src/GitHub.App/Services/TeamExplorerContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Linq;
using System.ComponentModel;
using System.ComponentModel.Composition;
using GitHub.Models;

namespace GitHub.Services
{
[Export(typeof(ITeamExplorerContext))]
[PartCreationPolicy(CreationPolicy.Shared)]
public class TeamExplorerContext : ITeamExplorerContext
{
readonly IVSGitExt vsGitExt;
readonly ITeamExplorerServiceHolder teamExplorerServiceHolder;

[ImportingConstructor]
public TeamExplorerContext(IVSGitExt vsGitExt, ITeamExplorerServiceHolder teamExplorerServiceHolder)
{
this.vsGitExt = vsGitExt;
this.teamExplorerServiceHolder = teamExplorerServiceHolder;

vsGitExt.ActiveRepositoriesChanged += () =>
{
StatusChanged?.Invoke(this, EventArgs.Empty);
};
}

public ILocalRepositoryModel GetActiveRepository()
{
var activeRepository = vsGitExt.ActiveRepositories.FirstOrDefault();
if (activeRepository == null)
{
// HACK: TeamExplorerServiceHolder does some magic to ensure that ActiveRepositories is aviablable.
activeRepository = teamExplorerServiceHolder.ActiveRepo;
}

return activeRepository;
}

public event EventHandler StatusChanged;
}
}
1 change: 1 addition & 0 deletions src/GitHub.Exports/GitHub.Exports.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
<Compile Include="Services\IEnterpriseProbeTask.cs" />
<Compile Include="Services\IGlobalConnection.cs" />
<Compile Include="Services\ILocalRepositories.cs" />
<Compile Include="Services\ITeamExplorerContext.cs" />
<Compile Include="Services\IVisualStudioBrowser.cs" />
<Compile Include="Models\UsageData.cs" />
<Compile Include="Services\IUsageService.cs" />
Expand Down
11 changes: 11 additions & 0 deletions src/GitHub.Exports/Services/ITeamExplorerContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using GitHub.Models;

namespace GitHub.Services
{
public interface ITeamExplorerContext
{
ILocalRepositoryModel GetActiveRepository();
event EventHandler StatusChanged;
}
}
17 changes: 7 additions & 10 deletions src/GitHub.InlineReviews/Services/PullRequestSessionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,24 @@ public PullRequestSessionManager(
IPullRequestSessionService sessionService,
IConnectionManager connectionManager,
IModelServiceFactory modelServiceFactory,
IVSGitExt vsGitExt)
ITeamExplorerContext teamExplorerContext)
{
Guard.ArgumentNotNull(service, nameof(service));
Guard.ArgumentNotNull(sessionService, nameof(sessionService));
Guard.ArgumentNotNull(connectionManager, nameof(connectionManager));
Guard.ArgumentNotNull(modelServiceFactory, nameof(modelServiceFactory));
Guard.ArgumentNotNull(vsGitExt, nameof(vsGitExt));
Guard.ArgumentNotNull(teamExplorerContext, nameof(teamExplorerContext));

this.service = service;
this.sessionService = sessionService;
this.connectionManager = connectionManager;
this.modelServiceFactory = modelServiceFactory;

RepoChanged(vsGitExt);
vsGitExt.ActiveRepositoriesChanged += () => RepoChanged(vsGitExt);
RepoChanged(teamExplorerContext.GetActiveRepository()).Forget();
teamExplorerContext.StatusChanged += (s, e) =>
{
RepoChanged(teamExplorerContext.GetActiveRepository()).Forget();
};
}

/// <inheritdoc/>
Expand Down Expand Up @@ -180,12 +183,6 @@ public PullRequestTextBufferInfo GetTextBufferInfo(ITextBuffer buffer)
return null;
}

void RepoChanged(IVSGitExt vsGitExt)
{
var repo = vsGitExt.ActiveRepositories.FirstOrDefault();
RepoChanged(repo).Forget();
}

async Task RepoChanged(ILocalRepositoryModel localRepositoryModel)
{
try
Expand Down
Loading