Merge pull request #30 from bcmi-labs/PROEDITOR-19

PROEDITOR-19: Open new sketches in new windows
This commit is contained in:
Luca Cipriani 2019-07-25 09:21:15 +02:00 committed by GitHub
commit 5cc75118cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 12 deletions

View File

@ -22,7 +22,7 @@ import { ArduinoToolbar } from './toolbar/arduino-toolbar';
import { EditorManager, EditorMainMenu } from '@theia/editor/lib/browser'; import { EditorManager, EditorMainMenu } from '@theia/editor/lib/browser';
import { ContextMenuRenderer, OpenerService, Widget, StatusBar } from '@theia/core/lib/browser'; import { ContextMenuRenderer, OpenerService, Widget, StatusBar } 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, FileStat } from '@theia/filesystem/lib/common';
import { ArduinoToolbarContextMenu } from './arduino-file-menu'; import { ArduinoToolbarContextMenu } from './arduino-file-menu';
import { Sketch, SketchesService } from '../common/protocol/sketches-service'; import { Sketch, SketchesService } from '../common/protocol/sketches-service';
import { WindowService } from '@theia/core/lib/browser/window/window-service'; import { WindowService } from '@theia/core/lib/browser/window/window-service';
@ -30,7 +30,8 @@ import { CommonCommands, CommonMenus } from '@theia/core/lib/browser/common-fron
import { FileSystemCommands } from '@theia/filesystem/lib/browser/filesystem-frontend-contribution'; import { FileSystemCommands } from '@theia/filesystem/lib/browser/filesystem-frontend-contribution';
import { FileDownloadCommands } from '@theia/filesystem/lib/browser/download/file-download-command-contribution'; import { FileDownloadCommands } from '@theia/filesystem/lib/browser/download/file-download-command-contribution';
import { MonacoMenus } from '@theia/monaco/lib/browser/monaco-menu'; import { MonacoMenus } from '@theia/monaco/lib/browser/monaco-menu';
import {TerminalMenus} from '@theia/terminal/lib/browser/terminal-frontend-contribution'; import { TerminalMenus } from '@theia/terminal/lib/browser/terminal-frontend-contribution';
import { MaybePromise } from '@theia/core/lib/common/types';
import { SelectBoardDialog } from './boards/select-board-dialog'; import { SelectBoardDialog } from './boards/select-board-dialog';
import { BoardsToolBarItem } from './boards/boards-toolbar-item'; import { BoardsToolBarItem } from './boards/boards-toolbar-item';
@ -383,8 +384,13 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
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 this.openSketchFilesInNewWindow(destinationFileUri.toString()); const message = await this.validate(destinationFile);
return destinationFileUri; if (!message) {
await this.openSketchFilesInNewWindow(destinationFileUri.toString());
return destinationFileUri;
} else {
this.messageService.warn(message);
}
} }
} }
return undefined; return undefined;
@ -401,8 +407,24 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
return widget; return widget;
} }
/**
* Returns `undefined` if the `file` is valid. Otherwise, returns with the validation error message.
*/
protected validate(file: FileStat): MaybePromise<string | undefined> {
const uri = new URI(file.uri);
const path = uri.path;
const { name, ext, dir } = path;
if (ext !== '.ino') {
return "Only sketches with '.ino' extension can be opened.";
}
if (name !== dir.name) {
return `The file "${name}${ext}" needs to be inside a sketch folder named "${name}".`;
}
return undefined;
}
// private async onNoBoardsInstalled() { // private async onNoBoardsInstalled() {
// const action = await this.messageService.info("You have no boards installed. Use the boards mangager to install one.", "Open Boards Manager"); // const action = await this.messageService.info("You have no boards installed. Use the boards manager to install one.", "Open Boards Manager");
// if (!action) { // if (!action) {
// return; // return;
// } // }

View File

@ -1,7 +1,7 @@
import { injectable, inject } from "inversify"; import { injectable, inject } from "inversify";
import URI from "@theia/core/lib/common/uri"; import URI from "@theia/core/lib/common/uri";
import { OpenerService } from "@theia/core/lib/browser";
import { FileSystem } from "@theia/filesystem/lib/common"; import { FileSystem } from "@theia/filesystem/lib/common";
import { WindowService } from "@theia/core/lib/browser/window/window-service";
@injectable() @injectable()
export class SketchFactory { export class SketchFactory {
@ -9,8 +9,8 @@ export class SketchFactory {
@inject(FileSystem) @inject(FileSystem)
protected readonly fileSystem: FileSystem; protected readonly fileSystem: FileSystem;
@inject(OpenerService) @inject(WindowService)
protected readonly openerService: OpenerService; protected readonly windowService: WindowService;
public async createNewSketch(parent: URI): Promise<void> { public async createNewSketch(parent: URI): Promise<void> {
const monthNames = ["january", "february", "march", "april", "may", "june", const monthNames = ["january", "february", "march", "april", "may", "june",
@ -49,8 +49,9 @@ void loop() {
} }
` }); ` });
const opener = await this.openerService.getOpener(sketchFile) const location = new URL(window.location.href);
opener.open(sketchFile, { reveal: true }); location.searchParams.set('sketch', sketchFile.toString());
this.windowService.openNewWindow(location.toString());
} catch (e) { } catch (e) {
throw new Error("Cannot create new sketch: " + e); throw new Error("Cannot create new sketch: " + e);
} }

View File

@ -90,7 +90,7 @@ export class CoreClientProviderImpl implements CoreClientProvider {
throw new Error(`Could not retrieve instance from the initialize response.`); throw new Error(`Could not retrieve instance from the initialize response.`);
} }
// in a seperate promise, try and update the index // in a separate promise, try and update the index
let succeeded = true; let succeeded = true;
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
try { try {
@ -118,11 +118,24 @@ export class CoreClientProviderImpl implements CoreClientProvider {
const updateReq = new UpdateIndexReq(); const updateReq = new UpdateIndexReq();
updateReq.setInstance(instance); updateReq.setInstance(instance);
const updateResp = client.updateIndex(updateReq); const updateResp = client.updateIndex(updateReq);
let file: string | undefined;
updateResp.on('data', (o: UpdateIndexResp) => { updateResp.on('data', (o: UpdateIndexResp) => {
const progress = o.getDownloadProgress(); const progress = o.getDownloadProgress();
if (progress) { if (progress) {
if (!file && progress.getFile()) {
file = `${progress.getFile()}`;
}
if (progress.getCompleted()) { if (progress.getCompleted()) {
this.toolOutputService.publishNewOutput("daemon", `Download${progress.getFile() ? ` of ${progress.getFile()}` : ''} completed.\n`); if (file) {
if (/\s/.test(file)) {
this.toolOutputService.publishNewOutput("daemon", `${file} completed.\n`);
} else {
this.toolOutputService.publishNewOutput("daemon", `Download of '${file}' completed.\n'`);
}
} else {
this.toolOutputService.publishNewOutput("daemon", `The index has been successfully updated.\n'`);
}
file = undefined;
} }
} }
}); });