No save dialog prompt if closing untouched sketch.

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
This commit is contained in:
Akos Kitta 2022-08-24 16:36:54 +02:00 committed by Akos Kitta
parent d7bbfc515d
commit 1da2dfc349

View File

@ -8,6 +8,7 @@ import {
CommandRegistry, CommandRegistry,
MenuModelRegistry, MenuModelRegistry,
KeybindingRegistry, KeybindingRegistry,
Sketch,
URI, URI,
} from './contribution'; } from './contribution';
import { nls } from '@theia/core/lib/common'; import { nls } from '@theia/core/lib/common';
@ -47,12 +48,12 @@ export class Close extends SketchContribution {
return { return {
reason: 'temp-sketch', reason: 'temp-sketch',
action: () => { action: () => {
return this.showTempSketchDialog(); return this.showSaveTempSketchDialog();
}, },
}; };
} }
private async showTempSketchDialog(): Promise<boolean> { private async showSaveTempSketchDialog(): Promise<boolean> {
const sketch = await this.sketchServiceClient.currentSketch(); const sketch = await this.sketchServiceClient.currentSketch();
if (!CurrentSketch.isValid(sketch)) { if (!CurrentSketch.isValid(sketch)) {
return true; return true;
@ -61,6 +62,15 @@ export class Close extends SketchContribution {
if (!isTemp) { if (!isTemp) {
return true; return true;
} }
// If non of the sketch files were ever touched, do not prompt the save dialog. (#1274)
const wereTouched = await Promise.all(
Sketch.uris(sketch).map((uri) => this.wasTouched(uri))
);
if (wereTouched.every((wasTouched) => !Boolean(wasTouched))) {
return true;
}
const messageBoxResult = await remote.dialog.showMessageBox( const messageBoxResult = await remote.dialog.showMessageBox(
remote.getCurrentWindow(), remote.getCurrentWindow(),
{ {