diff --git a/terminus-core/src/components/appRoot.component.pug b/terminus-core/src/components/appRoot.component.pug index 07b2907d..5859a26f 100644 --- a/terminus-core/src/components/appRoot.component.pug +++ b/terminus-core/src/components/appRoot.component.pug @@ -19,7 +19,6 @@ title-bar( [class.drag-region]='hostApp.platform == Platform.macOS', @animateTab, (click)='app.selectTab(tab)', - (closeClicked)='app.closeTab(tab, true)', ) .btn-group diff --git a/terminus-core/src/components/tabHeader.component.pug b/terminus-core/src/components/tabHeader.component.pug index 7db00c35..c735fca0 100644 --- a/terminus-core/src/components/tabHeader.component.pug +++ b/terminus-core/src/components/tabHeader.component.pug @@ -1,3 +1,3 @@ .index {{index + 1}} .name([title]='tab.customTitle || tab.title') {{tab.customTitle || tab.title}} -button((click)='closeClicked.emit()') × +button((click)='app.closeTab(tab, true)') × diff --git a/terminus-core/src/components/tabHeader.component.ts b/terminus-core/src/components/tabHeader.component.ts index 0b47b1c8..9346e09b 100644 --- a/terminus-core/src/components/tabHeader.component.ts +++ b/terminus-core/src/components/tabHeader.component.ts @@ -1,7 +1,9 @@ -import { Component, Input, Output, EventEmitter, HostBinding, HostListener } from '@angular/core' +import { Component, Input, HostBinding, HostListener, NgZone } from '@angular/core' import { NgbModal } from '@ng-bootstrap/ng-bootstrap' import { BaseTabComponent } from './baseTab.component' import { RenameTabModalComponent } from './renameTabModal.component' +import { ElectronService } from '../services/electron.service' +import { AppService } from '../services/app.service' @Component({ selector: 'tab-header', @@ -13,11 +15,55 @@ export class TabHeaderComponent { @Input() @HostBinding('class.active') active: boolean @Input() @HostBinding('class.has-activity') hasActivity: boolean @Input() tab: BaseTabComponent - @Output() closeClicked = new EventEmitter() + private contextMenu: any constructor ( + zone: NgZone, + electron: ElectronService, + public app: AppService, private ngbModal: NgbModal, - ) { } + ) { + this.contextMenu = electron.remote.Menu.buildFromTemplate([ + { + label: 'Close', + click: () => { + this.zone.run(() => { + app.closeTab(this.tab, true) + }) + } + }, + { + label: 'Close other tabs', + click: () => { + zone.run(() => { + for (let tab of app.tabs.filter(x => x !== this.tab)) { + app.closeTab(tab, true) + } + }) + } + }, + { + label: 'Close tabs to the right', + click: () => { + zone.run(() => { + for (let tab of app.tabs.slice(app.tabs.indexOf(this.tab) + 1)) { + app.closeTab(tab, true) + } + }) + } + }, + { + label: 'Close tabs to the left', + click: () => { + zone.run(() => { + for (let tab of app.tabs.slice(0, app.tabs.indexOf(this.tab))) { + app.closeTab(tab, true) + } + }) + } + }, + ]) + } @HostListener('dblclick') onDoubleClick (): void { let modal = this.ngbModal.open(RenameTabModalComponent) @@ -29,7 +75,15 @@ export class TabHeaderComponent { @HostListener('auxclick', ['$event']) onAuxClick ($event: MouseEvent): void { if ($event.which === 2) { - this.closeClicked.emit() + this.app.closeTab(this.tab, true) + } + if ($event.which === 3) { + this.contextMenu.popup({ + x: $event.pageX, + y: $event.pageY, + async: true, + }) + event.preventDefault() } } }