From a49ba05d5e31588f22baf86d751ac2feaa05fbe3 Mon Sep 17 00:00:00 2001 From: Akos Kitta Date: Mon, 3 Aug 2020 10:05:44 +0200 Subject: [PATCH] wipe the entire sketch when deleting the main file Signed-off-by: Akos Kitta --- .../browser/arduino-ide-frontend-module.ts | 3 ++ .../workspace/workspace-delete-handler.ts | 36 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 arduino-ide-extension/src/browser/theia/workspace/workspace-delete-handler.ts diff --git a/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts b/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts index a11696cd..dc8f7cd2 100644 --- a/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts +++ b/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts @@ -111,6 +111,8 @@ import { SketchControl } from './contributions/sketch-control'; import { Settings } from './contributions/settings'; import { KeybindingRegistry } from './theia/core/keybindings'; import { WorkspaceCommandContribution } from './theia/workspace/workspace-commands'; +import { WorkspaceDeleteHandler as TheiaWorkspaceDeleteHandler } from '@theia/workspace/lib/browser/workspace-delete-handler'; +import { WorkspaceDeleteHandler } from './theia/workspace/workspace-delete-handler'; const ElementQueries = require('css-element-queries/src/ElementQueries'); @@ -289,6 +291,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => { rebind(TheiaPreferencesContribution).to(PreferencesContribution).inSingletonScope(); rebind(TheiaKeybindingRegistry).to(KeybindingRegistry).inSingletonScope(); rebind(TheiaWorkspaceCommandContribution).to(WorkspaceCommandContribution).inSingletonScope(); + rebind(TheiaWorkspaceDeleteHandler).to(WorkspaceDeleteHandler).inSingletonScope(); // Show a disconnected status bar, when the daemon is not available bind(ApplicationConnectionStatusContribution).toSelf().inSingletonScope(); diff --git a/arduino-ide-extension/src/browser/theia/workspace/workspace-delete-handler.ts b/arduino-ide-extension/src/browser/theia/workspace/workspace-delete-handler.ts new file mode 100644 index 00000000..8a5ca91d --- /dev/null +++ b/arduino-ide-extension/src/browser/theia/workspace/workspace-delete-handler.ts @@ -0,0 +1,36 @@ +import { inject, injectable } from 'inversify'; +import { remote } from 'electron'; +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'; + +@injectable() +export class WorkspaceDeleteHandler extends TheiaWorkspaceDeleteHandler { + + @inject(SketchesServiceClientImpl) + protected readonly sketchesServiceClient: SketchesServiceClientImpl; + + async execute(uris: URI[]): Promise { + 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({ + type: 'question', + buttons: ['Cancel', 'OK'], + title: 'Delete', + message: '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.fileSystem.delete(sketch.uri); + window.close(); + return; + } + } + return super.execute(uris); + } + +}