]>
Commit | Line | Data |
---|---|---|
66357162 | 1 | import { Hotkey, HotkeysService } from 'angular2-hotkeys' |
7aba23d1 | 2 | import { Subscription } from 'rxjs' |
66357162 | 3 | import { Component, Input, OnDestroy, OnInit } from '@angular/core' |
7aba23d1 RK |
4 | |
5 | @Component({ | |
6 | selector : 'my-hotkeys-cheatsheet', | |
7 | templateUrl : './hotkeys.component.html', | |
8 | styleUrls: [ './hotkeys.component.scss' ] | |
9 | }) | |
10 | export class CheatSheetComponent implements OnInit, OnDestroy { | |
66357162 | 11 | @Input() title = $localize`Keyboard Shortcuts:` |
bcb0c895 | 12 | helpVisible = false |
7aba23d1 RK |
13 | subscription: Subscription |
14 | ||
15 | hotkeys: Hotkey[] | |
16 | ||
17 | constructor ( | |
66357162 C |
18 | private hotkeysService: HotkeysService |
19 | ) {} | |
7aba23d1 RK |
20 | |
21 | public ngOnInit (): void { | |
22 | this.subscription = this.hotkeysService.cheatSheetToggle.subscribe((isOpen) => { | |
23 | if (isOpen !== false) { | |
24 | this.hotkeys = this.hotkeysService.hotkeys.filter(hotkey => hotkey.description) | |
25 | } | |
26 | ||
27 | if (isOpen === false) { | |
28 | this.helpVisible = false | |
29 | } else { | |
4a216666 | 30 | this.toggleHelpVisible() |
7aba23d1 RK |
31 | } |
32 | }) | |
33 | } | |
34 | ||
35 | public ngOnDestroy (): void { | |
36 | if (this.subscription) { | |
37 | this.subscription.unsubscribe() | |
38 | } | |
39 | } | |
40 | ||
41 | public toggleCheatSheet (): void { | |
4a216666 RK |
42 | this.hotkeysService.cheatSheetToggle.next(!this.helpVisible) |
43 | } | |
44 | ||
45 | public toggleHelpVisible (): void { | |
7aba23d1 RK |
46 | this.helpVisible = !this.helpVisible |
47 | } | |
48 | } |