| 14 | import { constants } from 'mo/services/builtinService/const'; |
| 15 | |
| 16 | export class SelectLocaleAction extends Action2 { |
| 17 | static readonly ID = constants.ACTION_SELECT_LOCALE; |
| 18 | static readonly LABEL = localize( |
| 19 | 'select.locale', |
| 20 | 'Select Display Language' |
| 21 | ); |
| 22 | |
| 23 | private get localeService(): ILocaleService { |
| 24 | return container.resolve(LocaleService); |
| 25 | } |
| 26 | |
| 27 | constructor() { |
| 28 | super({ |
| 29 | id: SelectLocaleAction.ID, |
| 30 | label: SelectLocaleAction.LABEL, |
| 31 | title: SelectLocaleAction.LABEL, |
| 32 | alias: 'Select Display Language', |
| 33 | precondition: undefined, |
| 34 | f1: true, |
| 35 | keybinding: { |
| 36 | when: undefined, |
| 37 | primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KeyL, |
| 38 | }, |
| 39 | }); |
| 40 | } |
| 41 | |
| 42 | run(accessor: ServicesAccessor): Promise<void> { |
| 43 | const quickInputService = accessor.get(IQuickInputService); |
| 44 | const data = this.localeService.getLocales(); |
| 45 | const current = this.localeService.getCurrentLocale(); |
| 46 | |
| 47 | const picks: QuickPickInput<ILocale>[] = data.map((item: ILocale) => { |
| 48 | return { |
| 49 | id: item.id, |
| 50 | label: item.name, |
| 51 | description: item.description, |
| 52 | }; |
| 53 | }); |
| 54 | |
| 55 | let timer: number | undefined; |
| 56 | |
| 57 | const onSelect = (locale: ILocale | undefined, apply: boolean) => { |
| 58 | if (timer) { |
| 59 | clearTimeout(timer); |
| 60 | } |
| 61 | timer = window.setTimeout( |
| 62 | () => { |
| 63 | timer = undefined; |
| 64 | if (locale && locale.id) { |
| 65 | this.localeService.setCurrentLocale(locale.id); |
| 66 | } |
| 67 | }, |
| 68 | apply ? 0 : 200 |
| 69 | ); |
| 70 | }; |
| 71 | |
| 72 | return new Promise((resolve) => { |
| 73 | let isCompleted = false; |
nothing calls this directly
no test coverage detected