33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6- import { coalesce , distinct , mergeSort , find } from 'vs/base/common/arrays' ;
6+ import { coalesce , distinct , find , mergeSort } from 'vs/base/common/arrays' ;
77import * as glob from 'vs/base/common/glob' ;
8- import { UnownedDisposable , Disposable } from 'vs/base/common/lifecycle' ;
8+ import { Lazy } from 'vs/base/common/lazy' ;
9+ import { Disposable , UnownedDisposable } from 'vs/base/common/lifecycle' ;
910import { Schemas } from 'vs/base/common/network' ;
1011import { basename , DataUri , isEqual } from 'vs/base/common/resources' ;
1112import { URI } from 'vs/base/common/uri' ;
1213import { generateUuid } from 'vs/base/common/uuid' ;
1314import * as nls from 'vs/nls' ;
1415import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
16+ import { IContextKey , IContextKeyService } from 'vs/platform/contextkey/common/contextkey' ;
1517import { IEditorOptions , ITextEditorOptions } from 'vs/platform/editor/common/editor' ;
1618import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
1719import { IQuickInputService , IQuickPickItem } from 'vs/platform/quickinput/common/quickInput' ;
@@ -21,14 +23,14 @@ import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
2123import { EditorInput , EditorOptions , IEditor , IEditorInput } from 'vs/workbench/common/editor' ;
2224import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput' ;
2325import { webviewEditorsExtensionPoint } from 'vs/workbench/contrib/customEditor/browser/extensionPoint' ;
24- import { CustomEditorPriority , CustomEditorInfo , CustomEditorSelector , ICustomEditorService , CONTEXT_HAS_CUSTOM_EDITORS , CONTEXT_FOCUSED_CUSTOM_EDITOR_IS_EDITABLE , ICustomEditor } from 'vs/workbench/contrib/customEditor/common/customEditor' ;
26+ import { CONTEXT_FOCUSED_CUSTOM_EDITOR_IS_EDITABLE , CONTEXT_HAS_CUSTOM_EDITORS , CustomEditorInfo , CustomEditorPriority , CustomEditorSelector , ICustomEditor , ICustomEditorService } from 'vs/workbench/contrib/customEditor/common/customEditor' ;
27+ import { CustomEditorModelManager } from 'vs/workbench/contrib/customEditor/common/customEditorModelManager' ;
2528import { FileEditorInput } from 'vs/workbench/contrib/files/common/editors/fileEditorInput' ;
26- import { IWebviewService } from 'vs/workbench/contrib/webview/browser/webview' ;
29+ import { IWebviewService , webviewHasOwnEditFunctionsContext } from 'vs/workbench/contrib/webview/browser/webview' ;
2730import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService' ;
2831import { IEditorService , IOpenEditorOverride } from 'vs/workbench/services/editor/common/editorService' ;
32+ import { IWorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService' ;
2933import { CustomFileEditorInput } from './customEditorInput' ;
30- import { IContextKeyService , IContextKey } from 'vs/platform/contextkey/common/contextkey' ;
31- import { Lazy } from 'vs/base/common/lazy' ;
3234
3335const defaultEditorId = 'default' ;
3436
@@ -73,11 +75,15 @@ export class CustomEditorService extends Disposable implements ICustomEditorServ
7375
7476 private readonly _editorInfoStore = new CustomEditorInfoStore ( ) ;
7577
78+ private readonly _models : CustomEditorModelManager ;
79+
7680 private readonly _hasCustomEditor : IContextKey < boolean > ;
7781 private readonly _focusedCustomEditorIsEditable : IContextKey < boolean > ;
82+ private readonly _webviewHasOwnEditFunctions : IContextKey < boolean > ;
7883
7984 constructor (
8085 @IContextKeyService contextKeyService : IContextKeyService ,
86+ @IWorkingCopyService workingCopyService : IWorkingCopyService ,
8187 @IConfigurationService private readonly configurationService : IConfigurationService ,
8288 @IEditorService private readonly editorService : IEditorService ,
8389 @IInstantiationService private readonly instantiationService : IInstantiationService ,
@@ -86,6 +92,8 @@ export class CustomEditorService extends Disposable implements ICustomEditorServ
8692 ) {
8793 super ( ) ;
8894
95+ this . _models = new CustomEditorModelManager ( workingCopyService ) ;
96+
8997 webviewEditorsExtensionPoint . setHandler ( extensions => {
9098 this . _editorInfoStore . clear ( ) ;
9199
@@ -104,21 +112,21 @@ export class CustomEditorService extends Disposable implements ICustomEditorServ
104112
105113 this . _hasCustomEditor = CONTEXT_HAS_CUSTOM_EDITORS . bindTo ( contextKeyService ) ;
106114 this . _focusedCustomEditorIsEditable = CONTEXT_FOCUSED_CUSTOM_EDITOR_IS_EDITABLE . bindTo ( contextKeyService ) ;
115+ this . _webviewHasOwnEditFunctions = webviewHasOwnEditFunctionsContext . bindTo ( contextKeyService ) ;
107116
108117 this . _register ( this . editorService . onDidActiveEditorChange ( ( ) => this . updateContexts ( ) ) ) ;
109118 this . updateContexts ( ) ;
110119 }
111120
121+ public get models ( ) { return this . _models ; }
122+
112123 public get activeCustomEditor ( ) : ICustomEditor | undefined {
113124 const activeInput = this . editorService . activeControl ?. input ;
114125 if ( ! ( activeInput instanceof CustomFileEditorInput ) ) {
115126 return undefined ;
116127 }
117-
118- return {
119- resource : activeInput . getResource ( ) ,
120- model : undefined ,
121- } ;
128+ const resource = activeInput . getResource ( ) ;
129+ return { resource, viewType : activeInput . viewType } ;
122130 }
123131
124132 public getContributedCustomEditors ( resource : URI ) : readonly CustomEditorInfo [ ] {
@@ -236,6 +244,7 @@ export class CustomEditorService extends Disposable implements ICustomEditorServ
236244 if ( ! resource ) {
237245 this . _hasCustomEditor . reset ( ) ;
238246 this . _focusedCustomEditorIsEditable . reset ( ) ;
247+ this . _webviewHasOwnEditFunctions . reset ( ) ;
239248 return ;
240249 }
241250
@@ -245,6 +254,7 @@ export class CustomEditorService extends Disposable implements ICustomEditorServ
245254 ] ;
246255 this . _hasCustomEditor . set ( possibleEditors . length > 0 ) ;
247256 this . _focusedCustomEditorIsEditable . set ( activeControl ?. input instanceof CustomFileEditorInput ) ;
257+ this . _webviewHasOwnEditFunctions . set ( true ) ;
248258 }
249259}
250260
0 commit comments