Skip to content

Commit 0925af4

Browse files
committed
Adopt EditorOverrideService for split editor microsoft#121668
1 parent 900f309 commit 0925af4

10 files changed

Lines changed: 150 additions & 115 deletions

File tree

src/vs/workbench/contrib/preferences/browser/keybindingsEditor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic
3434
import { EditorExtensionsRegistry } from 'vs/editor/browser/editorExtensions';
3535
import { WorkbenchTable } from 'vs/platform/list/browser/listService';
3636
import { INotificationService } from 'vs/platform/notification/common/notification';
37-
import { KeybindingsEditorInput } from 'vs/workbench/services/preferences/browser/preferencesEditorInput';
3837
import { CancellationToken } from 'vs/base/common/cancellation';
3938
import { attachStylerCallback, attachInputBoxStyler, attachCheckboxStyler, attachKeybindingLabelStyler } from 'vs/platform/theme/common/styler';
4039
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
@@ -48,6 +47,7 @@ import { IBaseActionViewItemOptions } from 'vs/base/browser/ui/actionbar/actionV
4847
import { IKeybindingItemEntry, IKeybindingsEditorPane } from 'vs/workbench/services/preferences/common/preferences';
4948
import { keybindingsRecordKeysIcon, keybindingsSortIcon, keybindingsAddIcon, preferencesClearInputIcon, keybindingsEditIcon } from 'vs/workbench/contrib/preferences/browser/preferencesIcons';
5049
import { ITableRenderer, ITableVirtualDelegate } from 'vs/base/browser/ui/table/table';
50+
import { KeybindingsEditorInput } from 'vs/workbench/services/preferences/browser/keybindingsEditorInput';
5151

5252
const $ = DOM.$;
5353

src/vs/workbench/contrib/preferences/browser/preferences.contribution.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic
3939
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
4040
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
4141
import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences';
42-
import { DefaultPreferencesEditorInput, KeybindingsEditorInput, PreferencesEditorInput, SettingsEditor2Input } from 'vs/workbench/services/preferences/browser/preferencesEditorInput';
42+
import { DefaultPreferencesEditorInput, PreferencesEditorInput, SettingsEditor2Input } from 'vs/workbench/services/preferences/common/preferencesEditorInput';
4343
import { preferencesOpenSettingsIcon } from 'vs/workbench/contrib/preferences/browser/preferencesIcons';
44+
import { KeybindingsEditorInput } from 'vs/workbench/services/preferences/browser/keybindingsEditorInput';
4445

4546
const SETTINGS_EDITOR_COMMAND_SEARCH = 'settings.action.search';
4647

