Added hotkey rename, right click rename, and auto select text in rename modal

This commit is contained in:
Austin Warren 2018-12-14 14:49:20 -08:00
parent 6387539980
commit 2b90a17d5e

View File

@ -3,6 +3,7 @@ import { SortableComponent } from 'ng2-dnd'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { BaseTabComponent } from './baseTab.component'
import { RenameTabModalComponent } from './renameTabModal.component'
import { HotkeysService } from '../services/hotkeys.service'
import { ElectronService } from '../services/electron.service'
import { AppService } from '../services/app.service'
import { HostAppService, Platform } from '../services/hostApp.service'
@ -38,8 +39,17 @@ export class TabHeaderComponent {
private zone: NgZone,
private hostApp: HostAppService,
private ngbModal: NgbModal,
private hotkeys: HotkeysService,
private parentDraggable: SortableComponent,
) { }
) {
this.hotkeys.matchedHotkey.subscribe((hotkey) => {
if (this.app.activeTab === this.tab) {
if (hotkey === 'rename-tab') {
this.showRenameTabModal()
}
}
})
}
ngOnInit () {
if (this.hostApp.platform === Platform.macOS) {
@ -50,15 +60,23 @@ export class TabHeaderComponent {
})
}
@HostListener('dblclick') onDoubleClick (): void {
showRenameTabModal (): void {
let modal = this.ngbModal.open(RenameTabModalComponent)
modal.componentInstance.value = this.tab.customTitle || this.tab.title
setTimeout(() => {
const inputElement = modal.componentInstance.input.nativeElement as HTMLInputElement
inputElement.select()
}, 250)
modal.result.then(result => {
this.tab.setTitle(result)
this.tab.customTitle = result
}).catch(() => null)
}
@HostListener('dblclick') onDoubleClick (): void {
this.showRenameTabModal()
}
@HostListener('auxclick', ['$event']) async onAuxClick ($event: MouseEvent) {
if ($event.which === 2) {
this.app.closeTab(this.tab, true)
@ -97,6 +115,10 @@ export class TabHeaderComponent {
}
})
},
{
label: 'Rename',
click: () => this.zone.run( () => this.showRenameTabModal() )
},
{
label: 'Color',
sublabel: COLORS.find(x => x.value === this.tab.color).name,