(accessor: ServicesAccessor)
| 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; |
| 74 | |
| 75 | const autoFocusIndex = picks.findIndex((p) => p.id === current?.id); |
| 76 | const quickPick = quickInputService.createQuickPick<ILocale>(); |
| 77 | quickPick.items = picks; |
| 78 | |
| 79 | quickPick.placeholder = localize( |
| 80 | 'locale.select', |
| 81 | 'Select Display Language (Up/Down Keys to Preview)' |
| 82 | ); |
| 83 | |
| 84 | quickPick.activeItems = [picks[autoFocusIndex]]; |
| 85 | quickPick.canSelectMany = false; |
| 86 | quickPick.onDidAccept((_) => { |
| 87 | const item = quickPick.activeItems[0]; |
| 88 | if (item) { |
| 89 | onSelect(item, true); |
| 90 | } |
| 91 | isCompleted = true; |
| 92 | quickPick.hide(); |
| 93 | resolve(); |
| 94 | }); |
| 95 | |
| 96 | quickPick.onDidHide(() => { |
| 97 | if (!isCompleted) { |
| 98 | onSelect(current, true); |
| 99 | resolve(); |
nothing calls this directly
no test coverage detected