Skip to content

Commit 3e11c1e

Browse files
committed
Merge branch 'BuraChuhadar-Feature-29241'
2 parents dc6451d + 15965f4 commit 3e11c1e

2 files changed

Lines changed: 59 additions & 11 deletions

File tree

src/vs/workbench/parts/scm/electron-browser/dirtydiffDecorator.ts

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { IMessageService, Severity } from 'vs/platform/message/common/message';
1919
import { ITextModelService } from 'vs/editor/common/services/resolverService';
2020
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
2121
import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService';
22+
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
2223
import URI from 'vs/base/common/uri';
2324
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
2425
import { ISCMService, ISCMRepository } from 'vs/workbench/services/scm/common/scm';
@@ -999,23 +1000,59 @@ class DirtyDiffItem {
9991000

10001001
export 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

src/vs/workbench/parts/scm/electron-browser/scm.contribution.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/edi
1919
import { StatusUpdater, StatusBarController } from './scmActivity';
2020
import { SCMViewlet } from 'vs/workbench/parts/scm/electron-browser/scmViewlet';
2121
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
22+
import { IConfigurationRegistry, Extensions as ConfigurationExtensions } from 'vs/platform/configuration/common/configurationRegistry';
2223

2324
class OpenSCMViewletAction extends ToggleViewletAction {
2425

@@ -61,3 +62,16 @@ Registry.as<IWorkbenchActionRegistry>(WorkbenchActionExtensions.WorkbenchActions
6162
'View: Show SCM',
6263
localize('view', "View")
6364
);
65+
66+
Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration).registerConfiguration({
67+
id: 'scm',
68+
order: 5,
69+
type: 'object',
70+
properties: {
71+
'scm.enableDiffDecorations': {
72+
'type': 'boolean',
73+
'default': true,
74+
'description': localize('enableDiffDecorations', "Enables or disables diff decorations in the editor.")
75+
},
76+
}
77+
});

0 commit comments

Comments
 (0)