src/vs/workbench/contrib/preferences/browser/preferencesEditor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import { CONTEXT_SETTINGS_EDITOR, CONTEXT_SETTINGS_JSON_EDITOR, CONTEXT_SETTINGS
4949
import { IEditorGroup, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
5050
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
5151
import { IFilterResult, IPreferencesService, ISetting, ISettingsEditorModel, ISettingsGroup, SettingsEditorOptions } from 'vs/workbench/services/preferences/common/preferences';
52-
import { DefaultPreferencesEditorInput, PreferencesEditorInput } from 'vs/workbench/services/preferences/browser/preferencesEditorInput';
52+
import { DefaultPreferencesEditorInput, PreferencesEditorInput } from 'vs/workbench/services/preferences/common/preferencesEditorInput';
5353
import { DefaultSettingsEditorModel, SettingsEditorModel } from 'vs/workbench/services/preferences/common/preferencesModels';
5454

5555
export class PreferencesEditor extends EditorPane {

src/vs/workbench/contrib/preferences/browser/settingsEditor2.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import { createTOCIterator, TOCTree, TOCTreeModel } from 'vs/workbench/contrib/p
4848
import { CONTEXT_SETTINGS_EDITOR, CONTEXT_SETTINGS_ROW_FOCUS, CONTEXT_SETTINGS_SEARCH_FOCUS, CONTEXT_TOC_ROW_FOCUS, EXTENSION_SETTING_TAG, FEATURE_SETTING_TAG, ID_SETTING_TAG, IPreferencesSearchService, ISearchProvider, MODIFIED_SETTING_TAG, REQUIRE_TRUSTED_WORKSPACE_SETTING_TAG, SETTINGS_EDITOR_COMMAND_CLEAR_SEARCH_RESULTS } from 'vs/workbench/contrib/preferences/common/preferences';
4949
import { IEditorGroup, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
5050
import { IPreferencesService, ISearchResult, ISettingsEditorModel, ISettingsEditorOptions, SettingsEditorOptions, SettingValueType } from 'vs/workbench/services/preferences/common/preferences';
51-
import { SettingsEditor2Input } from 'vs/workbench/services/preferences/browser/preferencesEditorInput';
51+
import { SettingsEditor2Input } from 'vs/workbench/services/preferences/common/preferencesEditorInput';
5252
import { Settings2EditorModel } from 'vs/workbench/services/preferences/common/preferencesModels';
5353
import { IUserDataSyncWorkbenchService } from 'vs/workbench/services/userDataSync/common/userDataSync';
5454
import { preferencesClearInputIcon } from 'vs/workbench/contrib/preferences/browser/preferencesIcons';

src/vs/workbench/contrib/preferences/common/preferencesContribution.ts

Lines changed: 41 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@ import { IModelService } from 'vs/editor/common/services/modelService';
1111
import { IModeService } from 'vs/editor/common/services/modeService';
1212
import { ITextModelService } from 'vs/editor/common/services/resolverService';
1313
import * as nls from 'vs/nls';
14-
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
14+
import { ConfigurationTarget, IConfigurationService } from 'vs/platform/configuration/common/configuration';
1515
import { ConfigurationScope, Extensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
1616
import { IEditorOptions, ITextEditorOptions } from 'vs/platform/editor/common/editor';
1717
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
1818
import * as JSONContributionRegistry from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
1919
import { Registry } from 'vs/platform/registry/common/platform';
2020
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
21+
import { workbenchConfigurationNodeBase } from 'vs/workbench/common/configuration';
2122
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
22-
import { IEditorInput } from 'vs/workbench/common/editor';
23+
import { IEditorInputWithOptions } from 'vs/workbench/common/editor';
2324
import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
24-
import { IEditorService, IOpenEditorOverride } from 'vs/workbench/services/editor/common/editorService';
25+
import { ContributedEditorPriority, IEditorOverrideService } from 'vs/workbench/services/editor/common/editorOverrideService';
2526
import { FOLDER_SETTINGS_PATH, IPreferencesService, USE_SPLIT_JSON_SETTING } from 'vs/workbench/services/preferences/common/preferences';
26-
import { workbenchConfigurationNodeBase } from 'vs/workbench/common/configuration';
27+
import { PreferencesEditorInput } from 'vs/workbench/services/preferences/common/preferencesEditorInput';
2728

2829
const schemaRegistry = Registry.as<JSONContributionRegistry.IJSONContributionRegistry>(JSONContributionRegistry.Extensions.JSONContribution);
2930

@@ -36,10 +37,10 @@ export class PreferencesContribution implements IWorkbenchContribution {
3637
@ITextModelService private readonly textModelResolverService: ITextModelService,
3738
@IPreferencesService private readonly preferencesService: IPreferencesService,
3839
@IModeService private readonly modeService: IModeService,
39-
@IEditorService private readonly editorService: IEditorService,
4040
@IEnvironmentService private readonly environmentService: IEnvironmentService,
4141
@IWorkspaceContextService private readonly workspaceService: IWorkspaceContextService,
42-
@IConfigurationService private readonly configurationService: IConfigurationService
42+
@IConfigurationService private readonly configurationService: IConfigurationService,
43+
@IEditorOverrideService private readonly editorOverrideService: IEditorOverrideService,
4344
) {
4445
this.settingsListener = this.configurationService.onDidChangeConfiguration(e => {
4546
if (e.affectsConfiguration(USE_SPLIT_JSON_SETTING)) {
@@ -58,54 +59,45 @@ export class PreferencesContribution implements IWorkbenchContribution {
5859

5960
// install editor opening listener unless user has disabled this
6061
if (!!this.configurationService.getValue(USE_SPLIT_JSON_SETTING)) {
61-
this.editorOpeningListener = this.editorService.overrideOpenEditor({
62-
open: (editor, options, group) => this.onEditorOpening(editor, options, group)
63-
});
64-
}
65-
}
66-
67-
private onEditorOpening(editor: IEditorInput, options: IEditorOptions | ITextEditorOptions | undefined, group: IEditorGroup): IOpenEditorOverride | undefined {
68-
const resource = editor.resource;
69-
if (
70-
!resource ||
71-
!resource.path.endsWith('settings.json') || // resource must end in settings.json
72-
!this.configurationService.getValue(USE_SPLIT_JSON_SETTING) // user has not disabled default settings editor
73-
) {
74-
return undefined;
75-
}
76-
77-
// If the resource was already opened before in the group, do not prevent
78-
// the opening of that resource. Otherwise we would have the same settings
79-
// opened twice (https://github.com/microsoft/vscode/issues/36447)
80-
if (group.contains(editor)) {
81-
return undefined;
82-
}
62+
this.editorOpeningListener = this.editorOverrideService.registerContributionPoint(
63+
'**/settings.json',
64+
{
65+
id: PreferencesEditorInput.ID,
66+
describes: editor => editor instanceof PreferencesEditorInput,
67+
detail: 'Split Settings Editor (deprecated)',
68+
label: 'label',
69+
priority: ContributedEditorPriority.builtin,
70+
},
71+
{},
72+
(resource: URI, options: IEditorOptions | ITextEditorOptions | undefined, group: IEditorGroup): IEditorInputWithOptions => {
73+
// Global User Settings File
74+
if (isEqual(resource, this.environmentService.settingsResource)) {
75+
return { editor: this.preferencesService.getCurrentOrNewSplitJsonEditorInput(ConfigurationTarget.USER_LOCAL, resource, group), options };
76+
}
8377

84-
// Global User Settings File
85-
if (isEqual(resource, this.environmentService.settingsResource)) {
86-
return { override: this.preferencesService.openGlobalSettings(true, options, group) };
87-
}
78+
// Single Folder Workspace Settings File
79+
const state = this.workspaceService.getWorkbenchState();
80+
if (state === WorkbenchState.FOLDER) {
81+
const folders = this.workspaceService.getWorkspace().folders;
82+
if (isEqual(resource, folders[0].toResource(FOLDER_SETTINGS_PATH))) {
83+
return { editor: this.preferencesService.getCurrentOrNewSplitJsonEditorInput(ConfigurationTarget.WORKSPACE, resource, group), options };
84+
}
85+
}
8886

89-
// Single Folder Workspace Settings File
90-
const state = this.workspaceService.getWorkbenchState();
91-
if (state === WorkbenchState.FOLDER) {
92-
const folders = this.workspaceService.getWorkspace().folders;
93-
if (isEqual(resource, folders[0].toResource(FOLDER_SETTINGS_PATH))) {
94-
return { override: this.preferencesService.openWorkspaceSettings(true, options, group) };
95-
}
96-
}
87+
// Multi Folder Workspace Settings File
88+
else if (state === WorkbenchState.WORKSPACE) {
89+
const folders = this.workspaceService.getWorkspace().folders;
90+
for (const folder of folders) {
91+
if (isEqual(resource, folder.toResource(FOLDER_SETTINGS_PATH))) {
92+
return { editor: this.preferencesService.getCurrentOrNewSplitJsonEditorInput(ConfigurationTarget.WORKSPACE_FOLDER, resource, group), options };
93+
}
94+
}
95+
}
9796

98-
// Multi Folder Workspace Settings File
99-
else if (state === WorkbenchState.WORKSPACE) {
100-
const folders = this.workspaceService.getWorkspace().folders;
101-
for (const folder of folders) {
102-
if (isEqual(resource, folder.toResource(FOLDER_SETTINGS_PATH))) {
103-
return { override: this.preferencesService.openFolderSettings(folder.uri, true, options, group) };
97+
return { editor: this.preferencesService.getCurrentOrNewSplitJsonEditorInput(ConfigurationTarget.USER_LOCAL, this.environmentService.settingsResource, group), options };
10498
}
105-
}
99+
);
106100
}
107-
108-
return undefined;
109101
}
110102

111103
private start(): void {

src/vs/workbench/contrib/userDataSync/browser/userDataSyncTrigger.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { Event } from 'vs/base/common/event';
77
import { Disposable } from 'vs/base/common/lifecycle';
88
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
9-
import { SettingsEditor2Input, KeybindingsEditorInput, PreferencesEditorInput } from 'vs/workbench/services/preferences/browser/preferencesEditorInput';
9+
import { SettingsEditor2Input, PreferencesEditorInput } from 'vs/workbench/services/preferences/common/preferencesEditorInput';
1010
import { isEqual } from 'vs/base/common/resources';
1111
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
1212
import { VIEWLET_ID } from 'vs/workbench/contrib/extensions/common/extensions';
@@ -16,6 +16,7 @@ import { IUserDataAutoSyncService } from 'vs/platform/userDataSync/common/userDa
1616
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
1717
import { isWeb } from 'vs/base/common/platform';
1818
import { IHostService } from 'vs/workbench/services/host/browser/host';
19+
import { KeybindingsEditorInput } from 'vs/workbench/services/preferences/browser/keybindingsEditorInput';
1920

2021
export class UserDataSyncTrigger extends Disposable implements IWorkbenchContribution {
2122

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { OS } from 'vs/base/common/platform';
7+
import * as nls from 'vs/nls';
8+
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
9+
import { EditorInput } from 'vs/workbench/common/editor';
10+
import { KeybindingsEditorModel } from 'vs/workbench/services/preferences/browser/keybindingsEditorModel';
11+
12+
export interface IKeybindingsEditorSearchOptions {
13+
searchValue: string;
14+
recordKeybindings: boolean;
15+
sortByPrecedence: boolean;
16+
}
17+
18+
export class KeybindingsEditorInput extends EditorInput {
19+
20+
static readonly ID: string = 'workbench.input.keybindings';
21+
readonly keybindingsModel: KeybindingsEditorModel;
22+
23+
searchOptions: IKeybindingsEditorSearchOptions | null = null;
24+
25+
readonly resource = undefined;
26+
27+
constructor(@IInstantiationService instantiationService: IInstantiationService) {
28+
super();
29+
30+
this.keybindingsModel = instantiationService.createInstance(KeybindingsEditorModel, OS);
31+
}
32+
33+
override get typeId(): string {
34+
return KeybindingsEditorInput.ID;
35+
}
36+
37+
override getName(): string {
38+
return nls.localize('keybindingsInputName', "Keyboard Shortcuts");
39+
}
40+
41+
override async resolve(): Promise<KeybindingsEditorModel> {
42+
return this.keybindingsModel;
43+
}
44+
45+
override matches(otherInput: unknown): boolean {
46+
return otherInput instanceof KeybindingsEditorInput;
47+
}
48+
49+
override dispose(): void {
50+
this.keybindingsModel.dispose();
51+
52+
super.dispose();
53+
}
54+
}

0 commit comments

Comments
 (0)