From 74ef4b0eedce408ea5bd4c9f8c83e992ab8b2967 Mon Sep 17 00:00:00 2001 From: "s.malakhov" Date: Wed, 3 May 2023 08:10:37 +0300 Subject: [PATCH] [MPQEditor] Implement UI messages This commit implements 'removeVisqFile' and 'VisqInputPathChanged' messages. ONE-vscode-DCO-1.0-Signed-off-by: s.malakhov --- src/MPQEditor/MPQEditor.ts | 62 +++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/src/MPQEditor/MPQEditor.ts b/src/MPQEditor/MPQEditor.ts index 7bda8896..f35a6f77 100644 --- a/src/MPQEditor/MPQEditor.ts +++ b/src/MPQEditor/MPQEditor.ts @@ -334,6 +334,12 @@ export class MPQEditorProvider case "toggleCircleGraphIsShown": this.toggleCircleGraphIsShown(e.show, document, webviewPanel); break; + case "removeVisqFile": + this.removeVisqFile(document, webviewPanel); + break; + case "VisqInputPathChanged": + this.handleVisqInputPathChanged(e.path, document, webviewPanel); + break; default: break; } @@ -651,9 +657,63 @@ export class MPQEditorProvider webviewPanel: vscode.WebviewPanel ) { if (show) { - this.showCircleModelGraph(document, webviewPanel); + const docUri = document.uri.toString(); + const visqPath = this._mpqDataMap[docUri].visqPath; + if (visqPath.length < 1) { + this.showCircleModelGraph(document, webviewPanel); + } else { + this.showVisqCircleModelGraph(visqPath, document, webviewPanel); + } } else { this.closeModelGraphView(document); } } + + /** + * @brief Called when it's needed to show visq data in circle-graph + */ + private showVisqCircleModelGraph( + _visqPath: string, + _document: vscode.TextDocument, + _webviewPanel: vscode.WebviewPanel + ) { + // TODO + } + + /** + * @brief Called when visq path was changed in UI + */ + private handleVisqInputPathChanged( + path: string, + document: vscode.TextDocument, + webviewPanel: vscode.WebviewPanel + ): void { + if ( + (path === "" || !path.endsWith(".visq.json")) && + this._mpqDataMap[document.uri.toString()].visqPath.length > 0 + ) { + // remove invalid path + this.removeVisqFile(document, webviewPanel); + } else if (path.endsWith(".visq.json")) { + // reload visq + this._mpqDataMap[document.uri.toString()].visqPath = path; + this.closeModelGraphView(document); + this.showVisqCircleModelGraph(path, document, webviewPanel); + } + } + + /** + * @brief Called when visq path was cleared in UI + */ + private removeVisqFile( + document: vscode.TextDocument, + webviewPanel: vscode.WebviewPanel + ) { + if (this._mpqDataMap[document.uri.toString()].visqPath !== "") { + this._mpqDataMap[document.uri.toString()].visqPath = ""; // clear visqPath + + this.closeModelGraphView(document); + this.showCircleModelGraph(document, webviewPanel); + } + } }