text file service - make api fit for resource arrays
This commit is contained in:
parent
9ace9db63c
commit
f3e6aed456
5 changed files with 20 additions and 23 deletions
|
@ -154,7 +154,7 @@ export class BaseFileAction extends Action {
|
|||
|
||||
protected handleDirty(): TPromise<boolean /* cancel */> {
|
||||
if (this.textFileService.isDirty(this._element.resource)) {
|
||||
let res = this.textFileService.confirmSave(this._element.resource);
|
||||
let res = this.textFileService.confirmSave([this._element.resource]);
|
||||
if (res === Files.ConfirmResult.SAVE) {
|
||||
return this.textFileService.save(this._element.resource).then(() => false);
|
||||
}
|
||||
|
@ -1832,7 +1832,7 @@ export class CloseWorkingFileAction extends Action {
|
|||
// Handle dirty
|
||||
let saveOrRevertPromise: TPromise<Files.ITextFileOperationResult> = Promise.as(null);
|
||||
if (this.textFileService.isDirty(this.element ? this.element.resource : void 0 /* all */)) {
|
||||
let confirmResult = this.textFileService.confirmSave(this.element ? this.element.resource : void 0 /* all */);
|
||||
let confirmResult = this.textFileService.confirmSave(this.element ? [this.element.resource] : void 0 /* all */);
|
||||
|
||||
switch (confirmResult) {
|
||||
case Files.ConfirmResult.SAVE:
|
||||
|
|
|
@ -127,8 +127,8 @@ export abstract class TextFileService implements ITextFileService {
|
|||
}
|
||||
}
|
||||
|
||||
public getDirty(resource?: URI): URI[] {
|
||||
return this.getDirtyFileModels(resource).map((m) => m.getResource());
|
||||
public getDirty(resources?: URI[]): URI[] {
|
||||
return this.getDirtyFileModels(resources).map((m) => m.getResource());
|
||||
}
|
||||
|
||||
public isDirty(resource?: URI): boolean {
|
||||
|
@ -187,7 +187,7 @@ export abstract class TextFileService implements ITextFileService {
|
|||
|
||||
public abstract saveAs(resource: URI, targetResource?: URI): TPromise<URI>;
|
||||
|
||||
public confirmSave(resource?: URI): ConfirmResult {
|
||||
public confirmSave(resources?: URI[]): ConfirmResult {
|
||||
throw new Error('Unsupported');
|
||||
}
|
||||
|
||||
|
|
|
@ -826,7 +826,7 @@ export class FileDragAndDrop implements IDragAndDrop {
|
|||
// Handle dirty
|
||||
let saveOrRevertPromise: Promise = Promise.as(null);
|
||||
if (this.textFileService.isDirty(source.resource)) {
|
||||
let res = this.textFileService.confirmSave(source.resource);
|
||||
let res = this.textFileService.confirmSave([source.resource]);
|
||||
if (res === ConfirmResult.SAVE) {
|
||||
saveOrRevertPromise = this.textFileService.save(source.resource);
|
||||
} else if (res === ConfirmResult.DONT_SAVE) {
|
||||
|
|
|
@ -314,12 +314,12 @@ export interface ITextFileService extends IDisposable {
|
|||
isDirty(resource?: URI): boolean;
|
||||
|
||||
/**
|
||||
* Returns all resources that are currently dirty matching the provided resource or all dirty resources.
|
||||
* Returns all resources that are currently dirty matching the provided resources or all dirty resources.
|
||||
*
|
||||
* @param resource the resource to check for being dirty. If it is not specified, will check for
|
||||
* @param resources the resources to check for being dirty. If it is not specified, will check for
|
||||
* all dirty resources.
|
||||
*/
|
||||
getDirty(resource?: URI): URI[];
|
||||
getDirty(resources?: URI[]): URI[];
|
||||
|
||||
/**
|
||||
* Saves the resource.
|
||||
|
@ -364,9 +364,10 @@ export interface ITextFileService extends IDisposable {
|
|||
/**
|
||||
* Brings up the confirm dialog to either save, don't save or cancel.
|
||||
*
|
||||
* @param resource the resource of the file to ask for confirmation.
|
||||
* @param resources the resources of the files to ask for confirmation or null if
|
||||
* confirming for all dirty resources.
|
||||
*/
|
||||
confirmSave(resource?: URI): ConfirmResult;
|
||||
confirmSave(resources?: URI[]): ConfirmResult;
|
||||
|
||||
/**
|
||||
* Provides access to the list of working files.
|
||||
|
|
|
@ -119,19 +119,17 @@ export class TextFileService extends AbstractTextFileService {
|
|||
});
|
||||
}
|
||||
|
||||
public getDirty(resource?: URI): URI[] {
|
||||
public getDirty(resources?: URI[]): URI[] {
|
||||
|
||||
// Collect files
|
||||
let dirty = super.getDirty(resource);
|
||||
let dirty = super.getDirty(resources);
|
||||
|
||||
// Add untitled ones
|
||||
if (!resource) {
|
||||
if (!resources) {
|
||||
dirty.push(...this.untitledEditorService.getDirty());
|
||||
} else {
|
||||
let input = this.untitledEditorService.get(resource);
|
||||
if (input && input.isDirty()) {
|
||||
dirty.push(input.getResource());
|
||||
}
|
||||
let dirtyUntitled = resources.map(r => this.untitledEditorService.get(r)).filter(u => u && u.isDirty()).map(u => u.getResource());
|
||||
dirty.push(...dirtyUntitled);
|
||||
}
|
||||
|
||||
return dirty;
|
||||
|
@ -145,12 +143,12 @@ export class TextFileService extends AbstractTextFileService {
|
|||
return this.untitledEditorService.getDirty().some((dirty) => !resource || dirty.toString() === resource.toString());
|
||||
}
|
||||
|
||||
public confirmSave(resource?: URI): ConfirmResult {
|
||||
public confirmSave(resources?: URI[]): ConfirmResult {
|
||||
if (!!this.contextService.getConfiguration().env.pluginDevelopmentPath) {
|
||||
return ConfirmResult.DONT_SAVE; // no veto when we are in plugin dev mode because we cannot assum we run interactive (e.g. tests)
|
||||
}
|
||||
|
||||
let resourcesToConfirm = this.getDirty(resource);
|
||||
let resourcesToConfirm = this.getDirty(resources);
|
||||
if (resourcesToConfirm.length === 0) {
|
||||
return ConfirmResult.DONT_SAVE;
|
||||
}
|
||||
|
@ -210,9 +208,7 @@ export class TextFileService extends AbstractTextFileService {
|
|||
// get all dirty
|
||||
let toSave: URI[] = [];
|
||||
if (Array.isArray(arg1)) {
|
||||
(<URI[]>arg1).forEach((r) => {
|
||||
toSave.push(...this.getDirty(r));
|
||||
});
|
||||
toSave = this.getDirty(arg1);
|
||||
} else {
|
||||
toSave = this.getDirty();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue