mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-06-18 10:06:33 +00:00
Merge pull request #39 from bcmi-labs/sketch-loader-bug-fix-win
[win] Open sketch.
This commit is contained in:
commit
40eb74aeff
@ -357,11 +357,10 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
|
||||
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.uri);
|
||||
this.editorManager.open(uri);
|
||||
});
|
||||
const uris = await this.sketches.getSketchFiles(fileStat);
|
||||
for (const uri of uris) {
|
||||
this.editorManager.open(new URI(uri));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ export const SketchesServicePath = '/services/sketches-service';
|
||||
export const SketchesService = Symbol('SketchesService');
|
||||
export interface SketchesService {
|
||||
getSketches(fileStat?: FileStat): Promise<Sketch[]>
|
||||
getSketchFiles(fileStat: FileStat): Promise<FileStat[]>
|
||||
getSketchFiles(fileStat: FileStat): Promise<string[]>
|
||||
}
|
||||
|
||||
export interface Sketch {
|
||||
|
@ -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 { 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 { ElectronArduinoMenuContribution } from "./electron-arduino-menu-contribution";
|
||||
|
||||
export default new ContainerModule((bind, unbind, isBound, rebind) => {
|
||||
bind(ElectronArduinoMainMenuFactory).toSelf().inSingletonScope();
|
||||
rebind(ElectronMainMenuFactory).to(ElectronArduinoMainMenuFactory);
|
||||
|
||||
bind(ElectronArduinoMenuContribution).toSelf().inSingletonScope();
|
||||
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 * as fs from 'fs';
|
||||
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"];
|
||||
|
||||
@ -19,16 +20,16 @@ export class SketchesServiceImpl implements SketchesService {
|
||||
const uri = new URI(fileStat.uri);
|
||||
const sketchFolderPath = await this.filesystem.getFsPath(uri.toString());
|
||||
if (sketchFolderPath) {
|
||||
const files = fs.readdirSync(sketchFolderPath);
|
||||
files.forEach(file => {
|
||||
const filePath = path.join(sketchFolderPath, file);
|
||||
if (this.isSketchFolder(filePath, file)) {
|
||||
const fileNames = fs.readdirSync(sketchFolderPath);
|
||||
for (const fileName of fileNames) {
|
||||
const filePath = path.join(sketchFolderPath, fileName);
|
||||
if (this.isSketchFolder(filePath, fileName)) {
|
||||
sketches.push({
|
||||
name: file,
|
||||
uri: filePath
|
||||
name: fileName,
|
||||
uri: FileUri.create(filePath).toString()
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return sketches;
|
||||
@ -38,25 +39,19 @@ export class SketchesServiceImpl implements SketchesService {
|
||||
* Return all allowed files.
|
||||
* File extensions: "c", "cpp", "h", "hh", "hpp", "s", "pde", "ino"
|
||||
*/
|
||||
async getSketchFiles(sketchFileStat: FileStat): Promise<FileStat[]> {
|
||||
const files: FileStat[] = [];
|
||||
async getSketchFiles(sketchFileStat: FileStat): Promise<string[]> {
|
||||
const uris: string[] = [];
|
||||
const sketchUri = new URI(sketchFileStat.uri);
|
||||
const sketchPath = await this.filesystem.getFsPath(sketchUri.toString());
|
||||
if (sketchPath) {
|
||||
if (sketchFileStat.isDirectory && this.isSketchFolder(sketchPath, sketchUri.displayName)) {
|
||||
const sketchDirContents = fs.readdirSync(sketchPath);
|
||||
for (const i in sketchDirContents) {
|
||||
const fileName = sketchDirContents[i];
|
||||
const fileNames = fs.readdirSync(sketchPath);
|
||||
for (const fileName of fileNames) {
|
||||
const filePath = path.join(sketchPath, fileName);
|
||||
if (fs.existsSync(filePath) &&
|
||||
fs.lstatSync(filePath).isFile() &&
|
||||
ALLOWED_FILE_EXTENSIONS.indexOf(path.extname(filePath)) !== -1) {
|
||||
const fileStat = await this.filesystem.getFileStat(filePath);
|
||||
if (fileStat) {
|
||||
console.log("111111111111", fileStat);
|
||||
files.push(fileStat);
|
||||
console.log("222222222222222", files);
|
||||
}
|
||||
if (ALLOWED_FILE_EXTENSIONS.indexOf(path.extname(filePath)) !== -1
|
||||
&& fs.existsSync(filePath)
|
||||
&& fs.lstatSync(filePath).isFile()) {
|
||||
uris.push(FileUri.create(filePath).toString())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -65,13 +60,12 @@ export class SketchesServiceImpl implements SketchesService {
|
||||
const sketchFolderStat = await this.filesystem.getFileStat(sketchUri.path.dir.toString());
|
||||
if (sketchFolderStat) {
|
||||
const sketchDirContents = await this.getSketchFiles(sketchFolderStat);
|
||||
files.push(...sketchDirContents);
|
||||
uris.push(...sketchDirContents);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log("###FILEPATH###", files);
|
||||
return files;
|
||||
return uris;
|
||||
}
|
||||
|
||||
protected isSketchFolder(path: string, name: string): boolean {
|
||||
|
Loading…
x
Reference in New Issue
Block a user