Skip to content

Commit 0215be1

Browse files
committed
git: status bar commands scope
1 parent 1775a08 commit 0215be1

5 files changed

Lines changed: 22 additions & 12 deletions

File tree

extensions/git/src/repository.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,8 @@ export class Repository implements Disposable {
300300
private _onDidChangeState = new EventEmitter<State>();
301301
readonly onDidChangeState: Event<State> = this._onDidChangeState.event;
302302

303-
@memoize
304-
get onDidChange(): Event<void> {
305-
return anyEvent<any>(this.onDidChangeState);
306-
}
303+
private _onDidChangeStatus = new EventEmitter<void>();
304+
readonly onDidChangeStatus: Event<void> = this._onDidChangeStatus.event;
307305

308306
private _onRunOperation = new EventEmitter<Operation>();
309307
readonly onRunOperation: Event<Operation> = this._onRunOperation.event;
@@ -789,6 +787,7 @@ export class Repository implements Disposable {
789787
}
790788

791789
commands.executeCommand('setContext', 'gitState', stateContextKey);
790+
this._onDidChangeStatus.fire();
792791
}
793792

794793
private onFSChange(uri: Uri): void {

extensions/git/src/statusbar.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class CheckoutStatusBar {
2020
private disposables: Disposable[] = [];
2121

2222
constructor(private repository: Repository) {
23-
repository.onDidChange(this._onDidChange.fire, this._onDidChange, this.disposables);
23+
repository.onDidChangeStatus(this._onDidChange.fire, this._onDidChange, this.disposables);
2424
}
2525

2626
get command(): Command | undefined {
@@ -42,7 +42,8 @@ class CheckoutStatusBar {
4242
return {
4343
command: 'git.checkout',
4444
tooltip: localize('checkout', 'Checkout...'),
45-
title
45+
title,
46+
arguments: [this.repository.sourceControl]
4647
};
4748
}
4849

@@ -77,7 +78,7 @@ class SyncStatusBar {
7778
}
7879

7980
constructor(private repository: Repository) {
80-
repository.onDidChange(this.onModelChange, this, this.disposables);
81+
repository.onDidChangeStatus(this.onModelChange, this, this.disposables);
8182
repository.onDidChangeOperations(this.onOperationsChange, this, this.disposables);
8283
this._onDidChange.fire();
8384
}
@@ -98,6 +99,7 @@ class SyncStatusBar {
9899
}
99100

100101
get command(): Command | undefined {
102+
console.log(this.repository.remotes, this.state.hasRemotes);
101103
if (!this.state.hasRemotes) {
102104
return undefined;
103105
}
@@ -134,7 +136,8 @@ class SyncStatusBar {
134136
return {
135137
command,
136138
title: [icon, text].join(' ').trim(),
137-
tooltip
139+
tooltip,
140+
arguments: [this.repository.sourceControl]
138141
};
139142
}
140143

@@ -171,6 +174,7 @@ export class StatusBarCommands {
171174
}
172175

173176
const sync = this.syncStatusBar.command;
177+
console.log(sync);
174178

175179
if (sync) {
176180
result.push(sync);

src/vs/platform/statusbar/common/statusbar.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ export interface IStatusbarEntry {
4242
*/
4343
command?: string;
4444

45+
/**
46+
* Optional arguments for the command.
47+
*/
48+
arguments?: any[];
49+
4550
/**
4651
* An optional extension ID if this entry is provided from an extension.
4752
*/

src/vs/workbench/browser/parts/statusbar/statusbarPart.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ class StatusBarEntryItem implements IStatusbarItem {
238238
if (this.entry.command) {
239239
textContainer = document.createElement('a');
240240

241-
$(textContainer).on('click', () => this.executeCommand(this.entry.command), toDispose);
241+
$(textContainer).on('click', () => this.executeCommand(this.entry.command, this.entry.arguments), toDispose);
242242
} else {
243243
textContainer = document.createElement('span');
244244
}
@@ -287,7 +287,8 @@ class StatusBarEntryItem implements IStatusbarItem {
287287
};
288288
}
289289

290-
private executeCommand(id: string) {
290+
private executeCommand(id: string, args?: any[]) {
291+
args = args || [];
291292

292293
// Lookup built in commands
293294
const builtInActionDescriptor = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions).getWorkbenchAction(id);
@@ -314,7 +315,7 @@ class StatusBarEntryItem implements IStatusbarItem {
314315
}
315316

316317
// Fallback to the command service for any other case
317-
this.commandService.executeCommand(id).done(undefined, err => this.messageService.show(Severity.Error, toErrorMessage(err)));
318+
this.commandService.executeCommand(id, ...args).done(undefined, err => this.messageService.show(Severity.Error, toErrorMessage(err)));
318319
}
319320
}
320321

src/vs/workbench/parts/scm/electron-browser/scmActivity.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ export class StatusBarController implements IWorkbenchContribution {
121121
const disposables = commands.map(c => this.statusbarService.addEntry({
122122
text: c.title,
123123
tooltip: c.tooltip,
124-
command: c.id
124+
command: c.id,
125+
arguments: c.arguments
125126
}, MainThreadStatusBarAlignment.LEFT, 10000));
126127

127128
this.statusBarDisposable = combinedDisposable(disposables);

0 commit comments

Comments
 (0)