diff --git a/terminus-core/src/components/appRoot.component.ts b/terminus-core/src/components/appRoot.component.ts index 2dd14c8d..938b1d31 100644 --- a/terminus-core/src/components/appRoot.component.ts +++ b/terminus-core/src/components/appRoot.component.ts @@ -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 + } } diff --git a/terminus-terminal/src/index.ts b/terminus-terminal/src/index.ts index cdabae93..65e70e73 100644 --- a/terminus-terminal/src/index.ts +++ b/terminus-terminal/src/index.ts @@ -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, diff --git a/terminus-terminal/src/pathDrop.ts b/terminus-terminal/src/pathDrop.ts new file mode 100644 index 00000000..8196c3cf --- /dev/null +++ b/terminus-terminal/src/pathDrop.ts @@ -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 { } +}