@@ -41,7 +41,6 @@ import { loadModeledMethods, saveModeledMethods } from "./modeled-method-fs";
4141import { pickExtensionPack } from "./extension-pack-picker" ;
4242import { getLanguageDisplayName } from "../common/query-language" ;
4343import { AutoModeler } from "./auto-modeler" ;
44- import { INITIAL_HIDE_MODELED_METHODS_VALUE } from "./shared/hide-modeled-methods" ;
4544import { telemetryListener } from "../common/vscode/telemetry" ;
4645import { ModelingStore } from "./modeling-store" ;
4746
@@ -51,9 +50,6 @@ export class ModelEditorView extends AbstractWebview<
5150> {
5251 private readonly autoModeler : AutoModeler ;
5352
54- private methods : Method [ ] ;
55- private hideModeledMethods : boolean ;
56-
5753 public constructor (
5854 protected readonly app : App ,
5955 private readonly modelingStore : ModelingStore ,
@@ -65,24 +61,15 @@ export class ModelEditorView extends AbstractWebview<
6561 private readonly databaseItem : DatabaseItem ,
6662 private readonly extensionPack : ExtensionPack ,
6763 private mode : Mode ,
68- private readonly updateMethodsUsagePanelState : (
69- methods : Method [ ] ,
70- databaseItem : DatabaseItem ,
71- hideModeledMethods : boolean ,
72- ) => Promise < void > ,
7364 private readonly showMethod : (
7465 method : Method ,
7566 usage : Usage ,
7667 ) => Promise < void > ,
77- private readonly handleViewBecameActive : ( view : ModelEditorView ) => void ,
78- private readonly handleViewWasDisposed : ( view : ModelEditorView ) => void ,
79- private readonly isMostRecentlyActiveView : (
80- view : ModelEditorView ,
81- ) => boolean ,
8268 ) {
8369 super ( app ) ;
8470
8571 this . modelingStore . initializeStateForDb ( databaseItem ) ;
72+ this . registerToModelingStoreEvents ( ) ;
8673
8774 this . autoModeler = new AutoModeler (
8875 app ,
@@ -101,8 +88,6 @@ export class ModelEditorView extends AbstractWebview<
10188 await this . postMessage ( { t : "addModeledMethods" , modeledMethods } ) ;
10289 } ,
10390 ) ;
104- this . methods = [ ] ;
105- this . hideModeledMethods = INITIAL_HIDE_MODELED_METHODS_VALUE ;
10691 }
10792
10893 public async openView ( ) {
@@ -111,20 +96,15 @@ export class ModelEditorView extends AbstractWebview<
11196
11297 panel . onDidChangeViewState ( async ( ) => {
11398 if ( panel . active ) {
114- this . handleViewBecameActive ( this ) ;
115- await this . updateMethodsUsagePanelState (
116- this . methods ,
117- this . databaseItem ,
118- this . hideModeledMethods ,
119- ) ;
99+ this . modelingStore . setActiveDb ( this . databaseItem ) ;
120100 await this . markModelEditorAsActive ( ) ;
121101 } else {
122102 await this . updateModelEditorActiveContext ( ) ;
123103 }
124104 } ) ;
125105
126106 panel . onDidDispose ( ( ) => {
127- this . handleViewWasDisposed ( this ) ;
107+ this . modelingStore . removeDb ( this . databaseItem ) ;
128108 // onDidDispose is called after the tab has been closed,
129109 // so we want to check if there are any others still open.
130110 void this . app . commands . execute (
@@ -313,11 +293,11 @@ export class ModelEditorView extends AbstractWebview<
313293 break ;
314294 case "switchMode" :
315295 this . mode = msg . mode ;
316- this . methods = [ ] ;
296+ this . modelingStore . setMethods ( this . databaseItem , [ ] ) ;
317297 await Promise . all ( [
318298 this . postMessage ( {
319299 t : "setMethods" ,
320- methods : this . methods ,
300+ methods : [ ] ,
321301 } ) ,
322302 this . setViewState ( ) ,
323303 withProgress ( ( progress ) => this . loadMethods ( progress ) , {
@@ -328,11 +308,9 @@ export class ModelEditorView extends AbstractWebview<
328308
329309 break ;
330310 case "hideModeledMethods" :
331- this . hideModeledMethods = msg . hideModeledMethods ;
332- await this . updateMethodsUsagePanelState (
333- this . methods ,
311+ this . modelingStore . setHideModeledMethods (
334312 this . databaseItem ,
335- this . hideModeledMethods ,
313+ msg . hideModeledMethods ,
336314 ) ;
337315 void telemetryListener ?. sendUIInteraction (
338316 "model-editor-hide-modeled-methods" ,
@@ -413,19 +391,8 @@ export class ModelEditorView extends AbstractWebview<
413391 if ( ! queryResult ) {
414392 return ;
415393 }
416- this . methods = queryResult ;
417394
418- await this . postMessage ( {
419- t : "setMethods" ,
420- methods : this . methods ,
421- } ) ;
422- if ( this . isMostRecentlyActiveView ( this ) ) {
423- await this . updateMethodsUsagePanelState (
424- this . methods ,
425- this . databaseItem ,
426- this . hideModeledMethods ,
427- ) ;
428- }
395+ this . modelingStore . setMethods ( this . databaseItem , queryResult ) ;
429396 } catch ( err ) {
430397 void showAndLogExceptionWithTelemetry (
431398 this . app . logger ,
@@ -540,11 +507,7 @@ export class ModelEditorView extends AbstractWebview<
540507 addedDatabase ,
541508 modelFile ,
542509 Mode . Framework ,
543- this . updateMethodsUsagePanelState ,
544510 this . showMethod ,
545- this . handleViewBecameActive ,
546- this . handleViewWasDisposed ,
547- this . isMostRecentlyActiveView ,
548511 ) ;
549512 await view . openView ( ) ;
550513 } ) ;
@@ -622,4 +585,17 @@ export class ModelEditorView extends AbstractWebview<
622585
623586 return addedDatabase ;
624587 }
588+
589+ private registerToModelingStoreEvents ( ) {
590+ this . push (
591+ this . modelingStore . onMethodsChanged ( async ( event ) => {
592+ if ( event . dbUri === this . databaseItem . databaseUri . toString ( ) ) {
593+ await this . postMessage ( {
594+ t : "setMethods" ,
595+ methods : event . methods ,
596+ } ) ;
597+ }
598+ } ) ,
599+ ) ;
600+ }
625601}
0 commit comments