@@ -1779,6 +1779,7 @@ const enum SCMInputCommandId {
1779
1779
}
1780
1780
1781
1781
const SCMInputContextKeys = {
1782
+ ActionCount : new RawContextKey < number > ( 'scmInputActionCount' , 0 ) ,
1782
1783
ActionIsEnabled : new RawContextKey < boolean > ( 'scmInputActionIsEnabled' , false ) ,
1783
1784
ActionIsRunning : new RawContextKey < boolean > ( 'scmInputActionIsRunning' , false ) ,
1784
1785
} ;
@@ -1846,6 +1847,8 @@ class SCMInputWidgetToolbar extends WorkbenchToolBar {
1846
1847
private _dropdownActions : IAction [ ] = [ ] ;
1847
1848
get dropdownActions ( ) : IAction [ ] { return this . _dropdownActions ; }
1848
1849
1850
+ private readonly _ctxActionCount : IContextKey < number > ;
1851
+
1849
1852
constructor (
1850
1853
container : HTMLElement ,
1851
1854
menuId : MenuId ,
@@ -1868,6 +1871,8 @@ class SCMInputWidgetToolbar extends WorkbenchToolBar {
1868
1871
icon : Codicon . debugStop ,
1869
1872
} , undefined , undefined , undefined , contextKeyService , commandService ) ;
1870
1873
1874
+ this . _ctxActionCount = SCMInputContextKeys . ActionCount . bindTo ( contextKeyService ) ;
1875
+
1871
1876
const updateToolbar = ( ) => {
1872
1877
const actions : IAction [ ] = [ ] ;
1873
1878
createAndFillInActionBarActions ( menu , options ?. menuOptions , actions ) ;
@@ -1883,6 +1888,7 @@ class SCMInputWidgetToolbar extends WorkbenchToolBar {
1883
1888
primaryAction = actions . find ( a => a . id === lastActionId ) ?? actions [ 0 ] ;
1884
1889
}
1885
1890
1891
+ this . _ctxActionCount . set ( actions . length ) ;
1886
1892
this . _dropdownActions = actions . length === 1 ? [ ] : actions ;
1887
1893
1888
1894
container . classList . toggle ( 'has-no-actions' , actions . length === 0 ) ;
@@ -1917,6 +1923,7 @@ class SCMInputWidget {
1917
1923
private placeholderTextContainer : HTMLElement ;
1918
1924
private inputEditor : CodeEditorWidget ;
1919
1925
private toolbarContainer : HTMLElement ;
1926
+ private toolbarContextKeyService : IContextKeyService ;
1920
1927
private actionBar : ActionBar ;
1921
1928
private readonly disposables = new DisposableStore ( ) ;
1922
1929
@@ -2074,9 +2081,9 @@ class SCMInputWidget {
2074
2081
const onDidChangeActionButton = ( ) => {
2075
2082
this . actionBar . clear ( ) ;
2076
2083
2077
- const defaultProvider = this . scmService . getDefaultInputValueProvider ( input . repository ) ;
2084
+ const actionCount = this . toolbarContextKeyService . getContextKeyValue < number > ( SCMInputContextKeys . ActionCount . key ) ?? 0 ;
2078
2085
2079
- if ( input . actionButton && defaultProvider === undefined ) {
2086
+ if ( input . actionButton && actionCount === 0 ) {
2080
2087
const action = new Action (
2081
2088
input . actionButton . command . id ,
2082
2089
input . actionButton . command . title ,
@@ -2093,6 +2100,9 @@ class SCMInputWidget {
2093
2100
this . layout ( ) ;
2094
2101
} ;
2095
2102
2103
+ const ctxKeys = new Set < string > ( [ SCMInputContextKeys . ActionCount . key ] ) ;
2104
+ this . repositoryDisposables . add ( Event . filter ( this . toolbarContextKeyService . onDidChangeContext , e => e . affectsSome ( ctxKeys ) ) ( onDidChangeActionButton , this ) ) ;
2105
+
2096
2106
this . repositoryDisposables . add ( input . onDidChangeActionButton ( onDidChangeActionButton , this ) ) ;
2097
2107
this . repositoryDisposables . add ( this . scmService . onDidChangeInputValueProviders ( onDidChangeActionButton , this ) ) ;
2098
2108
this . repositoryDisposables . add ( Event . filter ( this . configurationService . onDidChangeConfiguration , e => e . affectsConfiguration ( 'scm.showInputActionButton' ) ) ( onDidChangeActionButton , this ) ) ;
@@ -2113,12 +2123,10 @@ class SCMInputWidget {
2113
2123
}
2114
2124
2115
2125
private createToolbar ( input : ISCMInput ) : void {
2116
- const contextKeyService2 = this . contextKeyService . createScoped ( this . toolbarContainer ) ;
2117
-
2118
- const services = new ServiceCollection ( [ IContextKeyService , contextKeyService2 ] ) ;
2126
+ const services = new ServiceCollection ( [ IContextKeyService , this . toolbarContextKeyService ] ) ;
2119
2127
const instantiationService2 = this . instantiationService . createChild ( services ) ;
2120
2128
2121
- const ctxIsActionEnabled = SCMInputContextKeys . ActionIsEnabled . bindTo ( contextKeyService2 ) ;
2129
+ const ctxIsActionEnabled = SCMInputContextKeys . ActionIsEnabled . bindTo ( this . toolbarContextKeyService ) ;
2122
2130
this . repositoryDisposables . add ( input . repository . provider . onDidChangeResources ( ( ) => ctxIsActionEnabled . set ( input . repository . provider . groups . some ( r => r . resources . length > 0 ) ) ) ) ;
2123
2131
2124
2132
const actionRunner = instantiationService2 . createInstance ( SCMInputWidgetActionRunner , input ) ;
@@ -2128,7 +2136,7 @@ class SCMInputWidget {
2128
2136
actionRunner,
2129
2137
actionViewItemProvider : action => {
2130
2138
if ( action instanceof MenuItemAction && toolbar . dropdownActions . length > 1 ) {
2131
- const scmInputActionIsEnabled = contextKeyService2 . getContextKeyValue < boolean > ( 'scmInputActionIsEnabled' ) === true ;
2139
+ const scmInputActionIsEnabled = this . toolbarContextKeyService . getContextKeyValue < boolean > ( 'scmInputActionIsEnabled' ) === true ;
2132
2140
const dropdownAction = new Action ( 'scmInputMoreActions' , localize ( 'scmInputMoreActions' , 'More Actions...' ) , 'codicon-chevron-down' , scmInputActionIsEnabled ) ;
2133
2141
2134
2142
return instantiationService2 . createInstance ( DropdownWithPrimaryActionViewItem , action , dropdownAction , toolbar . dropdownActions , '' , this . contextMenuService , { actionRunner } ) ;
@@ -2188,6 +2196,8 @@ class SCMInputWidget {
2188
2196
2189
2197
this . setPlaceholderFontStyles ( fontFamily , fontSize , lineHeight ) ;
2190
2198
2199
+ this . toolbarContextKeyService = this . contextKeyService . createScoped ( this . toolbarContainer ) ;
2200
+
2191
2201
const contextKeyService2 = contextKeyService . createScoped ( this . element ) ;
2192
2202
this . repositoryIdContextKey = contextKeyService2 . createKey ( 'scmRepository' , undefined ) ;
2193
2203
0 commit comments