-
-
Notifications
You must be signed in to change notification settings - Fork 431
/
Copy pathworkspace-delete-handler.ts
52 lines (50 loc) · 1.8 KB
/
workspace-delete-handler.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { inject, injectable } from 'inversify';
import * as remote from '@theia/core/electron-shared/@electron/remote';
import URI from '@theia/core/lib/common/uri';
import { WorkspaceDeleteHandler as TheiaWorkspaceDeleteHandler } from '@theia/workspace/lib/browser/workspace-delete-handler';
import { SketchesServiceClientImpl } from '../../../common/protocol/sketches-service-client-impl';
import { nls } from '@theia/core/lib/common';
@injectable()
export class WorkspaceDeleteHandler extends TheiaWorkspaceDeleteHandler {
@inject(SketchesServiceClientImpl)
protected readonly sketchesServiceClient: SketchesServiceClientImpl;
async execute(uris: URI[]): Promise<void> {
const sketch = await this.sketchesServiceClient.currentSketch();
if (!sketch) {
return;
}
// Deleting the main sketch file.
if (
uris
.map((uri) => uri.toString())
.some((uri) => uri === sketch.mainFileUri)
) {
const { response } = await remote.dialog.showMessageBox({
title: nls.localize('vscode/fileActions/delete', 'Delete'),
type: 'question',
buttons: [
nls.localize('vscode/issueMainService/cancel', 'Cancel'),
nls.localize('vscode/issueMainService/ok', 'OK'),
],
message: nls.localize(
'theia/workspace/deleteCurrentSketch',
'Do you want to delete the current sketch?'
),
});
if (response === 1) {
// OK
await Promise.all(
[
...sketch.additionalFileUris,
...sketch.otherSketchFileUris,
sketch.mainFileUri,
].map((uri) => this.closeWithoutSaving(new URI(uri)))
);
await this.fileService.delete(new URI(sketch.uri));
window.close();
}
return;
}
return super.execute(uris);
}
}