33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6+ import * as nls from 'vs/nls' ;
67import { IInstantiationService , ServicesAccessor } from 'vs/platform/instantiation/common/instantiation' ;
78import { IResourceEditorInput , ITextEditorOptions , IEditorOptions , EditorActivation } from 'vs/platform/editor/common/editor' ;
89import { SideBySideEditor , IEditorInput , IEditorPane , GroupIdentifier , IFileEditorInput , IUntitledTextResourceEditorInput , IResourceDiffEditorInput , IEditorInputFactoryRegistry , Extensions as EditorExtensions , EditorInput , SideBySideEditorInput , IEditorInputWithOptions , isEditorInputWithOptions , EditorOptions , TextEditorOptions , IEditorIdentifier , IEditorCloseEvent , ITextEditorPane , ITextDiffEditorPane , IRevertOptions , SaveReason , EditorsOrder , isTextEditorPane , IWorkbenchEditorConfiguration , toResource , IVisibleEditorPane } from 'vs/workbench/common/editor' ;
@@ -17,7 +18,7 @@ import { URI } from 'vs/base/common/uri';
1718import { basename , isEqualOrParent , joinPath } from 'vs/base/common/resources' ;
1819import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput' ;
1920import { IEditorGroupsService , IEditorGroup , GroupsOrder , IEditorReplacement , GroupChangeKind , preferredSideBySideGroupDirection } from 'vs/workbench/services/editor/common/editorGroupsService' ;
20- import { IResourceEditorInputType , SIDE_GROUP , IResourceEditorReplacement , IOpenEditorOverrideHandler , IEditorService , SIDE_GROUP_TYPE , ACTIVE_GROUP_TYPE , ISaveEditorsOptions , ISaveAllEditorsOptions , IRevertAllEditorsOptions , IBaseSaveRevertAllEditorOptions , IOpenEditorOverrideEntry } from 'vs/workbench/services/editor/common/editorService' ;
21+ import { IResourceEditorInputType , SIDE_GROUP , IResourceEditorReplacement , IOpenEditorOverrideHandler , IEditorService , SIDE_GROUP_TYPE , ACTIVE_GROUP_TYPE , ISaveEditorsOptions , ISaveAllEditorsOptions , IRevertAllEditorsOptions , IBaseSaveRevertAllEditorOptions , IOpenEditorOverrideEntry , ICustomEditorViewTypesHandler , ICustomEditorInfo } from 'vs/workbench/services/editor/common/editorService' ;
2122import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
2223import { Disposable , IDisposable , dispose , toDisposable , DisposableStore } from 'vs/base/common/lifecycle' ;
2324import { coalesce , distinct , insert } from 'vs/base/common/arrays' ;
@@ -33,6 +34,8 @@ import { UntitledTextEditorInput } from 'vs/workbench/services/untitled/common/u
3334import { timeout } from 'vs/base/common/async' ;
3435import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace' ;
3536import { indexOfPath } from 'vs/base/common/extpath' ;
37+ import { DEFAULT_CUSTOM_EDITOR , updateViewTypeSchema , editorAssociationsConfigurationNode } from 'vs/workbench/services/editor/browser/editorAssociationsSetting' ;
38+ import { Extensions as ConfigurationExtensions , IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry' ;
3639
3740type CachedEditorInput = ResourceEditorInput | IFileEditorInput | UntitledTextEditorInput ;
3841type OpenInEditorGroup = IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE ;
@@ -1088,6 +1091,48 @@ export class EditorService extends Disposable implements EditorServiceImpl {
10881091
10891092 //#endregion
10901093
1094+ //#region Custom View Type
1095+ private customEditorViewTypesHandlers = new Map < string , ICustomEditorViewTypesHandler > ( ) ;
1096+ registerCustomEditorViewTypesHandler ( source : string , handler : ICustomEditorViewTypesHandler ) : IDisposable {
1097+ if ( this . customEditorViewTypesHandlers . has ( source ) ) {
1098+ throw new Error ( `Use a different name for the custom editor component, ${ source } is already occupied.` ) ;
1099+ }
1100+
1101+ this . customEditorViewTypesHandlers . set ( source , handler ) ;
1102+ this . updateSchema ( ) ;
1103+
1104+ const viewTypeChangeEvent = handler . onDidChangeViewTypes ( ( ) => {
1105+ this . updateSchema ( ) ;
1106+ } ) ;
1107+
1108+ return {
1109+ dispose : ( ) => {
1110+ viewTypeChangeEvent . dispose ( ) ;
1111+ this . customEditorViewTypesHandlers . delete ( source ) ;
1112+ this . updateSchema ( ) ;
1113+ }
1114+ } ;
1115+ }
1116+
1117+ private updateSchema ( ) {
1118+ const enumValues : string [ ] = [ ] ;
1119+ const enumDescriptions : string [ ] = [ ] ;
1120+
1121+ const infos : ICustomEditorInfo [ ] = [ DEFAULT_CUSTOM_EDITOR ] ;
1122+
1123+ for ( const [ , handler ] of this . customEditorViewTypesHandlers ) {
1124+ infos . push ( ...handler . getViewTypes ( ) ) ;
1125+ }
1126+
1127+ infos . forEach ( info => {
1128+ enumValues . push ( info . id ) ;
1129+ enumDescriptions . push ( nls . localize ( 'editorAssociations.viewType.sourceDescription' , "Source: {0}" , info . providerDisplayName ) ) ;
1130+ } ) ;
1131+
1132+ updateViewTypeSchema ( enumValues , enumDescriptions ) ;
1133+ }
1134+
1135+ //#endregion
10911136 dispose ( ) : void {
10921137 super . dispose ( ) ;
10931138
@@ -1195,7 +1240,14 @@ export class DelegatingEditorService implements IEditorService {
11951240 revert ( editors : IEditorIdentifier | IEditorIdentifier [ ] , options ?: IRevertOptions ) : Promise < void > { return this . editorService . revert ( editors , options ) ; }
11961241 revertAll ( options ?: IRevertAllEditorsOptions ) : Promise < void > { return this . editorService . revertAll ( options ) ; }
11971242
1243+ registerCustomEditorViewTypesHandler ( source : string , handler : ICustomEditorViewTypesHandler ) : IDisposable {
1244+ throw new Error ( 'Method not implemented.' ) ;
1245+ }
1246+
11981247 //#endregion
11991248}
12001249
12011250registerSingleton ( IEditorService , EditorService ) ;
1251+
1252+ Registry . as < IConfigurationRegistry > ( ConfigurationExtensions . Configuration )
1253+ . registerConfiguration ( editorAssociationsConfigurationNode ) ;
0 commit comments