Skip to content

Commit 21c0931

Browse files
author
Benjamin Pasero
committed
files - add auto save config service
1 parent d87b077 commit 21c0931

24 files changed

Lines changed: 265 additions & 178 deletions

File tree

src/vs/platform/instantiation/common/instantiationService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export class InstantiationService implements IInstantiationService {
157157
graph.lookupOrInsertNode(item);
158158

159159
// a weak but working heuristic for cycle checks
160-
if (cycleCount++ > 100) {
160+
if (cycleCount++ > 150) {
161161
throw new CyclicDependencyError(graph);
162162
}
163163

src/vs/workbench/browser/parts/editor/textDiffEditor.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { EditorMemento } from 'vs/workbench/browser/parts/editor/baseEditor';
3333
import { IHostService } from 'vs/workbench/services/host/browser/host';
3434
import { EditorActivation, IEditorOptions } from 'vs/platform/editor/common/editor';
3535
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
36+
import { IAutoSaveConfigurationService } from 'vs/workbench/services/autoSaveConfiguration/common/autoSaveConfigurationService';
3637

3738
/**
3839
* The text editor that leverages the diff text editor for the editing experience.
@@ -55,8 +56,9 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor {
5556
@ITextFileService textFileService: ITextFileService,
5657
@IHostService hostService: IHostService,
5758
@IClipboardService private _clipboardService: IClipboardService,
59+
@IAutoSaveConfigurationService autoSaveConfigurationService: IAutoSaveConfigurationService
5860
) {
59-
super(TextDiffEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService, textFileService, editorService, editorGroupService, hostService);
61+
super(TextDiffEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService, textFileService, editorService, editorGroupService, hostService, autoSaveConfigurationService);
6062
}
6163

6264
protected getEditorMemento<T>(editorGroupService: IEditorGroupsService, key: string, limit: number = 10): IEditorMemento<T> {

src/vs/workbench/browser/parts/editor/textEditor.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ import { IStorageService } from 'vs/platform/storage/common/storage';
1616
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
1717
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
1818
import { IThemeService } from 'vs/platform/theme/common/themeService';
19-
import { ITextFileService, SaveReason, AutoSaveMode } from 'vs/workbench/services/textfile/common/textfiles';
19+
import { ITextFileService, SaveReason } from 'vs/workbench/services/textfile/common/textfiles';
2020
import { ITextResourceConfigurationService } from 'vs/editor/common/services/resourceConfiguration';
2121
import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
2222
import { isDiffEditor, isCodeEditor, getCodeEditor } from 'vs/editor/browser/editorBrowser';
2323
import { IEditorGroupsService, IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
2424
import { CancellationToken } from 'vs/base/common/cancellation';
2525
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
2626
import { IHostService } from 'vs/workbench/services/host/browser/host';
27+
import { IAutoSaveConfigurationService, AutoSaveMode } from 'vs/workbench/services/autoSaveConfiguration/common/autoSaveConfigurationService';
2728

2829
const TEXT_EDITOR_VIEW_STATE_PREFERENCE_KEY = 'textEditorViewState';
2930

@@ -53,7 +54,8 @@ export abstract class BaseTextEditor extends BaseEditor implements ITextEditor {
5354
@ITextFileService private readonly _textFileService: ITextFileService,
5455
@IEditorService protected editorService: IEditorService,
5556
@IEditorGroupsService protected editorGroupService: IEditorGroupsService,
56-
@IHostService private readonly hostService: IHostService
57+
@IHostService private readonly hostService: IHostService,
58+
@IAutoSaveConfigurationService private readonly autoSaveConfigurationService: IAutoSaveConfigurationService
5759
) {
5860
super(id, telemetryService, themeService, storageService);
5961

@@ -165,7 +167,7 @@ export abstract class BaseTextEditor extends BaseEditor implements ITextEditor {
165167
}
166168

167169
private maybeTriggerSaveAll(reason: SaveReason): void {
168-
const mode = this.textFileService.getAutoSaveMode();
170+
const mode = this.autoSaveConfigurationService.getAutoSaveMode();
169171

170172
// Determine if we need to save all. In case of a window focus change we also save if auto save mode
171173
// is configured to be ON_FOCUS_CHANGE (editor focus change)

src/vs/workbench/browser/parts/editor/textResourceEditor.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editor
2424
import { CancellationToken } from 'vs/base/common/cancellation';
2525
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
2626
import { IHostService } from 'vs/workbench/services/host/browser/host';
27+
import { IAutoSaveConfigurationService } from 'vs/workbench/services/autoSaveConfiguration/common/autoSaveConfigurationService';
2728

2829
/**
2930
* An editor implementation that is capable of showing the contents of resource inputs. Uses
@@ -41,9 +42,10 @@ export class AbstractTextResourceEditor extends BaseTextEditor {
4142
@IEditorGroupsService editorGroupService: IEditorGroupsService,
4243
@ITextFileService textFileService: ITextFileService,
4344
@IEditorService editorService: IEditorService,
44-
@IHostService hostService: IHostService
45+
@IHostService hostService: IHostService,
46+
@IAutoSaveConfigurationService autoSaveConfigurationService: IAutoSaveConfigurationService
4547
) {
46-
super(id, telemetryService, instantiationService, storageService, configurationService, themeService, textFileService, editorService, editorGroupService, hostService);
48+
super(id, telemetryService, instantiationService, storageService, configurationService, themeService, textFileService, editorService, editorGroupService, hostService, autoSaveConfigurationService);
4749
}
4850

4951
getTitle(): string | undefined {
@@ -205,8 +207,9 @@ export class TextResourceEditor extends AbstractTextResourceEditor {
205207
@ITextFileService textFileService: ITextFileService,
206208
@IEditorService editorService: IEditorService,
207209
@IEditorGroupsService editorGroupService: IEditorGroupsService,
208-
@IHostService hostService: IHostService
210+
@IHostService hostService: IHostService,
211+
@IAutoSaveConfigurationService autoSaveConfigurationService: IAutoSaveConfigurationService
209212
) {
210-
super(TextResourceEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService, editorGroupService, textFileService, editorService, hostService);
213+
super(TextResourceEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService, editorGroupService, textFileService, editorService, hostService, autoSaveConfigurationService);
211214
}
212215
}

src/vs/workbench/browser/parts/quickopen/quickOpenController.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { Mode, IEntryRunContext, IAutoFocus, IQuickNavigateConfiguration, IModel
1616
import { QuickOpenEntry, QuickOpenModel, QuickOpenEntryGroup, QuickOpenItemAccessorClass } from 'vs/base/parts/quickopen/browser/quickOpenModel';
1717
import { QuickOpenWidget, HideReason } from 'vs/base/parts/quickopen/browser/quickOpenWidget';
1818
import { ContributableActionProvider } from 'vs/workbench/browser/actions';
19-
import { ITextFileService, AutoSaveMode } from 'vs/workbench/services/textfile/common/textfiles';
19+
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
2020
import { Registry } from 'vs/platform/registry/common/platform';
2121
import { IResourceInput } from 'vs/platform/editor/common/editor';
2222
import { IModeService } from 'vs/editor/common/services/modeService';
@@ -51,6 +51,7 @@ import { IQuickInputService, IQuickPickItem } from 'vs/platform/quickinput/commo
5151
import { CancellationTokenSource, CancellationToken } from 'vs/base/common/cancellation';
5252
import { IStorageService } from 'vs/platform/storage/common/storage';
5353
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
54+
import { IAutoSaveConfigurationService, AutoSaveMode } from 'vs/workbench/services/autoSaveConfiguration/common/autoSaveConfigurationService';
5455

5556
const HELP_PREFIX = '?';
5657

@@ -735,7 +736,8 @@ export class EditorHistoryEntry extends EditorQuickOpenEntry {
735736
@ITextFileService private readonly textFileService: ITextFileService,
736737
@IConfigurationService private readonly configurationService: IConfigurationService,
737738
@ILabelService labelService: ILabelService,
738-
@IFileService fileService: IFileService
739+
@IFileService fileService: IFileService,
740+
@IAutoSaveConfigurationService private readonly autoSaveConfigurationService: IAutoSaveConfigurationService
739741
) {
740742
super(editorService);
741743

@@ -753,7 +755,7 @@ export class EditorHistoryEntry extends EditorQuickOpenEntry {
753755
this.description = labelService.getUriLabel(resources.dirname(this.resource), { relative: true });
754756
this.dirty = this.resource && this.textFileService.isDirty(this.resource);
755757

756-
if (this.dirty && this.textFileService.getAutoSaveMode() === AutoSaveMode.AFTER_SHORT_DELAY) {
758+
if (this.dirty && this.autoSaveConfigurationService.getAutoSaveMode() === AutoSaveMode.AFTER_SHORT_DELAY) {
757759
this.dirty = false; // no dirty decoration if auto save is on with a short timeout
758760
}
759761
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
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, IAutoSaveConfiguration } from 'vs/workbench/services/textfile/common/textfiles';
9+
import { ITextFileService, TextFileModelChangeEvent, StateChange } from 'vs/workbench/services/textfile/common/textfiles';
1010
import { IUntitledTextEditorService } from 'vs/workbench/services/untitled/common/untitledTextEditorService';
1111
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
1212
import { CONTENT_CHANGE_EVENT_BUFFER_DELAY } from 'vs/platform/files/common/files';
13+
import { IAutoSaveConfigurationService, IAutoSaveConfiguration } from 'vs/workbench/services/autoSaveConfiguration/common/autoSaveConfigurationService';
1314

1415
const AUTO_SAVE_AFTER_DELAY_DISABLED_TIME = CONTENT_CHANGE_EVENT_BUFFER_DELAY + 500;
1516

@@ -21,6 +22,7 @@ export class BackupModelTracker extends Disposable implements IWorkbenchContribu
2122
@IBackupFileService private readonly backupFileService: IBackupFileService,
2223
@ITextFileService private readonly textFileService: ITextFileService,
2324
@IUntitledTextEditorService private readonly untitledTextEditorService: IUntitledTextEditorService,
25+
@IAutoSaveConfigurationService private readonly autoSaveConfigurationService: IAutoSaveConfigurationService
2426
) {
2527
super();
2628

@@ -38,8 +40,8 @@ export class BackupModelTracker extends Disposable implements IWorkbenchContribu
3840
this._register(this.untitledTextEditorService.onDidChangeContent(e => this.onUntitledModelChanged(e)));
3941
this._register(this.untitledTextEditorService.onDidDisposeModel(e => this.discardBackup(e)));
4042

41-
// Listen to config changes
42-
this._register(this.textFileService.onAutoSaveConfigurationChange(c => this.onAutoSaveConfigurationChange(c)));
43+
// Listen to auto save config changes
44+
this._register(this.autoSaveConfigurationService.onAutoSaveConfigurationChange(c => this.onAutoSaveConfigurationChange(c)));
4345
}
4446

4547
private onAutoSaveConfigurationChange(configuration: IAutoSaveConfiguration): void {

src/vs/workbench/contrib/files/browser/editors/textFileEditor.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { IEditorGroupView } from 'vs/workbench/browser/parts/editor/editor';
3232
import { createErrorWithActions } from 'vs/base/common/errorsWithActions';
3333
import { MutableDisposable } from 'vs/base/common/lifecycle';
3434
import { EditorActivation, IEditorOptions } from 'vs/platform/editor/common/editor';
35+
import { IAutoSaveConfigurationService } from 'vs/workbench/services/autoSaveConfiguration/common/autoSaveConfigurationService';
3536

3637
/**
3738
* An implementation of editor for file system resources.
@@ -56,9 +57,10 @@ export class TextFileEditor extends BaseTextEditor {
5657
@IEditorGroupsService editorGroupService: IEditorGroupsService,
5758
@ITextFileService textFileService: ITextFileService,
5859
@IHostService hostService: IHostService,
59-
@IExplorerService private readonly explorerService: IExplorerService
60+
@IExplorerService private readonly explorerService: IExplorerService,
61+
@IAutoSaveConfigurationService autoSaveConfigurationService: IAutoSaveConfigurationService
6062
) {
61-
super(TextFileEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService, textFileService, editorService, editorGroupService, hostService);
63+
super(TextFileEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService, textFileService, editorService, editorGroupService, hostService, autoSaveConfigurationService);
6264

6365
this.updateRestoreViewStateConfiguration();
6466

src/vs/workbench/contrib/files/browser/fileActions.contribution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { isMacintosh } from 'vs/base/common/platform';
1818
import { FilesExplorerFocusCondition, ExplorerRootContext, ExplorerFolderContext, ExplorerResourceNotReadonlyContext, ExplorerResourceCut, IExplorerService, ExplorerResourceMoveableToTrash, ExplorerViewletVisibleContext } from 'vs/workbench/contrib/files/common/files';
1919
import { ADD_ROOT_FOLDER_COMMAND_ID, ADD_ROOT_FOLDER_LABEL } from 'vs/workbench/browser/actions/workspaceCommands';
2020
import { CLOSE_SAVED_EDITORS_COMMAND_ID, CLOSE_EDITORS_IN_GROUP_COMMAND_ID, CLOSE_EDITOR_COMMAND_ID, CLOSE_OTHER_EDITORS_IN_GROUP_COMMAND_ID } from 'vs/workbench/browser/parts/editor/editorCommands';
21-
import { AutoSaveContext } from 'vs/workbench/services/textfile/common/textfiles';
21+
import { AutoSaveContext } from 'vs/workbench/services/autoSaveConfiguration/common/autoSaveConfigurationService';
2222
import { ResourceContextKey } from 'vs/workbench/common/resources';
2323
import { WorkbenchListDoubleSelection } from 'vs/platform/list/browser/listService';
2424
import { URI } from 'vs/base/common/uri';

src/vs/workbench/contrib/files/browser/fileActions.ts

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import 'vs/css!./media/fileactions';
77
import * as nls from 'vs/nls';
8-
import * as types from 'vs/base/common/types';
98
import { isWindows, isWeb } from 'vs/base/common/platform';
109
import * as extpath from 'vs/base/common/extpath';
1110
import { extname, basename } from 'vs/base/common/path';
@@ -17,7 +16,7 @@ import { Action } from 'vs/base/common/actions';
1716
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
1817
import { VIEWLET_ID, IExplorerService, IFilesConfiguration } from 'vs/workbench/contrib/files/common/files';
1918
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
20-
import { IFileService, AutoSaveConfiguration } from 'vs/platform/files/common/files';
19+
import { IFileService } from 'vs/platform/files/common/files';
2120
import { toResource, SideBySideEditor } from 'vs/workbench/common/editor';
2221
import { ExplorerViewlet } from 'vs/workbench/contrib/files/browser/explorerViewlet';
2322
import { IUntitledTextEditorService } from 'vs/workbench/services/untitled/common/untitledTextEditorService';
@@ -47,6 +46,7 @@ import { ExplorerItem, NewExplorerItem } from 'vs/workbench/contrib/files/common
4746
import { onUnexpectedError, getErrorMessage } from 'vs/base/common/errors';
4847
import { asDomUri, triggerDownload } from 'vs/base/browser/dom';
4948
import { mnemonicButtonLabel } from 'vs/base/common/labels';
49+
import { IAutoSaveConfigurationService } from 'vs/workbench/services/autoSaveConfiguration/common/autoSaveConfigurationService';
5050

5151
export const NEW_FILE_COMMAND_ID = 'explorer.newFile';
5252
export const NEW_FILE_LABEL = nls.localize('newFile', "New File");
@@ -496,26 +496,13 @@ export class ToggleAutoSaveAction extends Action {
496496
constructor(
497497
id: string,
498498
label: string,
499-
@IConfigurationService private readonly configurationService: IConfigurationService
499+
@IAutoSaveConfigurationService private readonly autoSaveConfigurationService: IAutoSaveConfigurationService
500500
) {
501501
super(id, label);
502502
}
503503

504504
run(): Promise<any> {
505-
const setting = this.configurationService.inspect('files.autoSave');
506-
let userAutoSaveConfig = setting.user;
507-
if (types.isUndefinedOrNull(userAutoSaveConfig)) {
508-
userAutoSaveConfig = setting.default; // use default if setting not defined
509-
}
510-
511-
let newAutoSaveValue: string;
512-
if ([AutoSaveConfiguration.AFTER_DELAY, AutoSaveConfiguration.ON_FOCUS_CHANGE, AutoSaveConfiguration.ON_WINDOW_CHANGE].some(s => s === userAutoSaveConfig)) {
513-
newAutoSaveValue = AutoSaveConfiguration.OFF;
514-
} else {
515-
newAutoSaveValue = AutoSaveConfiguration.AFTER_DELAY;
516-
}
517-
518-
return this.configurationService.updateValue('files.autoSave', newAutoSaveValue, ConfigurationTarget.USER);
505+
return this.autoSaveConfigurationService.toggleAutoSave();
519506
}
520507
}
521508

src/vs/workbench/contrib/files/browser/views/openEditorsView.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
1515
import { IEditorInput, Verbosity } from 'vs/workbench/common/editor';
1616
import { SaveAllAction, SaveAllInGroupAction, CloseGroupAction } from 'vs/workbench/contrib/files/browser/fileActions';
1717
import { OpenEditorsFocusedContext, ExplorerFocusedContext, IFilesConfiguration, OpenEditor } from 'vs/workbench/contrib/files/common/files';
18-
import { ITextFileService, AutoSaveMode } from 'vs/workbench/services/textfile/common/textfiles';
18+
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
1919
import { IUntitledTextEditorService } from 'vs/workbench/services/untitled/common/untitledTextEditorService';
2020
import { CloseAllEditorsAction, CloseEditorAction } from 'vs/workbench/browser/parts/editor/editorActions';
2121
import { ToggleEditorLayoutAction } from 'vs/workbench/browser/actions/layoutActions';
@@ -43,6 +43,7 @@ import { ElementsDragAndDropData, DesktopDragAndDropData } from 'vs/base/browser
4343
import { URI } from 'vs/base/common/uri';
4444
import { withNullAsUndefined, withUndefinedAsNull } from 'vs/base/common/types';
4545
import { isWeb } from 'vs/base/common/platform';
46+
import { IAutoSaveConfigurationService, AutoSaveMode } from 'vs/workbench/services/autoSaveConfiguration/common/autoSaveConfigurationService';
4647

4748
const $ = dom.$;
4849

@@ -76,7 +77,8 @@ export class OpenEditorsView extends ViewletPanel {
7677
@IContextKeyService private readonly contextKeyService: IContextKeyService,
7778
@IThemeService private readonly themeService: IThemeService,
7879
@ITelemetryService private readonly telemetryService: ITelemetryService,
79-
@IMenuService private readonly menuService: IMenuService
80+
@IMenuService private readonly menuService: IMenuService,
81+
@IAutoSaveConfigurationService private readonly autoSaveConfigurationService: IAutoSaveConfigurationService
8082
) {
8183
super({
8284
...(options as IViewletPanelOptions),
@@ -413,7 +415,7 @@ export class OpenEditorsView extends ViewletPanel {
413415
}
414416

415417
private updateDirtyIndicator(): void {
416-
let dirty = this.textFileService.getAutoSaveMode() !== AutoSaveMode.AFTER_SHORT_DELAY ? this.textFileService.getDirty().length
418+
let dirty = this.autoSaveConfigurationService.getAutoSaveMode() !== AutoSaveMode.AFTER_SHORT_DELAY ? this.textFileService.getDirty().length
417419
: this.untitledTextEditorService.getDirty().length;
418420
if (dirty === 0) {
419421
dom.addClass(this.dirtyCountElement, 'hidden');

0 commit comments

Comments
 (0)