Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions src/GitHub.Exports/Settings/Guids.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public static class Guids
public const string GitSccProviderId = "11B8E6D7-C08B-4385-B321-321078CDD1F8";
public const string TeamExplorerInstall3rdPartyGitTools = "DF785C7C-8454-4836-9686-D1C4A01D0BB9";

// UIContexts
public const string UIContext_Git = "565515AD-F4C1-4D59-BC14-AE77396DDDD7";

// Guids defined in GitHub.VisualStudio.vsct
public const string guidGitHubPkgString = "c3d3dc68-c977-411f-b3e8-03b0dccf7dfc";
public const string guidAssemblyResolverPkgString = "a6424dba-34cb-360d-a4de-1b0b0411e57d";
Expand Down
36 changes: 36 additions & 0 deletions src/GitHub.VisualStudio/GitContextPackage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Threading;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.Shell;
using GitHub.Services;
using Task = System.Threading.Tasks.Task;

namespace GitHub.VisualStudio
{
/// <summary>
/// This package creates a custom UIContext <see cref="Guids.UIContext_Git"/> that is activated when a
/// repository is active in <see cref="IVSGitExt"/>.
/// </summary>
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
[Guid(Guids.UIContext_Git)]
// this is the Git service GUID, so we load whenever it loads
[ProvideAutoLoad(Guids.GitSccProviderId, PackageAutoLoadFlags.BackgroundLoad)]
public class GitContextPackage : AsyncPackage
{
protected async override Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
var gitExt = (IVSGitExt)await GetServiceAsync(typeof(IVSGitExt));
var context = UIContext.FromUIContextGuid(new Guid(Guids.UIContext_Git));
RefreshContext(context, gitExt);
gitExt.ActiveRepositoriesChanged += () =>
{
RefreshContext(context, gitExt);
};
}

static void RefreshContext(UIContext context, IVSGitExt gitExt)
{
context.IsActive = gitExt.ActiveRepositories.Count > 0;
}
}
}
1 change: 1 addition & 0 deletions src/GitHub.VisualStudio/GitHub.VisualStudio.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@
<Link>Properties\SolutionInfo.cs</Link>
</Compile>
<Compile Include="AssemblyResolverPackage.cs" />
<Compile Include="GitContextPackage.cs" />
<Compile Include="IServiceProviderPackage.cs" />
<Compile Include="Menus\BlameLink.cs" />
<Compile Include="Menus\MenuBase.cs" />
Expand Down
4 changes: 2 additions & 2 deletions src/GitHub.VisualStudio/GitHubPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ namespace GitHub.VisualStudio
[InstalledProductRegistration("#110", "#112", System.AssemblyVersionInformation.Version, IconResourceID = 400)]
[Guid(Guids.guidGitHubPkgString)]
[ProvideMenuResource("Menus.ctmenu", 1)]
// this is the Git service GUID, so we load whenever it loads
[ProvideAutoLoad(Guids.GitSccProviderId)]
// Only initialize when we're in the context of a Git repository.
[ProvideAutoLoad(Guids.UIContext_Git, PackageAutoLoadFlags.BackgroundLoad)]
[ProvideToolWindow(typeof(GitHubPane), Orientation = ToolWindowOrientation.Right, Style = VsDockStyle.Tabbed, Window = EnvDTE.Constants.vsWindowKindSolutionExplorer)]
[ProvideOptionPage(typeof(OptionsPage), "GitHub for Visual Studio", "General", 0, 0, supportsAutomation: true)]
public class GitHubPackage : AsyncPackage
Expand Down