splitTabPaneLabel.component.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
  2. import { Component, Input, HostBinding, ElementRef } from '@angular/core'
  3. import { HotkeysService } from '../services/hotkeys.service'
  4. import { AppService } from '../services/app.service'
  5. import { BaseTabComponent } from './baseTab.component'
  6. import { SelfPositioningComponent } from './selfPositioning.component'
  7. /** @hidden */
  8. @Component({
  9. selector: 'split-tab-pane-label',
  10. template: `
  11. <div
  12. cdkDrag
  13. [cdkDragData]='tab'
  14. (cdkDragStarted)='onTabDragStart(tab)'
  15. (cdkDragEnded)='onTabDragEnd()'
  16. >
  17. <i class="fa fa-window-maximize me-3"></i>
  18. <label>{{tab.title}}</label>
  19. </div>
  20. `,
  21. styleUrls: ['./splitTabPaneLabel.component.scss'],
  22. })
  23. export class SplitTabPaneLabelComponent extends SelfPositioningComponent {
  24. @Input() tab: BaseTabComponent
  25. @Input() parent: BaseTabComponent
  26. @HostBinding('class.active') isActive = false
  27. // eslint-disable-next-line @typescript-eslint/no-useless-constructor
  28. constructor (
  29. element: ElementRef,
  30. hotkeys: HotkeysService,
  31. private app: AppService,
  32. ) {
  33. super(element)
  34. this.subscribeUntilDestroyed(hotkeys.hotkey$, hk => {
  35. if (hk === 'rearrange-panes' && this.parent.hasFocus) {
  36. this.isActive = true
  37. this.layout()
  38. }
  39. })
  40. this.subscribeUntilDestroyed(hotkeys.hotkeyOff$, hk => {
  41. if (hk === 'rearrange-panes') {
  42. this.isActive = false
  43. }
  44. })
  45. }
  46. ngOnChanges () {
  47. this.layout()
  48. }
  49. onTabDragStart (tab: BaseTabComponent): void {
  50. this.app.emitTabDragStarted(tab)
  51. }
  52. onTabDragEnd (): void {
  53. setTimeout(() => {
  54. this.app.emitTabDragEnded()
  55. this.app.emitTabsChanged()
  56. })
  57. }
  58. layout () {
  59. const tabElement: HTMLElement|undefined = this.tab.viewContainerEmbeddedRef?.rootNodes[0]
  60. if (!tabElement) {
  61. // being destroyed
  62. return
  63. }
  64. this.setDimensions(
  65. tabElement.offsetLeft,
  66. tabElement.offsetTop,
  67. tabElement.clientWidth,
  68. tabElement.clientHeight,
  69. 'px',
  70. )
  71. }
  72. }