1
1
mirror of https://github.com/Eugeny/tabby.git synced 2024-11-27 18:55:58 +03:00

handle files dragged into the terminal

This commit is contained in:
Eugene Pankov 2017-06-21 23:06:23 +02:00
parent 1a7437ed7c
commit 3459d6c78f
3 changed files with 44 additions and 2 deletions

View File

@ -1,4 +1,4 @@
import { Component, Inject, Input } from '@angular/core'
import { Component, Inject, Input, HostListener } from '@angular/core'
import { trigger, style, animate, transition, state } from '@angular/animations'
import { ElectronService } from '../services/electron.service'
@ -143,4 +143,13 @@ export class AppRootComponent {
.sort((a: IToolbarButton, b: IToolbarButton) => (a.weight || 0) - (b.weight || 0))
}
@HostListener('dragover')
onDragOver () {
return false
}
@HostListener('drop')
onDrop () {
return false
}
}

View File

@ -15,8 +15,9 @@ import { SessionsService } from './services/sessions.service'
import { ScreenPersistenceProvider } from './persistenceProviders'
import { ButtonProvider } from './buttonProvider'
import { RecoveryProvider } from './recoveryProvider'
import { SessionPersistenceProvider, TerminalColorSchemeProvider } from './api'
import { SessionPersistenceProvider, TerminalColorSchemeProvider, TerminalDecorator } from './api'
import { TerminalSettingsTabProvider } from './settings'
import { PathDropDecorator } from './pathDrop'
import { TerminalConfigProvider } from './config'
import { HyperColorSchemes } from './colorSchemes'
import { hterm } from './hterm'
@ -46,6 +47,7 @@ import { hterm } from './hterm'
{ provide: SettingsTabProvider, useClass: TerminalSettingsTabProvider, multi: true },
{ provide: ConfigProvider, useClass: TerminalConfigProvider, multi: true },
{ provide: TerminalColorSchemeProvider, useClass: HyperColorSchemes, multi: true },
{ provide: TerminalDecorator, useClass: PathDropDecorator, multi: true },
],
entryComponents: [
TerminalTabComponent,

View File

@ -0,0 +1,31 @@
import { Injectable } from '@angular/core'
import { TerminalDecorator } from './api'
import { TerminalTabComponent } from './components/terminalTab.component'
@Injectable()
export class PathDropDecorator extends TerminalDecorator {
attach (terminal: TerminalTabComponent): void {
setTimeout(() => {
terminal.hterm.scrollPort_.document_.addEventListener('dragover', (event) => {
event.preventDefault()
})
terminal.hterm.scrollPort_.document_.addEventListener('drop', (event) => {
for (let file of event.dataTransfer.files) {
this.injectPath(terminal, file.path)
}
event.preventDefault()
})
})
}
injectPath (terminal: TerminalTabComponent, path: string) {
if (path.indexOf(' ') >= 0) {
path = `"${path}"`
}
terminal.sendInput(path + ' ')
}
// tslint:disable-next-line no-empty
detach (terminal: TerminalTabComponent): void { }
}