Show context menu
All checks were successful
E2E Testing / test (push) Successful in 1m24s

This commit is contained in:
Sebastian Böckelmann 2024-01-27 12:41:36 +01:00
parent 7680cd7edd
commit 35a323e97a
3 changed files with 48 additions and 2 deletions

View File

@ -1,4 +1,4 @@
import {app, BrowserWindow, screen} from 'electron'; import {app, BrowserWindow, screen, Menu, ipcMain} from 'electron';
import * as path from 'path'; import * as path from 'path';
import * as fs from 'fs'; import * as fs from 'fs';
@ -50,6 +50,41 @@ function createWindow(): BrowserWindow {
win = null; win = null;
}); });
const contextMenuTemplate = [
{
label: 'New',
submenu: [
{
label: "Gamesystem",
click: () => {
win!.webContents.send('context-menu', "new-location");
}
},
{
label: "ScriptAccount",
click: () => {
win!.webContents.send('context-menu', "new-scriptaccount");
}
}
]
},
{
label: 'Edit...'
},
{
label: 'Delete...'
}
]
const contextMenu = Menu.buildFromTemplate(contextMenuTemplate);
win.webContents.on('context-menu', (e, params) => {
console.log("Electron: Context menu showing")
contextMenu.popup({ window: win!, x: params.x, y: params.y });
})
return win; return win;
} }

View File

@ -1,6 +1,6 @@
<mat-action-list> <mat-action-list>
<mat-list-item class="scriptAccount-item" *ngFor="let scriptAccount of gameModel!.scriptAccounts" <mat-list-item class="scriptAccount-item" *ngFor="let scriptAccount of gameModel!.scriptAccounts"
(dblclick)="onOpenScriptAccount(scriptAccount)"> (dblclick)="onOpenScriptAccount(scriptAccount)" (contextmenu)="onContextMenu($event)">
<mat-icon class="scriptAccount-icon">inventory_2</mat-icon>{{scriptAccount.componentName}} <mat-icon class="scriptAccount-icon">inventory_2</mat-icon>{{scriptAccount.componentName}}
</mat-list-item> </mat-list-item>
</mat-action-list> </mat-action-list>

View File

@ -1,6 +1,7 @@
import {Component, EventEmitter, Input, Output} from '@angular/core'; import {Component, EventEmitter, Input, Output} from '@angular/core';
import {GameModel} from "../../game-model/GameModel"; import {GameModel} from "../../game-model/GameModel";
import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount"; import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount";
import {ElectronService} from "../../core/services";
@Component({ @Component({
selector: 'app-script-account-overview', selector: 'app-script-account-overview',
@ -11,6 +12,9 @@ export class ScriptAccountOverviewComponent {
@Input("gameModel") gameModel: GameModel | undefined @Input("gameModel") gameModel: GameModel | undefined
@Output("onOpenScriptAccount") openScriptAccountEmitter: EventEmitter<ScriptAccount> = new EventEmitter<ScriptAccount>(); @Output("onOpenScriptAccount") openScriptAccountEmitter: EventEmitter<ScriptAccount> = new EventEmitter<ScriptAccount>();
constructor(private electronService: ElectronService) {
}
onOpenScriptAccount(scriptAccount: ScriptAccount) { onOpenScriptAccount(scriptAccount: ScriptAccount) {
console.log("onOpenScriptAccount (overview)") console.log("onOpenScriptAccount (overview)")
this.openScriptAccountEmitter.emit(scriptAccount); this.openScriptAccountEmitter.emit(scriptAccount);
@ -22,5 +26,12 @@ export class ScriptAccountOverviewComponent {
return scriptAccount; return scriptAccount;
} }
onContextMenu(event: MouseEvent) {
if(this.electronService.isElectron) {
console.log("[DEBUG] [ScriptAccountOverviewComponent] App is executed in electron")
} else {
console.log("[DEBUG] [ScriptAccountOverviewComponent] App is not executed in electron")
}
}
} }