mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 12:04:04 +01:00
use object hierarchy in API
This commit is contained in:
@@ -11,7 +11,7 @@ import * as path from 'path';
|
||||
|
||||
const Status: any = {};
|
||||
|
||||
class GitSCMResource implements SCMResource {
|
||||
class Resource implements SCMResource {
|
||||
|
||||
get uri(): Uri { return this._uri; }
|
||||
|
||||
@@ -20,24 +20,41 @@ class GitSCMResource implements SCMResource {
|
||||
}
|
||||
}
|
||||
|
||||
class GitSCMResourceGroup implements SCMResourceGroup {
|
||||
resources: GitSCMResource[] = [];
|
||||
class ResourceGroup implements SCMResourceGroup {
|
||||
|
||||
get id(): string { return this._id; }
|
||||
get label(): string { return this._label; }
|
||||
get resources(): SCMResource[] { return this._resources; }
|
||||
|
||||
constructor(private _id: string, private _label: string, private _resources: SCMResource[]) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class MergeGroup extends ResourceGroup {
|
||||
constructor(resources: SCMResource[]) {
|
||||
super('merge', 'Merge Changes', resources);
|
||||
}
|
||||
}
|
||||
|
||||
class IndexGroup extends ResourceGroup {
|
||||
constructor(resources: SCMResource[]) {
|
||||
super('index', 'Staged Changes', resources);
|
||||
}
|
||||
}
|
||||
|
||||
class WorkingTreeGroup extends ResourceGroup {
|
||||
constructor(resources: SCMResource[]) {
|
||||
super('workingTree', 'Changes', resources);
|
||||
}
|
||||
}
|
||||
|
||||
export class GitSCMProvider implements SCMProvider {
|
||||
|
||||
private disposables: Disposable[] = [];
|
||||
|
||||
private merge: GitSCMResourceGroup = new GitSCMResourceGroup();
|
||||
private index: GitSCMResourceGroup = new GitSCMResourceGroup();
|
||||
private workingTree: GitSCMResourceGroup = new GitSCMResourceGroup();
|
||||
|
||||
get resourceGroups(): SCMResourceGroup[] {
|
||||
return [this.merge, this.index, this.workingTree];
|
||||
}
|
||||
|
||||
private _onDidChangeResourceGroup = new EventEmitter<SCMResourceGroup>();
|
||||
get onDidChangeResourceGroup(): Event<SCMResourceGroup> { return this._onDidChangeResourceGroup.event; }
|
||||
private _onDidChange = new EventEmitter<SCMResourceGroup[]>();
|
||||
get onDidChange(): Event<SCMResourceGroup[]> { return this._onDidChange.event; }
|
||||
|
||||
constructor(private model: Model) {
|
||||
model.onDidChange(this.onModelChange, this, this.disposables);
|
||||
@@ -54,48 +71,56 @@ export class GitSCMProvider implements SCMProvider {
|
||||
|
||||
private onModelChange(): void {
|
||||
const status = this.model.status;
|
||||
const index: GitSCMResource[] = [];
|
||||
const workingTree: GitSCMResource[] = [];
|
||||
const merge: GitSCMResource[] = [];
|
||||
const index: SCMResource[] = [];
|
||||
const workingTree: SCMResource[] = [];
|
||||
const merge: SCMResource[] = [];
|
||||
|
||||
status.forEach(raw => {
|
||||
const uri = Uri.file(path.join(this.model.repositoryRoot, raw.path));
|
||||
|
||||
switch (raw.x + raw.y) {
|
||||
case '??': return workingTree.push(new GitSCMResource(uri, Status.UNTRACKED));
|
||||
case '!!': return workingTree.push(new GitSCMResource(uri, Status.IGNORED));
|
||||
case 'DD': return merge.push(new GitSCMResource(uri, Status.BOTH_DELETED));
|
||||
case 'AU': return merge.push(new GitSCMResource(uri, Status.ADDED_BY_US));
|
||||
case 'UD': return merge.push(new GitSCMResource(uri, Status.DELETED_BY_THEM));
|
||||
case 'UA': return merge.push(new GitSCMResource(uri, Status.ADDED_BY_THEM));
|
||||
case 'DU': return merge.push(new GitSCMResource(uri, Status.DELETED_BY_US));
|
||||
case 'AA': return merge.push(new GitSCMResource(uri, Status.BOTH_ADDED));
|
||||
case 'UU': return merge.push(new GitSCMResource(uri, Status.BOTH_MODIFIED));
|
||||
case '??': return workingTree.push(new Resource(uri, Status.UNTRACKED));
|
||||
case '!!': return workingTree.push(new Resource(uri, Status.IGNORED));
|
||||
case 'DD': return merge.push(new Resource(uri, Status.BOTH_DELETED));
|
||||
case 'AU': return merge.push(new Resource(uri, Status.ADDED_BY_US));
|
||||
case 'UD': return merge.push(new Resource(uri, Status.DELETED_BY_THEM));
|
||||
case 'UA': return merge.push(new Resource(uri, Status.ADDED_BY_THEM));
|
||||
case 'DU': return merge.push(new Resource(uri, Status.DELETED_BY_US));
|
||||
case 'AA': return merge.push(new Resource(uri, Status.BOTH_ADDED));
|
||||
case 'UU': return merge.push(new Resource(uri, Status.BOTH_MODIFIED));
|
||||
}
|
||||
|
||||
let isModifiedInIndex = false;
|
||||
|
||||
switch (raw.x) {
|
||||
case 'M': index.push(new GitSCMResource(uri, Status.INDEX_MODIFIED)); isModifiedInIndex = true; break;
|
||||
case 'A': index.push(new GitSCMResource(uri, Status.INDEX_ADDED)); break;
|
||||
case 'D': index.push(new GitSCMResource(uri, Status.INDEX_DELETED)); break;
|
||||
case 'R': index.push(new GitSCMResource(uri, Status.INDEX_RENAMED/*, raw.rename*/)); break;
|
||||
case 'C': index.push(new GitSCMResource(uri, Status.INDEX_COPIED)); break;
|
||||
case 'M': index.push(new Resource(uri, Status.INDEX_MODIFIED)); isModifiedInIndex = true; break;
|
||||
case 'A': index.push(new Resource(uri, Status.INDEX_ADDED)); break;
|
||||
case 'D': index.push(new Resource(uri, Status.INDEX_DELETED)); break;
|
||||
case 'R': index.push(new Resource(uri, Status.INDEX_RENAMED/*, raw.rename*/)); break;
|
||||
case 'C': index.push(new Resource(uri, Status.INDEX_COPIED)); break;
|
||||
}
|
||||
|
||||
switch (raw.y) {
|
||||
case 'M': workingTree.push(new GitSCMResource(uri, Status.MODIFIED/*, raw.rename*/)); break;
|
||||
case 'D': workingTree.push(new GitSCMResource(uri, Status.DELETED/*, raw.rename*/)); break;
|
||||
case 'M': workingTree.push(new Resource(uri, Status.MODIFIED/*, raw.rename*/)); break;
|
||||
case 'D': workingTree.push(new Resource(uri, Status.DELETED/*, raw.rename*/)); break;
|
||||
}
|
||||
});
|
||||
|
||||
this.merge.resources = merge;
|
||||
this.index.resources = index;
|
||||
this.workingTree.resources = workingTree;
|
||||
const groups: SCMResourceGroup[] = [];
|
||||
|
||||
this._onDidChangeResourceGroup.fire(this.merge);
|
||||
this._onDidChangeResourceGroup.fire(this.index);
|
||||
this._onDidChangeResourceGroup.fire(this.workingTree);
|
||||
if (merge.length > 0) {
|
||||
groups.push(new MergeGroup(merge));
|
||||
}
|
||||
|
||||
if (index.length > 0) {
|
||||
groups.push(new IndexGroup(index));
|
||||
}
|
||||
|
||||
if (workingTree.length > 0) {
|
||||
groups.push(new WorkingTreeGroup(workingTree));
|
||||
}
|
||||
|
||||
this._onDidChange.fire(groups);
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
|
||||
Reference in New Issue
Block a user