This commit is contained in:
Joao
2017-09-01 11:23:34 +02:00
parent ee29fc9c61
commit f23b0d7974
+42 -3
View File
@@ -47,9 +47,39 @@ export class Model {
private possibleGitRepositoryPaths = new Set<string>();
private enabled = false;
private configurationChangeDisposable: Disposable;
private disposables: Disposable[] = [];
constructor(private git: Git) {
const config = workspace.getConfiguration('git');
this.enabled = config.get<boolean>('enabled') === true;
this.configurationChangeDisposable = workspace.onDidChangeConfiguration(this.onDidChangeConfiguration, this);
if (this.enabled) {
this.enable();
}
}
private onDidChangeConfiguration(): void {
const config = workspace.getConfiguration('git');
const enabled = config.get<boolean>('enabled') === true;
if (enabled === this.enabled) {
return;
}
this.enabled = enabled;
if (enabled) {
this.enable();
} else {
this.disable();
}
}
private enable(): void {
workspace.onDidChangeWorkspaceFolders(this.onDidChangeWorkspaceFolders, this, this.disposables);
this.onDidChangeWorkspaceFolders({ added: workspace.workspaceFolders || [], removed: [] });
@@ -67,6 +97,15 @@ export class Model {
this.scanWorkspaceFolders();
}
private disable(): void {
const openRepositories = [...this.openRepositories];
openRepositories.forEach(r => r.dispose());
this.openRepositories = [];
this.possibleGitRepositoryPaths.clear();
this.disposables = dispose(this.disposables);
}
/**
* Scans the first level of each workspace folder, looking
* for git repositories.
@@ -94,7 +133,7 @@ export class Model {
this.tryOpenRepository(path);
}
this.possibleGitRepositoryPaths = new Set<string>();
this.possibleGitRepositoryPaths.clear();
}
private async onDidChangeWorkspaceFolders({ added, removed }: WorkspaceFoldersChangeEvent): Promise<void> {
@@ -246,7 +285,7 @@ export class Model {
}
dispose(): void {
[...this.openRepositories].forEach(r => r.dispose());
this.disposables = dispose(this.disposables);
this.disable();
this.configurationChangeDisposable.dispose();
}
}