Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Wade Anderson
authored and
Wade Anderson
committed
Jun 21, 2017
1 parent
7dca39e
commit 79d6d8a
Showing
5 changed files
with
110 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "es6", | ||
"outDir": "out", | ||
"lib": [ | ||
"es6" | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.