@@ -3,6 +3,7 @@ const vscode = require('vscode')
33const path = require ( 'path' )
44const fs = require ( 'fs' )
55
6+
67class Treeview {
78 constructor ( context ) {
89 const treeDataProvider = new AudioTreeDataProvider (
@@ -46,39 +47,54 @@ class AudioTreeDataProvider {
4647 getFiles ( thePath ) {
4748 const toFileItem = ( name , path , type ) => {
4849 if ( type == 'directory' ) {
49- return new fileItem ( name , path , vscode . TreeItemCollapsibleState . Collapsed )
50+ let descriptionText , collapsibleState
51+ const filesCount = ( fs . readdirSync ( `${ path } \\${ name } ` ) . filter ( this . isMp3 ) ) . length
52+ if ( filesCount > 0 ) {
53+ collapsibleState = vscode . TreeItemCollapsibleState . Collapsed
54+ descriptionText = `${ filesCount } song`
55+ if ( filesCount > 1 ) descriptionText += 's'
56+
57+ } else {
58+ collapsibleState = vscode . TreeItemCollapsibleState . None
59+ descriptionText = 'Empty'
60+ }
61+ return new fileItem ( name , path , collapsibleState , descriptionText )
5062 } else {
5163 return new fileItem ( name , path , vscode . TreeItemCollapsibleState . None )
5264 }
5365 }
5466 const isDirectory = name => fs . lstatSync ( path . join ( thePath , name ) ) . isDirectory ( )
55- const isMp3 = name => name . indexOf ( '.mp3' ) != - 1 ? true : false
5667
5768 const subdirs = fs . readdirSync ( thePath ) . filter ( isDirectory )
58- const mp3s = fs . readdirSync ( thePath ) . filter ( isMp3 )
69+ const mp3s = fs . readdirSync ( thePath ) . filter ( this . isMp3 )
5970
6071 const subdirsItem = subdirs . map ( name => toFileItem ( name , thePath , 'directory' ) )
6172 const mp3filesItem = mp3s . map ( name => toFileItem ( name , thePath , 'mp3' ) )
6273
6374 return subdirsItem . concat ( mp3filesItem )
6475
6576 }
77+
78+ isMp3 ( name ) {
79+ return name . indexOf ( '.mp3' ) != - 1 ? true : false
80+ }
6681}
6782
6883class fileItem extends vscode . TreeItem {
69- constructor ( label , filePath , collapsibleState , command ) {
84+ constructor ( label , filePath , collapsibleState , descriptionText , command ) {
7085 super ( label , collapsibleState )
7186 this . label = label
7287 this . collapsibleState = collapsibleState
7388 this . filePath = filePath
7489 this . command = command
7590 this . contextValue = 'dependency'
91+ this . descriptionText = descriptionText
7692 }
7793 get tooltip ( ) {
7894 return `${ this . filePath } \\${ this . label } `
7995 }
8096 get description ( ) {
81- return this . label
97+ return this . descriptionText
8298 }
8399}
84100
0 commit comments