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 all commits
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
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
35 changes: 35 additions & 0 deletions src/GitHub.App/Services/TeamExplorerContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.ComponentModel;
using System.ComponentModel.Composition;
using GitHub.Models;

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

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

teamExplorerServiceHolder.Subscribe(this, repo =>
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ActiveRepository)));
});

teamExplorerServiceHolder.StatusChanged += (s, e) =>
{
StatusChanged?.Invoke(this, e);
};
}

public ILocalRepositoryModel ActiveRepository => teamExplorerServiceHolder.ActiveRepo;

public event EventHandler StatusChanged;
public event PropertyChangedEventHandler PropertyChanged;
}
}
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
12 changes: 12 additions & 0 deletions src/GitHub.Exports/Services/ITeamExplorerContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.ComponentModel;
using GitHub.Models;

namespace GitHub.Services
{
public interface ITeamExplorerContext : INotifyPropertyChanged
{
ILocalRepositoryModel ActiveRepository { get; }
event EventHandler StatusChanged;
}
}
5 changes: 5 additions & 0 deletions src/GitHub.Exports/Services/ITeamExplorerServiceHolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public interface ITeamExplorerServiceHolder
/// Refresh the information on the active repo (in case of remote url changes or other such things)
/// </summary>
void Refresh();

/// <summary>
/// Fired when the repo or its status changes.
/// </summary>
event EventHandler StatusChanged;
}

public interface IGitAwareItem
Expand Down
11 changes: 8 additions & 3 deletions src/GitHub.InlineReviews/Services/PullRequestSessionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,24 @@ public PullRequestSessionManager(
IPullRequestSessionService sessionService,
IConnectionManager connectionManager,
IModelServiceFactory modelServiceFactory,
ITeamExplorerServiceHolder teamExplorerService)
ITeamExplorerContext teamExplorerContext)
{
Guard.ArgumentNotNull(service, nameof(service));
Guard.ArgumentNotNull(sessionService, nameof(sessionService));
Guard.ArgumentNotNull(connectionManager, nameof(connectionManager));
Guard.ArgumentNotNull(modelServiceFactory, nameof(modelServiceFactory));
Guard.ArgumentNotNull(teamExplorerService, nameof(teamExplorerService));
Guard.ArgumentNotNull(teamExplorerContext, nameof(teamExplorerContext));

this.service = service;
this.sessionService = sessionService;
this.connectionManager = connectionManager;
this.modelServiceFactory = modelServiceFactory;
teamExplorerService.Subscribe(this, x => RepoChanged(x).Forget());

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

/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,14 @@ async void UIContextChanged(bool active, bool refresh)
void UpdateActiveRepo()
{
var repo = gitService.ActiveRepositories.FirstOrDefault();

if (!Equals(repo, ActiveRepo))
{
// so annoying that this is on the wrong thread
syncContext.Post(r => ActiveRepo = r as ILocalRepositoryModel, repo);
}

StatusChanged?.Invoke(this, EventArgs.Empty);
}

void ActiveRepoPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
Expand Down Expand Up @@ -269,6 +274,8 @@ IVSUIContextFactory UIContextFactory
return uiContextFactory;
}
}

public event EventHandler StatusChanged;
}

[Export(typeof(IVSUIContextFactory))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@
</Compile>
<Compile Include="Services\DiffServiceTests.cs" />
<Compile Include="Services\PullRequestSessionTests.cs" />
<Compile Include="TestDoubles\FakeTeamExplorerServiceHolder.cs" />
<Compile Include="ViewModels\InlineCommentPeekViewModelTests.cs" />
<Compile Include="ViewModels\InlineCommentThreadViewModelTests.cs" />
<Compile Include="ViewModels\NewInlineCommentThreadViewModelTests.cs" />
Expand Down
Loading