scm: move from pull to push model

This commit is contained in:
Joao Moreno
2017-03-29 22:44:25 +02:00
parent 12470dccf6
commit ccfcbe6c6f
15 changed files with 660 additions and 549 deletions

View File

@@ -5,17 +5,15 @@
'use strict';
import { scm, Uri, Disposable, SCMProvider, SCMResourceGroup, Event, workspace } from 'vscode';
import { Model, Resource, State } from './model';
import { scm, Uri, Disposable, SourceControl, SourceControlResourceGroup, Event, workspace, commands } from 'vscode';
import { Model, State } from './model';
import { CommandCenter } from './commands';
import { mapEvent } from './util';
export class GitSCMProvider implements SCMProvider {
export class GitSCMProvider {
private disposables: Disposable[] = [];
get contextKey(): string { return 'git'; }
get resources(): SCMResourceGroup[] { return this.model.resources; }
get onDidChange(): Event<this> {
return mapEvent(this.model.onDidChange, () => this);
@@ -38,16 +36,40 @@ export class GitSCMProvider implements SCMProvider {
switch (countBadge) {
case 'off': return 0;
case 'tracked': return this.model.indexGroup.resources.length;
default: return this.model.resources.reduce((r, g) => r + g.resources.length, 0);
default:
return this.model.mergeGroup.resources.length
+ this.model.indexGroup.resources.length
+ this.model.workingTreeGroup.resources.length;
}
}
constructor(private model: Model, private commandCenter: CommandCenter) {
scm.registerSCMProvider(this);
private _sourceControl: SourceControl;
get sourceControl(): SourceControl {
return this._sourceControl;
}
open(resource: Resource): void {
this.commandCenter.open(resource);
private mergeGroup: SourceControlResourceGroup;
private indexGroup: SourceControlResourceGroup;
private workingTreeGroup: SourceControlResourceGroup;
constructor(private model: Model, private commandCenter: CommandCenter) {
this._sourceControl = scm.createSourceControl('git', 'Git');
this._sourceControl.quickDiffProvider = this;
this.disposables.push(this._sourceControl);
this.mergeGroup = this._sourceControl.createResourceGroup(model.mergeGroup.id, model.mergeGroup.label);
this.indexGroup = this._sourceControl.createResourceGroup(model.indexGroup.id, model.indexGroup.label);
this.workingTreeGroup = this._sourceControl.createResourceGroup(model.workingTreeGroup.id, model.workingTreeGroup.label);
this.mergeGroup.hideWhenEmpty = true;
this.indexGroup.hideWhenEmpty = true;
this.disposables.push(this.mergeGroup);
this.disposables.push(this.indexGroup);
this.disposables.push(this.workingTreeGroup);
model.onDidChange(this.onDidModelChange, this, this.disposables);
}
provideOriginalResource(uri: Uri): Uri | undefined {
@@ -60,6 +82,14 @@ export class GitSCMProvider implements SCMProvider {
return new Uri().with({ scheme: 'git-original', query: uri.path, path: uri.path + '.git' });
}
private onDidModelChange(): void {
this.mergeGroup.resourceStates = this.model.mergeGroup.resources;
this.indexGroup.resourceStates = this.model.indexGroup.resources;
this.workingTreeGroup.resourceStates = this.model.workingTreeGroup.resources;
this._sourceControl.count = this.count;
commands.executeCommand('setContext', 'gitState', this.stateContextKey);
}
dispose(): void {
this.disposables.forEach(d => d.dispose());
this.disposables = [];