Skip to content

Commit b529eb9

Browse files
Merge branch 'main' into do-198248
2 parents 5b90766 + b3b84b5 commit b529eb9

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/vs/workbench/contrib/scm/browser/scmViewPane.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,6 +1779,7 @@ const enum SCMInputCommandId {
17791779
}
17801780

17811781
const SCMInputContextKeys = {
1782+
ActionCount: new RawContextKey<number>('scmInputActionCount', 0),
17821783
ActionIsEnabled: new RawContextKey<boolean>('scmInputActionIsEnabled', false),
17831784
ActionIsRunning: new RawContextKey<boolean>('scmInputActionIsRunning', false),
17841785
};
@@ -1846,6 +1847,8 @@ class SCMInputWidgetToolbar extends WorkbenchToolBar {
18461847
private _dropdownActions: IAction[] = [];
18471848
get dropdownActions(): IAction[] { return this._dropdownActions; }
18481849

1850+
private readonly _ctxActionCount: IContextKey<number>;
1851+
18491852
constructor(
18501853
container: HTMLElement,
18511854
menuId: MenuId,
@@ -1868,6 +1871,8 @@ class SCMInputWidgetToolbar extends WorkbenchToolBar {
18681871
icon: Codicon.debugStop,
18691872
}, undefined, undefined, undefined, contextKeyService, commandService);
18701873

1874+
this._ctxActionCount = SCMInputContextKeys.ActionCount.bindTo(contextKeyService);
1875+
18711876
const updateToolbar = () => {
18721877
const actions: IAction[] = [];
18731878
createAndFillInActionBarActions(menu, options?.menuOptions, actions);
@@ -1883,6 +1888,7 @@ class SCMInputWidgetToolbar extends WorkbenchToolBar {
18831888
primaryAction = actions.find(a => a.id === lastActionId) ?? actions[0];
18841889
}
18851890

1891+
this._ctxActionCount.set(actions.length);
18861892
this._dropdownActions = actions.length === 1 ? [] : actions;
18871893

18881894
container.classList.toggle('has-no-actions', actions.length === 0);
@@ -1917,6 +1923,7 @@ class SCMInputWidget {
19171923
private placeholderTextContainer: HTMLElement;
19181924
private inputEditor: CodeEditorWidget;
19191925
private toolbarContainer: HTMLElement;
1926+
private toolbarContextKeyService: IContextKeyService;
19201927
private actionBar: ActionBar;
19211928
private readonly disposables = new DisposableStore();
19221929

@@ -2074,9 +2081,9 @@ class SCMInputWidget {
20742081
const onDidChangeActionButton = () => {
20752082
this.actionBar.clear();
20762083

2077-
const defaultProvider = this.scmService.getDefaultInputValueProvider(input.repository);
2084+
const actionCount = this.toolbarContextKeyService.getContextKeyValue<number>(SCMInputContextKeys.ActionCount.key) ?? 0;
20782085

2079-
if (input.actionButton && defaultProvider === undefined) {
2086+
if (input.actionButton && actionCount === 0) {
20802087
const action = new Action(
20812088
input.actionButton.command.id,
20822089
input.actionButton.command.title,
@@ -2093,6 +2100,9 @@ class SCMInputWidget {
20932100
this.layout();
20942101
};
20952102

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+
20962106
this.repositoryDisposables.add(input.onDidChangeActionButton(onDidChangeActionButton, this));
20972107
this.repositoryDisposables.add(this.scmService.onDidChangeInputValueProviders(onDidChangeActionButton, this));
20982108
this.repositoryDisposables.add(Event.filter(this.configurationService.onDidChangeConfiguration, e => e.affectsConfiguration('scm.showInputActionButton'))(onDidChangeActionButton, this));
@@ -2113,12 +2123,10 @@ class SCMInputWidget {
21132123
}
21142124

21152125
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]);
21192127
const instantiationService2 = this.instantiationService.createChild(services);
21202128

2121-
const ctxIsActionEnabled = SCMInputContextKeys.ActionIsEnabled.bindTo(contextKeyService2);
2129+
const ctxIsActionEnabled = SCMInputContextKeys.ActionIsEnabled.bindTo(this.toolbarContextKeyService);
21222130
this.repositoryDisposables.add(input.repository.provider.onDidChangeResources(() => ctxIsActionEnabled.set(input.repository.provider.groups.some(r => r.resources.length > 0))));
21232131

21242132
const actionRunner = instantiationService2.createInstance(SCMInputWidgetActionRunner, input);
@@ -2128,7 +2136,7 @@ class SCMInputWidget {
21282136
actionRunner,
21292137
actionViewItemProvider: action => {
21302138
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;
21322140
const dropdownAction = new Action('scmInputMoreActions', localize('scmInputMoreActions', 'More Actions...'), 'codicon-chevron-down', scmInputActionIsEnabled);
21332141

21342142
return instantiationService2.createInstance(DropdownWithPrimaryActionViewItem, action, dropdownAction, toolbar.dropdownActions, '', this.contextMenuService, { actionRunner });
@@ -2188,6 +2196,8 @@ class SCMInputWidget {
21882196

21892197
this.setPlaceholderFontStyles(fontFamily, fontSize, lineHeight);
21902198

2199+
this.toolbarContextKeyService = this.contextKeyService.createScoped(this.toolbarContainer);
2200+
21912201
const contextKeyService2 = contextKeyService.createScoped(this.element);
21922202
this.repositoryIdContextKey = contextKeyService2.createKey('scmRepository', undefined);
21932203

0 commit comments

Comments
 (0)