From 62c44f5fe99cb95b2136afec8b7219b80e159f8a Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 28 Sep 2017 23:24:08 +0200 Subject: [PATCH] refactor: Adds GunController --- src/extension.ts | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 391f3ee..26e629e 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -3,24 +3,31 @@ import * as vscode from 'vscode'; export function activate(context: vscode.ExtensionContext) { - const intelliSenseSettings = new IntelliSenseSettings(vscode.workspace.getConfiguration()) + const gunControllers : GunController[] = [ + new IntelliSenseGunController(vscode.workspace.getConfiguration()) + ] let gunsOff = vscode.commands.registerCommand('withoutGuns.gunsOff', () => { - vscode.window.showInformationMessage('We just took your guns. That\'s for your own good.'); - intelliSenseSettings.removeIntelliSense(); + vscode.window.showInformationMessage('We just took your guns. That\'s for your own good.'); + gunControllers.forEach(gunController => gunController.takeTheGun()); }); let gunsOn = vscode.commands.registerCommand('withoutGuns.gunsOn', () => { vscode.window.showInformationMessage('You got your guns back. Be careful what you do with them.'); - intelliSenseSettings.applyInitialSettings(); + gunControllers.forEach(gunController => gunController.giveTheGunBack()); }); context.subscriptions.push(gunsOff); context.subscriptions.push(gunsOn); } -class IntelliSenseSettings { - private readonly configuration : vscode.WorkspaceConfiguration; +interface GunController { + takeTheGun(); + giveTheGunBack(); +} + +class IntelliSenseGunController implements GunController { + private readonly configuration: vscode.WorkspaceConfiguration; private readonly initialQuickSuggestions : boolean; private readonly initialWordBasedSuggestions : boolean; @@ -36,17 +43,17 @@ class IntelliSenseSettings { this.initialsuggestOnTriggerCharacters = configuration.get("editor.suggestOnTriggerCharacters"); } - applyInitialSettings() { - this.configuration.update("editor.quickSuggestions", this.initialQuickSuggestions); - this.configuration.update("editor.wordBasedSuggestions", this.initialWordBasedSuggestions); - this.configuration.update("editor.parameterHints", this.initialParameterHints); - this.configuration.update("editor.suggestOnTriggerCharacters", this.initialsuggestOnTriggerCharacters); - } - - removeIntelliSense() { + takeTheGun() { this.configuration.update("editor.quickSuggestions", false); this.configuration.update("editor.wordBasedSuggestions", false); this.configuration.update("editor.parameterHints", false); this.configuration.update("editor.suggestOnTriggerCharacters", false); } + + giveTheGunBack() { + this.configuration.update("editor.quickSuggestions", this.initialQuickSuggestions); + this.configuration.update("editor.wordBasedSuggestions", this.initialWordBasedSuggestions); + this.configuration.update("editor.parameterHints", this.initialParameterHints); + this.configuration.update("editor.suggestOnTriggerCharacters", this.initialsuggestOnTriggerCharacters); + } } \ No newline at end of file