提交 5fd42b76 编写于 作者: B Benjamin Pasero

editor - add group to revert()

上级 df8cdd94
......@@ -543,13 +543,13 @@ export class RevertAndCloseEditorAction extends Action {
// first try a normal revert where the contents of the editor are restored
try {
await editor.revert();
await editor.revert(group.id);
} catch (error) {
// if that fails, since we are about to close the editor, we accept that
// the editor cannot be reverted and instead do a soft revert that just
// enables us to close the editor. With this, a user can always close a
// dirty editor even when reverting fails.
await editor.revert({ soft: true });
await editor.revert(group.id, { soft: true });
}
group.closeEditor(editor);
......
......@@ -1330,7 +1330,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
// Otherwise, handle accordingly
switch (res) {
case ConfirmResult.SAVE:
const result = await editor.save(this._group.id, { reason: SaveReason.EXPLICIT, context: SaveContext.EDITOR_CLOSE });
const result = await editor.save(this.id, { reason: SaveReason.EXPLICIT, context: SaveContext.EDITOR_CLOSE });
return !result;
case ConfirmResult.DONT_SAVE:
......@@ -1338,7 +1338,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
try {
// first try a normal revert where the contents of the editor are restored
const result = await editor.revert();
const result = await editor.revert(this.id);
return !result;
} catch (error) {
......@@ -1346,7 +1346,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
// the editor cannot be reverted and instead do a soft revert that just
// enables us to close the editor. With this, a user can always close a
// dirty editor even when reverting fails.
const result = await editor.revert({ soft: true });
const result = await editor.revert(this.id, { soft: true });
return !result;
}
......
......@@ -16,7 +16,7 @@ import { IConfigurationService, IConfigurationChangeEvent } from 'vs/platform/co
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { DisposableStore, dispose } from 'vs/base/common/lifecycle';
import * as nls from 'vs/nls';
import { EditorInput, toResource, Verbosity, SideBySideEditor } from 'vs/workbench/common/editor';
import { toResource, Verbosity, SideBySideEditor } from 'vs/workbench/common/editor';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { IWorkspaceContextService, WorkbenchState, IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
import { IThemeService, registerThemingParticipant, ITheme, ICssStyleCollector } from 'vs/platform/theme/common/themeService';
......@@ -195,7 +195,7 @@ export class TitlebarPart extends Part implements ITitleService {
// Apply listener for dirty and label changes
const activeEditor = this.editorService.activeEditor;
if (activeEditor instanceof EditorInput) {
if (activeEditor) {
this.activeEditorListeners.add(activeEditor.onDidChangeDirty(() => this.titleUpdater.schedule()));
this.activeEditorListeners.add(activeEditor.onDidChangeLabel(() => this.titleUpdater.schedule()));
}
......
......@@ -362,6 +362,16 @@ export interface IEditorInput extends IDisposable {
*/
readonly onDispose: Event<void>;
/**
* Triggered when this input changes its dirty state.
*/
readonly onDidChangeDirty: Event<void>;
/**
* Triggered when this input changes its label
*/
readonly onDidChangeLabel: Event<void>;
/**
* Returns the associated resource of this input.
*/
......@@ -416,9 +426,9 @@ export interface IEditorInput extends IDisposable {
isSaving(): boolean;
/**
* Saves the editor. The provided groupId helps
* implementors to e.g. preserve view state of the editor
* and re-open it in the correct group after saving.
* Saves the editor. The provided groupId helps implementors
* to e.g. preserve view state of the editor and re-open it
* in the correct group after saving.
*/
save(groupId: GroupIdentifier, options?: ISaveOptions): Promise<boolean>;
......@@ -430,9 +440,9 @@ export interface IEditorInput extends IDisposable {
saveAs(groupId: GroupIdentifier, options?: ISaveOptions): Promise<boolean>;
/**
* Reverts this input.
* Reverts this input from the provided group.
*/
revert(options?: IRevertOptions): Promise<boolean>;
revert(group: GroupIdentifier, options?: IRevertOptions): Promise<boolean>;
/**
* Returns if the other object matches this input.
......@@ -532,7 +542,7 @@ export abstract class EditorInput extends Disposable implements IEditorInput {
return true;
}
async revert(options?: IRevertOptions): Promise<boolean> {
async revert(group: GroupIdentifier, options?: IRevertOptions): Promise<boolean> {
return true;
}
......@@ -614,6 +624,10 @@ export abstract class TextEditorInput extends EditorInput {
return true;
}
revert(group: GroupIdentifier, options?: IRevertOptions): Promise<boolean> {
return this.textFileService.revert(this.resource, options);
}
}
export const enum EncodingMode {
......@@ -743,8 +757,8 @@ export class SideBySideEditorInput extends EditorInput {
return this.master.saveAs(groupId, options);
}
revert(options?: IRevertOptions): Promise<boolean> {
return this.master.revert(options);
revert(group: GroupIdentifier, options?: IRevertOptions): Promise<boolean> {
return this.master.revert(group, options);
}
getTelemetryDescriptor(): { [key: string]: unknown } {
......
......@@ -193,7 +193,7 @@ export class UntitledTextEditorInput extends TextEditorInput implements IEncodin
return this.doSaveAs(group, options, () => this.textFileService.saveAs(this.resource, undefined, options), true /* replace editor across all groups */);
}
async revert(options?: IRevertOptions): Promise<boolean> {
async revert(group: GroupIdentifier, options?: IRevertOptions): Promise<boolean> {
if (this.cachedModel) {
this.cachedModel.revert();
}
......
......@@ -149,7 +149,7 @@ export class CustomFileEditorInput extends LazilyResolvedWebviewEditorInput {
return true;
}
public revert(options?: IRevertOptions): Promise<boolean> {
public revert(group: GroupIdentifier, options?: IRevertOptions): Promise<boolean> {
return this._model ? this._model.revert(options) : Promise.resolve(false);
}
......
......@@ -7,7 +7,7 @@ import { localize } from 'vs/nls';
import { createMemoizer } from 'vs/base/common/decorators';
import { dirname } from 'vs/base/common/resources';
import { URI } from 'vs/base/common/uri';
import { EncodingMode, IFileEditorInput, ITextEditorModel, Verbosity, TextEditorInput, IRevertOptions } from 'vs/workbench/common/editor';
import { EncodingMode, IFileEditorInput, ITextEditorModel, Verbosity, TextEditorInput } from 'vs/workbench/common/editor';
import { TextFileEditorModel } from 'vs/workbench/services/textfile/common/textFileEditorModel';
import { BinaryEditorModel } from 'vs/workbench/common/editor/binaryEditorModel';
import { FileOperationError, FileOperationResult, IFileService, FileSystemProviderCapabilities } from 'vs/platform/files/common/files';
......@@ -262,10 +262,6 @@ export class FileEditorInput extends TextEditorInput implements IFileEditorInput
return false;
}
revert(options?: IRevertOptions): Promise<boolean> {
return this.textFileService.revert(this.resource, options);
}
getPreferredEditorId(candidates: string[]): string {
return this.forceOpenAs === ForceOpenAs.Binary ? BINARY_FILE_EDITOR_ID : TEXT_FILE_EDITOR_ID;
}
......
......@@ -152,7 +152,7 @@ suite('Files - FileEditorInput', () => {
resolved.textEditorModel!.setValue('changed');
assert.ok(input.isDirty());
assert.ok(await input.revert());
assert.ok(await input.revert(0));
assert.ok(!input.isDirty());
input.dispose();
......
......@@ -79,7 +79,7 @@ export class SearchEditorInput extends EditorInput {
isDirty: () => this.isDirty(),
backup: () => this.backup(),
save: (options) => this.save(0, options),
revert: () => this.revert(),
revert: () => this.revert(0),
};
this.workingCopyService.registerWorkingCopy(workingCopyAdapter);
......@@ -181,9 +181,9 @@ export class SearchEditorInput extends EditorInput {
return false;
}
async revert(options?: IRevertOptions) {
async revert(group: GroupIdentifier, options?: IRevertOptions) {
// TODO: this should actually revert the contents. But it needs to set dirty false.
super.revert(options);
super.revert(group, options);
this.setDirty(false);
return true;
}
......
......@@ -737,7 +737,7 @@ export class EditorService extends Disposable implements EditorServiceImpl {
// Use revert as a hint to pin the editor
this.editorGroupService.getGroup(groupId)?.pinEditor(editor);
return editor.revert(options);
return editor.revert(groupId, options);
}));
return result.every(success => !!success);
......
......@@ -80,7 +80,7 @@ class TestEditorInput extends EditorInput implements IFileEditorInput {
this.gotSavedAs = true;
return true;
}
async revert(options?: IRevertOptions): Promise<boolean> {
async revert(group: GroupIdentifier, options?: IRevertOptions): Promise<boolean> {
this.gotReverted = true;
this.gotSaved = false;
this.gotSavedAs = false;
......
......@@ -579,7 +579,7 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
if (resource.scheme === Schemas.untitled) {
const model = this.untitled.get(resource);
if (model) {
return model.revert(options);
return model.revert(0, options);
}
return false;
......
......@@ -62,7 +62,7 @@ suite('Workbench untitled text editors', () => {
assert.equal(service.get(input2.getResource()), input2);
// revert()
input1.revert();
input1.revert(0);
assert.ok(input1.isDisposed());
assert.ok(!service.get(input1.getResource()));
......@@ -82,8 +82,8 @@ suite('Workbench untitled text editors', () => {
assert.ok(workingCopyService.isDirty(input2.getResource()));
assert.equal(workingCopyService.dirtyCount, 1);
input1.revert();
input2.revert();
input1.revert(0);
input2.revert(0);
assert.ok(!service.get(input1.getResource()));
assert.ok(!service.get(input2.getResource()));
assert.ok(!input2.isDirty());
......@@ -92,7 +92,7 @@ suite('Workbench untitled text editors', () => {
assert.ok(!workingCopyService.isDirty(input2.getResource()));
assert.equal(workingCopyService.dirtyCount, 0);
assert.ok(input1.revert());
assert.ok(input1.revert(0));
assert.ok(input1.isDisposed());
assert.ok(!service.exists(input1.getResource()));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册