-
Notifications
You must be signed in to change notification settings - Fork 1
/
romTree.ts
60 lines (51 loc) · 1.83 KB
/
romTree.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { join } from 'path'
import * as vscode from 'vscode'
import { RomTreeItem } from './romTreeItem'
import { localRoms } from './utils'
type RomInfo = [string, string]
export class LocalRomTree implements vscode.TreeDataProvider<RomTreeItem> {
private readonly _onChangeTreeData = new vscode.EventEmitter<RomTreeItem | undefined>()
public readonly onDidChangeTreeData = this._onChangeTreeData.event
emitDataChange() {
this._onChangeTreeData.fire(void 0)
}
getTreeItem(element: RomTreeItem): vscode.TreeItem | Thenable<vscode.TreeItem> {
return element
}
getChildren(): Thenable<RomTreeItem[]> {
const list = Object.keys(localRoms)
if (list.length === 0) {
return Promise.resolve([])
}
const result: RomTreeItem[] = []
list.forEach(key => {
result.push(new RomTreeItem(key, localRoms[key], new vscode.ThemeIcon('file')))
})
return Promise.resolve(result)
}
}
export class RemoteRomTree implements vscode.TreeDataProvider<RomTreeItem> {
private readonly _onChangeTreeData = new vscode.EventEmitter<RomTreeItem | undefined>()
public readonly onDidChangeTreeData = this._onChangeTreeData.event
constructor() {
vscode.workspace.onDidChangeConfiguration((e) => {
if (e.affectsConfiguration('vscodeNes.romPath')) {
this._onChangeTreeData.fire(void 0)
}
})
}
emitDataChange() {
this._onChangeTreeData.fire(void 0)
}
getChildren(): Thenable<RomTreeItem[]> {
const roms = vscode.workspace.getConfiguration('vscodeNes').get('romPath') as RomInfo[]
const result: RomTreeItem[] = []
roms.forEach(rom => {
result.push(new RomTreeItem(rom[0], rom[1], join(__dirname, '../res/nes-rom.svg')))
})
return Promise.resolve(result)
}
getTreeItem(element: RomTreeItem): vscode.TreeItem | Thenable<vscode.TreeItem> {
return element
}
}