import { ContentType } from './helpers/ContentType' ; import { Dashboard } from './commands/Dashboard' ; import * as vscode from 'vscode' ; import { Article , Settings , StatusListener } from './commands' ; import { Folders } from './commands/Folders' ; import { Preview } from './commands/Preview' ; import { Project } from './commands/Project' ; import { Template } from './commands/Template' ; import { COMMAND_NAME } from './constants' ; import { TaxonomyType } from './models' ; import { MarkdownFoldingProvider } from './providers/MarkdownFoldingProvider' ; import { TagType } from './panelWebView/TagType' ; import { ExplorerView } from './explorerView/ExplorerView' ; import { Extension } from './helpers/Extension' ; import { DashboardData } from './models/DashboardData' ; import { Settings as SettingsHelper } from './helpers' ; import { Content } from './commands/Content' ; import ContentProvider from './providers/ContentProvider' ; import { Wysiwyg } from './commands/Wysiwyg' ; import { Diagnostics } from './commands/Diagnostics' ; import { PagesListener } from './listeners' ; let frontMatterStatusBar ; let statusDebouncer ; let editDebounce ; let collection ; const mdSelector = { language : 'markdown' , scheme : 'file' } ; export async function activate ( context ) { const { subscriptions , extensionUri , extensionPath } = context ; const extension = Extension . getInstance ( context ) ; if ( ! extension . checkIfExtensionCanRun ( ) ) { return undefined ; } SettingsHelper . init ( ) ; extension . migrateSettings ( ) ; SettingsHelper . checkToPromote ( ) ; PagesListener . startWatchers ( ) ; collection = vscode . languages . createDiagnosticCollection ( 'frontMatter' ) ; Dashboard . init ( ) ; subscriptions . push ( vscode . commands . registerCommand ( COMMAND_NAME . dashboard , ( data ? ) => { if ( ! data ) { Dashboard . open ( { type : "contents" } ) ; } else { Dashboard . open ( data ) ; } } ) ) ; subscriptions . push ( vscode . commands . registerCommand ( COMMAND_NAME . dashboardMedia , ( data ? ) => { Dashboard . open ( { type : "media" } ) ; } ) ) ; subscriptions . push ( vscode . commands . registerCommand ( COMMAND_NAME . dashboardClose , ( data ? ) => { Dashboard . close ( ) ; } ) ) ; if ( ! extension . getVersion ( ) . usedVersion ) { vscode . commands . executeCommand ( COMMAND_NAME . dashboard ) ; } const explorerSidebar = ExplorerView . getInstance ( extensionUri ) ; const explorerView = vscode . window . registerWebviewViewProvider ( ExplorerView . viewType , explorerSidebar , { webviewOptions : { retainContextWhenHidden : true } } ) ; vscode . languages . registerFoldingRangeProvider ( mdSelector , new MarkdownFoldingProvider ( ) ) ; const insertTags = vscode . commands . registerCommand ( COMMAND_NAME . insertTags , async ( ) => { await vscode . commands . executeCommand ( 'workbench.view.extension.frontmatter-explorer' ) ; await vscode . commands . executeCommand ( 'workbench.action.focusSideBar' ) ; explorerSidebar . triggerInputFocus ( TagType . tags ) ; } ) ; const insertCategories = vscode . commands . registerCommand ( COMMAND_NAME . insertCategories , async ( ) => { await vscode . commands . executeCommand ( 'workbench.view.extension.frontmatter-explorer' ) ; await vscode . commands . executeCommand ( 'workbench.action.focusSideBar' ) ; explorerSidebar . triggerInputFocus ( TagType . categories ) ; } ) ; const createTag = vscode . commands . registerCommand ( COMMAND_NAME . createTag , ( ) => { Settings . create ( TaxonomyType . Tag ) ; } ) ; const createCategory = vscode . commands . registerCommand ( COMMAND_NAME . createCategory , ( ) => { Settings . create ( TaxonomyType . Category ) ; } ) ; const exportTaxonomy = vscode . commands . registerCommand ( COMMAND_NAME . exportTaxonomy , Settings . export ) ; const remap = vscode . commands . registerCommand ( COMMAND_NAME . remap , Settings . remap ) ; const setLastModifiedDate = vscode . commands . registerCommand ( COMMAND_NAME . setLastModifiedDate , Article . setLastModifiedDate ) ; const generateSlug = vscode . commands . registerCommand ( COMMAND_NAME . generateSlug , Article . generateSlug ) ; const createFromTemplate = vscode . commands . registerCommand ( COMMAND_NAME . createFromTemplate , ( folder ) => { const folderPath = Folders . getFolderPath ( folder ) ; if ( folderPath ) { Template . create ( folderPath ) ; } } ) ; let createTemplate = vscode . commands . registerCommand ( COMMAND_NAME . createTemplate , Template . generate ) ; const toggleDraftCommand = COMMAND_NAME . toggleDraft ; const toggleDraft = vscode . commands . registerCommand ( toggleDraftCommand , async ( ) => { await Article . toggleDraft ( ) ; triggerShowDraftStatus ( ) ; } ) ; const registerFolder = vscode . commands . registerCommand ( COMMAND_NAME . registerFolder , Folders . register ) ; const unregisterFolder = vscode . commands . registerCommand ( COMMAND_NAME . unregisterFolder , Folders . unregister ) ; const createFolder = vscode . commands . registerCommand ( COMMAND_NAME . createFolder , Folders . addMediaFolder ) ; const createByContentType = vscode . commands . registerCommand ( COMMAND_NAME . createByContentType , ContentType . createContent ) ; const createByTemplate = vscode . commands . registerCommand ( COMMAND_NAME . createByTemplate , Folders . create ) ; const createContent = vscode . commands . registerCommand ( COMMAND_NAME . createContent , Content . create ) ; Template . init ( ) ; const projectInit = vscode . commands . registerCommand ( COMMAND_NAME . init , async ( cb ) => { await Project . init ( ) ; if ( cb ) { cb ( ) ; } } ) ; subscriptions . push ( vscode . commands . registerCommand ( COMMAND_NAME . promote , SettingsHelper . promote ) ) ; const collapseAll = vscode . commands . registerCommand ( COMMAND_NAME . collapseSections , ( ) => { ExplorerView . getInstance ( ) ?. collapseAll ( ) ; } ) ; SettingsHelper . onConfigChange ( ( global ? ) => { Template . init ( ) ; Preview . init ( ) ; const exView = ExplorerView . getInstance ( ) ; exView . getSettings ( ) ; exView . getFoldersAndFiles ( ) ; MarkdownFoldingProvider . triggerHighlighting ( ) ; } ) ; frontMatterStatusBar = vscode . window . createStatusBarItem ( vscode . StatusBarAlignment . Left , 100 ) ; frontMatterStatusBar . command = toggleDraftCommand ; subscriptions . push ( frontMatterStatusBar ) ; statusDebouncer = debounceCallback ( ) ; subscriptions . push ( vscode . window . onDidChangeActiveTextEditor ( triggerShowDraftStatus ) ) ; subscriptions . push ( vscode . window . onDidChangeTextEditorSelection ( triggerShowDraftStatus ) ) ; triggerShowDraftStatus ( ) ; subscriptions . push ( vscode . workspace . onWillSaveTextDocument ( handleAutoDateUpdate ) ) ; subscriptions . push ( vscode . workspace . onDidSaveTextDocument ( ( doc ) => { if ( doc . languageId === 'markdown' ) { ExplorerView . getInstance ( ) . getFoldersAndFiles ( ) ; } } ) ) ; Preview . init ( ) ; subscriptions . push ( vscode . commands . registerCommand ( COMMAND_NAME . preview , ( ) => Preview . open ( extensionPath ) ) ) ; subscriptions . push ( vscode . commands . registerCommand ( COMMAND_NAME . insertImage , Article . insertImage ) ) ; subscriptions . push ( vscode . workspace . registerTextDocumentContentProvider ( ContentProvider . scheme , new ContentProvider ( ) ) ) ; Wysiwyg . registerCommands ( subscriptions ) ; subscriptions . push ( vscode . commands . registerCommand ( COMMAND_NAME . diagnostics , Diagnostics . show ) ) ; subscriptions . push ( insertTags , explorerView , insertCategories , createTag , createCategory , exportTaxonomy , remap , setLastModifiedDate , generateSlug , createFromTemplate , createTemplate , toggleDraft , registerFolder , unregisterFolder , createContent , createByContentType , createByTemplate , projectInit , collapseAll , createFolder ) ; } export function deactivate ( ) { } const handleAutoDateUpdate = ( e ) => { Article . autoUpdate ( e ) ; } ; const triggerShowDraftStatus = ( ) => { statusDebouncer ( ( ) => { StatusListener . verify ( frontMatterStatusBar , collection ) ; } , 1000 ) ; } ; const debounceCallback = ( ) => { let timeout ; return ( fnc , time ) => { const functionCall = ( ... args ) => fnc . apply ( args ) ; clearTimeout ( timeout ) ; timeout = setTimeout ( functionCall , time ) as any ; } ; } ;