Skip to content

Commit 557d444

Browse files
committed
open editors - adopt working copy service and track unsaved properly (#84672)
1 parent 44a7079 commit 557d444

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

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

+17-14
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ 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 } from 'vs/workbench/services/textfile/common/textfiles';
19-
import { IUntitledTextEditorService } from 'vs/workbench/services/untitled/common/untitledTextEditorService';
2018
import { CloseAllEditorsAction, CloseEditorAction } from 'vs/workbench/browser/parts/editor/editorActions';
2119
import { ToggleEditorLayoutAction } from 'vs/workbench/browser/actions/layoutActions';
2220
import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
@@ -43,7 +41,7 @@ import { ElementsDragAndDropData, DesktopDragAndDropData } from 'vs/base/browser
4341
import { URI } from 'vs/base/common/uri';
4442
import { withNullAsUndefined, withUndefinedAsNull } from 'vs/base/common/types';
4543
import { isWeb } from 'vs/base/common/platform';
46-
import { IAutoSaveConfigurationService, AutoSaveMode } from 'vs/workbench/services/autoSaveConfiguration/common/autoSaveConfigurationService';
44+
import { IWorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService';
4745

4846
const $ = dom.$;
4947

@@ -68,17 +66,15 @@ export class OpenEditorsView extends ViewletPanel {
6866
options: IViewletViewOptions,
6967
@IInstantiationService private readonly instantiationService: IInstantiationService,
7068
@IContextMenuService contextMenuService: IContextMenuService,
71-
@ITextFileService private readonly textFileService: ITextFileService,
7269
@IEditorService private readonly editorService: IEditorService,
7370
@IEditorGroupsService private readonly editorGroupService: IEditorGroupsService,
7471
@IConfigurationService configurationService: IConfigurationService,
7572
@IKeybindingService keybindingService: IKeybindingService,
76-
@IUntitledTextEditorService private readonly untitledTextEditorService: IUntitledTextEditorService,
7773
@IContextKeyService private readonly contextKeyService: IContextKeyService,
7874
@IThemeService private readonly themeService: IThemeService,
7975
@ITelemetryService private readonly telemetryService: ITelemetryService,
8076
@IMenuService private readonly menuService: IMenuService,
81-
@IAutoSaveConfigurationService private readonly autoSaveConfigurationService: IAutoSaveConfigurationService
77+
@IWorkingCopyService private readonly workingCopyService: IWorkingCopyService
8278
) {
8379
super({
8480
...(options as IViewletPanelOptions),
@@ -102,11 +98,7 @@ export class OpenEditorsView extends ViewletPanel {
10298
this._register(this.configurationService.onDidChangeConfiguration(e => this.onConfigurationChange(e)));
10399

104100
// Handle dirty counter
105-
this._register(this.untitledTextEditorService.onDidChangeDirty(() => this.updateDirtyIndicator()));
106-
this._register(this.textFileService.models.onModelsDirty(() => this.updateDirtyIndicator()));
107-
this._register(this.textFileService.models.onModelsSaved(() => this.updateDirtyIndicator()));
108-
this._register(this.textFileService.models.onModelsSaveError(() => this.updateDirtyIndicator()));
109-
this._register(this.textFileService.models.onModelsReverted(() => this.updateDirtyIndicator()));
101+
this._register(this.workingCopyService.onDidChangeDirty(() => this.updateDirtyIndicator()));
110102
}
111103

112104
private registerUpdateEvents(): void {
@@ -248,7 +240,7 @@ export class OpenEditorsView extends ViewletPanel {
248240
const element = e.elements.length ? e.elements[0] : undefined;
249241
if (element instanceof OpenEditor) {
250242
const resource = element.getResource();
251-
this.dirtyEditorFocusedContext.set(this.textFileService.isDirty(resource));
243+
this.dirtyEditorFocusedContext.set(element.editor.isDirty());
252244
this.resourceContext.set(withUndefinedAsNull(resource));
253245
} else if (!!element) {
254246
this.groupFocusedContext.set(true);
@@ -415,8 +407,7 @@ export class OpenEditorsView extends ViewletPanel {
415407
}
416408

417409
private updateDirtyIndicator(): void {
418-
let dirty = this.autoSaveConfigurationService.getAutoSaveMode() !== AutoSaveMode.AFTER_SHORT_DELAY ? this.textFileService.getDirty().length
419-
: this.untitledTextEditorService.getDirty().length;
410+
let dirty = this.dirtyCount;
420411
if (dirty === 0) {
421412
dom.addClass(this.dirtyCountElement, 'hidden');
422413
} else {
@@ -425,6 +416,18 @@ export class OpenEditorsView extends ViewletPanel {
425416
}
426417
}
427418

419+
private get dirtyCount(): number {
420+
let dirtyCount = 0;
421+
422+
for (const element of this.elements) {
423+
if (element instanceof OpenEditor && element.editor.isDirty()) {
424+
dirtyCount++;
425+
}
426+
}
427+
428+
return dirtyCount;
429+
}
430+
428431
private get elementCount(): number {
429432
return this.editorGroupService.groups.map(g => g.count)
430433
.reduce((first, second) => first + second, this.showGroups ? this.editorGroupService.groups.length : 0);

src/vs/workbench/contrib/testCustomEditors/browser/testCustomEditors.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ import { generateUuid } from 'vs/base/common/uuid';
2525
import { CancellationToken } from 'vs/base/common/cancellation';
2626
import { editorBackground, editorForeground } from 'vs/platform/theme/common/colorRegistry';
2727
import { IWorkingCopy, IWorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService';
28+
import { env } from 'vs/base/common/process';
2829

2930
const CUSTOM_SCHEME = 'testCustomEditor';
30-
const ENABLE = false;
31+
const ENABLE = !!env['VSCODE_DEV'];
3132

3233
class TestCustomEditorsAction extends Action {
3334

0 commit comments

Comments
 (0)