Skip to content

Commit f8930cd

Browse files
committed
update treeview
1 parent 19dabb1 commit f8930cd

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

src/extension.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ function activate(context) {
1717

1818
const test = new tv.Treeview
1919

20-
test.audiosViewer.onDidChangeSelection((one, two, three) => {
21-
console.log(one, two, three)
20+
test.audiosViewer.onDidChangeSelection(file => {
21+
console.log(file)
22+
console.log(test.audiosViewer.selection)
2223
})
24+
25+
2326
// vscode.workspace.onDidChangeConfiguration()
2427

2528
const compiledFunction = pug.compileFile(`${__dirname}\\index.pug`)

src/treeview.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const vscode = require('vscode')
33
const path = require('path')
44
const fs = require('fs')
55

6+
67
class 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

6883
class 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

Comments
 (0)