mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-08 03:46:33 +00:00
Merge pull request #30 from bcmi-labs/PROEDITOR-19
PROEDITOR-19: Open new sketches in new windows
This commit is contained in:
commit
5cc75118cd
@ -22,7 +22,7 @@ import { ArduinoToolbar } from './toolbar/arduino-toolbar';
|
||||
import { EditorManager, EditorMainMenu } from '@theia/editor/lib/browser';
|
||||
import { ContextMenuRenderer, OpenerService, Widget, StatusBar } from '@theia/core/lib/browser';
|
||||
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 { Sketch, SketchesService } from '../common/protocol/sketches-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 { FileDownloadCommands } from '@theia/filesystem/lib/browser/download/file-download-command-contribution';
|
||||
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 { BoardsToolBarItem } from './boards/boards-toolbar-item';
|
||||
|
||||
@ -383,8 +384,13 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
|
||||
if (destinationFileUri) {
|
||||
const destinationFile = await this.fileSystem.getFileStat(destinationFileUri.toString());
|
||||
if (destinationFile && !destinationFile.isDirectory) {
|
||||
await this.openSketchFilesInNewWindow(destinationFileUri.toString());
|
||||
return destinationFileUri;
|
||||
const message = await this.validate(destinationFile);
|
||||
if (!message) {
|
||||
await this.openSketchFilesInNewWindow(destinationFileUri.toString());
|
||||
return destinationFileUri;
|
||||
} else {
|
||||
this.messageService.warn(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
@ -401,8 +407,24 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
|
||||
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() {
|
||||
// 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) {
|
||||
// return;
|
||||
// }
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { injectable, inject } from "inversify";
|
||||
import URI from "@theia/core/lib/common/uri";
|
||||
import { OpenerService } from "@theia/core/lib/browser";
|
||||
import { FileSystem } from "@theia/filesystem/lib/common";
|
||||
import { WindowService } from "@theia/core/lib/browser/window/window-service";
|
||||
|
||||
@injectable()
|
||||
export class SketchFactory {
|
||||
@ -9,8 +9,8 @@ export class SketchFactory {
|
||||
@inject(FileSystem)
|
||||
protected readonly fileSystem: FileSystem;
|
||||
|
||||
@inject(OpenerService)
|
||||
protected readonly openerService: OpenerService;
|
||||
@inject(WindowService)
|
||||
protected readonly windowService: WindowService;
|
||||
|
||||
public async createNewSketch(parent: URI): Promise<void> {
|
||||
const monthNames = ["january", "february", "march", "april", "may", "june",
|
||||
@ -49,8 +49,9 @@ void loop() {
|
||||
|
||||
}
|
||||
` });
|
||||
const opener = await this.openerService.getOpener(sketchFile)
|
||||
opener.open(sketchFile, { reveal: true });
|
||||
const location = new URL(window.location.href);
|
||||
location.searchParams.set('sketch', sketchFile.toString());
|
||||
this.windowService.openNewWindow(location.toString());
|
||||
} catch (e) {
|
||||
throw new Error("Cannot create new sketch: " + e);
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ export class CoreClientProviderImpl implements CoreClientProvider {
|
||||
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;
|
||||
for (let i = 0; i < 10; i++) {
|
||||
try {
|
||||
@ -118,11 +118,24 @@ export class CoreClientProviderImpl implements CoreClientProvider {
|
||||
const updateReq = new UpdateIndexReq();
|
||||
updateReq.setInstance(instance);
|
||||
const updateResp = client.updateIndex(updateReq);
|
||||
let file: string | undefined;
|
||||
updateResp.on('data', (o: UpdateIndexResp) => {
|
||||
const progress = o.getDownloadProgress();
|
||||
if (progress) {
|
||||
if (!file && progress.getFile()) {
|
||||
file = `${progress.getFile()}`;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user