diff --git a/extension.js b/extension.js new file mode 100644 index 0000000..c963b84 --- /dev/null +++ b/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 }; diff --git a/invalid_keybindings.json b/invalid_keybindings.json deleted file mode 100644 index aad3844..0000000 --- a/invalid_keybindings.json +++ /dev/null @@ -1,17 +0,0 @@ -[ - { - "mac": "cmd++", - "win": "ctrl++", - "linux": "ctrl++", - "key": "ctrl++", - "command": "workbench.action.zoomIn" - }, - { - "mac": "cmd+shift+{", - "command": "workbench.action.nextEditor" - }, - { - "mac": "cmd+shift+}", - "command": "workbench.action.previousEditor" - } -] \ No newline at end of file diff --git a/tsconfig.json b/jsconfig.json similarity index 90% rename from tsconfig.json rename to jsconfig.json index 11282c9..e459dfe 100644 --- a/tsconfig.json +++ b/jsconfig.json @@ -2,7 +2,6 @@ "compilerOptions": { "module": "commonjs", "target": "es6", - "outDir": "out", "lib": [ "es6" ], diff --git a/package.json b/package.json index 37a5f90..ee481f7 100644 --- a/package.json +++ b/package.json @@ -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" @@ -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": { diff --git a/src/extension.ts b/src/extension.ts deleted file mode 100644 index 6b14f1e..0000000 --- a/src/extension.ts +++ /dev/null @@ -1,9 +0,0 @@ -'use strict'; - -import * as vscode from 'vscode'; - -export function activate(context: vscode.ExtensionContext) { - // let config = vscode.workspace.getConfiguration('editor'); - // config.update('formatOnPaste', true); - // config.update('minimap.enabled', true); -} \ No newline at end of file