mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-27 05:06:42 +00:00
Merge branch 'sketch-loader-bug-fix'
This commit is contained in:
commit
4ced8237f7
@ -357,11 +357,10 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
|
|||||||
async openSketchFiles(uri: string) {
|
async openSketchFiles(uri: string) {
|
||||||
const fileStat = await this.fileSystem.getFileStat(uri);
|
const fileStat = await this.fileSystem.getFileStat(uri);
|
||||||
if (fileStat) {
|
if (fileStat) {
|
||||||
const sketchFiles = await this.sketches.getSketchFiles(fileStat);
|
const uris = await this.sketches.getSketchFiles(fileStat);
|
||||||
sketchFiles.forEach(sketchFile => {
|
for (const uri of uris) {
|
||||||
const uri = new URI(sketchFile);
|
this.editorManager.open(new URI(uri));
|
||||||
this.editorManager.open(uri);
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
import { injectable } from "inversify";
|
|
||||||
import * as electron from 'electron';
|
|
||||||
import { ElectronMainMenuFactory } from "@theia/core/lib/electron-browser/menu/electron-main-menu-factory";
|
|
||||||
import {
|
|
||||||
isOSX
|
|
||||||
} from '@theia/core/lib/common';
|
|
||||||
|
|
||||||
@injectable()
|
|
||||||
export class ElectronArduinoMainMenuFactory extends ElectronMainMenuFactory {
|
|
||||||
createMenuBar(): Electron.Menu {
|
|
||||||
const menuModel = this.menuProvider.getMenu();
|
|
||||||
const template = this.fillMenuTemplate([], menuModel);
|
|
||||||
if (isOSX) {
|
|
||||||
template.unshift(this.createOSXMenu());
|
|
||||||
}
|
|
||||||
const menu = electron.remote.Menu.buildFromTemplate(template);
|
|
||||||
this._menu = menu;
|
|
||||||
return menu;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +1,8 @@
|
|||||||
import { ContainerModule } from "inversify";
|
import { ContainerModule } from "inversify";
|
||||||
import { ElectronArduinoMainMenuFactory } from "./electron-arduino-main-menu-factory";
|
|
||||||
import { ElectronMainMenuFactory } from "@theia/core/lib/electron-browser/menu/electron-main-menu-factory";
|
|
||||||
import { ElectronMenuContribution } from "@theia/core/lib/electron-browser/menu/electron-menu-contribution"
|
import { ElectronMenuContribution } from "@theia/core/lib/electron-browser/menu/electron-menu-contribution"
|
||||||
import { ElectronArduinoMenuContribution } from "./electron-arduino-menu-contribution";
|
import { ElectronArduinoMenuContribution } from "./electron-arduino-menu-contribution";
|
||||||
|
|
||||||
export default new ContainerModule((bind, unbind, isBound, rebind) => {
|
export default new ContainerModule((bind, unbind, isBound, rebind) => {
|
||||||
bind(ElectronArduinoMainMenuFactory).toSelf().inSingletonScope();
|
|
||||||
rebind(ElectronMainMenuFactory).to(ElectronArduinoMainMenuFactory);
|
|
||||||
|
|
||||||
bind(ElectronArduinoMenuContribution).toSelf().inSingletonScope();
|
bind(ElectronArduinoMenuContribution).toSelf().inSingletonScope();
|
||||||
rebind(ElectronMenuContribution).to(ElectronArduinoMenuContribution);
|
rebind(ElectronMenuContribution).to(ElectronArduinoMenuContribution);
|
||||||
})
|
})
|
@ -4,6 +4,7 @@ import URI from "@theia/core/lib/common/uri";
|
|||||||
import { FileStat, FileSystem } 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';
|
||||||
|
import { FileUri } from "@theia/core/lib/node";
|
||||||
|
|
||||||
export const ALLOWED_FILE_EXTENSIONS = [".c", ".cpp", ".h", ".hh", ".hpp", ".s", ".pde", ".ino"];
|
export const ALLOWED_FILE_EXTENSIONS = [".c", ".cpp", ".h", ".hh", ".hpp", ".s", ".pde", ".ino"];
|
||||||
|
|
||||||
@ -17,17 +18,19 @@ export class SketchesServiceImpl implements SketchesService {
|
|||||||
const sketches: Sketch[] = [];
|
const sketches: Sketch[] = [];
|
||||||
if (fileStat && fileStat.isDirectory) {
|
if (fileStat && fileStat.isDirectory) {
|
||||||
const uri = new URI(fileStat.uri);
|
const uri = new URI(fileStat.uri);
|
||||||
const sketchFolderPath = uri.path.toString()
|
const sketchFolderPath = await this.filesystem.getFsPath(uri.toString());
|
||||||
const files = fs.readdirSync(sketchFolderPath);
|
if (sketchFolderPath) {
|
||||||
files.forEach(file => {
|
const fileNames = fs.readdirSync(sketchFolderPath);
|
||||||
const filePath = path.join(sketchFolderPath, file);
|
for (const fileName of fileNames) {
|
||||||
if (this.isSketchFolder(filePath, file)) {
|
const filePath = path.join(sketchFolderPath, fileName);
|
||||||
|
if (this.isSketchFolder(filePath, fileName)) {
|
||||||
sketches.push({
|
sketches.push({
|
||||||
name: file,
|
name: fileName,
|
||||||
uri: filePath
|
uri: FileUri.create(filePath).toString()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return sketches;
|
return sketches;
|
||||||
}
|
}
|
||||||
@ -37,30 +40,32 @@ export class SketchesServiceImpl implements SketchesService {
|
|||||||
* File extensions: "c", "cpp", "h", "hh", "hpp", "s", "pde", "ino"
|
* File extensions: "c", "cpp", "h", "hh", "hpp", "s", "pde", "ino"
|
||||||
*/
|
*/
|
||||||
async getSketchFiles(sketchFileStat: FileStat): Promise<string[]> {
|
async getSketchFiles(sketchFileStat: FileStat): Promise<string[]> {
|
||||||
const files: string[] = [];
|
const uris: string[] = [];
|
||||||
const sketchUri = new URI(sketchFileStat.uri);
|
const sketchUri = new URI(sketchFileStat.uri);
|
||||||
const sketchPath = sketchUri.path.toString();
|
const sketchPath = await this.filesystem.getFsPath(sketchUri.toString());
|
||||||
|
if (sketchPath) {
|
||||||
if (sketchFileStat.isDirectory && this.isSketchFolder(sketchPath, sketchUri.displayName)) {
|
if (sketchFileStat.isDirectory && this.isSketchFolder(sketchPath, sketchUri.displayName)) {
|
||||||
const sketchDirContents = fs.readdirSync(sketchPath);
|
const fileNames = fs.readdirSync(sketchPath);
|
||||||
sketchDirContents.forEach(fileName => {
|
for (const fileName of fileNames) {
|
||||||
const filePath = path.join(sketchPath, fileName);
|
const filePath = path.join(sketchPath, fileName);
|
||||||
if (fs.existsSync(filePath) &&
|
if (ALLOWED_FILE_EXTENSIONS.indexOf(path.extname(filePath)) !== -1
|
||||||
fs.lstatSync(filePath).isFile() &&
|
&& fs.existsSync(filePath)
|
||||||
ALLOWED_FILE_EXTENSIONS.indexOf(path.extname(filePath)) !== -1) {
|
&& fs.lstatSync(filePath).isFile()) {
|
||||||
files.push(filePath);
|
uris.push(FileUri.create(filePath).toString())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
const sketchDir = sketchUri.path.dir;
|
const sketchDir = path.dirname(sketchPath);
|
||||||
if (this.isSketchFolder(sketchDir.toString(), sketchDir.name)) {
|
if (sketchDir && this.isSketchFolder(sketchDir, sketchUri.path.dir.name)) {
|
||||||
const sketchFolderStat = await this.filesystem.getFileStat(sketchDir.toString());
|
const sketchFolderStat = await this.filesystem.getFileStat(sketchUri.path.dir.toString());
|
||||||
if (sketchFolderStat) {
|
if (sketchFolderStat) {
|
||||||
const sketchDirContents = await this.getSketchFiles(sketchFolderStat);
|
const sketchDirContents = await this.getSketchFiles(sketchFolderStat);
|
||||||
files.push(...sketchDirContents);
|
uris.push(...sketchDirContents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return files;
|
}
|
||||||
|
return uris;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected isSketchFolder(path: string, name: string): boolean {
|
protected isSketchFolder(path: string, name: string): boolean {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user