fix sketch uri issue.

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
Akos Kitta 2020-07-21 18:49:23 +02:00
parent e1d86d0bda
commit 230bacfd01
5 changed files with 31 additions and 14 deletions

View File

@ -1,7 +1,7 @@
import { inject, injectable } from 'inversify';
import { remote } from 'electron';
import { ArduinoMenus } from '../menu/arduino-menus';
import { SketchContribution, Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry, URI, Sketch } from './contribution';
import { SketchContribution, Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry, URI } from './contribution';
import { SaveAsSketch } from './save-as-sketch';
import { EditorManager } from '@theia/editor/lib/browser';
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';
@ -20,7 +20,11 @@ export class CloseSketch extends SketchContribution {
return;
}
const isTemp = await this.sketchService.isTemp(sketch);
if (isTemp && await this.wasTouched(sketch)) {
const uri = await this.currentSketchFile();
if (!uri) {
return;
}
if (isTemp && await this.wasTouched(uri)) {
const { response } = await remote.dialog.showMessageBox({
type: 'question',
buttons: ["Don't Save", 'Cancel', 'Save'],
@ -60,8 +64,8 @@ export class CloseSketch extends SketchContribution {
/**
* If the file was ever touched/modified. We get this based on the `version` of the monaco model.
*/
protected async wasTouched(sketch: Sketch): Promise<boolean> {
const editorWidget = await this.editorManager.getByUri(new URI(sketch.uri).resolve(`${sketch.name}.ino`));
protected async wasTouched(uri: string): Promise<boolean> {
const editorWidget = await this.editorManager.getByUri(new URI(uri));
if (editorWidget) {
const { editor } = editorWidget;
if (editor instanceof MonacoEditor) {

View File

@ -80,6 +80,20 @@ export abstract class SketchContribution extends Contribution {
return sketches[0];
}
protected async currentSketchFile(): Promise<string | undefined> {
const sketch = await this.currentSketch();
if (sketch) {
const uri = new URI(sketch.uri).resolve(`${sketch.name}.ino`).toString();
const exists = await this.fileSystem.exists(uri);
if (!exists) {
this.messageService.warn(`Could not find sketch file: ${uri}`);
return undefined;
}
return uri;
}
return undefined;
}
}
export namespace Contribution {

View File

@ -1,7 +1,7 @@
import { injectable } from 'inversify';
import { remote } from 'electron';
import { ArduinoMenus } from '../menu/arduino-menus';
import { SketchContribution, Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry, URI } from './contribution';
import { SketchContribution, Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry } from './contribution';
@injectable()
export class OpenSketchExternal extends SketchContribution {
@ -28,9 +28,8 @@ export class OpenSketchExternal extends SketchContribution {
}
protected async openExternal(): Promise<void> {
const sketch = await this.currentSketch();
if (sketch) {
const uri = new URI(sketch.uri).resolve(`${sketch.name}.ino`).toString();
const uri = await this.currentSketchFile();
if (uri) {
const exists = this.fileSystem.exists(uri);
if (exists) {
const fsPath = await this.fileSystem.getFsPath(uri);

View File

@ -57,8 +57,8 @@ export class UploadSketch extends SketchContribution {
}
async uploadSketch(): Promise<void> {
const sketch = await this.currentSketch();
if (!sketch) {
const uri = await this.currentSketchFile();
if (!uri) {
return;
}
const monitorConfig = this.monitorConnection.monitorConfig;
@ -79,7 +79,7 @@ export class UploadSketch extends SketchContribution {
}
const fqbn = await this.boardsDataStore.appendConfigToFqbn(boardsConfig.selectedBoard.fqbn);
await this.coreService.upload({
sketchUri: sketch.uri,
sketchUri: uri,
fqbn,
port: selectedPort.address,
optimizeForDebug: this.editorMode.compileForDebug

View File

@ -53,8 +53,8 @@ export class VerifySketch extends SketchContribution {
}
async verifySketch(): Promise<void> {
const sketch = await this.currentSketch();
if (!sketch) {
const uri = await this.currentSketchFile();
if (!uri) {
return;
}
try {
@ -67,7 +67,7 @@ export class VerifySketch extends SketchContribution {
}
const fqbn = await this.boardsDataStore.appendConfigToFqbn(boardsConfig.selectedBoard.fqbn);
await this.coreService.compile({
sketchUri: sketch.uri,
sketchUri: uri,
fqbn,
optimizeForDebug: this.editorMode.compileForDebug
});