Skip to content

Commit 226c0cf

Browse files
authored
Merge pull request #61 from edgardmessias/change_config
Added support for enable/disable without reload window
2 parents 06b929e + 112a300 commit 226c0cf

File tree

2 files changed

+58
-28
lines changed

2 files changed

+58
-28
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* "svn.layout.depth" : Maximum depth to find subfolders using SVN
2424
* "svn.multipleFolders.ignore" : Folders to ignore using SVN
2525
(Ex.: '\*\*/vendor', '\*\*/node_modules')
26+
* @edgardmessias Added support for enable/disable without reload window,
2627

2728
## Bug Fixes
2829

src/model.ts

Lines changed: 57 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export class Model {
2323
private ignorePattern: RegExp = /^$/;
2424
private maxDepth: number = 0;
2525

26+
private configurationChangeDisposable: Disposable;
27+
2628
get repositories(): Repository[] {
2729
return this.openRepositories.map(r => r.repository);
2830
}
@@ -31,39 +33,61 @@ export class Model {
3133
const config = workspace.getConfiguration("svn");
3234
this.enabled = config.get("enabled") === true;
3335

36+
this.configurationChangeDisposable = workspace.onDidChangeConfiguration(
37+
this.onDidChangeConfiguration,
38+
this
39+
);
40+
3441
if (this.enabled) {
35-
this.init();
36-
37-
const multipleFolders = config.get<boolean>(
38-
"multipleFolders.enabled",
39-
false
40-
);
41-
42-
if (multipleFolders) {
43-
this.maxDepth = config.get<number>("multipleFolders.depth", 0);
44-
45-
const ignoreList = config.get("multipleFolders.ignore", []);
46-
47-
// Base on https://github.com/aleclarson/glob-regex/blob/master/index.js
48-
const pattern = ignoreList
49-
.join("|")
50-
.replace(/\./g, "\\.")
51-
.replace(/\*\*\//g, "(.+[\\\\\/])?")
52-
.replace(/\*\*/g, "(.+[\\\\\/])?*")
53-
.replace(/\*/g, "[^\\\\\/]+");
54-
55-
try {
56-
this.ignorePattern = new RegExp("^(" + pattern + ")$");
57-
} catch (error) {
58-
window.showErrorMessage("Invalid pattern for: " + pattern);
59-
}
60-
}
42+
this.enable();
43+
}
44+
}
45+
46+
private onDidChangeConfiguration(): void {
47+
const config = workspace.getConfiguration("svn");
48+
const enabled = config.get("enabled") === true;
49+
50+
if (enabled === this.enabled) {
51+
return;
52+
}
53+
54+
this.enabled = enabled;
55+
56+
if (enabled) {
57+
this.enable();
6158
} else {
6259
this.disable();
6360
}
6461
}
6562

66-
private init(): void {
63+
private enable(): void {
64+
const config = workspace.getConfiguration("svn");
65+
66+
const multipleFolders = config.get<boolean>(
67+
"multipleFolders.enabled",
68+
false
69+
);
70+
71+
if (multipleFolders) {
72+
this.maxDepth = config.get<number>("multipleFolders.depth", 0);
73+
74+
const ignoreList = config.get("multipleFolders.ignore", []);
75+
76+
// Base on https://github.com/aleclarson/glob-regex/blob/master/index.js
77+
const pattern = ignoreList
78+
.join("|")
79+
.replace(/\./g, "\\.")
80+
.replace(/\*\*\//g, "(.+[\\\\/])?")
81+
.replace(/\*\*/g, "(.+[\\\\/])?*")
82+
.replace(/\*/g, "[^\\\\/]+");
83+
84+
try {
85+
this.ignorePattern = new RegExp("^(" + pattern + ")$");
86+
} catch (error) {
87+
window.showErrorMessage("Invalid pattern for: " + pattern);
88+
}
89+
}
90+
6791
workspace.onDidChangeWorkspaceFolders(
6892
this.onDidChangeWorkspaceFolders,
6993
this,
@@ -112,6 +136,8 @@ export class Model {
112136
private disable(): void {
113137
this.repositories.forEach(repository => repository.dispose());
114138
this.openRepositories = [];
139+
140+
this.possibleSvnRepositoryPaths.clear();
115141
this.disposables = dispose(this.disposables);
116142
}
117143

@@ -246,5 +272,8 @@ export class Model {
246272
return pick && pick.repository;
247273
}
248274

249-
dispose(): void {}
275+
dispose(): void {
276+
this.disable();
277+
this.configurationChangeDisposable.dispose();
278+
}
250279
}

0 commit comments

Comments
 (0)