Path: blob/main/src/vs/workbench/contrib/preferences/browser/preferences.contribution.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { KeyChord, KeyCode, KeyMod } from '../../../../base/common/keyCodes.js';6import { Disposable, DisposableStore, MutableDisposable } from '../../../../base/common/lifecycle.js';7import { Schemas } from '../../../../base/common/network.js';8import { isBoolean, isObject, isString } from '../../../../base/common/types.js';9import { URI } from '../../../../base/common/uri.js';10import { ICodeEditor, isCodeEditor } from '../../../../editor/browser/editorBrowser.js';11import { EditorContributionInstantiation, registerEditorContribution } from '../../../../editor/browser/editorExtensions.js';12import { Context as SuggestContext } from '../../../../editor/contrib/suggest/browser/suggest.js';13import * as nls from '../../../../nls.js';14import { Categories } from '../../../../platform/action/common/actionCommonCategories.js';15import { Action2, MenuId, MenuRegistry, registerAction2 } from '../../../../platform/actions/common/actions.js';16import { CommandsRegistry, ICommandService } from '../../../../platform/commands/common/commands.js';17import { ConfigurationTarget } from '../../../../platform/configuration/common/configuration.js';18import { ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js';19import { InputFocusedContext, IsMacNativeContext } from '../../../../platform/contextkey/common/contextkeys.js';20import { SyncDescriptor } from '../../../../platform/instantiation/common/descriptors.js';21import { IInstantiationService, ServicesAccessor } from '../../../../platform/instantiation/common/instantiation.js';22import { KeybindingWeight, KeybindingsRegistry } from '../../../../platform/keybinding/common/keybindingsRegistry.js';23import { ILabelService } from '../../../../platform/label/common/label.js';24import { IListService } from '../../../../platform/list/browser/listService.js';25import { Registry } from '../../../../platform/registry/common/platform.js';26import { IUserDataProfilesService } from '../../../../platform/userDataProfile/common/userDataProfile.js';27import { IWorkspaceContextService, IWorkspaceFolder, WorkbenchState } from '../../../../platform/workspace/common/workspace.js';28import { PICK_WORKSPACE_FOLDER_COMMAND_ID } from '../../../browser/actions/workspaceCommands.js';29import { EditorPaneDescriptor, IEditorPaneRegistry } from '../../../browser/editor.js';30import { resolveCommandsContext } from '../../../browser/parts/editor/editorCommandsContext.js';31import { RemoteNameContext, ResourceContextKey, WorkbenchStateContext } from '../../../common/contextkeys.js';32import { IWorkbenchContribution, WorkbenchPhase, registerWorkbenchContribution2 } from '../../../common/contributions.js';33import { EditorExtensions, IEditorFactoryRegistry, IEditorSerializer } from '../../../common/editor.js';34import { EditorInput } from '../../../common/editor/editorInput.js';35import { IEditorGroup, IEditorGroupsService } from '../../../services/editor/common/editorGroupsService.js';36import { IEditorService } from '../../../services/editor/common/editorService.js';37import { IWorkbenchEnvironmentService } from '../../../services/environment/common/environmentService.js';38import { IExtensionService } from '../../../services/extensions/common/extensions.js';39import { KeybindingsEditorInput } from '../../../services/preferences/browser/keybindingsEditorInput.js';40import { DEFINE_KEYBINDING_EDITOR_CONTRIB_ID, IDefineKeybindingEditorContribution, IPreferencesService } from '../../../services/preferences/common/preferences.js';41import { PreferencesEditorInput, SettingsEditor2Input } from '../../../services/preferences/common/preferencesEditorInput.js';42import { SettingsEditorModel } from '../../../services/preferences/common/preferencesModels.js';43import { CURRENT_PROFILE_CONTEXT, IUserDataProfileService } from '../../../services/userDataProfile/common/userDataProfile.js';44import { ExplorerFolderContext, ExplorerRootContext } from '../../files/common/files.js';45import { CONTEXT_AI_SETTING_RESULTS_AVAILABLE, CONTEXT_KEYBINDINGS_EDITOR, CONTEXT_KEYBINDINGS_SEARCH_FOCUS, CONTEXT_KEYBINDING_FOCUS, CONTEXT_SETTINGS_EDITOR, CONTEXT_SETTINGS_JSON_EDITOR, CONTEXT_SETTINGS_ROW_FOCUS, CONTEXT_SETTINGS_SEARCH_FOCUS, CONTEXT_TOC_ROW_FOCUS, CONTEXT_WHEN_FOCUS, KEYBINDINGS_EDITOR_COMMAND_ACCEPT_WHEN, KEYBINDINGS_EDITOR_COMMAND_ADD, KEYBINDINGS_EDITOR_COMMAND_CLEAR_SEARCH_HISTORY, KEYBINDINGS_EDITOR_COMMAND_CLEAR_SEARCH_RESULTS, KEYBINDINGS_EDITOR_COMMAND_COPY, KEYBINDINGS_EDITOR_COMMAND_COPY_COMMAND, KEYBINDINGS_EDITOR_COMMAND_COPY_COMMAND_TITLE, KEYBINDINGS_EDITOR_COMMAND_DEFINE, KEYBINDINGS_EDITOR_COMMAND_DEFINE_WHEN, KEYBINDINGS_EDITOR_COMMAND_FOCUS_KEYBINDINGS, KEYBINDINGS_EDITOR_COMMAND_RECORD_SEARCH_KEYS, KEYBINDINGS_EDITOR_COMMAND_REJECT_WHEN, KEYBINDINGS_EDITOR_COMMAND_REMOVE, KEYBINDINGS_EDITOR_COMMAND_RESET, KEYBINDINGS_EDITOR_COMMAND_SEARCH, KEYBINDINGS_EDITOR_COMMAND_SHOW_SIMILAR, KEYBINDINGS_EDITOR_COMMAND_SORTBY_PRECEDENCE, KEYBINDINGS_EDITOR_SHOW_DEFAULT_KEYBINDINGS, KEYBINDINGS_EDITOR_SHOW_EXTENSION_KEYBINDINGS, KEYBINDINGS_EDITOR_SHOW_USER_KEYBINDINGS, REQUIRE_TRUSTED_WORKSPACE_SETTING_TAG, SETTINGS_EDITOR_COMMAND_CLEAR_SEARCH_RESULTS, SETTINGS_EDITOR_COMMAND_SHOW_CONTEXT_MENU, SETTINGS_EDITOR_COMMAND_TOGGLE_AI_SEARCH } from '../common/preferences.js';46import { PreferencesContribution } from '../common/preferencesContribution.js';47import { KeybindingsEditor } from './keybindingsEditor.js';48import { ConfigureLanguageBasedSettingsAction } from './preferencesActions.js';49import { PreferencesEditor } from './preferencesEditor.js';50import { preferencesOpenSettingsIcon } from './preferencesIcons.js';51import { IPreferencesRenderer, UserSettingsRenderer, WorkspaceSettingsRenderer } from './preferencesRenderers.js';52import { SettingsEditor2, SettingsFocusContext } from './settingsEditor2.js';5354const SETTINGS_EDITOR_COMMAND_SEARCH = 'settings.action.search';5556const SETTINGS_EDITOR_COMMAND_FOCUS_FILE = 'settings.action.focusSettingsFile';57const SETTINGS_EDITOR_COMMAND_FOCUS_SETTINGS_FROM_SEARCH = 'settings.action.focusSettingsFromSearch';58const SETTINGS_EDITOR_COMMAND_FOCUS_SETTINGS_LIST = 'settings.action.focusSettingsList';59const SETTINGS_EDITOR_COMMAND_FOCUS_TOC = 'settings.action.focusTOC';60const SETTINGS_EDITOR_COMMAND_FOCUS_CONTROL = 'settings.action.focusSettingControl';61const SETTINGS_EDITOR_COMMAND_FOCUS_UP = 'settings.action.focusLevelUp';6263const SETTINGS_EDITOR_COMMAND_SWITCH_TO_JSON = 'settings.switchToJSON';64const SETTINGS_EDITOR_COMMAND_FILTER_ONLINE = 'settings.filterByOnline';65const SETTINGS_EDITOR_COMMAND_FILTER_UNTRUSTED = 'settings.filterUntrusted';6667const SETTINGS_COMMAND_OPEN_SETTINGS = 'workbench.action.openSettings';68const SETTINGS_COMMAND_FILTER_TELEMETRY = 'settings.filterByTelemetry';6970Registry.as<IEditorPaneRegistry>(EditorExtensions.EditorPane).registerEditorPane(71EditorPaneDescriptor.create(72SettingsEditor2,73SettingsEditor2.ID,74nls.localize('settingsEditor2', "Settings Editor 2")75),76[77new SyncDescriptor(SettingsEditor2Input)78]79);8081Registry.as<IEditorPaneRegistry>(EditorExtensions.EditorPane).registerEditorPane(82EditorPaneDescriptor.create(83PreferencesEditor,84PreferencesEditor.ID,85nls.localize('preferencesEditor', "Preferences Editor")86),87[88new SyncDescriptor(PreferencesEditorInput)89]90);9192class PreferencesEditorInputSerializer implements IEditorSerializer {9394canSerialize(editorInput: EditorInput): boolean {95return true;96}9798serialize(editorInput: EditorInput): string {99return '';100}101102deserialize(instantiationService: IInstantiationService): EditorInput {103return instantiationService.createInstance(PreferencesEditorInput);104}105}106107Registry.as<IEditorPaneRegistry>(EditorExtensions.EditorPane).registerEditorPane(108EditorPaneDescriptor.create(109KeybindingsEditor,110KeybindingsEditor.ID,111nls.localize('keybindingsEditor', "Keybindings Editor")112),113[114new SyncDescriptor(KeybindingsEditorInput)115]116);117118class KeybindingsEditorInputSerializer implements IEditorSerializer {119120canSerialize(editorInput: EditorInput): boolean {121return true;122}123124serialize(editorInput: EditorInput): string {125return '';126}127128deserialize(instantiationService: IInstantiationService): EditorInput {129return instantiationService.createInstance(KeybindingsEditorInput);130}131}132133class SettingsEditor2InputSerializer implements IEditorSerializer {134135canSerialize(editorInput: EditorInput): boolean {136return true;137}138139serialize(input: SettingsEditor2Input): string {140return '';141}142143deserialize(instantiationService: IInstantiationService): SettingsEditor2Input {144return instantiationService.createInstance(SettingsEditor2Input);145}146}147148Registry.as<IEditorFactoryRegistry>(EditorExtensions.EditorFactory).registerEditorSerializer(PreferencesEditorInput.ID, PreferencesEditorInputSerializer);149Registry.as<IEditorFactoryRegistry>(EditorExtensions.EditorFactory).registerEditorSerializer(KeybindingsEditorInput.ID, KeybindingsEditorInputSerializer);150Registry.as<IEditorFactoryRegistry>(EditorExtensions.EditorFactory).registerEditorSerializer(SettingsEditor2Input.ID, SettingsEditor2InputSerializer);151152const OPEN_USER_SETTINGS_UI_TITLE = nls.localize2('openSettings2', "Open Settings (UI)");153const OPEN_USER_SETTINGS_JSON_TITLE = nls.localize2('openUserSettingsJson', "Open User Settings (JSON)");154const OPEN_APPLICATION_SETTINGS_JSON_TITLE = nls.localize2('openApplicationSettingsJson', "Open Application Settings (JSON)");155const category = Categories.Preferences;156157interface IOpenSettingsActionOptions {158openToSide?: boolean;159query?: string;160revealSetting?: {161key: string;162edit?: boolean;163};164focusSearch?: boolean;165}166167function sanitizeBoolean(arg: any): boolean | undefined {168return isBoolean(arg) ? arg : undefined;169}170171function sanitizeString(arg: any): string | undefined {172return isString(arg) ? arg : undefined;173}174175function sanitizeOpenSettingsArgs(args: any): IOpenSettingsActionOptions {176if (!isObject(args)) {177args = {};178}179180let sanitizedObject: IOpenSettingsActionOptions = {181focusSearch: sanitizeBoolean(args?.focusSearch),182openToSide: sanitizeBoolean(args?.openToSide),183query: sanitizeString(args?.query)184};185186if (isString(args?.revealSetting?.key)) {187sanitizedObject = {188...sanitizedObject,189revealSetting: {190key: args.revealSetting.key,191edit: sanitizeBoolean(args.revealSetting?.edit)192}193};194}195196return sanitizedObject;197}198199class PreferencesActionsContribution extends Disposable implements IWorkbenchContribution {200201static readonly ID = 'workbench.contrib.preferencesActions';202203constructor(204@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,205@IUserDataProfileService private readonly userDataProfileService: IUserDataProfileService,206@IPreferencesService private readonly preferencesService: IPreferencesService,207@IWorkspaceContextService private readonly workspaceContextService: IWorkspaceContextService,208@ILabelService private readonly labelService: ILabelService,209@IExtensionService private readonly extensionService: IExtensionService,210@IUserDataProfilesService private readonly userDataProfilesService: IUserDataProfilesService,211) {212super();213214this.registerSettingsActions();215this.registerKeybindingsActions();216217this.updatePreferencesEditorMenuItem();218this._register(workspaceContextService.onDidChangeWorkbenchState(() => this.updatePreferencesEditorMenuItem()));219this._register(workspaceContextService.onDidChangeWorkspaceFolders(() => this.updatePreferencesEditorMenuItemForWorkspaceFolders()));220}221222private registerSettingsActions() {223this._register(registerAction2(class extends Action2 {224constructor() {225super({226id: SETTINGS_COMMAND_OPEN_SETTINGS,227title: {228...nls.localize2('settings', "Settings"),229mnemonicTitle: nls.localize({ key: 'miOpenSettings', comment: ['&& denotes a mnemonic'] }, "&&Settings"),230},231keybinding: {232weight: KeybindingWeight.WorkbenchContrib,233when: null,234primary: KeyMod.CtrlCmd | KeyCode.Comma,235},236menu: [{237id: MenuId.GlobalActivity,238group: '2_configuration',239order: 2240}, {241id: MenuId.MenubarPreferencesMenu,242group: '2_configuration',243order: 2244}],245});246}247run(accessor: ServicesAccessor, args: string | IOpenSettingsActionOptions) {248// args takes a string for backcompat249const opts = typeof args === 'string' ? { query: args } : sanitizeOpenSettingsArgs(args);250return accessor.get(IPreferencesService).openSettings(opts);251}252}));253this._register(registerAction2(class extends Action2 {254constructor() {255super({256id: 'workbench.action.openSettings2',257title: nls.localize2('openSettings2', "Open Settings (UI)"),258category,259f1: true,260});261}262run(accessor: ServicesAccessor, args: IOpenSettingsActionOptions) {263args = sanitizeOpenSettingsArgs(args);264return accessor.get(IPreferencesService).openSettings({ jsonEditor: false, ...args });265}266}));267268this._register(registerAction2(class extends Action2 {269constructor() {270super({271id: 'workbench.action.openSettingsJson',272title: OPEN_USER_SETTINGS_JSON_TITLE,273metadata: {274description: nls.localize2('workbench.action.openSettingsJson.description', "Opens the JSON file containing the current user profile settings")275},276category,277f1: true,278});279}280run(accessor: ServicesAccessor, args: IOpenSettingsActionOptions) {281args = sanitizeOpenSettingsArgs(args);282return accessor.get(IPreferencesService).openSettings({ jsonEditor: true, ...args });283}284}));285286const that = this;287this._register(registerAction2(class extends Action2 {288constructor() {289super({290id: 'workbench.action.openApplicationSettingsJson',291title: OPEN_APPLICATION_SETTINGS_JSON_TITLE,292category,293menu: {294id: MenuId.CommandPalette,295when: ContextKeyExpr.notEquals(CURRENT_PROFILE_CONTEXT.key, that.userDataProfilesService.defaultProfile.id)296}297});298}299run(accessor: ServicesAccessor, args: IOpenSettingsActionOptions) {300args = sanitizeOpenSettingsArgs(args);301return accessor.get(IPreferencesService).openApplicationSettings({ jsonEditor: true, ...args });302}303}));304305// Opens the User tab of the Settings editor306this._register(registerAction2(class extends Action2 {307constructor() {308super({309id: 'workbench.action.openGlobalSettings',310title: nls.localize2('openGlobalSettings', "Open User Settings"),311category,312f1: true,313});314}315run(accessor: ServicesAccessor, args: IOpenSettingsActionOptions) {316args = sanitizeOpenSettingsArgs(args);317return accessor.get(IPreferencesService).openUserSettings(args);318}319}));320this._register(registerAction2(class extends Action2 {321constructor() {322super({323id: 'workbench.action.openRawDefaultSettings',324title: nls.localize2('openRawDefaultSettings', "Open Default Settings (JSON)"),325category,326f1: true,327});328}329run(accessor: ServicesAccessor) {330return accessor.get(IPreferencesService).openRawDefaultSettings();331}332}));333334this._register(registerAction2(class extends Action2 {335constructor() {336super({337id: ConfigureLanguageBasedSettingsAction.ID,338title: ConfigureLanguageBasedSettingsAction.LABEL,339category,340f1: true,341});342}343run(accessor: ServicesAccessor) {344return accessor.get(IInstantiationService).createInstance(ConfigureLanguageBasedSettingsAction, ConfigureLanguageBasedSettingsAction.ID, ConfigureLanguageBasedSettingsAction.LABEL.value).run();345}346}));347this._register(registerAction2(class extends Action2 {348constructor() {349super({350id: 'workbench.action.openWorkspaceSettings',351title: nls.localize2('openWorkspaceSettings', "Open Workspace Settings"),352category,353menu: {354id: MenuId.CommandPalette,355when: WorkbenchStateContext.notEqualsTo('empty')356}357});358}359run(accessor: ServicesAccessor, args?: string | IOpenSettingsActionOptions) {360// Match the behaviour of workbench.action.openSettings361args = typeof args === 'string' ? { query: args } : sanitizeOpenSettingsArgs(args);362return accessor.get(IPreferencesService).openWorkspaceSettings(args);363}364}));365366this._register(registerAction2(class extends Action2 {367constructor() {368super({369id: 'workbench.action.openAccessibilitySettings',370title: nls.localize2('openAccessibilitySettings', "Open Accessibility Settings"),371category,372menu: {373id: MenuId.CommandPalette,374when: WorkbenchStateContext.notEqualsTo('empty')375}376});377}378async run(accessor: ServicesAccessor) {379await accessor.get(IPreferencesService).openSettings({ jsonEditor: false, query: '@tag:accessibility' });380}381}));382this._register(registerAction2(class extends Action2 {383constructor() {384super({385id: 'workbench.action.openWorkspaceSettingsFile',386title: nls.localize2('openWorkspaceSettingsFile', "Open Workspace Settings (JSON)"),387category,388menu: {389id: MenuId.CommandPalette,390when: WorkbenchStateContext.notEqualsTo('empty')391}392});393}394run(accessor: ServicesAccessor, args?: IOpenSettingsActionOptions) {395args = sanitizeOpenSettingsArgs(args);396return accessor.get(IPreferencesService).openWorkspaceSettings({ jsonEditor: true, ...args });397}398}));399this._register(registerAction2(class extends Action2 {400constructor() {401super({402id: 'workbench.action.openFolderSettings',403title: nls.localize2('openFolderSettings', "Open Folder Settings"),404category,405menu: {406id: MenuId.CommandPalette,407when: WorkbenchStateContext.isEqualTo('workspace')408}409});410}411async run(accessor: ServicesAccessor, args?: IOpenSettingsActionOptions) {412const commandService = accessor.get(ICommandService);413const preferencesService = accessor.get(IPreferencesService);414const workspaceFolder = await commandService.executeCommand<IWorkspaceFolder>(PICK_WORKSPACE_FOLDER_COMMAND_ID);415if (workspaceFolder) {416args = sanitizeOpenSettingsArgs(args);417await preferencesService.openFolderSettings({ folderUri: workspaceFolder.uri, ...args });418}419}420}));421this._register(registerAction2(class extends Action2 {422constructor() {423super({424id: 'workbench.action.openFolderSettingsFile',425title: nls.localize2('openFolderSettingsFile', "Open Folder Settings (JSON)"),426category,427menu: {428id: MenuId.CommandPalette,429when: WorkbenchStateContext.isEqualTo('workspace')430}431});432}433async run(accessor: ServicesAccessor, args?: IOpenSettingsActionOptions) {434const commandService = accessor.get(ICommandService);435const preferencesService = accessor.get(IPreferencesService);436const workspaceFolder = await commandService.executeCommand<IWorkspaceFolder>(PICK_WORKSPACE_FOLDER_COMMAND_ID);437if (workspaceFolder) {438args = sanitizeOpenSettingsArgs(args);439await preferencesService.openFolderSettings({ folderUri: workspaceFolder.uri, jsonEditor: true, ...args });440}441}442}));443this._register(registerAction2(class extends Action2 {444constructor() {445super({446id: '_workbench.action.openFolderSettings',447title: nls.localize('openFolderSettings', "Open Folder Settings"),448category,449menu: {450id: MenuId.ExplorerContext,451group: '2_workspace',452order: 20,453when: ContextKeyExpr.and(ExplorerRootContext, ExplorerFolderContext)454}455});456}457async run(accessor: ServicesAccessor, resource?: URI) {458if (URI.isUri(resource)) {459await accessor.get(IPreferencesService).openFolderSettings({ folderUri: resource });460} else {461const commandService = accessor.get(ICommandService);462const preferencesService = accessor.get(IPreferencesService);463const workspaceFolder = await commandService.executeCommand<IWorkspaceFolder>(PICK_WORKSPACE_FOLDER_COMMAND_ID);464if (workspaceFolder) {465await preferencesService.openFolderSettings({ folderUri: workspaceFolder.uri });466}467}468}469}));470this._register(registerAction2(class extends Action2 {471constructor() {472super({473id: SETTINGS_EDITOR_COMMAND_FILTER_ONLINE,474title: nls.localize({ key: 'miOpenOnlineSettings', comment: ['&& denotes a mnemonic'] }, "&&Online Services Settings"),475menu: {476id: MenuId.MenubarPreferencesMenu,477group: '3_settings',478order: 1,479}480});481}482run(accessor: ServicesAccessor) {483const editorPane = accessor.get(IEditorService).activeEditorPane;484if (editorPane instanceof SettingsEditor2) {485editorPane.focusSearch(`@tag:usesOnlineServices`);486} else {487accessor.get(IPreferencesService).openSettings({ jsonEditor: false, query: '@tag:usesOnlineServices' });488}489}490}));491this._register(registerAction2(class extends Action2 {492constructor() {493super({494id: SETTINGS_EDITOR_COMMAND_TOGGLE_AI_SEARCH,495precondition: CONTEXT_SETTINGS_EDITOR,496keybinding: {497primary: KeyMod.CtrlCmd | KeyCode.KeyI,498weight: KeybindingWeight.EditorContrib,499when: CONTEXT_AI_SETTING_RESULTS_AVAILABLE500},501category,502f1: true,503title: nls.localize2('settings.toggleAiSearch', "Toggle AI Settings Search")504});505}506run(accessor: ServicesAccessor) {507const editorPane = accessor.get(IEditorService).activeEditorPane;508if (editorPane instanceof SettingsEditor2) {509editorPane.toggleAiSearch();510}511}512}));513this._register(registerAction2(class extends Action2 {514constructor() {515super({516id: SETTINGS_EDITOR_COMMAND_FILTER_UNTRUSTED,517title: nls.localize2('filterUntrusted', "Show untrusted workspace settings"),518});519}520run(accessor: ServicesAccessor) {521accessor.get(IPreferencesService).openWorkspaceSettings({ jsonEditor: false, query: `@tag:${REQUIRE_TRUSTED_WORKSPACE_SETTING_TAG}` });522}523}));524525this._register(registerAction2(class extends Action2 {526constructor() {527super({528id: SETTINGS_COMMAND_FILTER_TELEMETRY,529title: nls.localize({ key: 'miOpenTelemetrySettings', comment: ['&& denotes a mnemonic'] }, "&&Telemetry Settings")530});531}532run(accessor: ServicesAccessor) {533const editorPane = accessor.get(IEditorService).activeEditorPane;534if (editorPane instanceof SettingsEditor2) {535editorPane.focusSearch(`@tag:telemetry`);536} else {537accessor.get(IPreferencesService).openSettings({ jsonEditor: false, query: '@tag:telemetry' });538}539}540}));541542this.registerSettingsEditorActions();543544this.extensionService.whenInstalledExtensionsRegistered()545.then(() => {546const remoteAuthority = this.environmentService.remoteAuthority;547const hostLabel = this.labelService.getHostLabel(Schemas.vscodeRemote, remoteAuthority) || remoteAuthority;548this._register(registerAction2(class extends Action2 {549constructor() {550super({551id: 'workbench.action.openRemoteSettings',552title: nls.localize2('openRemoteSettings', "Open Remote Settings ({0})", hostLabel),553category,554menu: {555id: MenuId.CommandPalette,556when: RemoteNameContext.notEqualsTo('')557}558});559}560run(accessor: ServicesAccessor, args?: IOpenSettingsActionOptions) {561args = sanitizeOpenSettingsArgs(args);562return accessor.get(IPreferencesService).openRemoteSettings(args);563}564}));565this._register(registerAction2(class extends Action2 {566constructor() {567super({568id: 'workbench.action.openRemoteSettingsFile',569title: nls.localize2('openRemoteSettingsJSON', "Open Remote Settings (JSON) ({0})", hostLabel),570category,571menu: {572id: MenuId.CommandPalette,573when: RemoteNameContext.notEqualsTo('')574}575});576}577run(accessor: ServicesAccessor, args?: IOpenSettingsActionOptions) {578args = sanitizeOpenSettingsArgs(args);579return accessor.get(IPreferencesService).openRemoteSettings({ jsonEditor: true, ...args });580}581}));582});583}584585private registerSettingsEditorActions() {586function getPreferencesEditor(accessor: ServicesAccessor): SettingsEditor2 | null {587const activeEditorPane = accessor.get(IEditorService).activeEditorPane;588if (activeEditorPane instanceof SettingsEditor2) {589return activeEditorPane;590}591return null;592}593594function settingsEditorFocusSearch(accessor: ServicesAccessor) {595const preferencesEditor = getPreferencesEditor(accessor);596preferencesEditor?.focusSearch();597}598599this._register(registerAction2(class extends Action2 {600constructor() {601super({602id: SETTINGS_EDITOR_COMMAND_SEARCH,603precondition: CONTEXT_SETTINGS_EDITOR,604keybinding: {605primary: KeyMod.CtrlCmd | KeyCode.KeyF,606weight: KeybindingWeight.EditorContrib,607when: null608},609category,610f1: true,611title: nls.localize2('settings.focusSearch', "Focus Settings Search")612});613}614615run(accessor: ServicesAccessor) { settingsEditorFocusSearch(accessor); }616}));617618this._register(registerAction2(class extends Action2 {619constructor() {620super({621id: SETTINGS_EDITOR_COMMAND_CLEAR_SEARCH_RESULTS,622precondition: CONTEXT_SETTINGS_EDITOR,623keybinding: {624primary: KeyCode.Escape,625weight: KeybindingWeight.EditorContrib,626when: CONTEXT_SETTINGS_SEARCH_FOCUS627},628category,629f1: true,630title: nls.localize2('settings.clearResults', "Clear Settings Search Results")631});632}633634run(accessor: ServicesAccessor) {635const preferencesEditor = getPreferencesEditor(accessor);636preferencesEditor?.clearSearchResults();637}638}));639640this._register(registerAction2(class extends Action2 {641constructor() {642super({643id: SETTINGS_EDITOR_COMMAND_FOCUS_FILE,644precondition: ContextKeyExpr.and(CONTEXT_SETTINGS_SEARCH_FOCUS, SuggestContext.Visible.toNegated()),645keybinding: {646primary: KeyCode.DownArrow,647weight: KeybindingWeight.EditorContrib,648when: null649},650title: nls.localize('settings.focusFile', "Focus settings file")651});652}653654run(accessor: ServicesAccessor, args: any): void {655const preferencesEditor = getPreferencesEditor(accessor);656preferencesEditor?.focusSettings();657}658}));659660this._register(registerAction2(class extends Action2 {661constructor() {662super({663id: SETTINGS_EDITOR_COMMAND_FOCUS_SETTINGS_FROM_SEARCH,664precondition: ContextKeyExpr.and(CONTEXT_SETTINGS_SEARCH_FOCUS, SuggestContext.Visible.toNegated()),665keybinding: {666primary: KeyCode.DownArrow,667weight: KeybindingWeight.WorkbenchContrib,668when: null669},670title: nls.localize('settings.focusFile', "Focus settings file")671});672}673674run(accessor: ServicesAccessor, args: any): void {675const preferencesEditor = getPreferencesEditor(accessor);676preferencesEditor?.focusSettings();677}678}));679680this._register(registerAction2(class extends Action2 {681constructor() {682super({683id: SETTINGS_EDITOR_COMMAND_FOCUS_SETTINGS_LIST,684precondition: ContextKeyExpr.and(CONTEXT_SETTINGS_EDITOR, CONTEXT_TOC_ROW_FOCUS),685keybinding: {686primary: KeyCode.Enter,687weight: KeybindingWeight.WorkbenchContrib,688when: null689},690title: nls.localize('settings.focusSettingsList', "Focus settings list")691});692}693694run(accessor: ServicesAccessor): void {695const preferencesEditor = getPreferencesEditor(accessor);696if (preferencesEditor instanceof SettingsEditor2) {697preferencesEditor.focusSettings();698}699}700}));701702this._register(registerAction2(class extends Action2 {703constructor() {704super({705id: SETTINGS_EDITOR_COMMAND_FOCUS_TOC,706precondition: CONTEXT_SETTINGS_EDITOR,707f1: true,708keybinding: [709{710primary: KeyCode.LeftArrow,711weight: KeybindingWeight.WorkbenchContrib,712when: CONTEXT_SETTINGS_ROW_FOCUS713}],714category,715title: nls.localize2('settings.focusSettingsTOC', "Focus Settings Table of Contents")716});717}718719run(accessor: ServicesAccessor): void {720const preferencesEditor = getPreferencesEditor(accessor);721if (!(preferencesEditor instanceof SettingsEditor2)) {722return;723}724725preferencesEditor.focusTOC();726}727}));728729this._register(registerAction2(class extends Action2 {730constructor() {731super({732id: SETTINGS_EDITOR_COMMAND_FOCUS_CONTROL,733precondition: ContextKeyExpr.and(CONTEXT_SETTINGS_EDITOR, CONTEXT_SETTINGS_ROW_FOCUS),734keybinding: {735primary: KeyCode.Enter,736weight: KeybindingWeight.WorkbenchContrib,737},738title: nls.localize('settings.focusSettingControl', "Focus Setting Control")739});740}741742run(accessor: ServicesAccessor): void {743const preferencesEditor = getPreferencesEditor(accessor);744if (!(preferencesEditor instanceof SettingsEditor2)) {745return;746}747748const activeElement = preferencesEditor.getContainer()?.ownerDocument.activeElement;749if (activeElement?.classList.contains('monaco-list')) {750preferencesEditor.focusSettings(true);751}752}753}));754755this._register(registerAction2(class extends Action2 {756constructor() {757super({758id: SETTINGS_EDITOR_COMMAND_SHOW_CONTEXT_MENU,759precondition: CONTEXT_SETTINGS_EDITOR,760keybinding: {761primary: KeyMod.Shift | KeyCode.F9,762weight: KeybindingWeight.WorkbenchContrib,763when: null764},765f1: true,766category,767title: nls.localize2('settings.showContextMenu', "Show Setting Context Menu")768});769}770771run(accessor: ServicesAccessor): void {772const preferencesEditor = getPreferencesEditor(accessor);773if (preferencesEditor instanceof SettingsEditor2) {774preferencesEditor.showContextMenu();775}776}777}));778779this._register(registerAction2(class extends Action2 {780constructor() {781super({782id: SETTINGS_EDITOR_COMMAND_FOCUS_UP,783precondition: ContextKeyExpr.and(CONTEXT_SETTINGS_EDITOR, CONTEXT_SETTINGS_SEARCH_FOCUS.toNegated(), CONTEXT_SETTINGS_JSON_EDITOR.toNegated()),784keybinding: {785primary: KeyCode.Escape,786weight: KeybindingWeight.WorkbenchContrib,787when: null788},789f1: true,790category,791title: nls.localize2('settings.focusLevelUp', "Move Focus Up One Level")792});793}794795run(accessor: ServicesAccessor): void {796const preferencesEditor = getPreferencesEditor(accessor);797if (!(preferencesEditor instanceof SettingsEditor2)) {798return;799}800801if (preferencesEditor.currentFocusContext === SettingsFocusContext.SettingControl) {802preferencesEditor.focusSettings();803} else if (preferencesEditor.currentFocusContext === SettingsFocusContext.SettingTree) {804preferencesEditor.focusTOC();805} else if (preferencesEditor.currentFocusContext === SettingsFocusContext.TableOfContents) {806preferencesEditor.focusSearch();807}808}809}));810}811812private registerKeybindingsActions() {813const that = this;814const category = nls.localize2('preferences', "Preferences");815const id = 'workbench.action.openGlobalKeybindings';816this._register(registerAction2(class extends Action2 {817constructor() {818super({819id,820title: nls.localize2('openGlobalKeybindings', "Open Keyboard Shortcuts"),821shortTitle: nls.localize('keyboardShortcuts', "Keyboard Shortcuts"),822category,823icon: preferencesOpenSettingsIcon,824keybinding: {825when: null,826weight: KeybindingWeight.WorkbenchContrib,827primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KeyK, KeyMod.CtrlCmd | KeyCode.KeyS)828},829menu: [830{ id: MenuId.CommandPalette },831{832id: MenuId.EditorTitle,833when: ResourceContextKey.Resource.isEqualTo(that.userDataProfileService.currentProfile.keybindingsResource.toString()),834group: 'navigation',835order: 1,836},837{838id: MenuId.GlobalActivity,839group: '2_configuration',840order: 4841}842]843});844}845run(accessor: ServicesAccessor, ...args: unknown[]) {846const query = typeof args[0] === 'string' ? args[0] : undefined;847const groupId = getEditorGroupFromArguments(accessor, args)?.id;848return accessor.get(IPreferencesService).openGlobalKeybindingSettings(false, { query, groupId });849}850}));851this._register(MenuRegistry.appendMenuItem(MenuId.MenubarPreferencesMenu, {852command: {853id,854title: nls.localize('keyboardShortcuts', "Keyboard Shortcuts"),855},856group: '2_configuration',857order: 4858}));859this._register(registerAction2(class extends Action2 {860constructor() {861super({862id: 'workbench.action.openDefaultKeybindingsFile',863title: nls.localize2('openDefaultKeybindingsFile', "Open Default Keyboard Shortcuts (JSON)"),864category,865menu: { id: MenuId.CommandPalette }866});867}868run(accessor: ServicesAccessor) {869return accessor.get(IPreferencesService).openDefaultKeybindingsFile();870}871}));872this._register(registerAction2(class extends Action2 {873constructor() {874super({875id: 'workbench.action.openGlobalKeybindingsFile',876title: nls.localize2('openGlobalKeybindingsFile', "Open Keyboard Shortcuts (JSON)"),877category,878icon: preferencesOpenSettingsIcon,879menu: [880{ id: MenuId.CommandPalette },881{882id: MenuId.EditorTitle,883when: ContextKeyExpr.and(CONTEXT_KEYBINDINGS_EDITOR),884group: 'navigation',885}886]887});888}889run(accessor: ServicesAccessor, ...args: unknown[]) {890const groupId = getEditorGroupFromArguments(accessor, args)?.id;891return accessor.get(IPreferencesService).openGlobalKeybindingSettings(true, { groupId });892}893}));894this._register(registerAction2(class extends Action2 {895constructor() {896super({897id: KEYBINDINGS_EDITOR_SHOW_DEFAULT_KEYBINDINGS,898title: nls.localize2('showDefaultKeybindings', "Show System Keybindings"),899menu: [900{901id: MenuId.EditorTitle,902when: ContextKeyExpr.and(CONTEXT_KEYBINDINGS_EDITOR),903group: '1_keyboard_preferences_actions'904}905]906});907}908run(accessor: ServicesAccessor, ...args: unknown[]) {909const group = getEditorGroupFromArguments(accessor, args);910const editorPane = group?.activeEditorPane;911if (editorPane instanceof KeybindingsEditor) {912editorPane.search('@source:system');913}914}915}));916this._register(registerAction2(class extends Action2 {917constructor() {918super({919id: KEYBINDINGS_EDITOR_SHOW_EXTENSION_KEYBINDINGS,920title: nls.localize2('showExtensionKeybindings', "Show Extension Keybindings"),921menu: [922{923id: MenuId.EditorTitle,924when: ContextKeyExpr.and(CONTEXT_KEYBINDINGS_EDITOR),925group: '1_keyboard_preferences_actions'926}927]928});929}930run(accessor: ServicesAccessor, ...args: unknown[]) {931const group = getEditorGroupFromArguments(accessor, args);932const editorPane = group?.activeEditorPane;933if (editorPane instanceof KeybindingsEditor) {934editorPane.search('@source:extension');935}936}937}));938this._register(registerAction2(class extends Action2 {939constructor() {940super({941id: KEYBINDINGS_EDITOR_SHOW_USER_KEYBINDINGS,942title: nls.localize2('showUserKeybindings', "Show User Keybindings"),943menu: [944{945id: MenuId.EditorTitle,946when: ContextKeyExpr.and(CONTEXT_KEYBINDINGS_EDITOR),947group: '1_keyboard_preferences_actions'948}949]950});951}952run(accessor: ServicesAccessor, ...args: unknown[]) {953const group = getEditorGroupFromArguments(accessor, args);954const editorPane = group?.activeEditorPane;955if (editorPane instanceof KeybindingsEditor) {956editorPane.search('@source:user');957}958}959}));960this._register(registerAction2(class extends Action2 {961constructor() {962super({963id: KEYBINDINGS_EDITOR_COMMAND_CLEAR_SEARCH_RESULTS,964title: nls.localize('clear', "Clear Search Results"),965keybinding: {966weight: KeybindingWeight.WorkbenchContrib,967when: ContextKeyExpr.and(CONTEXT_KEYBINDINGS_EDITOR, CONTEXT_KEYBINDINGS_SEARCH_FOCUS),968primary: KeyCode.Escape,969}970});971}972run(accessor: ServicesAccessor) {973const editorPane = accessor.get(IEditorService).activeEditorPane;974if (editorPane instanceof KeybindingsEditor) {975editorPane.clearSearchResults();976}977}978}));979980this._register(registerAction2(class extends Action2 {981constructor() {982super({983id: KEYBINDINGS_EDITOR_COMMAND_CLEAR_SEARCH_HISTORY,984title: nls.localize('clearHistory', "Clear Keyboard Shortcuts Search History"),985category,986menu: [987{988id: MenuId.CommandPalette,989when: ContextKeyExpr.and(CONTEXT_KEYBINDINGS_EDITOR),990}991]992});993}994run(accessor: ServicesAccessor) {995const editorPane = accessor.get(IEditorService).activeEditorPane;996if (editorPane instanceof KeybindingsEditor) {997editorPane.clearKeyboardShortcutSearchHistory();998}999}1000}));10011002this.registerKeybindingEditorActions();1003}10041005private registerKeybindingEditorActions(): void {1006const that = this;10071008KeybindingsRegistry.registerCommandAndKeybindingRule({1009id: KEYBINDINGS_EDITOR_COMMAND_DEFINE,1010weight: KeybindingWeight.WorkbenchContrib,1011when: ContextKeyExpr.and(CONTEXT_KEYBINDINGS_EDITOR, CONTEXT_KEYBINDING_FOCUS, CONTEXT_WHEN_FOCUS.toNegated()),1012primary: KeyCode.Enter,1013handler: (accessor, args: any) => {1014const editorPane = accessor.get(IEditorService).activeEditorPane;1015if (editorPane instanceof KeybindingsEditor) {1016editorPane.defineKeybinding(editorPane.activeKeybindingEntry!, false);1017}1018}1019});10201021KeybindingsRegistry.registerCommandAndKeybindingRule({1022id: KEYBINDINGS_EDITOR_COMMAND_ADD,1023weight: KeybindingWeight.WorkbenchContrib,1024when: ContextKeyExpr.and(CONTEXT_KEYBINDINGS_EDITOR, CONTEXT_KEYBINDING_FOCUS),1025primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KeyK, KeyMod.CtrlCmd | KeyCode.KeyA),1026handler: (accessor, args: any) => {1027const editorPane = accessor.get(IEditorService).activeEditorPane;1028if (editorPane instanceof KeybindingsEditor) {1029editorPane.defineKeybinding(editorPane.activeKeybindingEntry!, true);1030}1031}1032});10331034KeybindingsRegistry.registerCommandAndKeybindingRule({1035id: KEYBINDINGS_EDITOR_COMMAND_DEFINE_WHEN,1036weight: KeybindingWeight.WorkbenchContrib,1037when: ContextKeyExpr.and(CONTEXT_KEYBINDINGS_EDITOR, CONTEXT_KEYBINDING_FOCUS),1038primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KeyK, KeyMod.CtrlCmd | KeyCode.KeyE),1039handler: (accessor, args: any) => {1040const editorPane = accessor.get(IEditorService).activeEditorPane;1041if (editorPane instanceof KeybindingsEditor && editorPane.activeKeybindingEntry!.keybindingItem.keybinding) {1042editorPane.defineWhenExpression(editorPane.activeKeybindingEntry!);1043}1044}1045});10461047KeybindingsRegistry.registerCommandAndKeybindingRule({1048id: KEYBINDINGS_EDITOR_COMMAND_REMOVE,1049weight: KeybindingWeight.WorkbenchContrib,1050when: ContextKeyExpr.and(CONTEXT_KEYBINDINGS_EDITOR, CONTEXT_KEYBINDING_FOCUS, InputFocusedContext.toNegated()),1051primary: KeyCode.Delete,1052mac: {1053primary: KeyMod.CtrlCmd | KeyCode.Backspace1054},1055handler: (accessor, args: any) => {1056const editorPane = accessor.get(IEditorService).activeEditorPane;1057if (editorPane instanceof KeybindingsEditor) {1058editorPane.removeKeybinding(editorPane.activeKeybindingEntry!);1059}1060}1061});10621063KeybindingsRegistry.registerCommandAndKeybindingRule({1064id: KEYBINDINGS_EDITOR_COMMAND_RESET,1065weight: KeybindingWeight.WorkbenchContrib,1066when: ContextKeyExpr.and(CONTEXT_KEYBINDINGS_EDITOR, CONTEXT_KEYBINDING_FOCUS),1067primary: 0,1068handler: (accessor, args: any) => {1069const editorPane = accessor.get(IEditorService).activeEditorPane;1070if (editorPane instanceof KeybindingsEditor) {1071editorPane.resetKeybinding(editorPane.activeKeybindingEntry!);1072}1073}1074});10751076KeybindingsRegistry.registerCommandAndKeybindingRule({1077id: KEYBINDINGS_EDITOR_COMMAND_SEARCH,1078weight: KeybindingWeight.WorkbenchContrib,1079when: ContextKeyExpr.and(CONTEXT_KEYBINDINGS_EDITOR),1080primary: KeyMod.CtrlCmd | KeyCode.KeyF,1081handler: (accessor, args: any) => {1082const editorPane = accessor.get(IEditorService).activeEditorPane;1083if (editorPane instanceof KeybindingsEditor) {1084editorPane.focusSearch();1085}1086}1087});10881089KeybindingsRegistry.registerCommandAndKeybindingRule({1090id: KEYBINDINGS_EDITOR_COMMAND_RECORD_SEARCH_KEYS,1091weight: KeybindingWeight.WorkbenchContrib,1092when: ContextKeyExpr.and(CONTEXT_KEYBINDINGS_EDITOR, CONTEXT_KEYBINDINGS_SEARCH_FOCUS),1093primary: KeyMod.Alt | KeyCode.KeyK,1094mac: { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.KeyK },1095handler: (accessor, args: any) => {1096const editorPane = accessor.get(IEditorService).activeEditorPane;1097if (editorPane instanceof KeybindingsEditor) {1098editorPane.recordSearchKeys();1099}1100}1101});11021103KeybindingsRegistry.registerCommandAndKeybindingRule({1104id: KEYBINDINGS_EDITOR_COMMAND_SORTBY_PRECEDENCE,1105weight: KeybindingWeight.WorkbenchContrib,1106when: ContextKeyExpr.and(CONTEXT_KEYBINDINGS_EDITOR),1107primary: KeyMod.Alt | KeyCode.KeyP,1108mac: { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.KeyP },1109handler: (accessor, args: any) => {1110const editorPane = accessor.get(IEditorService).activeEditorPane;1111if (editorPane instanceof KeybindingsEditor) {1112editorPane.toggleSortByPrecedence();1113}1114}1115});11161117KeybindingsRegistry.registerCommandAndKeybindingRule({1118id: KEYBINDINGS_EDITOR_COMMAND_SHOW_SIMILAR,1119weight: KeybindingWeight.WorkbenchContrib,1120when: ContextKeyExpr.and(CONTEXT_KEYBINDINGS_EDITOR, CONTEXT_KEYBINDING_FOCUS),1121primary: 0,1122handler: (accessor, args: any) => {1123const editorPane = accessor.get(IEditorService).activeEditorPane;1124if (editorPane instanceof KeybindingsEditor) {1125editorPane.showSimilarKeybindings(editorPane.activeKeybindingEntry!);1126}1127}1128});11291130KeybindingsRegistry.registerCommandAndKeybindingRule({1131id: KEYBINDINGS_EDITOR_COMMAND_COPY,1132weight: KeybindingWeight.WorkbenchContrib,1133when: ContextKeyExpr.and(CONTEXT_KEYBINDINGS_EDITOR, CONTEXT_KEYBINDING_FOCUS, CONTEXT_WHEN_FOCUS.negate()),1134primary: KeyMod.CtrlCmd | KeyCode.KeyC,1135handler: async (accessor, args: any) => {1136const editorPane = accessor.get(IEditorService).activeEditorPane;1137if (editorPane instanceof KeybindingsEditor) {1138await editorPane.copyKeybinding(editorPane.activeKeybindingEntry!);1139}1140}1141});11421143KeybindingsRegistry.registerCommandAndKeybindingRule({1144id: KEYBINDINGS_EDITOR_COMMAND_COPY_COMMAND,1145weight: KeybindingWeight.WorkbenchContrib,1146when: ContextKeyExpr.and(CONTEXT_KEYBINDINGS_EDITOR, CONTEXT_KEYBINDING_FOCUS),1147primary: 0,1148handler: async (accessor, args: any) => {1149const editorPane = accessor.get(IEditorService).activeEditorPane;1150if (editorPane instanceof KeybindingsEditor) {1151await editorPane.copyKeybindingCommand(editorPane.activeKeybindingEntry!);1152}1153}1154});11551156KeybindingsRegistry.registerCommandAndKeybindingRule({1157id: KEYBINDINGS_EDITOR_COMMAND_COPY_COMMAND_TITLE,1158weight: KeybindingWeight.WorkbenchContrib,1159when: ContextKeyExpr.and(CONTEXT_KEYBINDINGS_EDITOR, CONTEXT_KEYBINDING_FOCUS),1160primary: 0,1161handler: async (accessor, args: any) => {1162const editorPane = accessor.get(IEditorService).activeEditorPane;1163if (editorPane instanceof KeybindingsEditor) {1164await editorPane.copyKeybindingCommandTitle(editorPane.activeKeybindingEntry!);1165}1166}1167});11681169KeybindingsRegistry.registerCommandAndKeybindingRule({1170id: KEYBINDINGS_EDITOR_COMMAND_FOCUS_KEYBINDINGS,1171weight: KeybindingWeight.WorkbenchContrib,1172when: ContextKeyExpr.and(CONTEXT_KEYBINDINGS_EDITOR, CONTEXT_KEYBINDINGS_SEARCH_FOCUS),1173primary: KeyMod.CtrlCmd | KeyCode.DownArrow,1174handler: (accessor, args: any) => {1175const editorPane = accessor.get(IEditorService).activeEditorPane;1176if (editorPane instanceof KeybindingsEditor) {1177editorPane.focusKeybindings();1178}1179}1180});11811182KeybindingsRegistry.registerCommandAndKeybindingRule({1183id: KEYBINDINGS_EDITOR_COMMAND_REJECT_WHEN,1184weight: KeybindingWeight.WorkbenchContrib,1185when: ContextKeyExpr.and(CONTEXT_KEYBINDINGS_EDITOR, CONTEXT_WHEN_FOCUS, SuggestContext.Visible.toNegated()),1186primary: KeyCode.Escape,1187handler: async (accessor, args: any) => {1188const editorPane = accessor.get(IEditorService).activeEditorPane;1189if (editorPane instanceof KeybindingsEditor) {1190editorPane.rejectWhenExpression(editorPane.activeKeybindingEntry!);1191}1192}1193});11941195KeybindingsRegistry.registerCommandAndKeybindingRule({1196id: KEYBINDINGS_EDITOR_COMMAND_ACCEPT_WHEN,1197weight: KeybindingWeight.WorkbenchContrib,1198when: ContextKeyExpr.and(CONTEXT_KEYBINDINGS_EDITOR, CONTEXT_WHEN_FOCUS, SuggestContext.Visible.toNegated()),1199primary: KeyCode.Enter,1200handler: async (accessor, args: any) => {1201const editorPane = accessor.get(IEditorService).activeEditorPane;1202if (editorPane instanceof KeybindingsEditor) {1203editorPane.acceptWhenExpression(editorPane.activeKeybindingEntry!);1204}1205}1206});12071208const profileScopedActionDisposables = this._register(new DisposableStore());1209const registerProfileScopedActions = () => {1210profileScopedActionDisposables.clear();1211profileScopedActionDisposables.add(registerAction2(class DefineKeybindingAction extends Action2 {1212constructor() {1213const when = ResourceContextKey.Resource.isEqualTo(that.userDataProfileService.currentProfile.keybindingsResource.toString());1214super({1215id: 'editor.action.defineKeybinding',1216title: nls.localize2('defineKeybinding.start', "Define Keybinding"),1217f1: true,1218precondition: when,1219keybinding: {1220weight: KeybindingWeight.WorkbenchContrib,1221when,1222primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KeyK, KeyMod.CtrlCmd | KeyCode.KeyK)1223},1224menu: {1225id: MenuId.EditorContent,1226when,1227}1228});1229}12301231async run(accessor: ServicesAccessor): Promise<void> {1232const codeEditor = accessor.get(IEditorService).activeTextEditorControl;1233if (isCodeEditor(codeEditor)) {1234codeEditor.getContribution<IDefineKeybindingEditorContribution>(DEFINE_KEYBINDING_EDITOR_CONTRIB_ID)?.showDefineKeybindingWidget();1235}1236}1237}));1238};12391240registerProfileScopedActions();1241this._register(this.userDataProfileService.onDidChangeCurrentProfile(() => registerProfileScopedActions()));1242}12431244private updatePreferencesEditorMenuItem() {1245const commandId = '_workbench.openWorkspaceSettingsEditor';1246if (this.workspaceContextService.getWorkbenchState() === WorkbenchState.WORKSPACE && !CommandsRegistry.getCommand(commandId)) {1247CommandsRegistry.registerCommand(commandId, () => this.preferencesService.openWorkspaceSettings({ jsonEditor: false }));1248MenuRegistry.appendMenuItem(MenuId.EditorTitle, {1249command: {1250id: commandId,1251title: OPEN_USER_SETTINGS_UI_TITLE,1252icon: preferencesOpenSettingsIcon1253},1254when: ContextKeyExpr.and(ResourceContextKey.Resource.isEqualTo(this.preferencesService.workspaceSettingsResource!.toString()), WorkbenchStateContext.isEqualTo('workspace'), ContextKeyExpr.not('isInDiffEditor')),1255group: 'navigation',1256order: 11257});1258}1259this.updatePreferencesEditorMenuItemForWorkspaceFolders();1260}12611262private updatePreferencesEditorMenuItemForWorkspaceFolders() {1263for (const folder of this.workspaceContextService.getWorkspace().folders) {1264const commandId = `_workbench.openFolderSettings.${folder.uri.toString()}`;1265if (!CommandsRegistry.getCommand(commandId)) {1266CommandsRegistry.registerCommand(commandId, (accessor: ServicesAccessor, ...args: any[]) => {1267const groupId = getEditorGroupFromArguments(accessor, args)?.id;1268if (this.workspaceContextService.getWorkbenchState() === WorkbenchState.FOLDER) {1269return this.preferencesService.openWorkspaceSettings({ jsonEditor: false, groupId });1270} else {1271return this.preferencesService.openFolderSettings({ folderUri: folder.uri, jsonEditor: false, groupId });1272}1273});1274MenuRegistry.appendMenuItem(MenuId.EditorTitle, {1275command: {1276id: commandId,1277title: OPEN_USER_SETTINGS_UI_TITLE,1278icon: preferencesOpenSettingsIcon1279},1280when: ContextKeyExpr.and(ResourceContextKey.Resource.isEqualTo(this.preferencesService.getFolderSettingsResource(folder.uri)!.toString()), ContextKeyExpr.not('isInDiffEditor')),1281group: 'navigation',1282order: 11283});1284}1285}1286}1287}12881289class SettingsEditorTitleContribution extends Disposable implements IWorkbenchContribution {12901291static readonly ID = 'workbench.contrib.settingsEditorTitleBarActions';12921293constructor(1294@IUserDataProfileService private readonly userDataProfileService: IUserDataProfileService,1295@IUserDataProfilesService private readonly userDataProfilesService: IUserDataProfilesService,1296) {1297super();1298this.registerSettingsEditorTitleActions();1299}13001301private registerSettingsEditorTitleActions() {1302const registerOpenUserSettingsEditorFromJsonActionDisposables = this._register(new MutableDisposable());1303const registerOpenUserSettingsEditorFromJsonAction = () => {1304const openUserSettingsEditorWhen = ContextKeyExpr.and(1305CONTEXT_SETTINGS_EDITOR.toNegated(),1306ContextKeyExpr.or(1307ResourceContextKey.Resource.isEqualTo(this.userDataProfileService.currentProfile.settingsResource.toString()),1308ResourceContextKey.Resource.isEqualTo(this.userDataProfilesService.defaultProfile.settingsResource.toString())),1309ContextKeyExpr.not('isInDiffEditor'));1310registerOpenUserSettingsEditorFromJsonActionDisposables.clear();1311registerOpenUserSettingsEditorFromJsonActionDisposables.value = registerAction2(class extends Action2 {1312constructor() {1313super({1314id: '_workbench.openUserSettingsEditor',1315title: OPEN_USER_SETTINGS_UI_TITLE,1316icon: preferencesOpenSettingsIcon,1317menu: [{1318id: MenuId.EditorTitle,1319when: openUserSettingsEditorWhen,1320group: 'navigation',1321order: 11322}]1323});1324}1325run(accessor: ServicesAccessor, ...args: unknown[]) {1326const sanitizedArgs = sanitizeOpenSettingsArgs(args[0]);1327const groupId = getEditorGroupFromArguments(accessor, args)?.id;1328return accessor.get(IPreferencesService).openUserSettings({ jsonEditor: false, ...sanitizedArgs, groupId });1329}1330});1331};13321333registerOpenUserSettingsEditorFromJsonAction();1334this._register(this.userDataProfileService.onDidChangeCurrentProfile(() => {1335// Force the action to check the context again.1336registerOpenUserSettingsEditorFromJsonAction();1337}));13381339const openSettingsJsonWhen = ContextKeyExpr.and(CONTEXT_SETTINGS_JSON_EDITOR.toNegated(), CONTEXT_SETTINGS_EDITOR);1340this._register(registerAction2(class extends Action2 {1341constructor() {1342super({1343id: SETTINGS_EDITOR_COMMAND_SWITCH_TO_JSON,1344title: nls.localize2('openSettingsJson', "Open Settings (JSON)"),1345icon: preferencesOpenSettingsIcon,1346menu: [{1347id: MenuId.EditorTitle,1348when: openSettingsJsonWhen,1349group: 'navigation',1350order: 11351}]1352});1353}1354run(accessor: ServicesAccessor, ...args: unknown[]) {1355const group = getEditorGroupFromArguments(accessor, args);1356const editorPane = group?.activeEditorPane;1357if (editorPane instanceof SettingsEditor2) {1358return editorPane.switchToSettingsFile();1359}1360return null;1361}1362}));1363}1364}13651366class SettingsEditorContribution extends Disposable {1367static readonly ID: string = 'editor.contrib.settings';13681369private currentRenderer: IPreferencesRenderer | undefined;1370private readonly disposables = this._register(new DisposableStore());13711372constructor(1373private readonly editor: ICodeEditor,1374@IInstantiationService private readonly instantiationService: IInstantiationService,1375@IPreferencesService private readonly preferencesService: IPreferencesService,1376@IWorkspaceContextService private readonly workspaceContextService: IWorkspaceContextService1377) {1378super();1379this._createPreferencesRenderer();1380this._register(this.editor.onDidChangeModel(e => this._createPreferencesRenderer()));1381this._register(this.workspaceContextService.onDidChangeWorkbenchState(() => this._createPreferencesRenderer()));1382}13831384private async _createPreferencesRenderer(): Promise<void> {1385this.disposables.clear();1386this.currentRenderer = undefined;13871388const model = this.editor.getModel();1389if (model && /\.(json|code-workspace)$/.test(model.uri.path)) {1390// Fast check: the preferences renderer can only appear1391// in settings files or workspace files1392const settingsModel = await this.preferencesService.createPreferencesEditorModel(model.uri);1393if (settingsModel instanceof SettingsEditorModel && this.editor.getModel()) {1394this.disposables.add(settingsModel);1395switch (settingsModel.configurationTarget) {1396case ConfigurationTarget.WORKSPACE:1397this.currentRenderer = this.disposables.add(this.instantiationService.createInstance(WorkspaceSettingsRenderer, this.editor, settingsModel));1398break;1399default:1400this.currentRenderer = this.disposables.add(this.instantiationService.createInstance(UserSettingsRenderer, this.editor, settingsModel));1401break;1402}1403}14041405this.currentRenderer?.render();1406}1407}1408}140914101411function getEditorGroupFromArguments(accessor: ServicesAccessor, args: unknown[]): IEditorGroup | undefined {1412const context = resolveCommandsContext(args, accessor.get(IEditorService), accessor.get(IEditorGroupsService), accessor.get(IListService));1413return context.groupedEditors[0]?.group;1414}14151416registerWorkbenchContribution2(PreferencesActionsContribution.ID, PreferencesActionsContribution, WorkbenchPhase.BlockStartup);1417registerWorkbenchContribution2(PreferencesContribution.ID, PreferencesContribution, WorkbenchPhase.BlockStartup);1418registerWorkbenchContribution2(SettingsEditorTitleContribution.ID, SettingsEditorTitleContribution, WorkbenchPhase.AfterRestored);14191420registerEditorContribution(SettingsEditorContribution.ID, SettingsEditorContribution, EditorContributionInstantiation.AfterFirstRender);14211422// Preferences menu14231424MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {1425title: nls.localize({ key: 'miPreferences', comment: ['&& denotes a mnemonic'] }, "&&Preferences"),1426submenu: MenuId.MenubarPreferencesMenu,1427group: '5_autosave',1428order: 2,1429when: IsMacNativeContext.toNegated() // on macOS native the preferences menu is separate under the application menu1430});143114321433