-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
ec2d465
commit 4d2501d
Showing
4 changed files
with
127 additions
and
0 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,39 @@ | ||
import { QuickInputButtons, commands, window } from 'vscode' | ||
import { defineQuickPickItems } from './utils' | ||
import { showTranslatePopmenu } from './translatePopmenu' | ||
import { showSettingsPopmenu } from './settingsPopmenu' | ||
import * as meta from '~/generated-meta' | ||
import type { Context } from '~/context' | ||
|
||
export function showClearTranslationCachePopconfirm(ctx: Context) { | ||
const quickPick = window.createQuickPick() | ||
quickPick.title = 'Are you sure to clear translation cache?' | ||
quickPick.matchOnDescription = true | ||
quickPick.matchOnDetail = true | ||
defineQuickPickItems(quickPick, [ | ||
{ | ||
label: '$(x) No', | ||
detail: 'Cancel', | ||
callback: () => showSettingsPopmenu(ctx), | ||
}, | ||
{ | ||
label: '$(check) Yes', | ||
detail: 'Clear translation cache', | ||
callback: () => commands.executeCommand(meta.commands.clearTranslationCache).then(() => showTranslatePopmenu(ctx)), | ||
}, | ||
]) | ||
|
||
quickPick.buttons = [ | ||
QuickInputButtons.Back, | ||
] | ||
quickPick.onDidTriggerButton((button) => { | ||
if (button === QuickInputButtons.Back) | ||
showSettingsPopmenu(ctx) | ||
}) | ||
|
||
quickPick.onDidHide(() => { | ||
quickPick.dispose() | ||
showSettingsPopmenu(ctx) | ||
}) | ||
quickPick.show() | ||
} |
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,35 @@ | ||
import { QuickInputButtons, window } from 'vscode' | ||
import { showTranslatePopmenu } from './translatePopmenu' | ||
import { showSettingsPopmenu } from './settingsPopmenu' | ||
import { config } from '~/config' | ||
import type { Context } from '~/context' | ||
|
||
export function showSetKnownPopularWordInput(ctx: Context) { | ||
const inputBox = window.createInputBox() | ||
inputBox.title = 'Known Popular Words' | ||
inputBox.value = String(config.knownPopularWordCount || 0) | ||
|
||
inputBox.onDidAccept(() => { | ||
const count = Number(inputBox.value) | ||
if (Number.isNaN(count)) { | ||
window.showErrorMessage('Invalid number') | ||
return | ||
} | ||
config.knownPopularWordCount = count | ||
showTranslatePopmenu(ctx) | ||
}) | ||
|
||
inputBox.buttons = [ | ||
QuickInputButtons.Back, | ||
] | ||
inputBox.onDidTriggerButton((button) => { | ||
if (button === QuickInputButtons.Back) | ||
showTranslatePopmenu(ctx) | ||
}) | ||
|
||
inputBox.onDidHide(() => { | ||
inputBox.dispose() | ||
showSettingsPopmenu(ctx) | ||
}) | ||
inputBox.show() | ||
} |
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,47 @@ | ||
import { QuickInputButtons, commands, window } from 'vscode' | ||
import { defineQuickPickItems } from './utils' | ||
import { showTranslatePopmenu } from './translatePopmenu' | ||
import { showSetKnownPopularWordInput } from './setKnownPopularWordInput' | ||
import { showClearTranslationCachePopconfirm } from './clearTranslationCachePopconfirm' | ||
import type { Context } from '~/context' | ||
import { translationCacheMap } from '~/model/cache' | ||
import { config } from '~/config' | ||
import * as extMeta from '~/generated-meta' | ||
|
||
export function showSettingsPopmenu(ctx: Context) { | ||
const quickPick = window.createQuickPick() | ||
quickPick.title = 'Interline Translate' | ||
let routeJumping = false | ||
quickPick.onDidChangeSelection(() => routeJumping = true) | ||
const numberOfPhrases = Array.from(translationCacheMap.values()).reduce((acc, cache) => acc + cache.size, 0) | ||
defineQuickPickItems(quickPick, [ | ||
{ | ||
label: '$(mortar-board) Known popular words', | ||
detail: `${config.knownPopularWordCount} words`, | ||
callback: () => showSetKnownPopularWordInput(ctx), | ||
}, | ||
{ | ||
label: '$(database) Clear translation cache', | ||
detail: `${numberOfPhrases} phrases`, | ||
callback: () => showClearTranslationCachePopconfirm(ctx), | ||
}, | ||
{ | ||
label: '$(gear) More settings', | ||
detail: 'Configure extension settings', | ||
callback: () => commands.executeCommand('workbench.action.openSettings', extMeta.name).then(() => quickPick.dispose()), | ||
}, | ||
]) | ||
|
||
quickPick.buttons = [QuickInputButtons.Back] | ||
quickPick.onDidTriggerButton((button) => { | ||
if (button === QuickInputButtons.Back) | ||
showTranslatePopmenu(ctx) | ||
}) | ||
|
||
quickPick.onDidHide(() => { | ||
quickPick.dispose() | ||
if (!routeJumping) | ||
showTranslatePopmenu(ctx) | ||
}) | ||
quickPick.show() | ||
} |
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