@@ -48,7 +48,6 @@ import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/
4848import { toLocalResource } from 'vs/base/common/resources' ;
4949import { Extensions as WorkbenchExtensions , IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions' ;
5050import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle' ;
51- import { withNullAsUndefined } from 'vs/base/common/types' ;
5251import { IFilesConfigurationService } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService' ;
5352import { EditorAutoSave } from 'vs/workbench/browser/parts/editor/editorAutoSave' ;
5453import { ThemeIcon } from 'vs/platform/theme/common/themeService' ;
@@ -169,9 +168,10 @@ class UntitledTextEditorInputFactory implements IEditorInputFactory {
169168
170169Registry . as < IEditorInputFactoryRegistry > ( EditorInputExtensions . EditorInputFactories ) . registerEditorInputFactory ( UntitledTextEditorInput . ID , UntitledTextEditorInputFactory ) ;
171170
171+ // Register SideBySide/DiffEditor Input Factory
172172interface ISerializedSideBySideEditorInput {
173173name : string ;
174- description : string ;
174+ description : string | undefined ;
175175
176176detailsSerialized : string ;
177177masterSerialized : string ;
@@ -180,16 +180,19 @@ interface ISerializedSideBySideEditorInput {
180180masterTypeId : string ;
181181}
182182
183- // Register Side by Side Editor Input Factory
184- class SideBySideEditorInputFactory implements IEditorInputFactory {
183+ export abstract class AbstractSideBySideEditorInputFactory implements IEditorInputFactory {
184+
185+ private getInputFactories ( detailsId : string , masterId : string ) : [ IEditorInputFactory | undefined , IEditorInputFactory | undefined ] {
186+ const registry = Registry . as < IEditorInputFactoryRegistry > ( EditorInputExtensions . EditorInputFactories ) ;
187+
188+ return [ registry . getEditorInputFactory ( detailsId ) , registry . getEditorInputFactory ( masterId ) ] ;
189+ }
185190
186191canSerialize ( editorInput : EditorInput ) : boolean {
187- const input = < SideBySideEditorInput > editorInput ;
192+ const input = editorInput as SideBySideEditorInput | DiffEditorInput ;
188193
189194if ( input . details && input . master ) {
190- const registry = Registry . as < IEditorInputFactoryRegistry > ( EditorInputExtensions . EditorInputFactories ) ;
191- const detailsInputFactory = registry . getEditorInputFactory ( input . details . getTypeId ( ) ) ;
192- const masterInputFactory = registry . getEditorInputFactory ( input . master . getTypeId ( ) ) ;
195+ const [ detailsInputFactory , masterInputFactory ] = this . getInputFactories ( input . details . getTypeId ( ) , input . master . getTypeId ( ) ) ;
193196
194197return ! ! ( detailsInputFactory ?. canSerialize ( input . details ) && masterInputFactory ?. canSerialize ( input . master ) ) ;
195198}
@@ -198,26 +201,25 @@ class SideBySideEditorInputFactory implements IEditorInputFactory {
198201}
199202
200203serialize ( editorInput : EditorInput ) : string | undefined {
201- const input = < SideBySideEditorInput > editorInput ;
204+ const input = editorInput as SideBySideEditorInput | DiffEditorInput ;
202205
203206if ( input . details && input . master ) {
204- const registry = Registry . as < IEditorInputFactoryRegistry > ( EditorInputExtensions . EditorInputFactories ) ;
205- const detailsInputFactory = registry . getEditorInputFactory ( input . details . getTypeId ( ) ) ;
206- const masterInputFactory = registry . getEditorInputFactory ( input . master . getTypeId ( ) ) ;
207-
207+ const [ detailsInputFactory , masterInputFactory ] = this . getInputFactories ( input . details . getTypeId ( ) , input . master . getTypeId ( ) ) ;
208208if ( detailsInputFactory && masterInputFactory ) {
209209const detailsSerialized = detailsInputFactory . serialize ( input . details ) ;
210210const masterSerialized = masterInputFactory . serialize ( input . master ) ;
211211
212212if ( detailsSerialized && masterSerialized ) {
213- return JSON . stringify ( < ISerializedSideBySideEditorInput > {
213+ const serializedEditorInput : ISerializedSideBySideEditorInput = {
214214name : input . getName ( ) ,
215215description : input . getDescription ( ) ,
216216detailsSerialized,
217217masterSerialized,
218218detailsTypeId : input . details . getTypeId ( ) ,
219219masterTypeId : input . master . getTypeId ( )
220- } ) ;
220+ } ;
221+
222+ return JSON . stringify ( serializedEditorInput ) ;
221223}
222224}
223225}
@@ -228,24 +230,38 @@ class SideBySideEditorInputFactory implements IEditorInputFactory {
228230deserialize ( instantiationService : IInstantiationService , serializedEditorInput : string ) : EditorInput | undefined {
229231const deserialized : ISerializedSideBySideEditorInput = JSON . parse ( serializedEditorInput ) ;
230232
231- const registry = Registry . as < IEditorInputFactoryRegistry > ( EditorInputExtensions . EditorInputFactories ) ;
232- const detailsInputFactory = registry . getEditorInputFactory ( deserialized . detailsTypeId ) ;
233- const masterInputFactory = registry . getEditorInputFactory ( deserialized . masterTypeId ) ;
234-
233+ const [ detailsInputFactory , masterInputFactory ] = this . getInputFactories ( deserialized . detailsTypeId , deserialized . masterTypeId ) ;
235234if ( detailsInputFactory && masterInputFactory ) {
236235const detailsInput = detailsInputFactory . deserialize ( instantiationService , deserialized . detailsSerialized ) ;
237236const masterInput = masterInputFactory . deserialize ( instantiationService , deserialized . masterSerialized ) ;
238237
239238if ( detailsInput && masterInput ) {
240- return new SideBySideEditorInput ( deserialized . name , withNullAsUndefined ( deserialized . description ) , detailsInput , masterInput ) ;
239+ return this . createEditorInput ( deserialized . name , deserialized . description , detailsInput , masterInput ) ;
241240}
242241}
243242
244243return undefined ;
245244}
245+
246+ protected abstract createEditorInput ( name : string , description : string | undefined , detailsInput : EditorInput , masterInput : EditorInput ) : EditorInput ;
247+ }
248+
249+ class SideBySideEditorInputFactory extends AbstractSideBySideEditorInputFactory {
250+
251+ protected createEditorInput ( name : string , description : string | undefined , detailsInput : EditorInput , masterInput : EditorInput ) : EditorInput {
252+ return new SideBySideEditorInput ( name , description , detailsInput , masterInput ) ;
253+ }
254+ }
255+
256+ class DiffEditorInputFactory extends AbstractSideBySideEditorInputFactory {
257+
258+ protected createEditorInput ( name : string , description : string | undefined , detailsInput : EditorInput , masterInput : EditorInput ) : EditorInput {
259+ return new DiffEditorInput ( name , description , detailsInput , masterInput ) ;
260+ }
246261}
247262
248263Registry . as < IEditorInputFactoryRegistry > ( EditorInputExtensions . EditorInputFactories ) . registerEditorInputFactory ( SideBySideEditorInput . ID , SideBySideEditorInputFactory ) ;
264+ Registry . as < IEditorInputFactoryRegistry > ( EditorInputExtensions . EditorInputFactories ) . registerEditorInputFactory ( DiffEditorInput . ID , DiffEditorInputFactory ) ;
249265
250266// Register Editor Contributions
251267registerEditorContribution ( OpenWorkspaceButtonContribution . ID , OpenWorkspaceButtonContribution ) ;
0 commit comments