diff --git a/package-lock.json b/package-lock.json index 7a16a23..83c628a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -360,6 +360,18 @@ } } }, + "@theia/navigator": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@theia/navigator/-/navigator-1.7.0.tgz", + "integrity": "sha512-APpJPuLFb0qSzoxTmQoB+sG7tvNYfaJ2ArlRetMuuUD6tpw26R6iJKQYKMPnJuFEAPRbAHOnp7gMLl39BNQIog==", + "requires": { + "@theia/core": "^1.7.0", + "@theia/filesystem": "^1.7.0", + "@theia/workspace": "^1.7.0", + "fuzzy": "^0.1.3", + "minimatch": "^3.0.4" + } + }, "@theia/variable-resolver": { "version": "1.7.0", "resolved": "https://registry.npmjs.org/@theia/variable-resolver/-/variable-resolver-1.7.0.tgz", diff --git a/package.json b/package.json index 25eb8e2..45e5881 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "dependencies": { "@theia/core": "latest", "@theia/workspace": "latest", - "@theia/filesystem": "latest" + "@theia/filesystem": "latest", + "@theia/navigator": "latest" }, "devDependencies": { "rimraf": "latest", diff --git a/src/browser/winery-contribution.ts b/src/browser/winery-contribution.ts index d39b670..d7e2331 100644 --- a/src/browser/winery-contribution.ts +++ b/src/browser/winery-contribution.ts @@ -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 { + // 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"); + } } } diff --git a/src/browser/winery-frontend-module.ts b/src/browser/winery-frontend-module.ts index b8988f2..86a30f6 100644 --- a/src/browser/winery-frontend-module.ts +++ b/src/browser/winery-frontend-module.ts @@ -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) + ); });