import { injectable, inject } from "inversify"; import { MenuModelRegistry } from "@theia/core"; import { GalileoIdeStorjWidgetWidget } from "./galileo-ide-storj-widget-widget"; import { AbstractViewContribution, ApplicationShell, FrontendApplication, } from "@theia/core/lib/browser"; import { Command, CommandRegistry } from "@theia/core/lib/common/command"; import { FrontendApplicationStateService } from "@theia/core/lib/browser/frontend-application-state"; export const GalileoIdeStorjWidgetCommand: Command = { id: "galileo-ide-storj-widget:command", }; const assets = require("../../src/browser/style/assets.useable.css"); function useAssets(): void { assets.use(); } useAssets(); @injectable() export class GalileoIdeStorjWidgetContribution extends AbstractViewContribution { @inject(FrontendApplicationStateService) protected readonly stateService: FrontendApplicationStateService; @inject(ApplicationShell) protected readonly sidePanelHandler: ApplicationShell; /** * `AbstractViewContribution` handles the creation and registering * of the widget including commands, menus, and keybindings. * * We can pass `defaultWidgetOptions` which define widget properties such as * its location `area` (`main`, `left`, `right`, `bottom`), `mode`, and `ref`. * */ constructor() { super({ widgetId: GalileoIdeStorjWidgetWidget.ID, widgetName: GalileoIdeStorjWidgetWidget.LABEL, defaultWidgetOptions: { area: "left" }, toggleCommandId: GalileoIdeStorjWidgetCommand.id, }); } async onStart(app: FrontendApplication): Promise { this.stateService.reachedState("ready").then(() => { this.openView({ reveal: false }); }); } /** * Example command registration to open the widget from the menu, and quick-open. * For a simpler use case, it is possible to simply call: ```ts super.registerCommands(commands) ``` * * For more flexibility, we can pass `OpenViewArguments` which define * options on how to handle opening the widget: * ```ts toggle?: boolean activate?: boolean; reveal?: boolean; ``` * * @param commands */ registerCommands(commands: CommandRegistry): void { commands.registerCommand(GalileoIdeStorjWidgetCommand, { execute: () => super.openView({ activate: false, reveal: true, toggle: true }), }); } /** * Example menu registration to contribute a menu item used to open the widget. * Default location when extending the `AbstractViewContribution` is the `View` main-menu item. * * We can however define new menu path locations in the following way: ```ts menus.registerMenuAction(CommonMenus.HELP, { commandId: 'id', label: 'label' }); ``` * * @param menus */ registerMenus(menus: MenuModelRegistry): void { super.registerMenus(menus); } }