import { ThemeIcon } from 'vscode' ; import { AzExtParentTreeItem , AzExtTreeItem , GenericTreeItem , IActionContext , TreeItemIconPath } from 'vscode-azureextensionui' ; import { localize } from '../localize' ; import { ParsedSite } from '../SiteClient' ; import { ISiteFileMetadata , listFiles } from '../siteFiles' ; import { FileTreeItem } from './FileTreeItem' ; export class FolderTreeItem extends AzExtParentTreeItem { public static contextValue : string = 'folder' ; public readonly contextValue : string = FolderTreeItem . contextValue ; public readonly childTypeLabel : string = localize ( 'fileOrFolder' , 'file or folder' ) ; public readonly label : string ; public readonly path : string ; public readonly isReadOnly : boolean ; public readonly site : ParsedSite ; protected readonly _isRoot : boolean = false ; constructor ( parent , site , label , path , isReadOnly ) { super ( parent ) ; this . site = site ; this . label = label ; this . path = path ; this . isReadOnly = isReadOnly ; } public get iconPath ( ) : TreeItemIconPath { return new ThemeIcon ( 'folder' ) ; } public hasMoreChildrenImpl ( ) { return false ; } public get description ( ) : string | undefined { return this . _isRoot && this . isReadOnly ? localize ( 'readOnly' , 'Read-only' ) : undefined ; } public async loadMoreChildrenImpl ( _clearCache , context ) { let files = await listFiles ( context , this . site , this . path ) ; files = files . filter ( f => f . mime !== 'text/xml' || ! f . name . includes ( 'LogFiles-kudu-trace_pending.xml' ) ) ; return files . map ( file => { const home = 'home' ; const fsPath = file . path . substring ( file . path . indexOf ( home ) + home . length + 1 ) ; return file . mime === 'inode/directory' ? new FolderTreeItem ( this , this . site , file . name , fsPath , this . isReadOnly ) : new FileTreeItem ( this , this . site , file . name , fsPath , this . isReadOnly ) ; } ) ; } public compareChildrenImpl ( ti1 , ti2 ) { let result = instanceOfCompare ( ti1 , ti2 , GenericTreeItem ) ; if ( result === undefined ) { result = instanceOfCompare ( ti1 , ti2 , FolderTreeItem ) ; } return result === undefined ? ti1 . label . localeCompare ( ti2 . label ) : result ; } } function instanceOfCompare < T > ( ti1 , ti2 , typeToCompare ) { if ( ! ( ti1 instanceof typeToCompare ) && ti2 instanceof typeToCompare ) { return 1 ; } else if ( ti1 instanceof typeToCompare && ! ( ti2 instanceof typeToCompare ) ) { return - 1 ; } else { return undefined ; } }