Skip to content

Commit 5564b91

Browse files
committed
Save dialog for closing temp sketch
1 parent 9e89964 commit 5564b91

File tree

4 files changed

+88
-1
lines changed

4 files changed

+88
-1
lines changed

Diff for: arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx

+33
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
FrontendApplication,
2121
FrontendApplicationContribution,
2222
LocalStorageService,
23+
OnWillStopAction,
2324
StatusBar,
2425
StatusBarAlignment,
2526
} from '@theia/core/lib/browser';
@@ -70,6 +71,7 @@ import { SaveAsSketch } from './contributions/save-as-sketch';
7071
import { SketchbookWidgetContribution } from './widgets/sketchbook/sketchbook-widget-contribution';
7172
import { IDEUpdaterDialog } from './dialogs/ide-updater/ide-updater-dialog';
7273
import { IDEUpdater } from '../common/protocol/ide-updater';
74+
import { TempSketchDialog } from './dialogs/temp-sketch-dialog';
7375

7476
const INIT_LIBS_AND_PACKAGES = 'initializedLibsAndPackages';
7577
export const SKIP_IDE_VERSION = 'skipIDEVersion';
@@ -549,6 +551,37 @@ export class ArduinoFrontendContribution
549551
}
550552
}
551553

554+
onWillStop(): OnWillStopAction {
555+
return {
556+
reason: 'Temp Sketch',
557+
action: async () => {
558+
const sketch = await this.sketchServiceClient.currentSketch();
559+
if (!sketch) {
560+
return true;
561+
}
562+
const isTemp = await this.sketchService.isTemp(sketch);
563+
if (!isTemp) {
564+
return true;
565+
}
566+
const dialog = new TempSketchDialog();
567+
const result = await dialog.open();
568+
if (result === "Don't Save") {
569+
return true;
570+
} else if (result === 'Save As...') {
571+
return !!(await this.commandRegistry.executeCommand(
572+
SaveAsSketch.Commands.SAVE_AS_SKETCH.id,
573+
{
574+
execOnlyIfTemp: false,
575+
openAfterMove: false,
576+
wipeOriginal: true,
577+
}
578+
));
579+
}
580+
return false;
581+
}
582+
}
583+
}
584+
552585
registerColors(colors: ColorRegistry): void {
553586
colors.register(
554587
{

Diff for: arduino-ide-extension/src/browser/arduino-preferences.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export const ArduinoConfigSchema: PreferenceSchema = {
8383
default: 'https://downloads.arduino.cc/arduino-ide',
8484
description: nls.localize(
8585
'arduino/preferences/ide.updateBaseUrl',
86-
`The base URL where to download updates from. Defaults to 'https://downloads.arduino.cc/arduino-ide'`
86+
"The base URL where to download updates from. Defaults to 'https://downloads.arduino.cc/arduino-ide'"
8787
),
8888
},
8989
'arduino.board.certificates': {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { nls } from "@theia/core";
2+
import { AbstractDialog, Dialog, Message } from "@theia/core/lib/browser";
3+
4+
export class TempSketchDialog extends AbstractDialog<TempSketchDialog.Options> {
5+
protected readonly dontSaveButton: HTMLButtonElement;
6+
protected _value: TempSketchDialog.Options = 'Cancel';
7+
8+
get value(): TempSketchDialog.Options {
9+
return this._value;
10+
}
11+
12+
constructor() {
13+
super({
14+
title: nls.localize('theia/core/quitTitle', 'Are you sure you want to quit?')
15+
});
16+
const messageNode = document.createElement('div');
17+
messageNode.textContent = nls.localize('arduino/sketch/saveTempSketch', 'Save your sketch to open it again later.');
18+
this.contentNode.appendChild(messageNode);
19+
this.dontSaveButton = this.createButton(nls.localizeByDefault(TempSketchDialog.Values["Don't Save"]));
20+
this.dontSaveButton.classList.add('secondary');
21+
this.controlPanel.appendChild(this.dontSaveButton);
22+
this.appendCloseButton(Dialog.CANCEL);
23+
this.appendAcceptButton(nls.localizeByDefault(TempSketchDialog.Values['Save As...']));
24+
}
25+
26+
protected onAfterAttach(msg: Message): void {
27+
super.onAfterAttach(msg);
28+
this.addAction(this.dontSaveButton, () => this.dontSave(), 'click');
29+
}
30+
31+
protected addAcceptAction<K extends keyof HTMLElementEventMap>(element: HTMLElement, ...additionalEventTypes: K[]): void {
32+
this.addAction(element, () => this.doSave(), 'click');
33+
}
34+
35+
protected dontSave(): void {
36+
this._value = TempSketchDialog.Values["Don't Save"];
37+
this.accept();
38+
}
39+
40+
protected doSave(): void {
41+
this._value = TempSketchDialog.Values['Save As...'];
42+
this.accept();
43+
}
44+
}
45+
46+
export namespace TempSketchDialog {
47+
export const enum Values {
48+
"Don't Save" = "Don't Save",
49+
Cancel = 'Cancel',
50+
'Save As...' = 'Save As...',
51+
};
52+
export type Options = keyof typeof Values;
53+
}

Diff for: arduino-ide-extension/src/electron-main/theia/electron-main-application.ts

+1
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
272272
}
273273
});
274274
this.attachClosedWorkspace(electronWindow);
275+
this.attachCloseListeners(electronWindow, options);
275276
this.attachReadyToShow(electronWindow);
276277
this.attachSaveWindowState(electronWindow);
277278
this.attachGlobalShortcuts(electronWindow);

0 commit comments

Comments
 (0)