forked from eclipsesource/ecore-glsp
-
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.
Added Quick-Commands for GenModel-Generation and Project-Creation
- Loading branch information
Showing
5 changed files
with
300 additions
and
0 deletions.
There are no files selected for viewing
143 changes: 143 additions & 0 deletions
143
client/theia-ecore/src/browser/CreateProjectCommandContribution.ts
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 |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2019 EclipseSource and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
import { FrontendApplication, OpenerService, QuickOpenOptions, QuickOpenService } from "@theia/core/lib/browser"; | ||
import { Command, CommandContribution, CommandRegistry } from "@theia/core/lib/common/command"; | ||
import { MessageService } from "@theia/core/lib/common/message-service"; | ||
import { ProgressService } from "@theia/core/lib/common/progress-service"; | ||
import { SelectionService } from "@theia/core/lib/common/selection-service"; | ||
import URI from "@theia/core/lib/common/uri"; | ||
import { UriAwareCommandHandler, UriCommandHandler } from "@theia/core/lib/common/uri-command-handler"; | ||
import { EDITOR_CONTEXT_MENU } from "@theia/editor/lib/browser"; | ||
import { FileDialogService } from "@theia/filesystem/lib/browser"; | ||
import { FileStat, FileSystem } from "@theia/filesystem/lib/common/filesystem"; | ||
import { NAVIGATOR_CONTEXT_MENU } from "@theia/navigator/lib/browser/navigator-contribution"; | ||
import { WorkspaceService } from "@theia/workspace/lib/browser"; | ||
import { inject, injectable } from "inversify"; | ||
|
||
import { FileGenServer } from "../common/generate-protocol"; | ||
|
||
|
||
|
||
export const EXAMPLE_NAVIGATOR = [...NAVIGATOR_CONTEXT_MENU, 'example']; | ||
export const EXAMPLE_EDITOR = [...EDITOR_CONTEXT_MENU, 'example']; | ||
|
||
|
||
|
||
export const CREATE_NEW_PROJECT: Command = { | ||
id: 'file.createNewProject', | ||
category: 'File', | ||
label: 'Create new Project', | ||
}; | ||
|
||
@injectable() | ||
export class CreateProjectCommandContribution implements CommandContribution { | ||
|
||
@inject(FileSystem) protected readonly fileSystem: FileSystem; | ||
@inject(SelectionService) protected readonly selectionService: SelectionService; | ||
@inject(OpenerService) protected readonly openerService: OpenerService; | ||
@inject(FrontendApplication) protected readonly app: FrontendApplication; | ||
@inject(MessageService) protected readonly messageService: MessageService; | ||
@inject(FileDialogService) protected readonly fileDialogService: FileDialogService; | ||
@inject(WorkspaceService) protected readonly workspaceService: WorkspaceService; | ||
@inject(ProgressService) protected readonly progressService: ProgressService; | ||
@inject(QuickOpenService) protected readonly quickOpenService: QuickOpenService; | ||
@inject(FileGenServer) private readonly fileGenServer: FileGenServer; | ||
|
||
registerCommands(registry: CommandRegistry): void { | ||
registry.registerCommand(CREATE_NEW_PROJECT, this.newWorkspaceRootUriAwareCommandHandler({ | ||
execute: uri => this.getDirectory(uri).then(parent => { | ||
if (parent) { | ||
const parentUri = new URI(parent.uri); | ||
// @Leo hier wird die Methode zum generieren aufgerufen. | ||
// Die Variable uri ist das aktuell markierte Element | ||
// und parentUri ist dann dementsprechend der Ordner darüber(wrsl der Workspace) | ||
this.fileGenServer.createNewProject().then(() => { | ||
// @Leo hier kannst du die files nachdem sie generiert wurden öffnen | ||
}); | ||
} | ||
}) | ||
})); | ||
} | ||
|
||
protected withProgress<T>(task: () => Promise<T>): Promise<T> { | ||
return this.progressService.withProgress('', 'scm', task); | ||
} | ||
|
||
protected newUriAwareCommandHandler(handler: UriCommandHandler<URI>): UriAwareCommandHandler<URI> { | ||
return new UriAwareCommandHandler(this.selectionService, handler); | ||
} | ||
|
||
protected newMultiUriAwareCommandHandler(handler: UriCommandHandler<URI[]>): UriAwareCommandHandler<URI[]> { | ||
return new UriAwareCommandHandler(this.selectionService, handler, { multi: true }); | ||
} | ||
|
||
protected newWorkspaceRootUriAwareCommandHandler(handler: UriCommandHandler<URI>): WorkspaceRootUriAwareCommandHandler { | ||
return new WorkspaceRootUriAwareCommandHandler(this.workspaceService, this.selectionService, handler); | ||
} | ||
|
||
protected async getDirectory(candidate: URI): Promise<FileStat | undefined> { | ||
const stat = await this.fileSystem.getFileStat(candidate.toString()); | ||
if (stat && stat.isDirectory) { | ||
return stat; | ||
} | ||
return this.getParent(candidate); | ||
} | ||
|
||
protected getParent(candidate: URI): Promise<FileStat | undefined> { | ||
return this.fileSystem.getFileStat(candidate.parent.toString()); | ||
} | ||
|
||
private getOptions(placeholder: string, fuzzyMatchLabel: boolean = true, onClose: (canceled: boolean) => void = () => { }): QuickOpenOptions { | ||
return QuickOpenOptions.resolve({ | ||
placeholder, | ||
fuzzyMatchLabel, | ||
fuzzySort: false, | ||
onClose | ||
}); | ||
} | ||
} | ||
|
||
export class WorkspaceRootUriAwareCommandHandler extends UriAwareCommandHandler<URI> { | ||
|
||
constructor( | ||
protected readonly workspaceService: WorkspaceService, | ||
protected readonly selectionService: SelectionService, | ||
protected readonly handler: UriCommandHandler<URI> | ||
) { | ||
super(selectionService, handler); | ||
} | ||
|
||
public isEnabled(...args: any[]): boolean { | ||
return super.isEnabled(...args) && !!this.workspaceService.tryGetRoots().length; | ||
} | ||
|
||
public isVisible(...args: any[]): boolean { | ||
return super.isVisible(...args) && !!this.workspaceService.tryGetRoots().length; | ||
} | ||
|
||
protected getUri(...args: any[]): URI | undefined { | ||
const uri = super.getUri(...args); | ||
// If the URI is available, return it immediately. | ||
if (uri) { | ||
return uri; | ||
} | ||
// Return the first root if available. | ||
if (!!this.workspaceService.tryGetRoots().length) { | ||
return new URI(this.workspaceService.tryGetRoots()[0].uri); | ||
} | ||
return undefined; | ||
} | ||
} |
143 changes: 143 additions & 0 deletions
143
client/theia-ecore/src/browser/GenerateGenModelCommandContribution.ts
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 |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2019 EclipseSource and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
import { FrontendApplication, OpenerService, QuickOpenOptions, QuickOpenService } from "@theia/core/lib/browser"; | ||
import { Command, CommandContribution, CommandRegistry } from "@theia/core/lib/common/command"; | ||
import { MessageService } from "@theia/core/lib/common/message-service"; | ||
import { ProgressService } from "@theia/core/lib/common/progress-service"; | ||
import { SelectionService } from "@theia/core/lib/common/selection-service"; | ||
import URI from "@theia/core/lib/common/uri"; | ||
import { UriAwareCommandHandler, UriCommandHandler } from "@theia/core/lib/common/uri-command-handler"; | ||
import { EDITOR_CONTEXT_MENU } from "@theia/editor/lib/browser"; | ||
import { FileDialogService } from "@theia/filesystem/lib/browser"; | ||
import { FileStat, FileSystem } from "@theia/filesystem/lib/common/filesystem"; | ||
import { NAVIGATOR_CONTEXT_MENU } from "@theia/navigator/lib/browser/navigator-contribution"; | ||
import { WorkspaceService } from "@theia/workspace/lib/browser"; | ||
import { inject, injectable } from "inversify"; | ||
|
||
import { FileGenServer } from "../common/generate-protocol"; | ||
|
||
|
||
|
||
export const EXAMPLE_NAVIGATOR = [...NAVIGATOR_CONTEXT_MENU, 'example']; | ||
export const EXAMPLE_EDITOR = [...EDITOR_CONTEXT_MENU, 'example']; | ||
|
||
|
||
|
||
export const GENERATE_GENMODEL: Command = { | ||
id: 'file.generateGenModel', | ||
category: 'File', | ||
label: 'Generate GenModel', | ||
}; | ||
|
||
@injectable() | ||
export class GenerateGenModelCommandContribution implements CommandContribution { | ||
|
||
@inject(FileSystem) protected readonly fileSystem: FileSystem; | ||
@inject(SelectionService) protected readonly selectionService: SelectionService; | ||
@inject(OpenerService) protected readonly openerService: OpenerService; | ||
@inject(FrontendApplication) protected readonly app: FrontendApplication; | ||
@inject(MessageService) protected readonly messageService: MessageService; | ||
@inject(FileDialogService) protected readonly fileDialogService: FileDialogService; | ||
@inject(WorkspaceService) protected readonly workspaceService: WorkspaceService; | ||
@inject(ProgressService) protected readonly progressService: ProgressService; | ||
@inject(QuickOpenService) protected readonly quickOpenService: QuickOpenService; | ||
@inject(FileGenServer) private readonly fileGenServer: FileGenServer; | ||
|
||
registerCommands(registry: CommandRegistry): void { | ||
registry.registerCommand(GENERATE_GENMODEL, this.newWorkspaceRootUriAwareCommandHandler({ | ||
execute: uri => this.getDirectory(uri).then(parent => { | ||
if (parent) { | ||
const parentUri = new URI(parent.uri); | ||
// @Leo hier wird die Methode zum generieren aufgerufen. | ||
// Die Variable uri ist das aktuell markierte Element | ||
// und parentUri ist dann dementsprechend der Ordner darüber(wrsl der Workspace) | ||
this.fileGenServer.generateGenModel().then(() => { | ||
// @Leo hier kannst du die files nachdem sie generiert wurden öffnen | ||
}); | ||
} | ||
}) | ||
})); | ||
} | ||
|
||
protected withProgress<T>(task: () => Promise<T>): Promise<T> { | ||
return this.progressService.withProgress('', 'scm', task); | ||
} | ||
|
||
protected newUriAwareCommandHandler(handler: UriCommandHandler<URI>): UriAwareCommandHandler<URI> { | ||
return new UriAwareCommandHandler(this.selectionService, handler); | ||
} | ||
|
||
protected newMultiUriAwareCommandHandler(handler: UriCommandHandler<URI[]>): UriAwareCommandHandler<URI[]> { | ||
return new UriAwareCommandHandler(this.selectionService, handler, { multi: true }); | ||
} | ||
|
||
protected newWorkspaceRootUriAwareCommandHandler(handler: UriCommandHandler<URI>): WorkspaceRootUriAwareCommandHandler { | ||
return new WorkspaceRootUriAwareCommandHandler(this.workspaceService, this.selectionService, handler); | ||
} | ||
|
||
protected async getDirectory(candidate: URI): Promise<FileStat | undefined> { | ||
const stat = await this.fileSystem.getFileStat(candidate.toString()); | ||
if (stat && stat.isDirectory) { | ||
return stat; | ||
} | ||
return this.getParent(candidate); | ||
} | ||
|
||
protected getParent(candidate: URI): Promise<FileStat | undefined> { | ||
return this.fileSystem.getFileStat(candidate.parent.toString()); | ||
} | ||
|
||
private getOptions(placeholder: string, fuzzyMatchLabel: boolean = true, onClose: (canceled: boolean) => void = () => { }): QuickOpenOptions { | ||
return QuickOpenOptions.resolve({ | ||
placeholder, | ||
fuzzyMatchLabel, | ||
fuzzySort: false, | ||
onClose | ||
}); | ||
} | ||
} | ||
|
||
export class WorkspaceRootUriAwareCommandHandler extends UriAwareCommandHandler<URI> { | ||
|
||
constructor( | ||
protected readonly workspaceService: WorkspaceService, | ||
protected readonly selectionService: SelectionService, | ||
protected readonly handler: UriCommandHandler<URI> | ||
) { | ||
super(selectionService, handler); | ||
} | ||
|
||
public isEnabled(...args: any[]): boolean { | ||
return super.isEnabled(...args) && !!this.workspaceService.tryGetRoots().length; | ||
} | ||
|
||
public isVisible(...args: any[]): boolean { | ||
return super.isVisible(...args) && !!this.workspaceService.tryGetRoots().length; | ||
} | ||
|
||
protected getUri(...args: any[]): URI | undefined { | ||
const uri = super.getUri(...args); | ||
// If the URI is available, return it immediately. | ||
if (uri) { | ||
return uri; | ||
} | ||
// Return the first root if available. | ||
if (!!this.workspaceService.tryGetRoots().length) { | ||
return new URI(this.workspaceService.tryGetRoots()[0].uri); | ||
} | ||
return undefined; | ||
} | ||
} |
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
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