2017-03-24 21:24:12 +00:00
|
|
|
import { Injectable } from '@angular/core'
|
2017-03-29 12:04:01 +00:00
|
|
|
import { HotkeysService, ToolbarButtonProvider, IToolbarButton, AppService } from 'api'
|
2017-03-24 21:24:12 +00:00
|
|
|
import { SessionsService } from './services/sessions'
|
2017-04-08 12:50:10 +00:00
|
|
|
import { TerminalTabComponent } from './components/terminalTab'
|
2017-03-24 21:24:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
@Injectable()
|
2017-03-25 17:12:43 +00:00
|
|
|
export class ButtonProvider extends ToolbarButtonProvider {
|
2017-03-24 21:24:12 +00:00
|
|
|
constructor (
|
|
|
|
private app: AppService,
|
|
|
|
private sessions: SessionsService,
|
2017-03-29 12:04:01 +00:00
|
|
|
hotkeys: HotkeysService,
|
2017-03-24 21:24:12 +00:00
|
|
|
) {
|
2017-03-25 17:12:43 +00:00
|
|
|
super()
|
2017-03-29 12:04:01 +00:00
|
|
|
hotkeys.matchedHotkey.subscribe(async (hotkey) => {
|
|
|
|
if (hotkey == 'new-tab') {
|
2017-04-08 12:50:10 +00:00
|
|
|
this.openNewTab()
|
2017-03-29 12:04:01 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-04-08 12:50:10 +00:00
|
|
|
async openNewTab (): Promise<void> {
|
2017-04-02 15:33:55 +00:00
|
|
|
let cwd = null
|
2017-04-08 12:50:10 +00:00
|
|
|
if (this.app.activeTab instanceof TerminalTabComponent) {
|
2017-04-02 15:33:55 +00:00
|
|
|
cwd = await this.app.activeTab.session.getWorkingDirectory()
|
|
|
|
}
|
2017-04-08 12:50:10 +00:00
|
|
|
this.app.openNewTab(
|
|
|
|
TerminalTabComponent,
|
|
|
|
{ session: await this.sessions.createNewSession({ command: 'zsh', cwd }) }
|
|
|
|
)
|
2017-03-24 21:24:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
provide (): IToolbarButton[] {
|
|
|
|
return [{
|
|
|
|
icon: 'plus',
|
|
|
|
title: 'New terminal',
|
2017-03-25 20:00:16 +00:00
|
|
|
click: async () => {
|
2017-04-08 12:50:10 +00:00
|
|
|
this.openNewTab()
|
2017-03-24 21:24:12 +00:00
|
|
|
}
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
}
|