Skip to content

Commit 08a4698

Browse files
authored
SCM - Add capability to disable the SCM action button (microsoft#152849)
Add capability to disable the SCM action button
1 parent 58a042c commit 08a4698

File tree

6 files changed

+54
-35
lines changed

6 files changed

+54
-35
lines changed

extensions/git/src/actionButton.ts

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const localize = nls.loadMessageBundle();
1313

1414
interface ActionButtonState {
1515
readonly HEAD: Branch | undefined;
16-
readonly isSyncRunning: boolean;
16+
readonly isActionRunning: boolean;
1717
readonly repositoryHasNoChanges: boolean;
1818
}
1919

@@ -33,7 +33,7 @@ export class ActionButtonCommand {
3333
private disposables: Disposable[] = [];
3434

3535
constructor(readonly repository: Repository) {
36-
this._state = { HEAD: undefined, isSyncRunning: false, repositoryHasNoChanges: false };
36+
this._state = { HEAD: undefined, isActionRunning: false, repositoryHasNoChanges: false };
3737

3838
repository.onDidRunGitStatus(this.onDidRunGitStatus, this, this.disposables);
3939
repository.onDidChangeOperations(this.onDidChangeOperations, this, this.disposables);
@@ -50,49 +50,63 @@ export class ActionButtonCommand {
5050
let actionButton: SourceControlActionButton | undefined;
5151
if (showActionButton === 'always' || (showActionButton === 'whenEmpty' && this.state.repositoryHasNoChanges && noPostCommitCommand)) {
5252
if (this.state.HEAD.upstream) {
53-
if (this.state.HEAD.ahead) {
54-
const config = workspace.getConfiguration('git', Uri.file(this.repository.root));
55-
const rebaseWhenSync = config.get<string>('rebaseWhenSync');
56-
57-
const ahead = `${this.state.HEAD.ahead}$(arrow-up)`;
58-
const behind = this.state.HEAD.behind ? `${this.state.HEAD.behind}$(arrow-down) ` : '';
59-
const icon = this.state.isSyncRunning ? '$(sync~spin)' : '$(sync)';
60-
61-
actionButton = {
62-
command: {
63-
command: this.state.isSyncRunning ? '' : rebaseWhenSync ? 'git.syncRebase' : 'git.sync',
64-
title: localize('scm button sync title', "{0} {1}{2}", icon, behind, ahead),
65-
tooltip: this.state.isSyncRunning ?
66-
localize('syncing changes', "Synchronizing Changes...")
67-
: this.repository.syncTooltip,
68-
arguments: [this.repository.sourceControl],
69-
},
70-
description: localize('scm button sync description', "{0} Sync Changes {1}{2}", icon, behind, ahead)
71-
};
72-
}
53+
// Sync Changes
54+
actionButton = this.getSyncChangesActionButton();
7355
} else {
74-
actionButton = {
75-
command: {
76-
command: this.state.isSyncRunning ? '' : 'git.publish',
77-
title: localize('scm button publish title', "$(cloud-upload) Publish Branch"),
78-
tooltip: this.state.isSyncRunning ?
79-
localize('scm button publish branch running', "Publishing Branch...") :
80-
localize('scm button publish branch', "Publish Branch"),
81-
arguments: [this.repository.sourceControl],
82-
}
83-
};
56+
// Publish Branch
57+
actionButton = this.getPublishBranchActionButton();
8458
}
8559
}
8660

8761
return actionButton;
8862
}
8963

64+
private getPublishBranchActionButton(): SourceControlActionButton {
65+
return {
66+
command: {
67+
command: 'git.publish',
68+
title: localize('scm button publish title', "$(cloud-upload) Publish Branch"),
69+
tooltip: this.state.isActionRunning ?
70+
localize('scm button publish branch running', "Publishing Branch...") :
71+
localize('scm button publish branch', "Publish Branch"),
72+
arguments: [this.repository.sourceControl],
73+
},
74+
enabled: !this.state.isActionRunning
75+
};
76+
}
77+
78+
private getSyncChangesActionButton(): SourceControlActionButton | undefined {
79+
if (this.state.HEAD?.ahead) {
80+
const config = workspace.getConfiguration('git', Uri.file(this.repository.root));
81+
const rebaseWhenSync = config.get<string>('rebaseWhenSync');
82+
83+
const ahead = `${this.state.HEAD.ahead}$(arrow-up)`;
84+
const behind = this.state.HEAD.behind ? `${this.state.HEAD.behind}$(arrow-down) ` : '';
85+
const icon = this.state.isActionRunning ? '$(sync~spin)' : '$(sync)';
86+
87+
return {
88+
command: {
89+
command: rebaseWhenSync ? 'git.syncRebase' : 'git.sync',
90+
title: localize('scm button sync title', "{0} {1}{2}", icon, behind, ahead),
91+
tooltip: this.state.isActionRunning ?
92+
localize('syncing changes', "Synchronizing Changes...")
93+
: this.repository.syncTooltip,
94+
arguments: [this.repository.sourceControl],
95+
},
96+
description: localize('scm button sync description', "{0} Sync Changes {1}{2}", icon, behind, ahead),
97+
enabled: !this.state.isActionRunning
98+
};
99+
}
100+
101+
return undefined;
102+
}
103+
90104
private onDidChangeOperations(): void {
91-
const isSyncRunning = this.repository.operations.isRunning(Operation.Sync) ||
105+
const isActionRunning = this.repository.operations.isRunning(Operation.Sync) ||
92106
this.repository.operations.isRunning(Operation.Push) ||
93107
this.repository.operations.isRunning(Operation.Pull);
94108

95-
this.state = { ...this.state, isSyncRunning };
109+
this.state = { ...this.state, isActionRunning: isActionRunning };
96110
}
97111

98112
private onDidRunGitStatus(): void {

src/vs/workbench/api/common/extHost.protocol.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,7 @@ export interface SCMProviderFeatures {
11441144
export interface SCMActionButtonDto {
11451145
command: ICommandDto;
11461146
description?: string;
1147+
enabled: boolean;
11471148
}
11481149

11491150
export interface SCMGroupFeatures {

src/vs/workbench/api/common/extHostSCM.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,8 @@ class ExtHostSourceControl implements vscode.SourceControl {
537537
const internal = actionButton !== undefined ?
538538
{
539539
command: this._commands.converter.toInternal(actionButton.command, this._actionButtonDisposables.value),
540-
description: actionButton.description
540+
description: actionButton.description,
541+
enabled: actionButton.enabled
541542
} : undefined;
542543
this.#proxy.$updateSourceControl(this.handle, { actionButton: internal ?? null });
543544
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2600,6 +2600,7 @@ export class SCMActionButton implements IDisposable {
26002600
this.button = new Button(this.container, { supportIcons: true, title: button.command.tooltip });
26012601
}
26022602

2603+
this.button.enabled = button.enabled;
26032604
this.button.label = button.command.title;
26042605
this.button.onDidClick(async () => {
26052606
try {

src/vs/workbench/contrib/scm/common/scm.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export interface ISCMInputChangeEvent {
100100
export interface ISCMActionButtonDescriptor {
101101
command: Command;
102102
description?: string;
103+
enabled: boolean;
103104
}
104105

105106
export interface ISCMActionButton {

src/vscode-dts/vscode.proposed.scmActionButton.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ declare module 'vscode' {
99
export interface SourceControlActionButton {
1010
command: Command;
1111
description?: string;
12+
enabled: boolean;
1213
}
1314

1415
export interface SourceControl {

0 commit comments

Comments
 (0)