feat:文件菜单下,添加选择显示语言的子菜单.

This commit is contained in:
chriswang521 2024-05-16 10:00:14 +08:00 committed by wangpenglong
parent d95d65301d
commit 4f4076891d
3 changed files with 54 additions and 2 deletions

View File

@ -7922,7 +7922,11 @@
"vscode.extension.contributes.localizations.translations": "与语言关联的翻译的列表。",
"vscode.extension.contributes.localizations.translations.id": "使用此翻译的 Kylin-Code 或扩展的 ID。Kylin-Code 的 ID 总为 \"vscode\",扩展的 ID 的格式应为 \"publisherId.extensionName\"。",
"vscode.extension.contributes.localizations.translations.id.pattern": "翻译 Kylin-Code 或者扩展ID 分别应为 \"vscode\" 或格式为 \"publisherId.extensionName\"。",
"vscode.extension.contributes.localizations.translations.path": "包含语言翻译的文件的相对路径。"
"vscode.extension.contributes.localizations.translations.path": "包含语言翻译的文件的相对路径。",
"relaunchDisplayLanguageDetail": "按下重启按钮来重新启动 {0} 并更改显示语言。",
"relaunchDisplayLanguageMessage": "要使显示语言的更改生效, 需要重新启动。",
"cancel": "取消",
"miSelectLanguage": "选择显示语言"
},
"vs/workbench/contrib/localization/common/localizationsActions": {
"available": "可用",

View File

@ -101,6 +101,9 @@ export class MenuId {
static readonly MenubarTerminalMenu = new MenuId('MenubarTerminalMenu');
static readonly MenubarViewMenu = new MenuId('MenubarViewMenu');
static readonly MenubarHomeMenu = new MenuId('MenubarHomeMenu');
//kylin ide add selecet disaplay language menu start{
static readonly MenubarSelectLanguageMenu = new MenuId('MenubarSelectLanguageMenu');
//kylin ide add selecet disaplay language menu start}
static readonly OpenEditorsContext = new MenuId('OpenEditorsContext');
static readonly OpenEditorsContextShare = new MenuId('OpenEditorsContextShare');
static readonly ProblemsPanelContext = new MenuId('ProblemsPanelContext');

View File

@ -18,9 +18,13 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { CancellationToken } from 'vs/base/common/cancellation';
import { IPaneCompositePartService } from 'vs/workbench/services/panecomposite/browser/panecomposite';
import { ViewContainerLocation } from 'vs/workbench/common/views';
import { Action2, MenuId, MenuRegistry, registerAction2 } from 'vs/platform/actions/common/actions';
import { ILocaleService } from 'vs/workbench/services/localization/common/locale';
import { IProductService } from 'vs/platform/product/common/productService';
import { BaseLocalizationWorkbenchContribution } from 'vs/workbench/contrib/localization/common/localization.contribution';
import { IsMacNativeContext } from 'vs/platform/contextkey/common/contextkeys';
import { ILanguagePackService } from 'vs/platform/languagePacks/common/languagePacks';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
class NativeLocalizationWorkbenchContribution extends BaseLocalizationWorkbenchContribution {
private static LANGUAGEPACK_SUGGESTION_IGNORE_STORAGE_KEY = 'extensionsAssistant/languagePackSuggestionIgnore';
@ -34,14 +38,44 @@ class NativeLocalizationWorkbenchContribution extends BaseLocalizationWorkbenchC
@IExtensionGalleryService private readonly galleryService: IExtensionGalleryService,
@IPaneCompositePartService private readonly paneCompositeService: IPaneCompositePartService,
@ITelemetryService private readonly telemetryService: ITelemetryService,
@ILanguagePackService private readonly languagePackService: ILanguagePackService
) {
super();
if (!platform.isWeb) {
this.registerSubMenu(this.languagePackService);
}
this.checkAndInstall();
this._register(this.extensionManagementService.onDidInstallExtensions(e => this.onDidInstallExtensions(e)));
this._register(this.extensionManagementService.onDidUninstallExtension(e => this.onDidUninstallExtension(e)));
}
private async registerSubMenu(languagePackService: ILanguagePackService) {
const installedLanguages = await languagePackService.getInstalledLanguages();
if (installedLanguages.length) {
installedLanguages.map((item, index) => {
registerAction2(class extends Action2 {
constructor() {
super({
id: item.id!,
title: item.label,
menu: {
id: MenuId.MenubarSelectLanguageMenu,
order: index
}
});
}
async run(accessor: ServicesAccessor): Promise<void> {
const localeService: ILocaleService = accessor.get(ILocaleService);
await localeService.setLocale(item);
}
});
});
}
}
private async onDidInstallExtensions(results: readonly InstallExtensionResult[]): Promise<void> {
for (const result of results) {
if (result.operation === InstallOperation.Install && result.local) {
@ -232,3 +266,14 @@ class NativeLocalizationWorkbenchContribution extends BaseLocalizationWorkbenchC
const workbenchRegistry = Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench);
workbenchRegistry.registerWorkbenchContribution(NativeLocalizationWorkbenchContribution, LifecyclePhase.Eventually);
if (!platform.isWeb) {
//选择语言菜单
MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
title: localize({ key: 'miSelectLanguage', comment: ['&& denotes a mnemonic'] }, "&&Display Language"),
submenu: MenuId.MenubarSelectLanguageMenu,
group: '5_autosave',
order: 4,
// on macOS native the preferences menu is separate under the application menu
when: IsMacNativeContext.toNegated()
});
}