Skip to content

Commit 4096afd

Browse files
committed
Open the sketch in a new window.
Signed-off-by: jbicker <jan.bicker@typefox.io>
1 parent 92afa48 commit 4096afd

File tree

3 files changed

+35
-20
lines changed

3 files changed

+35
-20
lines changed

arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx

+14-18
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import URI from '@theia/core/lib/common/uri';
44
import { EditorWidget } from '@theia/editor/lib/browser/editor-widget';
55
import { MessageService } from '@theia/core/lib/common/message-service';
66
import { CommandContribution, CommandRegistry } from '@theia/core/lib/common/command';
7-
import { DefaultFrontendApplicationContribution } from '@theia/core/lib/browser/frontend-application';
87
import { TabBarToolbarContribution, TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
98
import { BoardsService } from '../common/protocol/boards-service';
109
import { ArduinoCommands } from './arduino-commands';
@@ -21,15 +20,15 @@ import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service
2120
import { SketchFactory } from './sketch-factory';
2221
import { ArduinoToolbar } from './toolbar/arduino-toolbar';
2322
import { EditorManager } from '@theia/editor/lib/browser';
24-
import { ContextMenuRenderer, OpenerService, Widget } from '@theia/core/lib/browser';
23+
import { ContextMenuRenderer, OpenerService, Widget, Endpoint } from '@theia/core/lib/browser';
2524
import { OpenFileDialogProps, FileDialogService } from '@theia/filesystem/lib/browser/file-dialog';
2625
import { FileSystem } from '@theia/filesystem/lib/common';
2726
import { ArduinoOpenSketchContextMenu } from './arduino-file-menu';
2827
import { Sketch, SketchesService } from '../common/protocol/sketches-service';
2928
import { WindowService } from '@theia/core/lib/browser/window/window-service';
3029

3130
@injectable()
32-
export class ArduinoFrontendContribution extends DefaultFrontendApplicationContribution implements TabBarToolbarContribution, CommandContribution {
31+
export class ArduinoFrontendContribution implements TabBarToolbarContribution, CommandContribution {
3332

3433
@inject(MessageService)
3534
protected readonly messageService: MessageService;
@@ -79,12 +78,11 @@ export class ArduinoFrontendContribution extends DefaultFrontendApplicationContr
7978
@inject(OpenerService)
8079
protected readonly openerService: OpenerService;
8180

82-
@inject(SketchesService)
83-
protected readonly sketches: SketchesService;
84-
8581
@inject(WindowService)
8682
protected readonly windowService: WindowService;
8783

84+
@inject(SketchesService)
85+
protected readonly sketches: SketchesService;
8886

8987
@postConstruct()
9088
protected async init(): Promise<void> {
@@ -189,16 +187,7 @@ export class ArduinoFrontendContribution extends DefaultFrontendApplicationContr
189187
registry.registerCommand(ArduinoCommands.OPEN_SKETCH, {
190188
isEnabled: () => true,
191189
execute: async (sketch: Sketch) => {
192-
// const url = new URL(window.location.href);
193-
// if (this.workspaceService.workspace) {
194-
// const wsUri = this.workspaceService.workspace.uri;
195-
// const path = new URI(wsUri).path;
196-
// url.hash = path + '?sketch=' + sketch.name
197-
// }
198-
// this.windowService.openNewWindow(url.toString());
199-
200-
this.openSketchFiles(sketch.uri);
201-
190+
this.openSketchFilesInNewWindow(sketch.uri);
202191
}
203192
})
204193
registry.registerCommand(ArduinoCommands.NEW_SKETCH, new WorkspaceRootUriAwareCommandHandler(this.workspaceService, this.selectionService, {
@@ -221,7 +210,14 @@ export class ArduinoFrontendContribution extends DefaultFrontendApplicationContr
221210
})
222211
}
223212

224-
protected async openSketchFiles(uri: string) {
213+
protected async openSketchFilesInNewWindow(uri: string) {
214+
const location = new URL(window.location.href);
215+
let url = new Endpoint().getRestUrl().withQuery(uri).toString();
216+
url += location.hash;
217+
this.windowService.openNewWindow(url);
218+
}
219+
220+
async openSketchFiles(uri: string) {
225221
const fileStat = await this.fileSystem.getFileStat(uri);
226222
if (fileStat) {
227223
const sketchFiles = await this.sketches.getSketchFiles(fileStat);
@@ -251,7 +247,7 @@ export class ArduinoFrontendContribution extends DefaultFrontendApplicationContr
251247
if (destinationFileUri) {
252248
const destinationFile = await this.fileSystem.getFileStat(destinationFileUri.toString());
253249
if (destinationFile && !destinationFile.isDirectory) {
254-
await this.openSketchFiles(destinationFileUri.toString());
250+
await this.openSketchFilesInNewWindow(destinationFileUri.toString());
255251
return destinationFileUri;
256252
}
257253
}

arduino-ide-extension/src/browser/arduino-frontend-module.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { CommandContribution } from '@theia/core/lib/common/command';
55
import { bindViewContribution } from '@theia/core/lib/browser/shell/view-contribution';
66
import { TabBarToolbarContribution } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
77
import { WebSocketConnectionProvider } from '@theia/core/lib/browser/messaging/ws-connection-provider';
8-
import { FrontendApplicationContribution } from '@theia/core/lib/browser/frontend-application'
8+
import { FrontendApplicationContribution, FrontendApplication } from '@theia/core/lib/browser/frontend-application'
99
import { LanguageGrammarDefinitionContribution } from '@theia/monaco/lib/browser/textmate';
1010
import { LibraryListWidget } from './library/library-list-widget';
1111
import { ArduinoFrontendContribution } from './arduino-frontend-contribution';
@@ -45,12 +45,14 @@ import { MonacoStatusBarContribution } from '@theia/monaco/lib/browser/monaco-st
4545
import { SilentMonacoStatusBarContribution } from './customization/silent-monaco-status-bar-contribution';
4646
import { ApplicationShell } from '@theia/core/lib/browser';
4747
import { CustomApplicationShell } from './customization/custom-application-shell';
48+
import { CustomFrontendApplication } from './customization/custom-frontend-application';
4849

4950
export default new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Unbind, isBound: interfaces.IsBound, rebind: interfaces.Rebind) => {
5051
// Commands and toolbar items
5152
bind(ArduinoFrontendContribution).toSelf().inSingletonScope();
5253
bind(CommandContribution).toService(ArduinoFrontendContribution);
5354
bind(TabBarToolbarContribution).toService(ArduinoFrontendContribution);
55+
bind(FrontendApplicationContribution).toService(ArduinoFrontendContribution);
5456
bind(MenuContribution).to(ArduinoFileMenuContribution).inSingletonScope();
5557

5658
bind(ArduinoToolbarContribution).toSelf().inSingletonScope();
@@ -126,7 +128,6 @@ export default new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Un
126128
bind(OutlineViewContribution).to(SilentOutlineViewContribution).inSingletonScope();
127129
unbind(ProblemContribution);
128130
bind(ProblemContribution).to(SilentProblemContribution).inSingletonScope();
129-
130131
unbind(FileNavigatorContribution);
131132
bind(FileNavigatorContribution).to(SilentNavigatorContribution).inSingletonScope();
132133
unbind(OutputToolbarContribution);
@@ -137,4 +138,6 @@ export default new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Un
137138
bind(MonacoStatusBarContribution).to(SilentMonacoStatusBarContribution).inSingletonScope();
138139
unbind(ApplicationShell);
139140
bind(ApplicationShell).to(CustomApplicationShell).inSingletonScope();
141+
unbind(FrontendApplication);
142+
bind(FrontendApplication).to(CustomFrontendApplication).inSingletonScope();
140143
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { injectable, inject } from "inversify";
2+
import { FrontendApplication } from "@theia/core/lib/browser";
3+
import { ArduinoFrontendContribution } from "../arduino-frontend-contribution";
4+
import URI from "@theia/core/lib/common/uri";
5+
6+
@injectable()
7+
export class CustomFrontendApplication extends FrontendApplication {
8+
9+
@inject(ArduinoFrontendContribution)
10+
protected readonly frontendContribution: ArduinoFrontendContribution;
11+
12+
protected async initializeLayout(): Promise<void> {
13+
const location = new URI(window.location.href);
14+
this.frontendContribution.openSketchFiles(decodeURIComponent(location.query));
15+
}
16+
}

0 commit comments

Comments
 (0)