-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
70 additions
and
70 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
); | ||
}); |