Skip to content

Commit

Permalink
Open tosca file on open
Browse files Browse the repository at this point in the history
  • Loading branch information
nfode committed Nov 24, 2020
1 parent 45d064f commit f0038aa
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 70 deletions.
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"dependencies": {
"@theia/core": "latest",
"@theia/workspace": "latest",
"@theia/filesystem": "latest"
"@theia/filesystem": "latest",
"@theia/navigator": "latest"
},
"devDependencies": {
"rimraf": "latest",
Expand Down
106 changes: 49 additions & 57 deletions src/browser/winery-contribution.ts
Original file line number Diff line number Diff line change
@@ -1,72 +1,64 @@
import { injectable, inject } from "inversify";
import { CommandService, MessageService } from "@theia/core/lib/common";
import {
CommandContribution,
CommandRegistry,
MenuContribution,
MenuModelRegistry,
MessageService,
} from "@theia/core/lib/common";
import { CommonMenus, OpenerService, open } from "@theia/core/lib/browser";
OpenerService,
open,
FrontendApplicationContribution,
FrontendApplication,
} from "@theia/core/lib/browser";
import URI from "@theia/core/lib/common/uri";
import { FileService } from "@theia/filesystem/lib/browser/file-service";

export const TestCommand = {
id: "Test.command",
label: "Say Hello",
};
import { FrontendApplicationStateService } from "@theia/core/lib/browser/frontend-application-state";
import { FileNavigatorCommands } from "@theia/navigator/lib/browser/navigator-contribution";

@injectable()
export class WineryCommandContribution implements CommandContribution {
export class WineryFrontendContribution
implements FrontendApplicationContribution {
constructor(
@inject(CommandService) private readonly commandService: CommandService,
@inject(MessageService) private readonly messageService: MessageService,
@inject(OpenerService) private readonly openerService: OpenerService,
@inject(FileService) private readonly fileService: FileService
) {}
@inject(FileService) private readonly fileService: FileService,
@inject(FrontendApplicationStateService)
protected readonly frontendApplicationStateService: FrontendApplicationStateService
) {
this.frontendApplicationStateService
.reachedState("ready")
.then(() => this.onReady());
}

registerCommands(registry: CommandRegistry): void {
registry.registerCommand(TestCommand, {
execute: async () => {
const queryParams = window.parent.location
.toString()
.split("?")[1];
const cleanedUpQueryParams = queryParams.split("#")[0];
const params = new URLSearchParams(cleanedUpQueryParams);
const path = params.get("path");
if (path) {
const uri = new URI(path);
const stat = await this.fileService.resolve(uri);
if (stat.children) {
const files = stat.children?.filter(
(stat) => stat.isFile
async onStart(app: FrontendApplication): Promise<void> {
// load this module at FrontendApplication startup
}

private async onReady() {
const queryParams = window.parent.location.toString().split("?")[1];
const cleanedUpQueryParams = queryParams.split("#")[0];
const params = new URLSearchParams(cleanedUpQueryParams);
const path = params.get("path");
if (path) {
const uri = new URI(path);
const stat = await this.fileService.resolve(uri);
if (stat.children) {
const files = stat.children?.filter((stat) => stat.isFile);
if (files.length > 0) {
const toscaFile = files.filter((file) =>
file.resource.toString().endsWith(".tosca")
)[0];
if (toscaFile) {
open(this.openerService, toscaFile.resource);
this.commandService.executeCommand(
FileNavigatorCommands.OPEN.id
);
} else {
this.messageService.error(
"Could not find Tosca file in folder: " + path
);
if (files.length > 0) {
const toscaFile = files.filter((file) =>
file.resource.toString().endsWith(".tosca")
)[0];
if (toscaFile) {
open(this.openerService, toscaFile.resource);
} else {
this.messageService.error(
"Could not find Tosca file in folder: " +
path
);
}
}
}
} else {
this.messageService.error("Failed to parse folder path from URL")
}
},
});
}
}

@injectable()
export class WineryMenuContribution implements MenuContribution {
registerMenus(menus: MenuModelRegistry): void {
menus.registerMenuAction(CommonMenus.EDIT_FIND, {
commandId: TestCommand.id,
label: TestCommand.label,
});
}
} else {
this.messageService.error("Failed to parse folder path from URL");
}
}
}
19 changes: 7 additions & 12 deletions src/browser/winery-frontend-module.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
/**
* Generated using theia-extension-generator
*/
import { WineryCommandContribution, WineryMenuContribution } from './winery-contribution';
import {
CommandContribution,
MenuContribution
} from "@theia/core/lib/common";
import { WineryFrontendContribution } from "./winery-contribution";
import { ContainerModule } from "inversify";
import { FrontendApplicationContribution } from "@theia/core/lib/browser";

export default new ContainerModule(bind => {
// add your contribution bindings here
bind(CommandContribution).to(WineryCommandContribution);
bind(MenuContribution).to(WineryMenuContribution);
export default new ContainerModule((bind) => {
bind(WineryFrontendContribution).toSelf().inSingletonScope();
bind(FrontendApplicationContribution).toDynamicValue((c) =>
c.container.get(WineryFrontendContribution)
);
});

0 comments on commit f0038aa

Please sign in to comment.