mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-11-11 11:19:26 +00:00
More refactoring. Splitting up code.
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { injectable } from 'inversify';
|
||||
import { remote } from 'electron';
|
||||
import { WorkspaceCommands } from '@theia/workspace/lib/browser/workspace-commands';
|
||||
import { ArduinoMenus } from '../menu/arduino-menus';
|
||||
import { SketchContribution, Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry } from './contribution';
|
||||
@@ -16,9 +17,24 @@ export class CloseSketch extends SketchContribution {
|
||||
}
|
||||
const isTemp = await this.sketchService.isTemp(sketch);
|
||||
if (isTemp) {
|
||||
await this.commandService.executeCommand(SaveAsSketch.Commands.SAVE_AS_SKETCH.id, { openAfterMove: false, execOnlyIfTemp: true });
|
||||
await this.commandService.executeCommand(WorkspaceCommands.CLOSE.id);
|
||||
// TODO: check monaco model version. If `0` just close the app.
|
||||
const { response } = await remote.dialog.showMessageBox({
|
||||
type: 'question',
|
||||
buttons: ["Don't Save", 'Cancel', 'Save'],
|
||||
message: 'Do you want to save changes to this sketch before closing?',
|
||||
detail: "If you don't save, your changes will be lost."
|
||||
});
|
||||
if (response === 1) { // Cancel
|
||||
return;
|
||||
}
|
||||
if (response === 2) { // Save
|
||||
const saved = await this.commandService.executeCommand(SaveAsSketch.Commands.SAVE_AS_SKETCH.id, { openAfterMove: false, execOnlyIfTemp: true });
|
||||
if (!saved) { // If it was not saved, do bail the close.
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
await this.commandService.executeCommand(WorkspaceCommands.CLOSE.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -28,15 +28,18 @@ export class SaveAsSketch extends SketchContribution {
|
||||
});
|
||||
}
|
||||
|
||||
async saveAs({ execOnlyIfTemp, openAfterMove }: SaveAsSketch.Options = SaveAsSketch.Options.DEFAULT): Promise<void> {
|
||||
/**
|
||||
* Resolves `true` if the sketch was successfully saved as something.
|
||||
*/
|
||||
async saveAs({ execOnlyIfTemp, openAfterMove }: SaveAsSketch.Options = SaveAsSketch.Options.DEFAULT): Promise<boolean> {
|
||||
const sketch = await this.getCurrentSketch();
|
||||
if (!sketch) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
const isTemp = await this.sketchService.isTemp(sketch);
|
||||
if (!isTemp && !!execOnlyIfTemp) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
// If target does not exist, propose a `directories.user`/${sketch.name} path
|
||||
@@ -49,16 +52,17 @@ export class SaveAsSketch extends SketchContribution {
|
||||
const defaultPath = await this.fileSystem.getFsPath(defaultUri.toString())!;
|
||||
const { filePath, canceled } = await remote.dialog.showSaveDialog({ title: 'Save sketch folder as...', defaultPath });
|
||||
if (!filePath || canceled) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
const destinationUri = await this.fileSystemExt.getUri(filePath);
|
||||
if (!destinationUri) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
const workspaceUri = await this.sketchService.copy(sketch, { destinationUri });
|
||||
if (workspaceUri && openAfterMove) {
|
||||
this.workspaceService.open(new URI(workspaceUri));
|
||||
}
|
||||
return !!workspaceUri;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user