@@ -25,8 +25,17 @@ import { Logger } from "../Utils/Logger";
25
25
import { getNonce } from "../Utils/external/Nonce" ;
26
26
import { getUri } from "../Utils/external/Uri" ;
27
27
import { MPQData } from "./MPQData" ;
28
-
29
- export class MPQEditorProvider implements vscode . CustomTextEditorProvider {
28
+ import {
29
+ MPQSelectionPanel ,
30
+ MPQSelectionEvent ,
31
+ MPQSelectionCmdCloseArgs ,
32
+ MPQSelectionCmdOpenArgs ,
33
+ MPQSelectionCmdLayersChangedArgs ,
34
+ } from "./MPQCircleSelector" ;
35
+
36
+ export class MPQEditorProvider
37
+ implements vscode . CustomTextEditorProvider , MPQSelectionEvent
38
+ {
30
39
public static readonly viewType = "one.editor.mpq" ;
31
40
public static readonly fileExtension = ".mpq.json" ;
32
41
@@ -319,6 +328,12 @@ export class MPQEditorProvider implements vscode.CustomTextEditorProvider {
319
328
case "removeLayer" :
320
329
this . handleRemoveLayerFromLayers ( e . name , document ) ;
321
330
break ;
331
+ case "showModelNodes" :
332
+ this . handleShowModelNodes ( document , webviewPanel ) ;
333
+ break ;
334
+ case "toggleCircleGraphIsShown" :
335
+ this . toggleCircleGraphIsShown ( e . show , document , webviewPanel ) ;
336
+ break ;
322
337
default :
323
338
break ;
324
339
}
@@ -397,6 +412,20 @@ export class MPQEditorProvider implements vscode.CustomTextEditorProvider {
397
412
e . document . uri . toString ( ) === document . uri . toString ( )
398
413
) {
399
414
this . updateWebview ( document , webviewPanel . webview ) ;
415
+
416
+ {
417
+ // synchronize circle view
418
+ const args : MPQSelectionCmdLayersChangedArgs = {
419
+ modelPath : this . getModelFilePath ( document ) ,
420
+ document : document ,
421
+ names : this . _mpqDataMap [ document . uri . toString ( ) ] . getLayers ( ) ,
422
+ } ;
423
+ vscode . commands . executeCommand (
424
+ MPQSelectionPanel . cmdChanged ,
425
+ args ,
426
+ this
427
+ ) ;
428
+ }
400
429
}
401
430
}
402
431
) ;
@@ -414,6 +443,8 @@ export class MPQEditorProvider implements vscode.CustomTextEditorProvider {
414
443
) ;
415
444
416
445
webviewPanel . onDidDispose ( ( ) => {
446
+ this . closeModelGraphView ( document ) ;
447
+
417
448
changeDocumentSubscription . dispose ( ) ;
418
449
while ( this . _disposables . length ) {
419
450
const x = this . _disposables . pop ( ) ;
@@ -544,4 +575,85 @@ export class MPQEditorProvider implements vscode.CustomTextEditorProvider {
544
575
) ;
545
576
await vscode . workspace . applyEdit ( edit ) ;
546
577
}
578
+
579
+ /**
580
+ * @brief Called when selection changed in SelectionView
581
+ */
582
+ onSelection ( names : string [ ] , document : vscode . TextDocument ) : void {
583
+ let docUri = document . uri . toString ( ) ;
584
+ this . _mpqDataMap [ docUri ] . setLayers ( names ) ;
585
+ this . updateDocument ( document ) ;
586
+ }
587
+
588
+ /**
589
+ * @brief Called when MPQCircleSelector was closed
590
+ */
591
+ onClosed ( panel : vscode . WebviewPanel ) : void {
592
+ panel . webview . postMessage ( {
593
+ type : "modelGraphIsShown" ,
594
+ shown : false ,
595
+ } ) ;
596
+ }
597
+
598
+ /**
599
+ * @brief Called when MPQCircleSelector was opened
600
+ */
601
+ onOpened ( panel : vscode . WebviewPanel ) : void {
602
+ panel . webview . postMessage ( {
603
+ type : "modelGraphIsShown" ,
604
+ shown : true ,
605
+ } ) ;
606
+ }
607
+
608
+ /**
609
+ * @brief Close MPQCircleSelector
610
+ */
611
+ private closeModelGraphView ( document : vscode . TextDocument ) : void {
612
+ const args : MPQSelectionCmdCloseArgs = {
613
+ modelPath : this . getModelFilePath ( document ) ,
614
+ document : document ,
615
+ } ;
616
+ vscode . commands . executeCommand ( MPQSelectionPanel . cmdClose , args ) ;
617
+ }
618
+
619
+ /**
620
+ * @brief Open MPQCircleSelector panel
621
+ */
622
+ private showCircleModelGraph (
623
+ document : vscode . TextDocument ,
624
+ webviewPanel : vscode . WebviewPanel
625
+ ) {
626
+ const args : MPQSelectionCmdOpenArgs = {
627
+ modelPath : this . getModelFilePath ( document ) ,
628
+ document : document ,
629
+ names : this . _mpqDataMap [ document . uri . toString ( ) ] . getLayers ( ) ,
630
+ panel : webviewPanel ,
631
+ } ;
632
+ vscode . commands . executeCommand ( MPQSelectionPanel . cmdOpen , args , this ) ;
633
+ }
634
+
635
+ /**
636
+ * @brief Called when webview requests to Show Model Graph
637
+ */
638
+ private handleShowModelNodes (
639
+ document : vscode . TextDocument ,
640
+ webviewPanel : vscode . WebviewPanel
641
+ ) {
642
+ this . showCircleModelGraph ( document , webviewPanel ) ;
643
+ }
644
+
645
+ /**
646
+ * @brief Called when webview toggles whether Model Graph is shown
647
+ */
648
+ private toggleCircleGraphIsShown (
649
+ show : boolean ,
650
+ document : vscode . TextDocument ,
651
+ webviewPanel : vscode . WebviewPanel
652
+ ) {
653
+ if ( show ) {
654
+ this . showCircleModelGraph ( document , webviewPanel ) ;
655
+ } else {
656
+ this . closeModelGraphView ( document ) ;
657
+ }
658
+ }
547
659
}
0 commit comments