Skip to content

Commit 18687d2

Browse files
edgardmessiasJohnstonCode
authored andcommitted
refactor: Removed count opened repository from main (#528)
1 parent 395ae89 commit 18687d2

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

src/contexts/openRepositoryCount.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { commands, Disposable } from "vscode";
2+
import { debounce } from "../decorators";
3+
import { Model } from "../model";
4+
import { IDisposable } from "../util";
5+
6+
export class OpenRepositoryCount implements IDisposable {
7+
private disposables: Disposable[] = [];
8+
9+
constructor(private model: Model) {
10+
// When repository Opened or closed
11+
model.onDidOpenRepository(this.checkOpened, this, this.disposables);
12+
model.onDidCloseRepository(this.checkOpened, this, this.disposables);
13+
14+
this.checkOpened();
15+
}
16+
17+
@debounce(100)
18+
private checkOpened() {
19+
commands.executeCommand(
20+
"setContext",
21+
"svnOpenRepositoryCount",
22+
`${this.model.repositories.length}`
23+
);
24+
}
25+
26+
public dispose(): void {
27+
this.disposables.forEach(d => d.dispose());
28+
}
29+
}

src/extension.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import { registerCommands } from "./commands";
1111
import { ConstructorPolicy } from "./common/types";
1212
import { CheckActiveEditor } from "./contexts/checkActiveEditor";
13+
import { OpenRepositoryCount } from "./contexts/openRepositoryCount";
1314
import SvnDecorations from "./decorations/svnDecorations";
1415
import { configuration } from "./helpers/configuration";
1516
import { ItemLogProvider } from "./historyView/itemLogProvider";
@@ -30,8 +31,6 @@ async function init(
3031
outputChannel: OutputChannel,
3132
disposables: Disposable[]
3233
) {
33-
commands.executeCommand("setContext", "svnOpenRepositoryCount", "0");
34-
3534
const pathHint = configuration.get<string>("path");
3635
const svnFinder = new SvnFinder();
3736

@@ -57,21 +56,13 @@ async function init(
5756
window.registerTreeDataProvider("itemlog", itemLogProvider);
5857

5958
disposables.push(new CheckActiveEditor(model));
59+
disposables.push(new OpenRepositoryCount(model));
6060

6161
// First, check the vscode has support to DecorationProvider
6262
if (hasSupportToDecorationProvider()) {
6363
const decoration = new SvnDecorations(model);
6464
disposables.push(decoration);
6565
}
66-
const onRepository = () =>
67-
commands.executeCommand(
68-
"setContext",
69-
"svnOpenRepositoryCount",
70-
`${model.repositories.length}`
71-
);
72-
model.onDidOpenRepository(onRepository, null, disposables);
73-
model.onDidCloseRepository(onRepository, null, disposables);
74-
onRepository();
7566

7667
commands.executeCommand(
7768
"setContext",

0 commit comments

Comments
 (0)