mirror of
https://github.com/Eugeny/tabby.git
synced 2025-10-04 14:04:56 +00:00
Support empty directory.
This commit is contained in:
@@ -10,7 +10,7 @@ export { Theme } from './theme'
|
||||
export { TabContextMenuItemProvider } from './tabContextMenuProvider'
|
||||
export { SelectorOption } from './selector'
|
||||
export { CLIHandler, CLIEvent } from './cli'
|
||||
export { PlatformService, ClipboardContent, MessageBoxResult, MessageBoxOptions, FileDownload, FileUpload, FileTransfer, HTMLFileUpload, FileUploadOptions } from './platform'
|
||||
export { PlatformService, ClipboardContent, MessageBoxResult, MessageBoxOptions, FileDownload, FileUpload, FileTransfer, HTMLFileUpload, FileUploadOptions, DirectoryUpload } from './platform'
|
||||
export { MenuItemOptions } from './menu'
|
||||
export { BootstrapData, PluginInfo, BOOTSTRAP_DATA } from './mainProcess'
|
||||
export { HostWindowService } from './hostWindow'
|
||||
|
@@ -85,7 +85,26 @@ export abstract class FileUpload extends FileTransfer {
|
||||
|
||||
export interface FileUploadOptions {
|
||||
multiple: boolean
|
||||
directory: boolean
|
||||
}
|
||||
|
||||
export class DirectoryUpload {
|
||||
private childrens: (FileUpload|DirectoryUpload)[] = []
|
||||
|
||||
constructor(private name = '') {
|
||||
// Just set name for now.
|
||||
}
|
||||
|
||||
getName () {
|
||||
return this.name
|
||||
}
|
||||
|
||||
getChildrens () {
|
||||
return this.childrens
|
||||
}
|
||||
|
||||
pushChildren (item: FileUpload|DirectoryUpload) {
|
||||
this.childrens.push(item)
|
||||
}
|
||||
}
|
||||
|
||||
export type PlatformTheme = 'light'|'dark'
|
||||
@@ -108,31 +127,34 @@ export abstract class PlatformService {
|
||||
|
||||
abstract startDownload (name: string, mode: number, size: number): Promise<FileDownload|null>
|
||||
abstract startUpload (options?: FileUploadOptions): Promise<FileUpload[]>
|
||||
abstract startUploadDirectory (paths?: string[]): Promise<DirectoryUpload>
|
||||
|
||||
async startUploadFromDragEvent (event: DragEvent, multiple = false): Promise<FileUpload[]> {
|
||||
const result: FileUpload[] = []
|
||||
async startUploadFromDragEvent (event: DragEvent, multiple = false): Promise<DirectoryUpload> {
|
||||
const result = new DirectoryUpload()
|
||||
|
||||
if (!event.dataTransfer) {
|
||||
return Promise.resolve([])
|
||||
return Promise.resolve(result)
|
||||
}
|
||||
|
||||
const traverseFileTree = (item: any, path = ''): Promise<void> => {
|
||||
const traverseFileTree = (item: any, root: DirectoryUpload = result): Promise<void> => {
|
||||
return new Promise((resolve) => {
|
||||
if (item.isFile) {
|
||||
item.file((file: File) => {
|
||||
const transfer = new HTMLFileUpload(file, `${path}/${item.name}`)
|
||||
const transfer = new HTMLFileUpload(file)
|
||||
this.fileTransferStarted.next(transfer)
|
||||
result.push(transfer)
|
||||
root.pushChildren(transfer)
|
||||
resolve()
|
||||
})
|
||||
} else if (item.isDirectory) {
|
||||
const dirReader = item.createReader()
|
||||
const childrenFolder = new DirectoryUpload(item.name)
|
||||
dirReader.readEntries(async (entries: any[]) => {
|
||||
for (const entry of entries) {
|
||||
await traverseFileTree(entry, `${path}${item.name}/`)
|
||||
await traverseFileTree(entry, childrenFolder)
|
||||
}
|
||||
resolve()
|
||||
})
|
||||
root.pushChildren(childrenFolder)
|
||||
} else {
|
||||
resolve()
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { Directive, Output, ElementRef, EventEmitter, AfterViewInit } from '@angular/core'
|
||||
import { FileUpload, PlatformService } from '../api/platform'
|
||||
import { DirectoryUpload, PlatformService } from '../api/platform'
|
||||
import './dropZone.directive.scss'
|
||||
|
||||
/** @hidden */
|
||||
@@ -7,7 +7,7 @@ import './dropZone.directive.scss'
|
||||
selector: '[dropZone]',
|
||||
})
|
||||
export class DropZoneDirective implements AfterViewInit {
|
||||
@Output() transfer = new EventEmitter<FileUpload>()
|
||||
@Output() transfer = new EventEmitter<DirectoryUpload>()
|
||||
private dropHint?: HTMLElement
|
||||
|
||||
constructor (
|
||||
@@ -29,9 +29,7 @@ export class DropZoneDirective implements AfterViewInit {
|
||||
})
|
||||
this.el.nativeElement.addEventListener('drop', async (event: DragEvent) => {
|
||||
this.removeHint()
|
||||
for (const transfer of await this.platform.startUploadFromDragEvent(event, true)) {
|
||||
this.transfer.emit(transfer)
|
||||
}
|
||||
this.transfer.emit(await this.platform.startUploadFromDragEvent(event, true))
|
||||
})
|
||||
this.el.nativeElement.addEventListener('dragleave', () => {
|
||||
this.removeHint()
|
||||
|
Reference in New Issue
Block a user