api1.ts 1.9 KB
Newer Older
J
Joao Moreno 已提交
1 2 3 4 5 6 7 8
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

'use strict';

import { Model } from '../model';
J
Joao Moreno 已提交
9
import { Repository as BaseRepository } from '../repository';
J
Joao Moreno 已提交
10
import { InputBox, Git, API, Repository, Remote } from './git';
J
git api  
Joao Moreno 已提交
11 12 13
import { Event, SourceControlInputBox, Uri } from 'vscode';
import { mapEvent } from '../util';

J
Joao Moreno 已提交
14
class ApiInputBox implements InputBox {
J
git api  
Joao Moreno 已提交
15 16 17 18 19
	set value(value: string) { this._inputBox.value = value; }
	get value(): string { return this._inputBox.value; }
	constructor(private _inputBox: SourceControlInputBox) { }
}

J
Joao Moreno 已提交
20
export class ApiRepository implements Repository {
J
git api  
Joao Moreno 已提交
21

J
Joao Moreno 已提交
22 23
	readonly rootUri: Uri = Uri.file(this._repository.root);
	readonly inputBox: InputBox = new ApiInputBox(this._repository.inputBox);
J
Joao Moreno 已提交
24
	get remotes(): Remote[] { return [...this._repository.remotes]; }
J
git api  
Joao Moreno 已提交
25

J
Joao Moreno 已提交
26 27
	readonly onDidRunGitStatus: Event<void> = this._repository.onDidRunGitStatus;

J
Joao Moreno 已提交
28
	constructor(private _repository: BaseRepository) { }
J
Joao Moreno 已提交
29 30 31

	status(): Promise<void> {
		return this._repository.status();
J
git api  
Joao Moreno 已提交
32 33
	}
}
J
Joao Moreno 已提交
34

J
Joao Moreno 已提交
35 36 37 38 39 40
export class ApiGit implements Git {

	get path(): string { return this._model.git.path; }

	constructor(private _model: Model) { }
}
J
Joao Moreno 已提交
41

J
Joao Moreno 已提交
42 43 44 45 46
export class ApiImpl implements API {

	readonly git = new ApiGit(this._model);

	get onDidOpenRepository(): Event<Repository> {
J
git api  
Joao Moreno 已提交
47 48 49
		return mapEvent(this._model.onDidOpenRepository, r => new ApiRepository(r));
	}

J
Joao Moreno 已提交
50
	get onDidCloseRepository(): Event<Repository> {
J
git api  
Joao Moreno 已提交
51 52 53
		return mapEvent(this._model.onDidCloseRepository, r => new ApiRepository(r));
	}

J
Joao Moreno 已提交
54
	get repositories(): Repository[] {
J
Joao Moreno 已提交
55 56 57
		return this._model.repositories.map(r => new ApiRepository(r));
	}

J
Joao Moreno 已提交
58
	constructor(private _model: Model) { }
J
Joao Moreno 已提交
59
}