Skip to content

Commit

Permalink
add git.decorations.enabled setting, #37299
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Nov 1, 2017
1 parent 155fbe8 commit 5efffdf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
5 changes: 5 additions & 0 deletions extensions/git/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,11 @@
"type": "boolean",
"description": "%config.enableCommitSigning%",
"default": false
},
"git.decorations.enabled": {
"type": "boolean",
"default": true,
"description": "%config.decorations.enabled%"
}
}
},
Expand Down
1 change: 1 addition & 0 deletions extensions/git/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"config.enableSmartCommit": "Commit all changes when there are no staged changes.",
"config.enableCommitSigning": "Enables commit signing with GPG.",
"config.discardAllScope": "Controls what changes are discarded by the `Discard all changes` command. `all` discards all changes. `tracked` discards only tracked files. `prompt` shows a prompt dialog every time the action is run.",
"config.decorations.enabled": "Controls if Git contributes colors and badges to the explorer and the open editors view.",
"colors.modified": "Color for modified resources.",
"colors.deleted": "Color for deleted resources.",
"colors.untracked": "Color for untracked resources.",
Expand Down
35 changes: 28 additions & 7 deletions extensions/git/src/decorationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,35 @@ class GitDecorationProvider implements DecorationProvider {

export class GitDecorations {

private disposables: Disposable[] = [];
private configListener: Disposable;
private modelListener: Disposable[] = [];
private providers = new Map<Repository, Disposable>();

constructor(private model: Model) {
this.disposables.push(
model.onDidOpenRepository(this.onDidOpenRepository, this),
model.onDidCloseRepository(this.onDidCloseRepository, this)
);
model.repositories.forEach(this.onDidOpenRepository, this);
this.configListener = workspace.onDidChangeConfiguration(e => e.affectsConfiguration('git.decorations.enabled') && this.update());
this.update();
}

private update(): void {
const enabled = workspace.getConfiguration('git').get('decorations.enabled');
if (enabled) {
this.enable();
} else {
this.disable();
}
}

private enable(): void {
this.modelListener = [];
this.model.onDidOpenRepository(this.onDidOpenRepository, this, this.modelListener);
this.model.onDidCloseRepository(this.onDidCloseRepository, this, this.modelListener);
this.model.repositories.forEach(this.onDidOpenRepository, this);
}

private disable(): void {
this.modelListener.forEach(d => d.dispose());
this.providers.forEach(value => value.dispose());
this.providers.clear();
}

private onDidOpenRepository(repository: Repository): void {
Expand All @@ -144,7 +164,8 @@ export class GitDecorations {
}

dispose(): void {
this.disposables.forEach(d => d.dispose());
this.configListener.dispose();
this.modelListener.forEach(d => d.dispose());
this.providers.forEach(value => value.dispose);
this.providers.clear();
}
Expand Down

0 comments on commit 5efffdf

Please sign in to comment.