Skip to content

Commit

Permalink
new updates for v3
Browse files Browse the repository at this point in the history
  • Loading branch information
Wade Anderson authored and Wade Anderson committed Jun 21, 2017
1 parent 7dca39e commit 79d6d8a
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 31 deletions.
94 changes: 94 additions & 0 deletions extension.js
@@ -0,0 +1,94 @@
const vscode = require('vscode');

const showInformationMessage = vscode.window.showInformationMessage;
const isGlobalConfigValue = true;

class Setting {
constructor(name, value) {
this.name = name;
this.value = value;
}
}

const versionThreeSettings = [
new Setting('multiCursorModifier', 'ctrlCmd'),
new Setting('formatOnPaste', true)
];

function updateSettings(editorConfig, settings) {
settings.forEach((setting) => {
editorConfig.update(setting.name, setting.value, isGlobalConfigValue);
});
}

function isDefaultValueSet(editorConfig, settings) {
for (var i = 0; i < settings.length; i++) {
var setting = editorConfig.inspect(settings[i].name);
const dv = setting ? setting.defaultValue : null;
const gv = setting ? setting.globalValue : null;

if (gv === dv || gv === undefined) {
return true;
}
}

return false;
}

class VersionThreeUpdateSetting {
constructor() {
this.name = 'promptV3Features';
this.config = vscode.workspace.getConfiguration('atomKeymap');
this.hasPrompted = this.config.get(this.name) || false;
}

persist() {
this.config.update(this.name, true, isGlobalConfigValue);
}

}

class View {

constructor(updateSetting, editorConfig) {
this.updateSetting = updateSetting;
this.editorConfig = editorConfig;
this.messages = {
yes: 'Yes',
no: 'No',
learnMore: 'Learn More',
prompt: 'New features are available for Atom Keymap 3.0. Do you want to enable the new features?',
noChange: 'Atom Keymap: New features have not been enable.',
change: 'Atom Keymap: New features have been added.',
};
}

showMessage() {
const answer = showInformationMessage(this.messages.prompt, this.messages.yes, this.messages.no, this.messages.learnMore);

answer.then((selectedOption) => {

if (selectedOption === this.messages.yes) {
this.updateSetting.persist();
updateSettings(this.editorConfig, versionThreeSettings);
showInformationMessage(this.messages.change);
} else if (selectedOption === this.messages.no) {
this.updateSetting.persist();
showInformationMessage(this.messages.noChange);
} else if (selectedOption === this.messages.learnMore) {
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse('https://marketplace.visualstudio.com/items?itemName=ms-vscode.atom-keybindings'));
}
});
}
}

const activate = () => {
const editorConfig = vscode.workspace.getConfiguration('editor');
const updateSetting = new VersionThreeUpdateSetting();

if (!updateSetting.hasPrompted && isDefaultValueSet(editorConfig, versionThreeSettings)) {
new View(updateSetting, editorConfig).showMessage();
}
}

module.exports = { activate };
17 changes: 0 additions & 17 deletions invalid_keybindings.json

This file was deleted.

1 change: 0 additions & 1 deletion tsconfig.json → jsconfig.json
Expand Up @@ -2,7 +2,6 @@
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"outDir": "out",
"lib": [
"es6"
],
Expand Down
20 changes: 16 additions & 4 deletions package.json
Expand Up @@ -2,7 +2,7 @@
"name": "atom-keybindings",
"displayName": "Atom Keymap",
"description": "Popular Atom keybindings for Visual Studio Code",
"version": "2.0.1",
"version": "3.0.0",
"publisher": "ms-vscode",
"engines": {
"vscode": "^1.6.0"
Expand Down Expand Up @@ -517,11 +517,23 @@
"key": "shift+f11",
"command": "workbench.action.toggleZenMode"
}
]
],
"configuration": {
"type": "object",
"title": "Atom Keymap configuration",
"properties": {
"atomKeymap.promptV3Features": {
"type": [
"boolean",
"null"
],
"default": null,
"description": "Status of Atom Keymap version three features added."
}
}
}
},
"scripts": {
"vscode:prepublish": "tsc -p ./",
"compile": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install"
},
"devDependencies": {
Expand Down
9 changes: 0 additions & 9 deletions src/extension.ts

This file was deleted.

0 comments on commit 79d6d8a

Please sign in to comment.