-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix
- Loading branch information
Showing
15 changed files
with
167 additions
and
36 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
out/ | ||
dist/ | ||
samples/**/*.vue | ||
examples/**/*.* |
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 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 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 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 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,3 @@ | ||
export function keypathValidate (keypath: string) { | ||
return !!keypath.match(/^[\w\d][\w\d\-\[\]\.\ ]*$/g) | ||
} |
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 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,50 @@ | ||
import { window, commands } from 'vscode' | ||
import { CurrentFile, Config, Commands } from '../../core' | ||
import i18n from '../../i18n' | ||
import { Log } from '../../utils' | ||
import { overrideConfirm } from '../overrideConfirm' | ||
import { keypathValidate } from '../keypathValidate' | ||
|
||
export async function NewKey (keypath?: string) { | ||
try { | ||
keypath = await window.showInputBox({ | ||
value: keypath || '', | ||
prompt: i18n.t('prompt.new_key_path'), | ||
}) | ||
|
||
if (!keypath) | ||
return | ||
|
||
if (!keypathValidate(keypath)) | ||
return window.showWarningMessage(i18n.t('prompt.invalid_keypath')) | ||
|
||
const shouldOverride = await overrideConfirm(keypath, false, true) | ||
|
||
if (shouldOverride === 'retry') { | ||
commands.executeCommand(Commands.new_key, keypath) | ||
return | ||
} | ||
|
||
if (shouldOverride !== 'override') | ||
return | ||
|
||
const locale = Config.sourceLanguage | ||
const value = await window.showInputBox({ | ||
value: '', | ||
prompt: i18n.t('prompt.new_key_value', keypath, locale), | ||
}) | ||
|
||
if (value === undefined) | ||
return | ||
|
||
await CurrentFile.loader.write({ | ||
value, | ||
keypath, | ||
filepath: undefined, | ||
locale, | ||
}) | ||
} | ||
catch (err) { | ||
Log.error(err.toString()) | ||
} | ||
} |
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 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,40 @@ | ||
import { window } from 'vscode' | ||
import { CurrentFile } from '../core' | ||
import i18n from '../i18n' | ||
|
||
export async function overrideConfirm (keypath: string, allowSkip = false, allowRenter = false) { | ||
const node = CurrentFile.loader.getNodeByKey(keypath) | ||
|
||
if (node) { | ||
const Override = i18n.t('prompt.button_override') | ||
const Skip = i18n.t('prompt.button_skip') | ||
const Reenter = i18n.t('prompt.button_reenter') | ||
|
||
const options = [Override] | ||
|
||
if (allowSkip) | ||
options.push(Skip) | ||
|
||
if (allowRenter) | ||
options.push(Reenter) | ||
|
||
const result = await window.showInformationMessage( | ||
i18n.t('prompt.key_already_exists'), | ||
{ modal: true }, | ||
...options, | ||
) | ||
|
||
if (result === Override) | ||
return 'override' | ||
|
||
if (result === Reenter) | ||
return 'retry' | ||
|
||
else if (result === Skip) | ||
return 'skip' | ||
|
||
return 'canceled' | ||
} | ||
|
||
return 'override' | ||
} |
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 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