Skip to content

Commit

Permalink
Revert "improve revert logic for untitled"
Browse files Browse the repository at this point in the history
This reverts commit 0256f00.
  • Loading branch information
bpasero committed Jun 6, 2016
1 parent 8a9ddea commit 2d33d75
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 50 deletions.
4 changes: 2 additions & 2 deletions src/vs/workbench/browser/parts/editor/stringEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ export class StringEditor extends BaseTextEditor {

this.mapResourceToEditorViewState = Object.create(null);

this.toUnbind.push(this.eventService.addListener2(EventType.UNTITLED_FILE_SAVED, (e: UntitledEditorEvent) => this.onUntitledSavedEvent(e)));
this.toUnbind.push(this.eventService.addListener2(EventType.UNTITLED_FILE_DELETED, (e: UntitledEditorEvent) => this.onUntitledDeletedEvent(e)));
}

private onUntitledSavedEvent(e: UntitledEditorEvent): void {
private onUntitledDeletedEvent(e: UntitledEditorEvent): void {
delete this.mapResourceToEditorViewState[e.resource.toString()];
}

Expand Down
12 changes: 5 additions & 7 deletions src/vs/workbench/common/editor/untitledEditorInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput {
}

private registerListeners(): void {
this.toUnbind.push(this.eventService.addListener2(WorkbenchEventType.UNTITLED_FILE_SAVED, (e: UntitledEditorEvent) => this.onDirtyStateChange(e)));
this.toUnbind.push(this.eventService.addListener2(WorkbenchEventType.UNTITLED_FILE_DELETED, (e: UntitledEditorEvent) => this.onDirtyStateChange(e)));
this.toUnbind.push(this.eventService.addListener2(WorkbenchEventType.UNTITLED_FILE_DIRTY, (e: UntitledEditorEvent) => this.onDirtyStateChange(e)));
}

Expand Down Expand Up @@ -97,9 +97,7 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput {
}

public revert(): TPromise<boolean> {
this.cachedModel.revert();

return TPromise.as(true);
return this.textFileService.revert(this.resource);
}

public suggestFileName(): string {
Expand Down Expand Up @@ -181,15 +179,15 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput {

public dispose(): void {

// Listeners
dispose(this.toUnbind);

// Model
if (this.cachedModel) {
this.cachedModel.dispose();
this.cachedModel = null;
}

// Listeners
dispose(this.toUnbind);

super.dispose();
}
}
10 changes: 4 additions & 6 deletions src/vs/workbench/common/editor/untitledEditorModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,6 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
return this.dirty;
}

public revert(): void {
this.dirty = false;

this.eventService.emit(WorkbenchEventType.UNTITLED_FILE_SAVED, new UntitledEditorEvent(this.resource));
}

public load(): TPromise<EditorModel> {
return super.load().then((model) => {
const configuration = this.configurationService.getConfiguration<IFilesConfiguration>();
Expand Down Expand Up @@ -123,6 +117,8 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
public dispose(): void {
super.dispose();

this.dirty = false; // we can no longer be dirty

if (this.textModelChangeListener) {
this.textModelChangeListener.dispose();
this.textModelChangeListener = null;
Expand All @@ -132,5 +128,7 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
this.configurationChangeListener.dispose();
this.configurationChangeListener = null;
}

this.eventService.emit(WorkbenchEventType.UNTITLED_FILE_DELETED, new UntitledEditorEvent(this.resource));
}
}
4 changes: 2 additions & 2 deletions src/vs/workbench/common/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ export class EventType {
static UNTITLED_FILE_DIRTY = 'untitledFileDirty';

/**
* Event type for when an untitled file is saved.
* Event type for when an untitled file is deleted.
*/
static UNTITLED_FILE_SAVED = 'untitledFileSaved';
static UNTITLED_FILE_DELETED = 'untitledFileDeleted';

/**
* Event type for when a resources encoding changes.
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/parts/files/browser/fileActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,7 @@ export abstract class BaseSaveAllAction extends BaseActionWithErrorReporting {

if (this.includeUntitled()) {
this.toDispose.push(this.eventService.addListener2(WorkbenchEventType.UNTITLED_FILE_DIRTY, () => this.updateEnablement(true)));
this.toDispose.push(this.eventService.addListener2(WorkbenchEventType.UNTITLED_FILE_SAVED, () => this.updateEnablement(false)));
this.toDispose.push(this.eventService.addListener2(WorkbenchEventType.UNTITLED_FILE_DELETED, () => this.updateEnablement(false)));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/parts/files/browser/fileTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class FileTracker implements IWorkbenchContribution {

// Update editors and inputs from local changes and saves
this.toUnbind.push(this.editorGroupService.onEditorsChanged(() => this.onEditorsChanged()));
this.toUnbind.push(this.eventService.addListener2(WorkbenchEventType.UNTITLED_FILE_SAVED, (e: UntitledEditorEvent) => this.onUntitledEditorSaved(e)));
this.toUnbind.push(this.eventService.addListener2(WorkbenchEventType.UNTITLED_FILE_DELETED, (e: UntitledEditorEvent) => this.onUntitledEditorDeleted(e)));
this.toUnbind.push(this.eventService.addListener2(WorkbenchEventType.UNTITLED_FILE_DIRTY, (e: UntitledEditorEvent) => this.onUntitledEditorDirty(e)));
this.toUnbind.push(this.eventService.addListener2(FileEventType.FILE_DIRTY, (e: TextFileChangeEvent) => this.onTextFileDirty(e)));
this.toUnbind.push(this.eventService.addListener2(FileEventType.FILE_SAVE_ERROR, (e: TextFileChangeEvent) => this.onTextFileSaveError(e)));
Expand Down Expand Up @@ -107,7 +107,7 @@ export class FileTracker implements IWorkbenchContribution {
this.updateActivityBadge();
}

private onUntitledEditorSaved(e: UntitledEditorEvent): void {
private onUntitledEditorDeleted(e: UntitledEditorEvent): void {
if (this.lastDirtyCount > 0) {
this.updateActivityBadge();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class FileTracker implements IWorkbenchContribution {
private registerListeners(): void {

// Local text file changes
this.toUnbind.push(this.eventService.addListener2(WorkbenchEventType.UNTITLED_FILE_SAVED, () => this.onUntitledSavedEvent()));
this.toUnbind.push(this.eventService.addListener2(WorkbenchEventType.UNTITLED_FILE_DELETED, () => this.onUntitledDeletedEvent()));
this.toUnbind.push(this.eventService.addListener2(WorkbenchEventType.UNTITLED_FILE_DIRTY, () => this.onUntitledDirtyEvent()));
this.toUnbind.push(this.eventService.addListener2(FileEventType.FILE_DIRTY, (e: TextFileChangeEvent) => this.onTextFileDirty(e)));
this.toUnbind.push(this.eventService.addListener2(FileEventType.FILE_SAVED, (e: TextFileChangeEvent) => this.onTextFileSaved(e)));
Expand Down Expand Up @@ -199,7 +199,7 @@ export class FileTracker implements IWorkbenchContribution {
}
}

private onUntitledSavedEvent(): void {
private onUntitledDeletedEvent(): void {
if (this.isDocumentedEdited) {
this.updateDocumentEdited();
}
Expand Down
13 changes: 11 additions & 2 deletions src/vs/workbench/parts/files/electron-browser/textFileServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,17 @@ export class TextFileService extends AbstractTextFileService {
return super.revertAll(resources, force).then(r => {

// Revert untitled
const reverted = this.untitledEditorService.revertAll(resources);
reverted.forEach(res => r.results.push({ source: res, success: true }));
let untitledInputs = this.untitledEditorService.getAll(resources);
untitledInputs.forEach(input => {
if (input) {
input.dispose();

r.results.push({
source: input.getResource(),
success: true
});
}
});

return r;
});
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/parts/search/browser/searchViewlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ export class SearchViewlet extends Viewlet {
this.viewletSettings = this.getMemento(storageService, Scope.WORKSPACE);

this.toUnbind.push(this.eventService.addListener2(FileEventType.FILE_CHANGES, (e) => this.onFilesChanged(e)));
this.toUnbind.push(this.eventService.addListener2(WorkbenchEventType.UNTITLED_FILE_SAVED, (e) => this.onUntitledFileSaved(e)));
this.toUnbind.push(this.eventService.addListener2(WorkbenchEventType.UNTITLED_FILE_DELETED, (e) => this.onUntitledFileDeleted(e)));
this.toUnbind.push(this.configurationService.onDidUpdateConfiguration(e => this.onConfigurationUpdated(e.config)));
}

Expand Down Expand Up @@ -1456,7 +1456,7 @@ export class SearchViewlet extends Viewlet {
}, sideBySide);
}

private onUntitledFileSaved(e: UntitledEditorEvent): void {
private onUntitledFileDeleted(e: UntitledEditorEvent): void {
if (!this.viewModel) {
return;
}
Expand Down
20 changes: 0 additions & 20 deletions src/vs/workbench/services/untitled/common/untitledEditorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ export interface IUntitledEditorService {
*/
isDirty(resource: URI): boolean;

/**
* Reverts the untitled resources if found.
*/
revertAll(resources?: URI[]): URI[];

/**
* Creates a new untitled input with the optional resource URI or returns an existing one
* if the provided resource exists already as untitled input.
Expand Down Expand Up @@ -77,21 +72,6 @@ export class UntitledEditorService implements IUntitledEditorService {
return Object.keys(UntitledEditorService.CACHE).map((key) => UntitledEditorService.CACHE[key]);
}

public revertAll(resources?: URI[], force?: boolean): URI[] {
const reverted: URI[] = [];

const untitledInputs = this.getAll(resources);
untitledInputs.forEach(input => {
if (input) {
input.revert();

reverted.push(input.getResource());
}
});

return reverted;
}

public isDirty(resource: URI): boolean {
let input = this.get(resource);

Expand Down
4 changes: 0 additions & 4 deletions src/vs/workbench/test/common/servicesTestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,6 @@ export class TestUntitledEditorService implements IUntitledEditorService {
return [];
}

public revertAll(resources?: URI[]): URI[] {
return [];
}

public isDirty() {
return false;
}
Expand Down

0 comments on commit 2d33d75

Please sign in to comment.