Skip to content
This repository was archived by the owner on Jul 15, 2022. It is now read-only.

Commit 5b2e77c

Browse files
author
Leonardo Chaia
committed
feat: added tab shortcuts
1 parent 3405934 commit 5b2e77c

File tree

6 files changed

+92
-31
lines changed

6 files changed

+92
-31
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"@types/node": "10.5.4",
7070
"angular-pipes": "^8.0.0",
7171
"angular-split-ng6": "^1.0.0-rc.5",
72+
"angular2-hotkeys": "^2.1.2",
7273
"codelyzer": "^4.4.2",
7374
"commitlint": "^7.0.0",
7475
"conventional-changelog-cli": "^2.0.1",

src/app/app.module.ts

+2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import { DaemonToolsModule } from './daemon-tools/daemon-tools.module';
88
import { RegistryModule } from './registry/registry.module';
99
import { SettingsModule } from './settings/settings.module';
1010
import { ApplicationTemplatesModule } from './application-templates/application-templates.module';
11+
import { HotkeyModule } from 'angular2-hotkeys';
1112

1213
@NgModule({
1314
imports: [
1415
BrowserModule,
1516
BrowserAnimationsModule,
17+
HotkeyModule.forRoot(),
1618

1719
HomeModule,
1820
DaemonToolsModule,

src/app/navigation/tab.service.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ export class TabService {
5555
this.tabs.splice(index, 1);
5656
}
5757

58-
protected removeCurrentTab() {
58+
public removeCurrentTab() {
5959
this.tabs.splice(this.currentTab, 1);
6060
}
61+
62+
public removeAllTabs() {
63+
this.tabs = [];
64+
}
6165
}

src/app/navigation/tabs-container/tabs-container.component.scss

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ mat-tab-group {
1313
}
1414

1515
::ng-deep .mat-tab-body {
16-
overflow: auto !important;
16+
overflow-y: auto !important;
1717
}
1818

1919
::ng-deep .mat-tab-body-content {
20-
overflow: auto !important;
20+
overflow-y: auto !important;
2121
}

src/app/navigation/tabs-container/tabs-container.component.ts

+31-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from '@angular/core';
99
import { ITimoneerTab, TAB_DATA } from '../tab.model';
1010
import { TabService } from '../tab.service';
11+
import { HotkeysService, Hotkey } from 'angular2-hotkeys';
1112

1213
@Component({
1314
selector: 'tim-tabs-container',
@@ -33,10 +34,12 @@ export class TabsContainerComponent implements OnInit, AfterViewInit {
3334

3435
constructor(private cd: ChangeDetectorRef,
3536
private componentFactoryResolver: ComponentFactoryResolver,
36-
private tabService: TabService) {
37+
private tabService: TabService,
38+
private hotKey: HotkeysService) {
3739
}
3840

3941
public ngOnInit() {
42+
this.bindShortcuts();
4043
}
4144

4245
public ngAfterViewInit() {
@@ -69,9 +72,35 @@ export class TabsContainerComponent implements OnInit, AfterViewInit {
6972
const componentFactory = this.componentFactoryResolver.resolveComponentFactory(tab.component);
7073
const componentRef = template.createComponent(componentFactory, null, injector);
7174
tab.componentInstance = componentRef.instance;
72-
console.log(componentRef);
7375
this.cd.detectChanges();
7476
}
7577
}
7678
}
79+
80+
private bindShortcuts() {
81+
this.hotKey.add(new Hotkey(['command+w', 'ctrl+w'], (event: KeyboardEvent): boolean => {
82+
this.tabService.removeCurrentTab();
83+
return false;
84+
}));
85+
this.hotKey.add(new Hotkey(['command+shift+w', 'ctrl+shift+w'], (event: KeyboardEvent): boolean => {
86+
this.tabService.removeAllTabs();
87+
return false;
88+
}));
89+
this.hotKey.add(new Hotkey(['command+tab', 'ctrl+tab'], (event: KeyboardEvent): boolean => {
90+
let next = this.tabService.currentTab + 1;
91+
if (next >= this.tabs.length) {
92+
next = 0;
93+
}
94+
this.tabService.currentTab = next;
95+
return false;
96+
}));
97+
this.hotKey.add(new Hotkey(['command+shift+tab', 'ctrl+shift+tab'], (event: KeyboardEvent): boolean => {
98+
let next = this.tabService.currentTab - 1;
99+
if (next < 0) {
100+
next = this.tabs.length - 1;
101+
}
102+
this.tabService.currentTab = next;
103+
return false;
104+
}));
105+
}
77106
}

yarn.lock

+51-26
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,22 @@
1313
"@angular-devkit/core" "0.7.1"
1414
rxjs "^6.0.0"
1515

16-
"@angular-devkit/build-angular@0.7.1":
17-
version "0.7.1"
18-
resolved "https://registry.yarnpkg.com/@angular-devkit/build-angular/-/build-angular-0.7.1.tgz#797d78a5eb7d275cbe2b2bc90ca82285888c5a96"
16+
"@angular-devkit/architect@0.7.2":
17+
version "0.7.2"
18+
resolved "https://registry.yarnpkg.com/@angular-devkit/architect/-/architect-0.7.2.tgz#b630f201f338c2b145c360b2b816185e1994b2c0"
1919
dependencies:
20-
"@angular-devkit/architect" "0.7.1"
21-
"@angular-devkit/build-optimizer" "0.7.1"
22-
"@angular-devkit/build-webpack" "0.7.1"
23-
"@angular-devkit/core" "0.7.1"
24-
"@ngtools/webpack" "6.1.1"
20+
"@angular-devkit/core" "0.7.2"
21+
rxjs "^6.0.0"
22+
23+
"@angular-devkit/[email protected]":
24+
version "0.7.2"
25+
resolved "https://registry.yarnpkg.com/@angular-devkit/build-angular/-/build-angular-0.7.2.tgz#066f6475eb483542e36cadfbbff1a7913ecfcfb1"
26+
dependencies:
27+
"@angular-devkit/architect" "0.7.2"
28+
"@angular-devkit/build-optimizer" "0.7.2"
29+
"@angular-devkit/build-webpack" "0.7.2"
30+
"@angular-devkit/core" "0.7.2"
31+
"@ngtools/webpack" "6.1.2"
2532
ajv "~6.4.0"
2633
autoprefixer "^8.4.1"
2734
circular-dependency-plugin "^5.0.2"
@@ -66,21 +73,21 @@
6673
optionalDependencies:
6774
node-sass "^4.9.1"
6875

69-
"@angular-devkit/[email protected].1":
70-
version "0.7.1"
71-
resolved "https://registry.yarnpkg.com/@angular-devkit/build-optimizer/-/build-optimizer-0.7.1.tgz#05bb646ab7cc714172fd554bd3e0e1beb7d8becc"
76+
"@angular-devkit/[email protected].2":
77+
version "0.7.2"
78+
resolved "https://registry.yarnpkg.com/@angular-devkit/build-optimizer/-/build-optimizer-0.7.2.tgz#c7cf86e44fa541c0e1c2133cb5be9032c3c46445"
7279
dependencies:
7380
loader-utils "^1.1.0"
7481
source-map "^0.5.6"
7582
typescript "~2.9.1"
7683
webpack-sources "^1.1.0"
7784

78-
"@angular-devkit/[email protected].1":
79-
version "0.7.1"
80-
resolved "https://registry.yarnpkg.com/@angular-devkit/build-webpack/-/build-webpack-0.7.1.tgz#8ad519f598f89214a132207f7f5369cc4b51d18c"
85+
"@angular-devkit/[email protected].2":
86+
version "0.7.2"
87+
resolved "https://registry.yarnpkg.com/@angular-devkit/build-webpack/-/build-webpack-0.7.2.tgz#a10a4ea1ed5f91a281ec3df866fb9ae51842699c"
8188
dependencies:
82-
"@angular-devkit/architect" "0.7.1"
83-
"@angular-devkit/core" "0.7.1"
89+
"@angular-devkit/architect" "0.7.2"
90+
"@angular-devkit/core" "0.7.2"
8491
rxjs "^6.0.0"
8592

8693
"@angular-devkit/[email protected]":
@@ -92,6 +99,15 @@
9299
rxjs "^6.0.0"
93100
source-map "^0.5.6"
94101

102+
"@angular-devkit/[email protected]":
103+
version "0.7.2"
104+
resolved "https://registry.yarnpkg.com/@angular-devkit/core/-/core-0.7.2.tgz#f86c65c70daa8fccf67f4f5767a4ade7a5975caf"
105+
dependencies:
106+
ajv "~6.4.0"
107+
chokidar "^2.0.3"
108+
rxjs "^6.0.0"
109+
source-map "^0.5.6"
110+
95111
"@angular-devkit/[email protected]":
96112
version "0.7.1"
97113
resolved "https://registry.yarnpkg.com/@angular-devkit/schematics/-/schematics-0.7.1.tgz#4b805c66e38f09553ee953e4c81f993432a582fe"
@@ -195,12 +211,6 @@
195211
dependencies:
196212
tslib "^1.9.0"
197213

198-
"@angular/[email protected]":
199-
version "6.1.0"
200-
resolved "https://registry.yarnpkg.com/@angular/router/-/router-6.1.0.tgz#84cd28211faa31c53f49a571217603ac32a3cce8"
201-
dependencies:
202-
tslib "^1.9.0"
203-
204214
"@angularclass/hmr@^2.1.3":
205215
version "2.1.3"
206216
resolved "https://registry.yarnpkg.com/@angularclass/hmr/-/hmr-2.1.3.tgz#34e658ed3da37f23b0a200e2da5a89be92bb209f"
@@ -335,11 +345,11 @@
335345
mkdirp "^0.5.1"
336346
rimraf "^2.5.2"
337347

338-
"@ngtools/[email protected].1":
339-
version "6.1.1"
340-
resolved "https://registry.yarnpkg.com/@ngtools/webpack/-/webpack-6.1.1.tgz#dcfea287c0c1358f3e123621c65b0e3ccaab5b70"
348+
"@ngtools/[email protected].2":
349+
version "6.1.2"
350+
resolved "https://registry.yarnpkg.com/@ngtools/webpack/-/webpack-6.1.2.tgz#83d5af4af0e6186a35f83a48b10a7549c39b3236"
341351
dependencies:
342-
"@angular-devkit/core" "0.7.1"
352+
"@angular-devkit/core" "0.7.2"
343353
rxjs "^6.0.0"
344354
tree-kill "^1.0.0"
345355
webpack-sources "^1.1.0"
@@ -403,6 +413,10 @@
403413
dependencies:
404414
"@types/jasmine" "*"
405415

416+
"@types/mousetrap@^1.6.0":
417+
version "1.6.0"
418+
resolved "https://registry.yarnpkg.com/@types/mousetrap/-/mousetrap-1.6.0.tgz#c3951ab98b88ff6093cd0b1e4f8591af439141b8"
419+
406420
"@types/node@*", "@types/[email protected]":
407421
version "10.5.4"
408422
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.5.4.tgz#6eccc158504357d1da91434d75e86acde94bb10b"
@@ -689,6 +703,13 @@ angular-split-ng6@^1.0.0-rc.5:
689703
dependencies:
690704
tslib "^1.9.0"
691705

706+
angular2-hotkeys@^2.1.2:
707+
version "2.1.2"
708+
resolved "https://registry.yarnpkg.com/angular2-hotkeys/-/angular2-hotkeys-2.1.2.tgz#6693ecc2fbbf6f3874fb6715804e88ba6a584c0a"
709+
dependencies:
710+
"@types/mousetrap" "^1.6.0"
711+
mousetrap "^1.6.0"
712+
692713
ansi-align@^2.0.0:
693714
version "2.0.0"
694715
resolved "https://registry.yarnpkg.com/ansi-align/-/ansi-align-2.0.0.tgz#c36aeccba563b89ceb556f3690f0b1d9e3547f7f"
@@ -5681,6 +5702,10 @@ [email protected]:
56815702
version "2.22.2"
56825703
resolved "https://registry.yarnpkg.com/moment/-/moment-2.22.2.tgz#3c257f9839fc0e93ff53149632239eb90783ff66"
56835704

5705+
mousetrap@^1.6.0:
5706+
version "1.6.2"
5707+
resolved "https://registry.yarnpkg.com/mousetrap/-/mousetrap-1.6.2.tgz#caadd9cf886db0986fb2fee59a82f6bd37527587"
5708+
56845709
move-concurrently@^1.0.1, move-concurrently@~1.0.1:
56855710
version "1.0.1"
56865711
resolved "https://registry.yarnpkg.com/move-concurrently/-/move-concurrently-1.0.1.tgz#be2c005fda32e0b29af1f05d7c4b33214c701f92"

0 commit comments

Comments
 (0)