import * as vscode from "vscode" ; import path = require ( "path" ) ; import * as workspace from "./workspace" ; export class SmartContractsViewModel implements vscode . TreeDataProvider < SmartContract > { private _onDidChangeTreeData : vscode . EventEmitter < SmartContract | undefined > = new vscode . EventEmitter < SmartContract | undefined > ( ) ; readonly onDidChangeTreeData ? : vscode . Event < SmartContract > = this . _onDidChangeTreeData . event ; constructor ( ) { } async refresh ( ) { this . _onDidChangeTreeData . fire ( null ) ; } getTreeItem ( element ) { return element . getTreeItem ( ) ; } getChildren ( element ? ) { if ( element ) { return [ ] ; } let metadataObjects = workspace . getMetadataObjects ( ) ; let contracts = metadataObjects . map ( metadata => new SmartContract ( metadata ) ) ; return contracts ; } } export class SmartContract { readonly metadata : workspace . ProjectMetadata ; constructor ( metadata ) { this . metadata = metadata ; } getPath ( ) { return this . metadata . ProjectPath ; } getMetadataPath ( ) { return this . metadata . Path ; } getTreeItem ( ) { let item = new vscode . TreeItem ( this . metadata . ProjectName ) ; item . contextValue = "contract" ; item . iconPath = this . getIcons ( ) ; return item ; } private getIcons ( ) { let language = this . metadata . Language ; let contentPath = path . join ( __filename , ".." , ".." , "content" ) ; return { light : path . join ( contentPath , "light" , `lang-${ language }.png` ) , dark : path . join ( contentPath , "dark" , `lang-${ language }.png` ) } ; } }