@@ -19,6 +19,7 @@ import { IMessageService, Severity } from 'vs/platform/message/common/message';
1919import { ITextModelService } from 'vs/editor/common/services/resolverService' ;
2020import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService' ;
2121import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService' ;
22+ import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
2223import URI from 'vs/base/common/uri' ;
2324import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService' ;
2425import { ISCMService , ISCMRepository } from 'vs/workbench/services/scm/common/scm' ;
@@ -999,23 +1000,59 @@ class DirtyDiffItem {
9991000
10001001export class DirtyDiffWorkbenchController implements ext . IWorkbenchContribution , IModelRegistry {
10011002
1003+ private enabled = false ;
10021004 private models : IModel [ ] = [ ] ;
10031005 private items : { [ modelId : string ] : DirtyDiffItem ; } = Object . create ( null ) ;
1006+ private transientDisposables : IDisposable [ ] = [ ] ;
10041007 private disposables : IDisposable [ ] = [ ] ;
10051008
10061009 constructor (
10071010 @IWorkbenchEditorService private editorService : IWorkbenchEditorService ,
1008- @IEditorGroupService editorGroupService : IEditorGroupService ,
1009- @IInstantiationService private instantiationService : IInstantiationService
1011+ @IEditorGroupService private editorGroupService : IEditorGroupService ,
1012+ @IInstantiationService private instantiationService : IInstantiationService ,
1013+ @IConfigurationService private configurationService : IConfigurationService
10101014 ) {
1011- this . disposables . push ( editorGroupService . onEditorsChanged ( ( ) => this . onEditorsChanged ( ) ) ) ;
1015+ const onDidChangeEnablement = filterEvent ( configurationService . onDidChangeConfiguration , e => e . affectsConfiguration ( 'scm.enableDiffDecorations' ) ) ;
1016+ onDidChangeEnablement ( this . onDidChangeEnablement , this , this . disposables ) ;
1017+ this . onDidChangeEnablement ( ) ;
10121018 }
10131019
1014- private onEditorsChanged ( ) : void {
1015- // HACK: This is the best current way of figuring out whether to draw these decorations
1016- // or not. Needs context from the editor, to know whether it is a diff editor, in place editor
1017- // etc.
1020+ private onDidChangeEnablement ( ) : void {
1021+ const enabled = this . configurationService . getValue ( 'scm.enableDiffDecorations' ) ;
1022+
1023+ if ( enabled ) {
1024+ this . enable ( ) ;
1025+ } else {
1026+ this . disable ( ) ;
1027+ }
1028+ }
1029+
1030+ private enable ( ) : void {
1031+ if ( this . enabled ) {
1032+ return ;
1033+ }
10181034
1035+ this . transientDisposables . push ( this . editorGroupService . onEditorsChanged ( ( ) => this . onEditorsChanged ( ) ) ) ;
1036+ this . onEditorsChanged ( ) ;
1037+ this . enabled = true ;
1038+ }
1039+
1040+ private disable ( ) : void {
1041+ if ( ! this . enabled ) {
1042+ return ;
1043+ }
1044+
1045+ this . transientDisposables = dispose ( this . transientDisposables ) ;
1046+ this . models . forEach ( m => this . items [ m . id ] . dispose ( ) ) ;
1047+ this . models = [ ] ;
1048+ this . items = Object . create ( null ) ;
1049+ this . enabled = false ;
1050+ }
1051+
1052+ // HACK: This is the best current way of figuring out whether to draw these decorations
1053+ // or not. Needs context from the editor, to know whether it is a diff editor, in place editor
1054+ // etc.
1055+ private onEditorsChanged ( ) : void {
10191056 const models = this . editorService . getVisibleEditors ( )
10201057
10211058 // map to the editor controls
@@ -1067,11 +1104,8 @@ export class DirtyDiffWorkbenchController implements ext.IWorkbenchContribution,
10671104 }
10681105
10691106 dispose ( ) : void {
1107+ this . disable ( ) ;
10701108 this . disposables = dispose ( this . disposables ) ;
1071- this . models . forEach ( m => this . items [ m . id ] . dispose ( ) ) ;
1072-
1073- this . models = null ;
1074- this . items = null ;
10751109 }
10761110}
10771111
0 commit comments