Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f07c344

Browse filesBrowse files
committed
Save dialog for closing temp sketch
1 parent 9e89964 commit f07c344
Copy full SHA for f07c344

File tree

Expand file treeCollapse file tree

3 files changed

+90
-0
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+90
-0
lines changed

‎arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx

Copy file name to clipboardExpand all lines: arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx
+35Lines changed: 35 additions & 0 deletions
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,39 @@ 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+
title: 'Arduino-IDE'
568+
})
569+
const result = await dialog.open();
570+
if (result === "Don't Save") {
571+
return true;
572+
} else if (result === 'Save As...') {
573+
return !!(await this.commandRegistry.executeCommand(
574+
SaveAsSketch.Commands.SAVE_AS_SKETCH.id,
575+
{
576+
execOnlyIfTemp: false,
577+
openAfterMove: false,
578+
wipeOriginal: true,
579+
}
580+
));
581+
}
582+
return false;
583+
}
584+
}
585+
}
586+
552587
registerColors(colors: ColorRegistry): void {
553588
colors.register(
554589
{
+54Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { nls } from "@theia/core";
2+
import { AbstractDialog, Dialog, DialogProps, Message } from "@theia/core/lib/browser";
3+
import { inject } from "@theia/core/shared/inversify";
4+
5+
export class TempSketchDialog extends AbstractDialog<TempSketchDialog.Options> {
6+
protected readonly dontSaveButton: HTMLButtonElement;
7+
protected _value: TempSketchDialog.Options = 'Cancel';
8+
9+
get value(): TempSketchDialog.Options {
10+
return this._value;
11+
}
12+
13+
constructor(
14+
@inject(DialogProps) props: DialogProps
15+
) {
16+
super(props);
17+
const messageNode = document.createElement('div');
18+
messageNode.textContent = nls.localize('arduino/sketch/saveTempSketch', 'Save your sketch to open it again later.');
19+
this.contentNode.appendChild(messageNode);
20+
this.dontSaveButton = this.createButton(nls.localizeByDefault(TempSketchDialog.Values["Don't Save"]));
21+
this.dontSaveButton.classList.add('secondary');
22+
this.controlPanel.appendChild(this.dontSaveButton);
23+
this.appendCloseButton(Dialog.CANCEL);
24+
this.appendAcceptButton(nls.localizeByDefault(TempSketchDialog.Values['Save As...']));
25+
}
26+
27+
protected onAfterAttach(msg: Message): void {
28+
super.onAfterAttach(msg);
29+
this.addAction(this.dontSaveButton, () => this.dontSave(), 'click');
30+
}
31+
32+
protected addAcceptAction<K extends keyof HTMLElementEventMap>(element: HTMLElement, ...additionalEventTypes: K[]): void {
33+
this.addAction(element, () => this.doSave(), 'click');
34+
}
35+
36+
protected dontSave(): void {
37+
this._value = TempSketchDialog.Values["Don't Save"];
38+
this.accept();
39+
}
40+
41+
protected doSave(): void {
42+
this._value = TempSketchDialog.Values['Save As...'];
43+
this.accept();
44+
}
45+
}
46+
47+
export namespace TempSketchDialog {
48+
export const enum Values {
49+
"Don't Save" = "Don't Save",
50+
Cancel = 'Cancel',
51+
'Save As...' = 'Save As...',
52+
};
53+
export type Options = keyof typeof Values;
54+
}

‎arduino-ide-extension/src/electron-main/theia/electron-main-application.ts

Copy file name to clipboardExpand all lines: arduino-ide-extension/src/electron-main/theia/electron-main-application.ts
+1Lines changed: 1 addition & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.