This repository was archived by the owner on Jun 21, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +40
-0
lines changed
Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,9 @@ public static class Guids
2121 public const string GitSccProviderId = "11B8E6D7-C08B-4385-B321-321078CDD1F8" ;
2222 public const string TeamExplorerInstall3rdPartyGitTools = "DF785C7C-8454-4836-9686-D1C4A01D0BB9" ;
2323
24+ // UIContexts
25+ public const string UIContext_Git = "565515AD-F4C1-4D59-BC14-AE77396DDDD7" ;
26+
2427 // Guids defined in GitHub.VisualStudio.vsct
2528 public const string guidGitHubPkgString = "c3d3dc68-c977-411f-b3e8-03b0dccf7dfc" ;
2629 public const string guidAssemblyResolverPkgString = "a6424dba-34cb-360d-a4de-1b0b0411e57d" ;
Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Threading ;
3+ using System . Runtime . InteropServices ;
4+ using Microsoft . VisualStudio . Shell ;
5+ using GitHub . Services ;
6+ using Task = System . Threading . Tasks . Task ;
7+
8+ namespace GitHub . VisualStudio
9+ {
10+ /// <summary>
11+ /// This package creates a custom UIContext <see cref="Guids.UIContext_Git"/> that is activated when a
12+ /// repository is active in <see cref="IVSGitExt"/>.
13+ /// </summary>
14+ [ PackageRegistration ( UseManagedResourcesOnly = true , AllowsBackgroundLoading = true ) ]
15+ [ Guid ( Guids . UIContext_Git ) ]
16+ // this is the Git service GUID, so we load whenever it loads
17+ [ ProvideAutoLoad ( Guids . GitSccProviderId , PackageAutoLoadFlags . BackgroundLoad ) ]
18+ public class GitContextPackage : AsyncPackage
19+ {
20+ protected async override Task InitializeAsync ( CancellationToken cancellationToken , IProgress < ServiceProgressData > progress )
21+ {
22+ var gitExt = ( IVSGitExt ) await GetServiceAsync ( typeof ( IVSGitExt ) ) ;
23+ var context = UIContext . FromUIContextGuid ( new Guid ( Guids . UIContext_Git ) ) ;
24+ RefreshContext ( context , gitExt ) ;
25+ gitExt . ActiveRepositoriesChanged += ( ) =>
26+ {
27+ RefreshContext ( context , gitExt ) ;
28+ } ;
29+ }
30+
31+ static void RefreshContext ( UIContext context , IVSGitExt gitExt )
32+ {
33+ context . IsActive = gitExt . ActiveRepositories . Count > 0 ;
34+ }
35+ }
36+ }
Original file line number Diff line number Diff line change 306306 <Link >Properties\SolutionInfo.cs</Link >
307307 </Compile >
308308 <Compile Include =" AssemblyResolverPackage.cs" />
309+ <Compile Include =" GitContextPackage.cs" />
309310 <Compile Include =" IServiceProviderPackage.cs" />
310311 <Compile Include =" Menus\BlameLink.cs" />
311312 <Compile Include =" Menus\MenuBase.cs" />
You can’t perform that action at this time.
0 commit comments