From 388fcb044c3de2f23bcf52765e658289cd9d192d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Sat, 27 Jan 2024 13:36:12 +0100 Subject: [PATCH] Open ScriptAccount from ContextMenu for adding --- app/main.ts | 5 ++++- src/app/app.component.html | 2 +- src/app/app.component.ts | 22 +++++++++++++++---- .../script-account-overview.component.css | 4 ++++ .../script-account-overview.component.html | 4 +++- .../script-account-overview.component.spec.ts | 2 -- .../script-account-overview.component.ts | 7 ++++++ 7 files changed, 37 insertions(+), 9 deletions(-) diff --git a/app/main.ts b/app/main.ts index ffbea7c..d51d319 100644 --- a/app/main.ts +++ b/app/main.ts @@ -70,7 +70,10 @@ function createWindow(): BrowserWindow { }, { - label: 'Edit...' + label: 'Edit...', + click: () => { + win!.webContents.send('context-menu', "edit"); + } }, { label: 'Delete...' diff --git a/src/app/app.component.html b/src/app/app.component.html index 6384677..2beb7f6 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -19,7 +19,7 @@ - +
diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 85775ad..e818360 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,13 +1,15 @@ -import {Component, OnInit, ViewChild} from '@angular/core'; +import {Component, NgZone, OnInit, ViewChild} from '@angular/core'; import {ElectronService} from './core/services'; import {APP_CONFIG} from '../environments/environment'; import {ModelComponentType} from "./game-model/ModelComponentType"; import {MatDrawerContainer} from "@angular/material/sidenav"; import {ModelComponentTypeUtillities} from "./game-model/ModelComponentTypeUtillities"; import {GameModel} from "./game-model/GameModel"; -import {ScriptAccount} from "./game-model/scriptAccounts/ScriptAccount"; import {EditorComponent} from "./editor/editor.component"; import {ModelComponent} from "./game-model/ModelComponent"; +import { + ScriptAccountOverviewComponent +} from "./side-overviews/script-account-overview/script-account-overview.component"; @Component({ selector: 'app-root', @@ -19,11 +21,12 @@ export class AppComponent implements OnInit{ openContent : ModelComponentType | undefined = undefined; @ViewChild('drawer') drawer: MatDrawerContainer|undefined @ViewChild('editor') editor: EditorComponent|undefined + @ViewChild('scriptAccountOverview') scriptAccountOverview: ScriptAccountOverviewComponent | undefined gameModel: GameModel | undefined - constructor( - private electronService: ElectronService, + constructor(private electronService: ElectronService, + private zone: NgZone ) { console.log('APP_CONFIG', APP_CONFIG); @@ -32,6 +35,17 @@ export class AppComponent implements OnInit{ console.log('Run in electron'); console.log('Electron ipcRenderer', this.electronService.ipcRenderer); console.log('NodeJS childProcess', this.electronService.childProcess); + + electronService.ipcRenderer.on('context-menu', (event: any, message: string) => { + this.zone.run(() => { + if(message == "edit") { + console.log("Edit!") + if(this.openContent == ModelComponentType.SCRIPTACCOUNT && this.scriptAccountOverview != undefined && this.scriptAccountOverview.selectedScriptAccount != undefined) { + this.editor!.openGameModelComponent(this.scriptAccountOverview.selectedScriptAccount!); + } + } + }) + }) } else { console.log('Run in browser'); } diff --git a/src/app/side-overviews/script-account-overview/script-account-overview.component.css b/src/app/side-overviews/script-account-overview/script-account-overview.component.css index 0a8651a..0dde805 100644 --- a/src/app/side-overviews/script-account-overview/script-account-overview.component.css +++ b/src/app/side-overviews/script-account-overview/script-account-overview.component.css @@ -8,3 +8,7 @@ color: #ccffff; align-content: baseline; } + +.selected-item { + background-color: #8696b6; +} diff --git a/src/app/side-overviews/script-account-overview/script-account-overview.component.html b/src/app/side-overviews/script-account-overview/script-account-overview.component.html index d35d531..797174b 100644 --- a/src/app/side-overviews/script-account-overview/script-account-overview.component.html +++ b/src/app/side-overviews/script-account-overview/script-account-overview.component.html @@ -1,6 +1,8 @@ + (dblclick)="onOpenScriptAccount(scriptAccount)" (click)="selectScriptAccount(scriptAccount)" + [ngClass]="selectedScriptAccount === scriptAccount ?'selected-item':''" + (contextmenu)="selectScriptAccount(scriptAccount)"> inventory_2{{scriptAccount.componentName}} diff --git a/src/app/side-overviews/script-account-overview/script-account-overview.component.spec.ts b/src/app/side-overviews/script-account-overview/script-account-overview.component.spec.ts index 09f3d6f..991dc2e 100644 --- a/src/app/side-overviews/script-account-overview/script-account-overview.component.spec.ts +++ b/src/app/side-overviews/script-account-overview/script-account-overview.component.spec.ts @@ -40,8 +40,6 @@ describe('ScriptAccountOverview', () => { component.onCreateNewScriptAccount(); fixture.detectChanges() expect(component.openScriptAccountEmitter.emit).toBeCalledTimes(1); - - })) diff --git a/src/app/side-overviews/script-account-overview/script-account-overview.component.ts b/src/app/side-overviews/script-account-overview/script-account-overview.component.ts index e57d45a..f8621ee 100644 --- a/src/app/side-overviews/script-account-overview/script-account-overview.component.ts +++ b/src/app/side-overviews/script-account-overview/script-account-overview.component.ts @@ -12,6 +12,8 @@ export class ScriptAccountOverviewComponent { @Input("gameModel") gameModel: GameModel | undefined @Output("onOpenScriptAccount") openScriptAccountEmitter: EventEmitter = new EventEmitter(); + selectedScriptAccount: ScriptAccount | undefined + constructor(private electronService: ElectronService, private zone: NgZone) { if(electronService.isElectron) { @@ -36,4 +38,9 @@ export class ScriptAccountOverviewComponent { this.openScriptAccountEmitter.emit(scriptAccount); } } + + + selectScriptAccount(scriptAccount: ScriptAccount) { + this.selectedScriptAccount = scriptAccount; + } }