Skip to content

Commit 5d0bd49

Browse files
author
Benjamin Pasero
committed
💄 text files
1 parent 72186b2 commit 5d0bd49

3 files changed

Lines changed: 31 additions & 30 deletions

File tree

src/vs/workbench/contrib/files/browser/fileActions.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,11 @@ async function deleteFiles(workingCopyService: IWorkingCopyService, textFileServ
232232
});
233233
}
234234

235-
236-
237235
// Check for confirmation checkbox
238236
if (confirmation.confirmed && confirmation.checkboxChecked === true) {
239237
await configurationService.updateValue(CONFIRM_DELETE_SETTING_KEY, false, ConfigurationTarget.USER);
240238
}
241239

242-
243240
// Check for confirmation
244241
if (!confirmation.confirmed) {
245242
return;

src/vs/workbench/services/textfile/browser/textFileService.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
8787
this.lifecycleService.onShutdown(this.dispose, this);
8888
}
8989

90-
//#region text file IO primitives (read, create, move, delete, update)
90+
//#region text file read / write
9191

9292
async read(resource: URI, options?: IReadTextFileOptions): Promise<ITextFileContent> {
9393
const content = await this.fileService.readFile(resource, options);
@@ -143,6 +143,14 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
143143
}
144144
}
145145

146+
async write(resource: URI, value: string | ITextSnapshot, options?: IWriteTextFileOptions): Promise<IFileStatWithMetadata> {
147+
return this.fileService.writeFile(resource, toBufferOrReadable(value), options);
148+
}
149+
150+
//#endregion
151+
152+
//#region text file IO primitives (create, move, copy, delete)
153+
146154
async create(resource: URI, value?: string | ITextSnapshot, options?: ICreateFileOptions): Promise<IFileStatWithMetadata> {
147155

148156
// before event
@@ -169,24 +177,6 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
169177
return this.fileService.createFile(resource, toBufferOrReadable(value), options);
170178
}
171179

172-
async write(resource: URI, value: string | ITextSnapshot, options?: IWriteTextFileOptions): Promise<IFileStatWithMetadata> {
173-
return this.fileService.writeFile(resource, toBufferOrReadable(value), options);
174-
}
175-
176-
async delete(resource: URI, options?: { useTrash?: boolean, recursive?: boolean }): Promise<void> {
177-
178-
// before event
179-
await this._onWillRunOperation.fireAsync({ operation: FileOperation.DELETE, target: resource }, CancellationToken.None);
180-
181-
const dirtyFiles = this.getDirtyFileModels().map(dirtyFileModel => dirtyFileModel.resource).filter(dirty => isEqualOrParent(dirty, resource));
182-
await this.doRevertFiles(dirtyFiles, { soft: true });
183-
184-
await this.fileService.del(resource, options);
185-
186-
// after event
187-
this._onDidRunOperation.fire(new FileOperationDidRunEvent(FileOperation.DELETE, resource));
188-
}
189-
190180
async move(source: URI, target: URI, overwrite?: boolean): Promise<IFileStatWithMetadata> {
191181
return this.moveOrCopy(source, target, true, overwrite);
192182
}
@@ -287,6 +277,20 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
287277
return stat;
288278
}
289279

280+
async delete(resource: URI, options?: { useTrash?: boolean, recursive?: boolean }): Promise<void> {
281+
282+
// before event
283+
await this._onWillRunOperation.fireAsync({ operation: FileOperation.DELETE, target: resource }, CancellationToken.None);
284+
285+
const dirtyFiles = this.getDirtyFileModels().map(dirtyFileModel => dirtyFileModel.resource).filter(dirty => isEqualOrParent(dirty, resource));
286+
await this.doRevertFiles(dirtyFiles, { soft: true });
287+
288+
await this.fileService.del(resource, options);
289+
290+
// after event
291+
this._onDidRunOperation.fire(new FileOperationDidRunEvent(FileOperation.DELETE, resource));
292+
}
293+
290294
//#endregion
291295

292296
//#region save

src/vs/workbench/services/textfile/common/textfiles.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,6 @@ export interface ITextFileService extends IDisposable {
8484
*/
8585
revert(resource: URI, options?: IRevertOptions): Promise<boolean>;
8686

87-
/**
88-
* Create a file. If the file exists it will be overwritten with the contents if
89-
* the options enable to overwrite.
90-
*/
91-
create(resource: URI, contents?: string | ITextSnapshot, options?: { overwrite?: boolean }): Promise<IFileStatWithMetadata>;
92-
9387
/**
9488
* Read the contents of a file identified by the resource.
9589
*/
@@ -106,9 +100,10 @@ export interface ITextFileService extends IDisposable {
106100
write(resource: URI, value: string | ITextSnapshot, options?: IWriteTextFileOptions): Promise<IFileStatWithMetadata>;
107101

108102
/**
109-
* Delete a file. If the file is dirty, it will get reverted and then deleted from disk.
103+
* Create a file. If the file exists it will be overwritten with the contents if
104+
* the options enable to overwrite.
110105
*/
111-
delete(resource: URI, options?: { useTrash?: boolean, recursive?: boolean }): Promise<void>;
106+
create(resource: URI, contents?: string | ITextSnapshot, options?: { overwrite?: boolean }): Promise<IFileStatWithMetadata>;
112107

113108
/**
114109
* Move a file. If the file is dirty, its contents will be preserved and restored.
@@ -119,6 +114,11 @@ export interface ITextFileService extends IDisposable {
119114
* Copy a file. If the file is dirty, its contents will be preserved and restored.
120115
*/
121116
copy(source: URI, target: URI, overwrite?: boolean): Promise<IFileStatWithMetadata>;
117+
118+
/**
119+
* Delete a file. If the file is dirty, it will get reverted and then deleted from disk.
120+
*/
121+
delete(resource: URI, options?: { useTrash?: boolean, recursive?: boolean }): Promise<void>;
122122
}
123123

124124
export interface FileOperationWillRunEvent extends IWaitUntil {

0 commit comments

Comments
 (0)