tabby/terminus-core/src/components/baseTab.component.ts
2018-08-09 12:37:14 -07:00

63 lines
1.4 KiB
TypeScript

import { Observable, Subject } from 'rxjs'
import { ViewRef } from '@angular/core'
export abstract class BaseTabComponent {
private static lastTabID = 0
id: number
title: string
customTitle: string
hasActivity = false
hasFocus = false
hostView: ViewRef
protected titleChange = new Subject<string>()
protected focused = new Subject<void>()
protected blurred = new Subject<void>()
get focused$ (): Observable<void> { return this.focused }
get blurred$ (): Observable<void> { return this.blurred }
get titleChange$ (): Observable<string> { return this.titleChange }
constructor () {
this.id = BaseTabComponent.lastTabID++
this.focused$.subscribe(() => {
this.hasFocus = true
})
this.blurred$.subscribe(() => {
this.hasFocus = false
})
}
setTitle (title: string) {
this.title = title
if (!this.customTitle) {
this.titleChange.next(title)
}
}
displayActivity (): void {
this.hasActivity = true
}
getRecoveryToken (): any {
return null
}
async canClose (): Promise<boolean> {
return true
}
emitFocused () {
this.focused.next()
}
emitBlurred () {
this.blurred.next()
}
destroy (): void {
this.focused.complete()
this.blurred.complete()
this.titleChange.complete()
}
}