Skip to content

Commit b2d53b1

Browse files
committed
#192: Fixed Open... dialog
1 parent a9bbf47 commit b2d53b1

File tree

2 files changed

+40
-36
lines changed

2 files changed

+40
-36
lines changed

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

+39-35
Original file line numberDiff line numberDiff line change
@@ -311,14 +311,14 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
311311

312312
registry.registerCommand(ArduinoCommands.OPEN_SKETCH, {
313313
isEnabled: () => true,
314-
execute: async (sketch: Sketch) => {
314+
execute: (sketch: Sketch) => {
315315
this.workspaceService.open(new URI(sketch.uri));
316316
}
317317
});
318318

319319
registry.registerCommand(ArduinoCommands.SAVE_SKETCH, {
320320
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'left',
321-
execute: async (sketch: Sketch) => {
321+
execute: (sketch: Sketch) => {
322322
registry.executeCommand(CommonCommands.SAVE_ALL.id);
323323
}
324324
});
@@ -515,22 +515,21 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
515515
}
516516

517517
protected async registerSketchesInMenu(registry: MenuModelRegistry): Promise<void> {
518-
this.sketchService.getSketches().then(sketches => {
519-
this.wsSketchCount = sketches.length;
520-
sketches.forEach(sketch => {
521-
const command: Command = {
522-
id: 'openSketch' + sketch.name
523-
}
524-
this.commandRegistry.registerCommand(command, {
525-
execute: () => this.commandRegistry.executeCommand(ArduinoCommands.OPEN_SKETCH.id, sketch)
526-
});
527-
528-
registry.registerMenuAction(ArduinoToolbarContextMenu.WS_SKETCHES_GROUP, {
529-
commandId: command.id,
530-
label: sketch.name
531-
});
532-
})
533-
})
518+
const sketches = await this.sketchService.getSketches();
519+
this.wsSketchCount = sketches.length;
520+
sketches.forEach(sketch => {
521+
const command: Command = {
522+
id: 'openSketch' + sketch.name
523+
}
524+
this.commandRegistry.registerCommand(command, {
525+
execute: () => this.commandRegistry.executeCommand(ArduinoCommands.OPEN_SKETCH.id, sketch)
526+
});
527+
528+
registry.registerMenuAction(ArduinoToolbarContextMenu.WS_SKETCHES_GROUP, {
529+
commandId: command.id,
530+
label: sketch.name
531+
});
532+
});
534533
}
535534

536535
async openSketchFiles(uri: string): Promise<void> {
@@ -541,34 +540,39 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
541540
}
542541

543542
/**
544-
* Opens a file after prompting the `Open File` dialog. Resolves to `undefined`, if
545-
* - the workspace root is not set,
546-
* - the file to open does not exist, or
547-
* - it was not a file, but a directory.
543+
* Opens a file after prompting the `Open File` dialog. Shows a warning message if
544+
* - the file to open does not exist,
545+
* - it was not a file, but a directory, or
546+
* - the file does not pass validation.
548547
*
549548
* Otherwise, resolves to the URI of the file.
550549
*/
551-
protected async doOpenFile(): Promise<URI | undefined> {
550+
protected async doOpenFile(): Promise<void> {
552551
const props: OpenFileDialogProps = {
553552
title: WorkspaceCommands.OPEN_FILE.dialogLabel,
554553
canSelectFolders: false,
555554
canSelectFiles: true
556555
};
557556
const [rootStat] = await this.workspaceService.roots;
558557
const destinationFileUri = await this.fileDialogService.showOpenDialog(props, rootStat);
559-
if (destinationFileUri) {
560-
const destinationFile = await this.fileSystem.getFileStat(destinationFileUri.toString());
561-
if (destinationFile && !destinationFile.isDirectory) {
562-
const message = await this.validate(destinationFile);
563-
if (!message) {
564-
this.workspaceService.open(destinationFileUri);
565-
return destinationFileUri;
566-
} else {
567-
this.messageService.warn(message);
568-
}
569-
}
558+
if (!destinationFileUri) {
559+
return;
570560
}
571-
return undefined;
561+
const destinationFile = await this.fileSystem.getFileStat(destinationFileUri.toString());
562+
if (!destinationFile) {
563+
this.messageService.warn(`File does not exist: ${this.fileSystem.getFsPath(destinationFileUri.toString())}`)
564+
return;
565+
}
566+
if (destinationFile.isDirectory) {
567+
this.messageService.warn('Please select a sketch file, not a directory.')
568+
return;
569+
}
570+
const message = await this.validate(destinationFile);
571+
if (message) {
572+
this.messageService.warn(message);
573+
return;
574+
}
575+
this.workspaceService.open(destinationFileUri.parent);
572576
}
573577

574578
protected getCurrentWidget(): EditorWidget | undefined {

arduino-ide-extension/src/browser/arduino-workspace-resolver.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { MaybePromise } from '@theia/core/lib/common/types';
99
* `location.hash`, the historical workspace locations, and recent sketch files.
1010
*
1111
* The following logic is used for determining the default workspace location:
12-
* - `hash` points to an exists in location?
12+
* - `hash` points to an existing location?
1313
* - Yes
1414
* - `validate location`. Is valid sketch location?
1515
* - Yes

0 commit comments

Comments
 (0)