Skip to content

Commit ba40bd1

Browse files
author
Benjamin Pasero
committed
debt - use onAutoSaveConfigurationChange
1 parent f2c2c0d commit ba40bd1

1 file changed

Lines changed: 10 additions & 18 deletions

File tree

src/vs/workbench/contrib/backup/common/backupModelTracker.ts

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
import { URI as Uri } from 'vs/base/common/uri';
77
import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';
88
import { Disposable } from 'vs/base/common/lifecycle';
9-
import { ITextFileService, TextFileModelChangeEvent, StateChange } from 'vs/workbench/services/textfile/common/textfiles';
9+
import { ITextFileService, TextFileModelChangeEvent, StateChange, IAutoSaveConfiguration } from 'vs/workbench/services/textfile/common/textfiles';
1010
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
1111
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
12-
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
13-
import { IFilesConfiguration, AutoSaveConfiguration, CONTENT_CHANGE_EVENT_BUFFER_DELAY } from 'vs/platform/files/common/files';
12+
import { CONTENT_CHANGE_EVENT_BUFFER_DELAY } from 'vs/platform/files/common/files';
1413

1514
const AUTO_SAVE_AFTER_DELAY_DISABLED_TIME = CONTENT_CHANGE_EVENT_BUFFER_DELAY + 500;
1615

@@ -22,7 +21,6 @@ export class BackupModelTracker extends Disposable implements IWorkbenchContribu
2221
@IBackupFileService private readonly backupFileService: IBackupFileService,
2322
@ITextFileService private readonly textFileService: ITextFileService,
2423
@IUntitledEditorService private readonly untitledEditorService: IUntitledEditorService,
25-
@IConfigurationService private readonly configurationService: IConfigurationService
2624
) {
2725
super();
2826

@@ -32,26 +30,20 @@ export class BackupModelTracker extends Disposable implements IWorkbenchContribu
3230
private registerListeners() {
3331

3432
// Listen for text file model changes
35-
this._register(this.textFileService.models.onModelContentChanged((e) => this.onTextFileModelChanged(e)));
36-
this._register(this.textFileService.models.onModelSaved((e) => this.discardBackup(e.resource)));
37-
this._register(this.textFileService.models.onModelDisposed((e) => this.discardBackup(e)));
33+
this._register(this.textFileService.models.onModelContentChanged(e => this.onTextFileModelChanged(e)));
34+
this._register(this.textFileService.models.onModelSaved(e => this.discardBackup(e.resource)));
35+
this._register(this.textFileService.models.onModelDisposed(e => this.discardBackup(e)));
3836

3937
// Listen for untitled model changes
40-
this._register(this.untitledEditorService.onDidChangeContent((e) => this.onUntitledModelChanged(e)));
41-
this._register(this.untitledEditorService.onDidDisposeModel((e) => this.discardBackup(e)));
38+
this._register(this.untitledEditorService.onDidChangeContent(e => this.onUntitledModelChanged(e)));
39+
this._register(this.untitledEditorService.onDidDisposeModel(e => this.discardBackup(e)));
4240

4341
// Listen to config changes
44-
this._register(this.configurationService.onDidChangeConfiguration(e => this.onConfigurationChange(this.configurationService.getValue<IFilesConfiguration>())));
42+
this._register(this.textFileService.onAutoSaveConfigurationChange(c => this.onAutoSaveConfigurationChange(c)));
4543
}
4644

47-
private onConfigurationChange(configuration: IFilesConfiguration): void {
48-
if (!configuration || !configuration.files) {
49-
this.configuredAutoSaveAfterDelay = false;
50-
51-
return;
52-
}
53-
54-
this.configuredAutoSaveAfterDelay = (configuration.files.autoSave === AutoSaveConfiguration.AFTER_DELAY && configuration.files.autoSaveDelay <= AUTO_SAVE_AFTER_DELAY_DISABLED_TIME);
45+
private onAutoSaveConfigurationChange(configuration: IAutoSaveConfiguration): void {
46+
this.configuredAutoSaveAfterDelay = typeof configuration.autoSaveDelay === 'number' && configuration.autoSaveDelay < AUTO_SAVE_AFTER_DELAY_DISABLED_TIME;
5547
}
5648

5749
private onTextFileModelChanged(event: TextFileModelChangeEvent): void {

0 commit comments

Comments
 (0)