diff --git a/src/vs/workbench/electron-browser/actions.ts b/src/vs/workbench/electron-browser/actions.ts index 4162cbd8497..70f30c4faf7 100644 --- a/src/vs/workbench/electron-browser/actions.ts +++ b/src/vs/workbench/electron-browser/actions.ts @@ -24,7 +24,7 @@ import { IConfigurationService, ConfigurationTarget } from 'vs/platform/configur import { IExtensionManagementService, LocalExtensionType, ILocalExtension, IExtensionEnablementService } from 'vs/platform/extensionManagement/common/extensionManagement'; import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration'; import paths = require('vs/base/common/paths'); -import { isMacintosh, isLinux } from 'vs/base/common/platform'; +import { isMacintosh, isLinux, language } from 'vs/base/common/platform'; import { IQuickOpenService, IFilePickOpenEntry, ISeparator, IPickOpenAction, IPickOpenItem } from 'vs/platform/quickOpen/common/quickOpen'; import { KeyMod } from 'vs/base/common/keyCodes'; import * as browser from 'vs/base/browser/browser'; @@ -42,10 +42,11 @@ import { getPathLabel } from 'vs/base/common/labels'; import { IViewlet } from 'vs/workbench/common/viewlet'; import { IPanel } from 'vs/workbench/common/panel'; import { IWorkspaceIdentifier, getWorkspaceLabel, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces'; -import { FileKind } from 'vs/platform/files/common/files'; +import { FileKind, IFileService } from 'vs/platform/files/common/files'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IExtensionService } from 'vs/platform/extensions/common/extensions'; import { getEntries } from 'vs/base/common/performance'; +import { IEditor } from 'vs/platform/editor/common/editor'; // --- actions @@ -1633,3 +1634,45 @@ export class ToggleWindowTabsBar extends Action { return this.windowsService.toggleWindowTabsBar().then(() => true); } } + +export class ConfigureLocaleAction extends Action { + public static ID = 'workbench.action.configureLocale'; + public static LABEL = nls.localize('configureLocale', "Configure Language"); + + private static DEFAULT_CONTENT: string = [ + '{', + `\t// ${nls.localize('displayLanguage', 'Defines VSCode\'s display language.')}`, + `\t// ${nls.localize('doc', 'See {0} for a list of supported languages.', 'https://go.microsoft.com/fwlink/?LinkId=761051')}`, + `\t// ${nls.localize('restart', 'Changing the value requires restarting VSCode.')}`, + `\t"locale":"${language}"`, + '}' + ].join('\n'); + + constructor(id: string, label: string, + @IFileService private fileService: IFileService, + @IWorkspaceContextService private contextService: IWorkspaceContextService, + @IEnvironmentService private environmentService: IEnvironmentService, + @IWorkbenchEditorService private editorService: IWorkbenchEditorService + ) { + super(id, label); + } + + public run(event?: any): TPromise { + const file = URI.file(paths.join(this.environmentService.appSettingsHome, 'locale.json')); + return this.fileService.resolveFile(file).then(null, (error) => { + return this.fileService.createFile(file, ConfigureLocaleAction.DEFAULT_CONTENT); + }).then((stat) => { + if (!stat) { + return undefined; + } + return this.editorService.openEditor({ + resource: stat.resource, + options: { + forceOpen: true + } + }); + }, (error) => { + throw new Error(nls.localize('fail.createSettings', "Unable to create '{0}' ({1}).", getPathLabel(file, this.contextService), error)); + }); + } +} \ No newline at end of file diff --git a/src/vs/workbench/electron-browser/configureLocale.ts b/src/vs/workbench/electron-browser/configureLocale.ts deleted file mode 100644 index d360f840752..00000000000 --- a/src/vs/workbench/electron-browser/configureLocale.ts +++ /dev/null @@ -1,99 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ -'use strict'; - -import { TPromise } from 'vs/base/common/winjs.base'; -import nls = require('vs/nls'); -import * as Path from 'vs/base/common/paths'; -import URI from 'vs/base/common/uri'; -import * as Labels from 'vs/base/common/labels'; -import * as Platform from 'vs/base/common/platform'; -import { Action } from 'vs/base/common/actions'; - -import { Registry } from 'vs/platform/registry/common/platform'; -import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actions'; -import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; -import { IEnvironmentService } from 'vs/platform/environment/common/environment'; -import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; -import { IEditor } from 'vs/platform/editor/common/editor'; -import { IFileService } from 'vs/platform/files/common/files'; -import { SyncActionDescriptor } from 'vs/platform/actions/common/actions'; - -import { IJSONContributionRegistry, Extensions as JSONExtensions } from 'vs/platform/jsonschemas/common/jsonContributionRegistry'; -import { IJSONSchema } from 'vs/base/common/jsonSchema'; - -class ConfigureLocaleAction extends Action { - public static ID = 'workbench.action.configureLocale'; - public static LABEL = nls.localize('configureLocale', "Configure Language"); - - private static DEFAULT_CONTENT: string = [ - '{', - `\t// ${nls.localize('displayLanguage', 'Defines VSCode\'s display language.')}`, - `\t// ${nls.localize('doc', 'See {0} for a list of supported languages.', 'https://go.microsoft.com/fwlink/?LinkId=761051')}`, - `\t// ${nls.localize('restart', 'Changing the value requires restarting VSCode.')}`, - `\t"locale":"${Platform.language}"`, - '}' - ].join('\n'); - - constructor(id: string, label: string, - @IFileService private fileService: IFileService, - @IWorkspaceContextService private contextService: IWorkspaceContextService, - @IEnvironmentService private environmentService: IEnvironmentService, - @IWorkbenchEditorService private editorService: IWorkbenchEditorService - ) { - super(id, label); - } - - public run(event?: any): TPromise { - const file = URI.file(Path.join(this.environmentService.appSettingsHome, 'locale.json')); - return this.fileService.resolveFile(file).then(null, (error) => { - return this.fileService.createFile(file, ConfigureLocaleAction.DEFAULT_CONTENT); - }).then((stat) => { - if (!stat) { - return undefined; - } - return this.editorService.openEditor({ - resource: stat.resource, - options: { - forceOpen: true - } - }); - }, (error) => { - throw new Error(nls.localize('fail.createSettings', "Unable to create '{0}' ({1}).", Labels.getPathLabel(file, this.contextService), error)); - }); - } -} - -const registry = Registry.as(Extensions.WorkbenchActions); -registry.registerWorkbenchAction(new SyncActionDescriptor(ConfigureLocaleAction, ConfigureLocaleAction.ID, ConfigureLocaleAction.LABEL), 'Configure Language'); - -let enumValues: string[] = ['de', 'en', 'en-US', 'es', 'fr', 'it', 'ja', 'ko', 'ru', 'zh-CN', 'zh-TW']; -import product from 'vs/platform/node/product'; -if (product.quality !== 'stable') { - enumValues.push('hu'); -} - -const schemaId = 'vscode://schemas/locale'; -// Keep en-US since we generated files with that content. -const schema: IJSONSchema = - { - id: schemaId, - description: 'Locale Definition file', - type: 'object', - default: { - 'locale': 'en' - }, - required: ['locale'], - properties: { - locale: { - type: 'string', - enum: enumValues, - description: nls.localize('JsonSchema.locale', 'The UI Language to use.') - } - } - }; - -const jsonRegistry = Registry.as(JSONExtensions.JSONContribution); -jsonRegistry.registerSchema(schemaId, schema); \ No newline at end of file diff --git a/src/vs/workbench/electron-browser/main.contribution.ts b/src/vs/workbench/electron-browser/main.contribution.ts index fa982ff9eb9..6ee4c077e23 100644 --- a/src/vs/workbench/electron-browser/main.contribution.ts +++ b/src/vs/workbench/electron-browser/main.contribution.ts @@ -14,7 +14,7 @@ import { IConfigurationRegistry, Extensions as ConfigurationExtensions } from 'v import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actions'; import { KeyMod, KeyChord, KeyCode } from 'vs/base/common/keyCodes'; import { isWindows, isLinux, isMacintosh } from 'vs/base/common/platform'; -import { CloseEditorAction, KeybindingsReferenceAction, OpenDocumentationUrlAction, OpenIntroductoryVideosUrlAction, OpenTipsAndTricksUrlAction, ReportIssueAction, ReportPerformanceIssueAction, ZoomResetAction, ZoomOutAction, ZoomInAction, ToggleFullScreenAction, ToggleMenuBarAction, CloseWorkspaceAction, CloseCurrentWindowAction, SwitchWindow, NewWindowAction, CloseMessagesAction, NavigateUpAction, NavigateDownAction, NavigateLeftAction, NavigateRightAction, IncreaseViewSizeAction, DecreaseViewSizeAction, ShowStartupPerformance, ToggleSharedProcessAction, QuickSwitchWindow, QuickOpenRecentAction, inRecentFilesPickerContextKey } from 'vs/workbench/electron-browser/actions'; +import { CloseEditorAction, KeybindingsReferenceAction, OpenDocumentationUrlAction, OpenIntroductoryVideosUrlAction, OpenTipsAndTricksUrlAction, ReportIssueAction, ReportPerformanceIssueAction, ZoomResetAction, ZoomOutAction, ZoomInAction, ToggleFullScreenAction, ToggleMenuBarAction, CloseWorkspaceAction, CloseCurrentWindowAction, SwitchWindow, NewWindowAction, CloseMessagesAction, NavigateUpAction, NavigateDownAction, NavigateLeftAction, NavigateRightAction, IncreaseViewSizeAction, DecreaseViewSizeAction, ShowStartupPerformance, ToggleSharedProcessAction, QuickSwitchWindow, QuickOpenRecentAction, inRecentFilesPickerContextKey, ConfigureLocaleAction } from 'vs/workbench/electron-browser/actions'; import { MessagesVisibleContext } from 'vs/workbench/electron-browser/workbench'; import { IJSONSchema } from 'vs/base/common/jsonSchema'; import { registerCommands } from 'vs/workbench/electron-browser/commands'; @@ -22,6 +22,7 @@ import { AddRootFolderAction, GlobalRemoveRootFolderAction, OpenWorkspaceAction, import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; import { inQuickOpenContext, getQuickNavigateHandler } from 'vs/workbench/browser/parts/quickopen/quickopen'; import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry'; +import { IJSONContributionRegistry, Extensions as JSONExtensions } from 'vs/platform/jsonschemas/common/jsonContributionRegistry'; // Contribute Commands registerCommands(); @@ -449,3 +450,36 @@ configurationRegistry.registerConfiguration({ } } }); + +// Register action to configure locale and related settings + +const registry = Registry.as(Extensions.WorkbenchActions); +registry.registerWorkbenchAction(new SyncActionDescriptor(ConfigureLocaleAction, ConfigureLocaleAction.ID, ConfigureLocaleAction.LABEL), 'Configure Language'); + +let enumValues: string[] = ['de', 'en', 'en-US', 'es', 'fr', 'it', 'ja', 'ko', 'ru', 'zh-CN', 'zh-TW']; +if (product.quality !== 'stable') { + enumValues.push('hu'); +} + +const schemaId = 'vscode://schemas/locale'; +// Keep en-US since we generated files with that content. +const schema: IJSONSchema = + { + id: schemaId, + description: 'Locale Definition file', + type: 'object', + default: { + 'locale': 'en' + }, + required: ['locale'], + properties: { + locale: { + type: 'string', + enum: enumValues, + description: nls.localize('JsonSchema.locale', 'The UI Language to use.') + } + } + }; + +const jsonRegistry = Registry.as(JSONExtensions.JSONContribution); +jsonRegistry.registerSchema(schemaId, schema); \ No newline at end of file diff --git a/src/vs/workbench/workbench.main.ts b/src/vs/workbench/workbench.main.ts index 260fcc01793..0efbcde5c55 100644 --- a/src/vs/workbench/workbench.main.ts +++ b/src/vs/workbench/workbench.main.ts @@ -79,7 +79,6 @@ import 'vs/workbench/parts/terminal/browser/terminalQuickOpen'; import 'vs/workbench/parts/terminal/electron-browser/terminalPanel'; // can be packaged separately import 'vs/workbench/electron-browser/workbench'; -import 'vs/workbench/electron-browser/configureLocale'; import 'vs/workbench/parts/trust/electron-browser/unsupportedWorkspaceSettings.contribution';