import { Commands } from '../../commands' ; import { TreeViewOptions , commands , window } from 'vscode' ; import { BaseTreeView , ViewTypes } from '../common' ; import { ClassifyItem , HexoClassifyProvider , ClassifyTypes } from './hexoClassifyProvider' ; import { sleep } from '../../utils' ; export class ClassifyTreeView extends BaseTreeView < ClassifyItem > { provider : HexoClassifyProvider ; constructor ( viewId , type , opts = { } ) { const provider = new HexoClassifyProvider ( type ) ; super ( viewId , provider , opts ) ; this . provider = provider ; this . onDidChanged ( ) ; this . autoFocus ( ) ; } private focus ( editor = window . activeTextEditor ) { if ( ! editor || ! this . treeView . visible ) { return ; } const file = editor . document . uri ; const fsPath = file . scheme === 'git' ? file . fsPath . slice ( 0 , - 3 ) : file . fsPath ; const item = this . provider . getItem ( fsPath ) ; if ( ! item ) { return ; } this . treeView . reveal ( item ) ; } private autoFocus ( ) { this . subscribe ( window . onDidChangeActiveTextEditor ( async ( editor ) => { await sleep ( 300 ) ; this . focus ( editor ) ; } ) ) ; } onDidChanged ( ) { } registerRefreshCmd ( cmd ) { const _cmd = commands . registerCommand ( cmd , ( ) => this . provider . refresh ( ) ) ; this . subscribe ( _cmd ) ; } }