mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-06-06 04:06:32 +00:00
#192: Fixed Open... dialog
This commit is contained in:
parent
a9bbf47a59
commit
b2d53b1a35
@ -311,14 +311,14 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
|
|||||||
|
|
||||||
registry.registerCommand(ArduinoCommands.OPEN_SKETCH, {
|
registry.registerCommand(ArduinoCommands.OPEN_SKETCH, {
|
||||||
isEnabled: () => true,
|
isEnabled: () => true,
|
||||||
execute: async (sketch: Sketch) => {
|
execute: (sketch: Sketch) => {
|
||||||
this.workspaceService.open(new URI(sketch.uri));
|
this.workspaceService.open(new URI(sketch.uri));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
registry.registerCommand(ArduinoCommands.SAVE_SKETCH, {
|
registry.registerCommand(ArduinoCommands.SAVE_SKETCH, {
|
||||||
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'left',
|
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'left',
|
||||||
execute: async (sketch: Sketch) => {
|
execute: (sketch: Sketch) => {
|
||||||
registry.executeCommand(CommonCommands.SAVE_ALL.id);
|
registry.executeCommand(CommonCommands.SAVE_ALL.id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -515,22 +515,21 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected async registerSketchesInMenu(registry: MenuModelRegistry): Promise<void> {
|
protected async registerSketchesInMenu(registry: MenuModelRegistry): Promise<void> {
|
||||||
this.sketchService.getSketches().then(sketches => {
|
const sketches = await this.sketchService.getSketches();
|
||||||
this.wsSketchCount = sketches.length;
|
this.wsSketchCount = sketches.length;
|
||||||
sketches.forEach(sketch => {
|
sketches.forEach(sketch => {
|
||||||
const command: Command = {
|
const command: Command = {
|
||||||
id: 'openSketch' + sketch.name
|
id: 'openSketch' + sketch.name
|
||||||
}
|
}
|
||||||
this.commandRegistry.registerCommand(command, {
|
this.commandRegistry.registerCommand(command, {
|
||||||
execute: () => this.commandRegistry.executeCommand(ArduinoCommands.OPEN_SKETCH.id, sketch)
|
execute: () => this.commandRegistry.executeCommand(ArduinoCommands.OPEN_SKETCH.id, sketch)
|
||||||
});
|
});
|
||||||
|
|
||||||
registry.registerMenuAction(ArduinoToolbarContextMenu.WS_SKETCHES_GROUP, {
|
registry.registerMenuAction(ArduinoToolbarContextMenu.WS_SKETCHES_GROUP, {
|
||||||
commandId: command.id,
|
commandId: command.id,
|
||||||
label: sketch.name
|
label: sketch.name
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async openSketchFiles(uri: string): Promise<void> {
|
async openSketchFiles(uri: string): Promise<void> {
|
||||||
@ -541,14 +540,14 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens a file after prompting the `Open File` dialog. Resolves to `undefined`, if
|
* Opens a file after prompting the `Open File` dialog. Shows a warning message if
|
||||||
* - the workspace root is not set,
|
* - the file to open does not exist,
|
||||||
* - the file to open does not exist, or
|
* - it was not a file, but a directory, or
|
||||||
* - it was not a file, but a directory.
|
* - the file does not pass validation.
|
||||||
*
|
*
|
||||||
* Otherwise, resolves to the URI of the file.
|
* Otherwise, resolves to the URI of the file.
|
||||||
*/
|
*/
|
||||||
protected async doOpenFile(): Promise<URI | undefined> {
|
protected async doOpenFile(): Promise<void> {
|
||||||
const props: OpenFileDialogProps = {
|
const props: OpenFileDialogProps = {
|
||||||
title: WorkspaceCommands.OPEN_FILE.dialogLabel,
|
title: WorkspaceCommands.OPEN_FILE.dialogLabel,
|
||||||
canSelectFolders: false,
|
canSelectFolders: false,
|
||||||
@ -556,19 +555,24 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
|
|||||||
};
|
};
|
||||||
const [rootStat] = await this.workspaceService.roots;
|
const [rootStat] = await this.workspaceService.roots;
|
||||||
const destinationFileUri = await this.fileDialogService.showOpenDialog(props, rootStat);
|
const destinationFileUri = await this.fileDialogService.showOpenDialog(props, rootStat);
|
||||||
if (destinationFileUri) {
|
if (!destinationFileUri) {
|
||||||
const destinationFile = await this.fileSystem.getFileStat(destinationFileUri.toString());
|
return;
|
||||||
if (destinationFile && !destinationFile.isDirectory) {
|
|
||||||
const message = await this.validate(destinationFile);
|
|
||||||
if (!message) {
|
|
||||||
this.workspaceService.open(destinationFileUri);
|
|
||||||
return destinationFileUri;
|
|
||||||
} else {
|
|
||||||
this.messageService.warn(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return undefined;
|
const destinationFile = await this.fileSystem.getFileStat(destinationFileUri.toString());
|
||||||
|
if (!destinationFile) {
|
||||||
|
this.messageService.warn(`File does not exist: ${this.fileSystem.getFsPath(destinationFileUri.toString())}`)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (destinationFile.isDirectory) {
|
||||||
|
this.messageService.warn('Please select a sketch file, not a directory.')
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const message = await this.validate(destinationFile);
|
||||||
|
if (message) {
|
||||||
|
this.messageService.warn(message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.workspaceService.open(destinationFileUri.parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getCurrentWidget(): EditorWidget | undefined {
|
protected getCurrentWidget(): EditorWidget | undefined {
|
||||||
|
@ -9,7 +9,7 @@ import { MaybePromise } from '@theia/core/lib/common/types';
|
|||||||
* `location.hash`, the historical workspace locations, and recent sketch files.
|
* `location.hash`, the historical workspace locations, and recent sketch files.
|
||||||
*
|
*
|
||||||
* The following logic is used for determining the default workspace location:
|
* The following logic is used for determining the default workspace location:
|
||||||
* - `hash` points to an exists in location?
|
* - `hash` points to an existing location?
|
||||||
* - Yes
|
* - Yes
|
||||||
* - `validate location`. Is valid sketch location?
|
* - `validate location`. Is valid sketch location?
|
||||||
* - Yes
|
* - Yes
|
||||||
|
Loading…
x
Reference in New Issue
Block a user