提交 557d444f 编写于 作者: B Benjamin Pasero

open editors - adopt working copy service and track unsaved properly (#84672)

上级 44a7079e
......@@ -15,8 +15,6 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IEditorInput, Verbosity } from 'vs/workbench/common/editor';
import { SaveAllAction, SaveAllInGroupAction, CloseGroupAction } from 'vs/workbench/contrib/files/browser/fileActions';
import { OpenEditorsFocusedContext, ExplorerFocusedContext, IFilesConfiguration, OpenEditor } from 'vs/workbench/contrib/files/common/files';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { IUntitledTextEditorService } from 'vs/workbench/services/untitled/common/untitledTextEditorService';
import { CloseAllEditorsAction, CloseEditorAction } from 'vs/workbench/browser/parts/editor/editorActions';
import { ToggleEditorLayoutAction } from 'vs/workbench/browser/actions/layoutActions';
import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
......@@ -43,7 +41,7 @@ import { ElementsDragAndDropData, DesktopDragAndDropData } from 'vs/base/browser
import { URI } from 'vs/base/common/uri';
import { withNullAsUndefined, withUndefinedAsNull } from 'vs/base/common/types';
import { isWeb } from 'vs/base/common/platform';
import { IAutoSaveConfigurationService, AutoSaveMode } from 'vs/workbench/services/autoSaveConfiguration/common/autoSaveConfigurationService';
import { IWorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService';
const $ = dom.$;
......@@ -68,17 +66,15 @@ export class OpenEditorsView extends ViewletPanel {
options: IViewletViewOptions,
@IInstantiationService private readonly instantiationService: IInstantiationService,
@IContextMenuService contextMenuService: IContextMenuService,
@ITextFileService private readonly textFileService: ITextFileService,
@IEditorService private readonly editorService: IEditorService,
@IEditorGroupsService private readonly editorGroupService: IEditorGroupsService,
@IConfigurationService configurationService: IConfigurationService,
@IKeybindingService keybindingService: IKeybindingService,
@IUntitledTextEditorService private readonly untitledTextEditorService: IUntitledTextEditorService,
@IContextKeyService private readonly contextKeyService: IContextKeyService,
@IThemeService private readonly themeService: IThemeService,
@ITelemetryService private readonly telemetryService: ITelemetryService,
@IMenuService private readonly menuService: IMenuService,
@IAutoSaveConfigurationService private readonly autoSaveConfigurationService: IAutoSaveConfigurationService
@IWorkingCopyService private readonly workingCopyService: IWorkingCopyService
) {
super({
...(options as IViewletPanelOptions),
......@@ -102,11 +98,7 @@ export class OpenEditorsView extends ViewletPanel {
this._register(this.configurationService.onDidChangeConfiguration(e => this.onConfigurationChange(e)));
// Handle dirty counter
this._register(this.untitledTextEditorService.onDidChangeDirty(() => this.updateDirtyIndicator()));
this._register(this.textFileService.models.onModelsDirty(() => this.updateDirtyIndicator()));
this._register(this.textFileService.models.onModelsSaved(() => this.updateDirtyIndicator()));
this._register(this.textFileService.models.onModelsSaveError(() => this.updateDirtyIndicator()));
this._register(this.textFileService.models.onModelsReverted(() => this.updateDirtyIndicator()));
this._register(this.workingCopyService.onDidChangeDirty(() => this.updateDirtyIndicator()));
}
private registerUpdateEvents(): void {
......@@ -248,7 +240,7 @@ export class OpenEditorsView extends ViewletPanel {
const element = e.elements.length ? e.elements[0] : undefined;
if (element instanceof OpenEditor) {
const resource = element.getResource();
this.dirtyEditorFocusedContext.set(this.textFileService.isDirty(resource));
this.dirtyEditorFocusedContext.set(element.editor.isDirty());
this.resourceContext.set(withUndefinedAsNull(resource));
} else if (!!element) {
this.groupFocusedContext.set(true);
......@@ -415,8 +407,7 @@ export class OpenEditorsView extends ViewletPanel {
}
private updateDirtyIndicator(): void {
let dirty = this.autoSaveConfigurationService.getAutoSaveMode() !== AutoSaveMode.AFTER_SHORT_DELAY ? this.textFileService.getDirty().length
: this.untitledTextEditorService.getDirty().length;
let dirty = this.dirtyCount;
if (dirty === 0) {
dom.addClass(this.dirtyCountElement, 'hidden');
} else {
......@@ -425,6 +416,18 @@ export class OpenEditorsView extends ViewletPanel {
}
}
private get dirtyCount(): number {
let dirtyCount = 0;
for (const element of this.elements) {
if (element instanceof OpenEditor && element.editor.isDirty()) {
dirtyCount++;
}
}
return dirtyCount;
}
private get elementCount(): number {
return this.editorGroupService.groups.map(g => g.count)
.reduce((first, second) => first + second, this.showGroups ? this.editorGroupService.groups.length : 0);
......
......@@ -25,9 +25,10 @@ import { generateUuid } from 'vs/base/common/uuid';
import { CancellationToken } from 'vs/base/common/cancellation';
import { editorBackground, editorForeground } from 'vs/platform/theme/common/colorRegistry';
import { IWorkingCopy, IWorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService';
import { env } from 'vs/base/common/process';
const CUSTOM_SCHEME = 'testCustomEditor';
const ENABLE = false;
const ENABLE = !!env['VSCODE_DEV'];
class TestCustomEditorsAction extends Action {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册