1- import { type MarkdownPostProcessorContext , Plugin } from 'obsidian' ;
1+ import { type MarkdownPostProcessorContext , Plugin , type WorkspaceLeaf } from 'obsidian' ;
22import { MetaBindSettingTab } from './settings/SettingsTab' ;
33import { RenderChildType } from './renderChildren/InputFieldMDRC' ;
44import { DateParser } from './parsers/DateParser' ;
@@ -12,6 +12,7 @@ import { type IPlugin } from './IPlugin';
1212import { EnclosingPair , ParserUtils } from './utils/ParserUtils' ;
1313import { ErrorLevel , MetaBindParsingError } from './utils/errors/MetaBindErrors' ;
1414import { ObsidianMetadataAdapter } from './metadata/ObsidianMetadataAdapter' ;
15+ import { FaqView , MB_FAQ_VIEW_TYPE } from './utils/faq/FaqView' ;
1516
1617export default class MetaBindPlugin extends Plugin implements IPlugin {
1718 // @ts -ignore defined in `onload`
@@ -104,6 +105,16 @@ export default class MetaBindPlugin extends Plugin implements IPlugin {
104105 } ,
105106 } ) ;
106107
108+ this . addCommand ( {
109+ id : 'mb-open-faq' ,
110+ name : 'Open Meta Bind FAQ' ,
111+ callback : ( ) => {
112+ void this . activateView ( MB_FAQ_VIEW_TYPE ) ;
113+ } ,
114+ } ) ;
115+
116+ this . registerView ( MB_FAQ_VIEW_TYPE , leaf => new FaqView ( leaf ) ) ;
117+
107118 this . addSettingTab ( new MetaBindSettingTab ( this . app , this ) ) ;
108119 }
109120
@@ -206,4 +217,24 @@ export default class MetaBindPlugin extends Plugin implements IPlugin {
206217
207218 return oldSettings ;
208219 }
220+
221+ async activateView ( viewType : string ) : Promise < void > {
222+ const { workspace } = this . app ;
223+
224+ let leaf : WorkspaceLeaf | null = null ;
225+ const leaves = workspace . getLeavesOfType ( viewType ) ;
226+
227+ if ( leaves . length > 0 ) {
228+ // A leaf with our view already exists, use that
229+ leaf = leaves [ 0 ] ;
230+ } else {
231+ // Our view could not be found in the workspace, create a new leaf
232+ // in the right sidebar for it
233+ leaf = workspace . getLeaf ( 'tab' ) ;
234+ await leaf . setViewState ( { type : viewType , active : true } ) ;
235+ }
236+
237+ // "Reveal" the leaf in case it is in a collapsed sidebar
238+ workspace . revealLeaf ( leaf ) ;
239+ }
209240}
0 commit comments