@@ -10,14 +10,15 @@ import { Event } from 'vs/base/common/event';
1010import { VIEW_PANE_ID , ISCMService , ISCMRepository , ISCMViewService } from 'vs/workbench/contrib/scm/common/scm' ;
1111import { IActivityService , NumberBadge } from 'vs/workbench/services/activity/common/activity' ;
1212import { IWorkbenchContribution } from 'vs/workbench/common/contributions' ;
13- import { IContextKey , IContextKeyService } from 'vs/platform/contextkey/common/contextkey' ;
13+ import { IContextKey , IContextKeyService , RawContextKey } from 'vs/platform/contextkey/common/contextkey' ;
1414import { IStatusbarEntry , IStatusbarService , StatusbarAlignment as MainThreadStatusBarAlignment } from 'vs/workbench/services/statusbar/browser/statusbar' ;
1515import { IEditorService } from 'vs/workbench/services/editor/common/editorService' ;
1616import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
1717import { EditorResourceAccessor } from 'vs/workbench/common/editor' ;
1818import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity' ;
1919import { Schemas } from 'vs/base/common/network' ;
2020import { Iterable } from 'vs/base/common/iterator' ;
21+ import { ITitleService } from 'vs/workbench/services/title/browser/titleService' ;
2122
2223function getCount ( repository : ISCMRepository ) : number {
2324 if ( typeof repository . provider . count === 'number' ) {
@@ -27,10 +28,18 @@ function getCount(repository: ISCMRepository): number {
2728 }
2829}
2930
31+ const ContextKeys = {
32+ ActiveRepositoryName : new RawContextKey < string > ( 'scmActiveRepositoryName' , '' ) ,
33+ ActiveRepositoryBranchName : new RawContextKey < string > ( 'scmActiveRepositoryBranchName' , '' ) ,
34+ } ;
35+
3036export class SCMStatusController implements IWorkbenchContribution {
3137
38+ private activeRepositoryNameContextKey : IContextKey < string > ;
39+ private activeRepositoryBranchNameContextKey : IContextKey < string > ;
40+
3241 private statusBarDisposable : IDisposable = Disposable . None ;
33- private focusDisposable : IDisposable = Disposable . None ;
42+ private focusDisposables = new DisposableStore ( ) ;
3443 private focusedRepository : ISCMRepository | undefined = undefined ;
3544 private readonly badgeDisposable = new MutableDisposable < IDisposable > ( ) ;
3645 private readonly disposables = new DisposableStore ( ) ;
@@ -43,7 +52,9 @@ export class SCMStatusController implements IWorkbenchContribution {
4352 @IActivityService private readonly activityService : IActivityService ,
4453 @IEditorService private readonly editorService : IEditorService ,
4554 @IConfigurationService private readonly configurationService : IConfigurationService ,
46- @IUriIdentityService private readonly uriIdentityService : IUriIdentityService
55+ @IUriIdentityService private readonly uriIdentityService : IUriIdentityService ,
56+ @IContextKeyService contextKeyService : IContextKeyService ,
57+ @ITitleService titleService : ITitleService
4758 ) {
4859 this . scmService . onDidAddRepository ( this . onDidAddRepository , this , this . disposables ) ;
4960 this . scmService . onDidRemoveRepository ( this . onDidRemoveRepository , this , this . disposables ) ;
@@ -55,6 +66,14 @@ export class SCMStatusController implements IWorkbenchContribution {
5566 this . onDidAddRepository ( repository ) ;
5667 }
5768
69+ this . activeRepositoryNameContextKey = ContextKeys . ActiveRepositoryName . bindTo ( contextKeyService ) ;
70+ this . activeRepositoryBranchNameContextKey = ContextKeys . ActiveRepositoryBranchName . bindTo ( contextKeyService ) ;
71+
72+ titleService . registerVariables ( [
73+ { name : 'activeRepositoryName' , contextKey : ContextKeys . ActiveRepositoryName . key } ,
74+ { name : 'activeRepositoryBranchName' , contextKey : ContextKeys . ActiveRepositoryBranchName . key , }
75+ ] ) ;
76+
5877 this . scmViewService . onDidFocusRepository ( this . focusRepository , this , this . disposables ) ;
5978 this . focusRepository ( this . scmViewService . focusedRepository ) ;
6079
@@ -125,17 +144,33 @@ export class SCMStatusController implements IWorkbenchContribution {
125144 return ;
126145 }
127146
128- this . focusDisposable . dispose ( ) ;
147+ this . focusDisposables . clear ( ) ;
129148 this . focusedRepository = repository ;
130149
131- if ( repository && repository . provider . onDidChangeStatusBarCommands ) {
132- this . focusDisposable = repository . provider . onDidChangeStatusBarCommands ( ( ) => this . renderStatusBar ( repository ) ) ;
150+ if ( repository ) {
151+ if ( repository . provider . onDidChangeStatusBarCommands ) {
152+ this . focusDisposables . add ( repository . provider . onDidChangeStatusBarCommands ( ( ) => this . renderStatusBar ( repository ) ) ) ;
153+ }
154+
155+ this . focusDisposables . add ( repository . provider . onDidChangeHistoryProvider ( ( ) => {
156+ if ( repository . provider . historyProvider ) {
157+ this . focusDisposables . add ( repository . provider . historyProvider . onDidChangeCurrentHistoryItemGroup ( ( ) => this . updateContextKeys ( repository ) ) ) ;
158+ }
159+
160+ this . updateContextKeys ( repository ) ;
161+ } ) ) ;
133162 }
134163
164+ this . updateContextKeys ( repository ) ;
135165 this . renderStatusBar ( repository ) ;
136166 this . renderActivityCount ( ) ;
137167 }
138168
169+ private updateContextKeys ( repository : ISCMRepository | undefined ) : void {
170+ this . activeRepositoryNameContextKey . set ( repository ?. provider . name ?? '' ) ;
171+ this . activeRepositoryBranchNameContextKey . set ( repository ?. provider . historyProvider ?. currentHistoryItemGroup ?. label ?? '' ) ;
172+ }
173+
139174 private renderStatusBar ( repository : ISCMRepository | undefined ) : void {
140175 this . statusBarDisposable . dispose ( ) ;
141176
@@ -204,7 +239,7 @@ export class SCMStatusController implements IWorkbenchContribution {
204239 }
205240
206241 dispose ( ) : void {
207- this . focusDisposable . dispose ( ) ;
242+ this . focusDisposables . dispose ( ) ;
208243 this . statusBarDisposable . dispose ( ) ;
209244 this . badgeDisposable . dispose ( ) ;
210245 this . disposables . dispose ( ) ;
0 commit comments