Skip to content

Commit

Permalink
refactor: Adds GunController
Browse files Browse the repository at this point in the history
  • Loading branch information
ironcev committed Sep 28, 2017
1 parent 1fa9bba commit 62c44f5
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}

0 comments on commit 62c44f5

Please sign in to comment.