mirror of
https://github.com/Eugeny/tabby
synced 2025-03-05 07:37:15 +00:00
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { Subscription } from 'rxjs'
|
|
import { Injectable } from '@angular/core'
|
|
import { TerminalDecorator } from './api'
|
|
import { TerminalTabComponent } from './components/terminalTab.component'
|
|
|
|
/** @hidden */
|
|
@Injectable()
|
|
export class PathDropDecorator extends TerminalDecorator {
|
|
private subscriptions: Subscription[] = []
|
|
|
|
attach (terminal: TerminalTabComponent): void {
|
|
setTimeout(() => {
|
|
this.subscriptions = [
|
|
terminal.frontend.dragOver$.subscribe(event => {
|
|
event.preventDefault()
|
|
}),
|
|
terminal.frontend.drop$.subscribe(event => {
|
|
for (let file of event.dataTransfer.files as any) {
|
|
this.injectPath(terminal, file.path)
|
|
}
|
|
event.preventDefault()
|
|
}),
|
|
]
|
|
})
|
|
}
|
|
|
|
injectPath (terminal: TerminalTabComponent, path: string) {
|
|
if (path.indexOf(' ') >= 0) {
|
|
path = `"${path}"`
|
|
}
|
|
path = path.replace(/\\/g, '\\\\')
|
|
terminal.sendInput(path + ' ')
|
|
}
|
|
|
|
detach (terminal: TerminalTabComponent): void {
|
|
for (let s of this.subscriptions) {
|
|
s.unsubscribe()
|
|
}
|
|
}
|
|
}
|