mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-06-07 12:46:34 +00:00
Implemented possibility to open sketches via file navigator.
Signed-off-by: jbicker <jan.bicker@typefox.io>
This commit is contained in:
parent
9d3cbf2ea0
commit
92afa48c05
@ -21,7 +21,7 @@ import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service
|
|||||||
import { SketchFactory } from './sketch-factory';
|
import { SketchFactory } from './sketch-factory';
|
||||||
import { ArduinoToolbar } from './toolbar/arduino-toolbar';
|
import { ArduinoToolbar } from './toolbar/arduino-toolbar';
|
||||||
import { EditorManager } from '@theia/editor/lib/browser';
|
import { EditorManager } from '@theia/editor/lib/browser';
|
||||||
import { open, ContextMenuRenderer, OpenerService, Widget } from '@theia/core/lib/browser';
|
import { ContextMenuRenderer, OpenerService, Widget } from '@theia/core/lib/browser';
|
||||||
import { OpenFileDialogProps, FileDialogService } from '@theia/filesystem/lib/browser/file-dialog';
|
import { OpenFileDialogProps, FileDialogService } from '@theia/filesystem/lib/browser/file-dialog';
|
||||||
import { FileSystem } from '@theia/filesystem/lib/common';
|
import { FileSystem } from '@theia/filesystem/lib/common';
|
||||||
import { ArduinoOpenSketchContextMenu } from './arduino-file-menu';
|
import { ArduinoOpenSketchContextMenu } from './arduino-file-menu';
|
||||||
@ -197,14 +197,7 @@ export class ArduinoFrontendContribution extends DefaultFrontendApplicationContr
|
|||||||
// }
|
// }
|
||||||
// this.windowService.openNewWindow(url.toString());
|
// this.windowService.openNewWindow(url.toString());
|
||||||
|
|
||||||
const fileStat = await this.fileSystem.getFileStat(sketch.uri);
|
this.openSketchFiles(sketch.uri);
|
||||||
if (fileStat) {
|
|
||||||
const sketchFiles = await this.sketches.getSketchFiles(fileStat);
|
|
||||||
sketchFiles.forEach(sketchFile => {
|
|
||||||
const uri = new URI(sketchFile);
|
|
||||||
this.editorManager.open(uri);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -228,6 +221,17 @@ export class ArduinoFrontendContribution extends DefaultFrontendApplicationContr
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected async openSketchFiles(uri: string) {
|
||||||
|
const fileStat = await this.fileSystem.getFileStat(uri);
|
||||||
|
if (fileStat) {
|
||||||
|
const sketchFiles = await this.sketches.getSketchFiles(fileStat);
|
||||||
|
sketchFiles.forEach(sketchFile => {
|
||||||
|
const uri = new URI(sketchFile);
|
||||||
|
this.editorManager.open(uri);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens a file after prompting the `Open File` dialog. Resolves to `undefined`, if
|
* Opens a file after prompting the `Open File` dialog. Resolves to `undefined`, if
|
||||||
* - the workspace root is not set,
|
* - the workspace root is not set,
|
||||||
@ -247,7 +251,7 @@ export class ArduinoFrontendContribution extends DefaultFrontendApplicationContr
|
|||||||
if (destinationFileUri) {
|
if (destinationFileUri) {
|
||||||
const destinationFile = await this.fileSystem.getFileStat(destinationFileUri.toString());
|
const destinationFile = await this.fileSystem.getFileStat(destinationFileUri.toString());
|
||||||
if (destinationFile && !destinationFile.isDirectory) {
|
if (destinationFile && !destinationFile.isDirectory) {
|
||||||
await open(this.openerService, destinationFileUri);
|
await this.openSketchFiles(destinationFileUri.toString());
|
||||||
return destinationFileUri;
|
return destinationFileUri;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { injectable } from "inversify";
|
import { injectable, inject } from "inversify";
|
||||||
import { SketchesService, Sketch } from "../common/protocol/sketches-service";
|
import { SketchesService, Sketch } from "../common/protocol/sketches-service";
|
||||||
import URI from "@theia/core/lib/common/uri";
|
import URI from "@theia/core/lib/common/uri";
|
||||||
import { FileStat } from "@theia/filesystem/lib/common";
|
import { FileStat, FileSystem } from "@theia/filesystem/lib/common";
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
@ -10,10 +10,14 @@ export const ALLOWED_FILE_EXTENSIONS = [".c", ".cpp", ".h", ".hh", ".hpp", ".s",
|
|||||||
@injectable()
|
@injectable()
|
||||||
export class SketchesServiceImpl implements SketchesService {
|
export class SketchesServiceImpl implements SketchesService {
|
||||||
|
|
||||||
|
@inject(FileSystem)
|
||||||
|
protected readonly filesystem: FileSystem;
|
||||||
|
|
||||||
async getSketches(fileStat?: FileStat): Promise<Sketch[]> {
|
async getSketches(fileStat?: FileStat): Promise<Sketch[]> {
|
||||||
const sketches: Sketch[] = [];
|
const sketches: Sketch[] = [];
|
||||||
if (fileStat && fileStat.isDirectory) {
|
if (fileStat && fileStat.isDirectory) {
|
||||||
const sketchFolderPath = this.getPath(fileStat);
|
const uri = new URI(fileStat.uri);
|
||||||
|
const sketchFolderPath = uri.path.toString()
|
||||||
const files = fs.readdirSync(sketchFolderPath);
|
const files = fs.readdirSync(sketchFolderPath);
|
||||||
files.forEach(file => {
|
files.forEach(file => {
|
||||||
const filePath = path.join(sketchFolderPath, file);
|
const filePath = path.join(sketchFolderPath, file);
|
||||||
@ -32,18 +36,30 @@ export class SketchesServiceImpl implements SketchesService {
|
|||||||
* Return all allowed files.
|
* Return all allowed files.
|
||||||
* File extensions: "c", "cpp", "h", "hh", "hpp", "s", "pde", "ino"
|
* File extensions: "c", "cpp", "h", "hh", "hpp", "s", "pde", "ino"
|
||||||
*/
|
*/
|
||||||
async getSketchFiles(sketchDir: FileStat): Promise<string[]> {
|
async getSketchFiles(sketchFileStat: FileStat): Promise<string[]> {
|
||||||
const files: string[] = [];
|
const files: string[] = [];
|
||||||
const sketchDirPath = this.getPath(sketchDir);
|
const sketchUri = new URI(sketchFileStat.uri);
|
||||||
const sketchDirContents = fs.readdirSync(sketchDirPath);
|
const sketchPath = sketchUri.path.toString();
|
||||||
|
if (sketchFileStat.isDirectory && this.isSketchFolder(sketchPath, sketchUri.displayName)) {
|
||||||
|
const sketchDirContents = fs.readdirSync(sketchPath);
|
||||||
sketchDirContents.forEach(fileName => {
|
sketchDirContents.forEach(fileName => {
|
||||||
const filePath = path.join(sketchDirPath, fileName);
|
const filePath = path.join(sketchPath, fileName);
|
||||||
if (fs.existsSync(filePath) &&
|
if (fs.existsSync(filePath) &&
|
||||||
fs.lstatSync(filePath).isFile() &&
|
fs.lstatSync(filePath).isFile() &&
|
||||||
ALLOWED_FILE_EXTENSIONS.indexOf(path.extname(filePath)) !== -1) {
|
ALLOWED_FILE_EXTENSIONS.indexOf(path.extname(filePath)) !== -1) {
|
||||||
files.push(filePath);
|
files.push(filePath);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
const sketchDir = sketchUri.path.dir;
|
||||||
|
if (this.isSketchFolder(sketchDir.toString(), sketchDir.name)) {
|
||||||
|
const sketchFolderStat = await this.filesystem.getFileStat(sketchDir.toString());
|
||||||
|
if (sketchFolderStat) {
|
||||||
|
const sketchDirContents = await this.getSketchFiles(sketchFolderStat);
|
||||||
|
files.push(...sketchDirContents);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,10 +74,4 @@ export class SketchesServiceImpl implements SketchesService {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getPath(fileStat: FileStat) {
|
|
||||||
const fileStatUri = fileStat.uri;
|
|
||||||
const uri = new URI(fileStatUri);
|
|
||||||
return uri.path.toString();
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user