mirror of
https://github.com/Eugeny/tabby.git
synced 2025-10-05 22:44:55 +00:00
splits WIP (#49)
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import { Observable, Subject, AsyncSubject } from 'rxjs'
|
||||
import { takeUntil } from 'rxjs/operators'
|
||||
import { Injectable, ComponentFactoryResolver, Injector } from '@angular/core'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { BaseTabComponent } from '../components/baseTab.component'
|
||||
import { SplitTabComponent } from '../components/splitTab.component'
|
||||
import { Logger, LogService } from './log.service'
|
||||
import { ConfigService } from './config.service'
|
||||
import { HostAppService } from './hostApp.service'
|
||||
import { TabRecoveryService } from './tabRecovery.service'
|
||||
|
||||
export declare type TabComponentType = new (...args: any[]) => BaseTabComponent
|
||||
import { TabsService, TabComponentType } from './tabs.service'
|
||||
|
||||
class CompletionObserver {
|
||||
get done$ (): Observable<void> { return this.done }
|
||||
@@ -58,19 +58,20 @@ export class AppService {
|
||||
get ready$ (): Observable<void> { return this.ready }
|
||||
|
||||
constructor (
|
||||
private componentFactoryResolver: ComponentFactoryResolver,
|
||||
private config: ConfigService,
|
||||
private hostApp: HostAppService,
|
||||
private injector: Injector,
|
||||
private tabRecovery: TabRecoveryService,
|
||||
private tabsService: TabsService,
|
||||
log: LogService,
|
||||
) {
|
||||
this.logger = log.create('app')
|
||||
|
||||
this.hostApp.windowCloseRequest$.subscribe(() => this.closeWindow())
|
||||
|
||||
this.tabRecovery.recoverTabs().then(tabs => {
|
||||
for (let tab of tabs) {
|
||||
/*this.tabRecovery.recoverTabs().then(tabs => {
|
||||
for (let
|
||||
this.openNewTab(tab.type, tab.options)
|
||||
tab of tabs) {
|
||||
this.openNewTab(tab.type, tab.options)
|
||||
}
|
||||
|
||||
@@ -80,16 +81,10 @@ export class AppService {
|
||||
setInterval(() => {
|
||||
tabRecovery.saveTabs(this.tabs)
|
||||
}, 30000)
|
||||
})
|
||||
})*/
|
||||
}
|
||||
|
||||
openNewTab (type: TabComponentType, inputs?: any): BaseTabComponent {
|
||||
let componentFactory = this.componentFactoryResolver.resolveComponentFactory(type)
|
||||
let componentRef = componentFactory.create(this.injector)
|
||||
let tab = componentRef.instance
|
||||
tab.hostView = componentRef.hostView
|
||||
Object.assign(tab, inputs || {})
|
||||
|
||||
addTabRaw (tab: BaseTabComponent) {
|
||||
this.tabs.push(tab)
|
||||
this.selectTab(tab)
|
||||
this.tabsChanged.next()
|
||||
@@ -100,6 +95,19 @@ export class AppService {
|
||||
this.hostApp.setTitle(title)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
openNewTabRaw (type: TabComponentType, inputs?: any): BaseTabComponent {
|
||||
let tab = this.tabsService.create(type, inputs)
|
||||
this.addTabRaw(tab)
|
||||
return tab
|
||||
}
|
||||
|
||||
openNewTab (type: TabComponentType, inputs?: any): BaseTabComponent {
|
||||
let splitTab = this.tabsService.create(SplitTabComponent) as SplitTabComponent
|
||||
let tab = this.tabsService.create(type, inputs)
|
||||
splitTab.insert(tab, null, 'r')
|
||||
this.addTabRaw(splitTab)
|
||||
return tab
|
||||
}
|
||||
|
||||
@@ -178,13 +186,9 @@ export class AppService {
|
||||
}
|
||||
|
||||
async duplicateTab (tab: BaseTabComponent) {
|
||||
let token = await tab.getRecoveryToken()
|
||||
if (!token) {
|
||||
return
|
||||
}
|
||||
let recoveredTab = await this.tabRecovery.recoverTab(token)
|
||||
if (recoveredTab) {
|
||||
this.openNewTab(recoveredTab.type, recoveredTab.options)
|
||||
let dup = await this.tabsService.duplicate(tab)
|
||||
if (dup) {
|
||||
this.addTabRaw(dup)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -275,6 +275,38 @@ export class AppHotkeyProvider extends HotkeyProvider {
|
||||
id: 'tab-10',
|
||||
name: 'Tab 10',
|
||||
},
|
||||
{
|
||||
id: 'split-right',
|
||||
name: 'Split to the right',
|
||||
},
|
||||
{
|
||||
id: 'split-bottom',
|
||||
name: 'Split to the bottom',
|
||||
},
|
||||
{
|
||||
id: 'split-left',
|
||||
name: 'Split to the left',
|
||||
},
|
||||
{
|
||||
id: 'split-top',
|
||||
name: 'Split to the top',
|
||||
},
|
||||
{
|
||||
id: 'split-nav-up',
|
||||
name: 'Focus the pane above',
|
||||
},
|
||||
{
|
||||
id: 'split-nav-down',
|
||||
name: 'Focus the pane below',
|
||||
},
|
||||
{
|
||||
id: 'split-nav-left',
|
||||
name: 'Focus the pane on the left',
|
||||
},
|
||||
{
|
||||
id: 'split-nav-right',
|
||||
name: 'Focus the pane on the right',
|
||||
},
|
||||
]
|
||||
|
||||
async provide (): Promise<IHotkeyDescription[]> {
|
||||
|
38
terminus-core/src/services/tabs.service.ts
Normal file
38
terminus-core/src/services/tabs.service.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { Injectable, ComponentFactoryResolver, Injector } from '@angular/core'
|
||||
import { BaseTabComponent } from '../components/baseTab.component'
|
||||
import { TabRecoveryService } from './tabRecovery.service'
|
||||
|
||||
export declare type TabComponentType = new (...args: any[]) => BaseTabComponent
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class TabsService {
|
||||
constructor (
|
||||
private componentFactoryResolver: ComponentFactoryResolver,
|
||||
private injector: Injector,
|
||||
private tabRecovery: TabRecoveryService,
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
create (type: TabComponentType, inputs?: any): BaseTabComponent {
|
||||
let componentFactory = this.componentFactoryResolver.resolveComponentFactory(type)
|
||||
let componentRef = componentFactory.create(this.injector)
|
||||
let tab = componentRef.instance
|
||||
tab.hostView = componentRef.hostView
|
||||
Object.assign(tab, inputs || {})
|
||||
return tab
|
||||
}
|
||||
|
||||
async duplicate (tab: BaseTabComponent): Promise<BaseTabComponent> {
|
||||
let token = await tab.getRecoveryToken()
|
||||
if (!token) {
|
||||
return null
|
||||
}
|
||||
let dup = await this.tabRecovery.recoverTab(token)
|
||||
if (dup) {
|
||||
return this.create(dup.type, dup.options)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user