@@ -31,7 +31,7 @@ import { LOGGER } from 'services/Logger';
3131import { DatabaseCore , DatabaseFrontmatterOptions , DEFAULT_SETTINGS , YAML_INDENT } from 'helpers/Constants' ;
3232import { PreviewDatabaseModeService } from 'services/MarkdownPostProcessorService' ;
3333import { unmountComponentAtNode } from 'react-dom' ;
34- import { hasFrontmatterKey } from 'helpers/VaultManagement' ;
34+ import { isDatabaseNote } from 'helpers/VaultManagement' ;
3535import { getParentWindow } from 'helpers/WindowElement' ;
3636
3737interface WindowRegistry {
@@ -187,6 +187,16 @@ export default class DBFolderPlugin extends Plugin {
187187 return this . stateManagers . get ( file ) ;
188188 }
189189
190+ getStateManagerFromViewID ( id : string , win : Window ) {
191+ const view = this . getDatabaseView ( id , win ) ;
192+
193+ if ( ! view ) {
194+ return null ;
195+ }
196+
197+ return this . stateManagers . get ( view . file ) ;
198+ }
199+
190200 removeView ( view : DatabaseView ) {
191201 const entry = Array . from ( this . windowRegistry . entries ( ) ) . find ( ( [ , reg ] ) => {
192202 return reg . viewMap . has ( view . id ) ;
@@ -251,8 +261,20 @@ export default class DBFolderPlugin extends Plugin {
251261 return [ ] ;
252262 }
253263
254- getDatabaseView ( id : string ) {
255- return this . viewMap . get ( id ) ;
264+ getDatabaseView ( id : string , win : Window ) {
265+ const reg = this . windowRegistry . get ( win ) ;
266+
267+ if ( reg ?. viewMap . has ( id ) ) {
268+ return reg . viewMap . get ( id ) ;
269+ }
270+
271+ for ( const reg of this . windowRegistry . values ( ) ) {
272+ if ( reg . viewMap . has ( id ) ) {
273+ return reg . viewMap . get ( id ) ;
274+ }
275+ }
276+
277+ return null ;
256278 }
257279
258280 mount ( win : Window ) {
@@ -326,26 +348,26 @@ export default class DBFolderPlugin extends Plugin {
326348 } ) ;
327349 return ;
328350 }
351+ console . log ( 'file-menu' ) ;
329352 if (
330353 ! Platform . isMobile &&
331354 file instanceof TFile &&
332355 leaf &&
333356 source === 'sidebar-context-menu' &&
334- hasFrontmatterKey ( file )
357+ isDatabaseNote ( file )
335358 ) {
336359 const views = this . getDatabaseViews (
337360 getParentWindow ( leaf . view . containerEl )
338361 ) ;
339- let haveDatabaseView = false ;
340362
341- for ( const view of views ) {
363+ const haveDatabaseView = views . some ( ( view ) => {
342364 if ( view . file === file ) {
343365 view . onPaneMenu ( menu , 'more-options' , false ) ;
344- haveDatabaseView = true ;
345- break ;
366+ return true ;
346367 }
347- }
348-
368+ return false ;
369+ } ) ;
370+ console . log ( 'haveDatabaseView' , haveDatabaseView ) ;
349371 if ( ! haveDatabaseView ) {
350372 menu . addItem ( ( item ) => {
351373 item
@@ -358,7 +380,6 @@ export default class DBFolderPlugin extends Plugin {
358380 this . setDatabaseView ( leaf ) ;
359381 } ) ;
360382 } ) ;
361-
362383 return ;
363384 }
364385 }
@@ -367,7 +388,7 @@ export default class DBFolderPlugin extends Plugin {
367388 leaf ?. view instanceof MarkdownView &&
368389 file instanceof TFile &&
369390 source === 'pane-more-options' &&
370- hasFrontmatterKey ( file )
391+ isDatabaseNote ( file )
371392 ) {
372393 menu . addItem ( ( item ) => {
373394 item
@@ -455,43 +476,6 @@ export default class DBFolderPlugin extends Plugin {
455476 } ,
456477 } )
457478 ) ;
458-
459- // //Add a menu item to go back to database view
460- // this.register(
461- // around(MarkdownView.prototype, {
462- // onPaneMenu(next) {
463- // return function (menu: Menu) {
464- // const file = this.file;
465- // const cache = file
466- // ? self.app.metadataCache.getFileCache(file)
467- // : null;
468-
469- // if (
470- // !file ||
471- // !cache?.frontmatter ||
472- // !cache.frontmatter[DatabaseCore.FRONTMATTER_KEY]
473- // ) {
474- // return next.call(this, menu);
475- // }
476-
477- // menu
478- // .addItem((item) => {
479- // item
480- // .setTitle('Open as database folder')
481- // .setIcon(databaseIcon)
482- // .onClick(() => {
483- // self.databaseFileModes[this.leaf.id || file.path] =
484- // DatabaseCore.FRONTMATTER_KEY;
485- // self.setDatabaseView(this.leaf);
486- // });
487- // })
488- // .addSeparator();
489-
490- // next.call(this, menu);
491- // };
492- // },
493- // })
494- // );
495479 }
496480
497481 // private debuggingMobile(plugin:Plugin){
0 commit comments