Skip to content

Commit 0c64a31

Browse files
committed
more event stuff
1 parent 747d3b5 commit 0c64a31

File tree

3 files changed

+51
-17
lines changed

3 files changed

+51
-17
lines changed

src/model.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ export class Model {
5050
}
5151

5252
private disable(): void {
53-
const openRepositories = [...this.openRepositories];
54-
55-
openRepositories.forEach(repository => r.dispose());
56-
53+
this.repositories.forEach(repository => repository.dispose());
5754
this.openRepositories = [];
5855
this.disposables = dispose(this.disposables);
5956
}
@@ -66,8 +63,6 @@ export class Model {
6663
folder => !this.getOpenRepository(folder.uri)
6764
);
6865

69-
// console.log(workspace.workspaceFolders);
70-
7166
const openRepositoriesToDispose = removed
7267
.map(folder => this.getOpenRepository(folder.uri.fsPath))
7368
.filter(repository => !!repository)
@@ -76,10 +71,12 @@ export class Model {
7671
!(workspace.workspaceFolders || []).some(f =>
7772
repository!.repository.root.startsWith(f.uri.fsPath)
7873
)
79-
);
74+
) as OpenRepository[];
8075

81-
// console.log(removed);
82-
console.log(openRepositoriesToDispose);
76+
possibleRepositoryFolders.forEach(p =>
77+
this.tryOpenRepository(p.uri.fsPath)
78+
);
79+
openRepositoriesToDispose.forEach(r => r.repository.dispose());
8380
}
8481

8582
private async scanWorkspaceFolders() {

src/repository.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,26 @@ import {
55
FileSystemWatcher,
66
SourceControl,
77
SourceControlResourceGroup,
8-
SourceControlInputBox
8+
SourceControlInputBox,
9+
Disposable,
10+
EventEmitter,
11+
Event
912
} from "vscode";
1013
import { Resource } from "./resource";
1114
import { throttleAsync } from "./decorators";
1215
import { Repository as BaseRepository } from "./svn";
1316
import { SvnStatusBar } from "./statusBar";
17+
import { dispose } from "./util";
1418

1519
export class Repository {
1620
public watcher: FileSystemWatcher;
1721
private sourceControl: SourceControl;
1822
public changes: SourceControlResourceGroup;
1923
public notTracked: SourceControlResourceGroup;
24+
private disposables: Disposable[] = [];
25+
26+
private _onDidChangeStatus = new EventEmitter<void>();
27+
readonly onDidChangeStatus: Event<void> = this._onDidChangeStatus.event;
2028

2129
get root(): string {
2230
return this.repository.root;
@@ -32,6 +40,8 @@ export class Repository {
3240

3341
constructor(public repository: BaseRepository) {
3442
this.watcher = workspace.createFileSystemWatcher("**");
43+
this.disposables.push(this.watcher);
44+
3545
this.sourceControl = scm.createSourceControl(
3646
"svn",
3747
"SVN",
@@ -43,9 +53,16 @@ export class Repository {
4353
arguments: [this.sourceControl]
4454
};
4555
this.sourceControl.quickDiffProvider = this;
46-
47-
const test = new SvnStatusBar(this);
48-
this.sourceControl.statusBarCommands = test.commands;
56+
this.disposables.push(this.sourceControl);
57+
58+
const statusBar = new SvnStatusBar(this);
59+
this.disposables.push(statusBar);
60+
statusBar.onDidChange(
61+
() => (this.sourceControl.statusBarCommands = statusBar.commands),
62+
null,
63+
this.disposables
64+
);
65+
this.sourceControl.statusBarCommands = statusBar.commands;
4966

5067
this.changes = this.sourceControl.createResourceGroup("changes", "Changes");
5168
this.notTracked = this.sourceControl.createResourceGroup(
@@ -111,6 +128,8 @@ export class Repository {
111128
this.changes.resourceStates = changes;
112129
this.notTracked.resourceStates = notTracked;
113130

131+
this._onDidChangeStatus.fire();
132+
114133
return Promise.resolve();
115134
}
116135

@@ -132,4 +151,8 @@ export class Repository {
132151
addFile(filePath: string) {
133152
return this.repository.addFile(filePath);
134153
}
154+
155+
dispose(): void {
156+
this.disposables = dispose(this.disposables);
157+
}
135158
}

src/statusBar.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1-
import { window, StatusBarItem } from "vscode";
1+
import { window, StatusBarItem, Disposable, EventEmitter, Event } from "vscode";
22
import { Repository } from "./repository";
33

44
export class SvnStatusBar {
5-
private statusBar: StatusBarItem;
6-
private currentBranch: string;
5+
private disposables: Disposable[] = [];
6+
private _onDidChange = new EventEmitter<void>();
77

8-
constructor(private repository: Repository) {}
8+
get onDidChange(): Event<void> {
9+
return this._onDidChange.event;
10+
}
11+
12+
constructor(private repository: Repository) {
13+
repository.onDidChangeStatus(
14+
this._onDidChange.fire,
15+
this._onDidChange,
16+
this.disposables
17+
);
18+
}
919

1020
get commands() {
1121
// const title = `$(git-branch) ${this.repository.headLabel}`;
@@ -19,4 +29,8 @@ export class SvnStatusBar {
1929
}
2030
];
2131
}
32+
33+
dispose(): void {
34+
this.disposables.forEach(disposable => disposable.dispose());
35+
}
2236
}

0 commit comments

Comments
 (0)