diff --git a/src/components/popover/key-action-saver.ts b/src/components/popover/key-action-saver.ts
new file mode 100644
index 00000000..56380b9d
--- /dev/null
+++ b/src/components/popover/key-action-saver.ts
@@ -0,0 +1,6 @@
+import {KeyAction} from '../../../config-serializer/config-items/KeyAction';
+
+export interface KeyActionSaver {
+ keyActionValid(): boolean;
+ toKeyAction(): KeyAction;
+}
diff --git a/src/components/popover/popover.component.ts b/src/components/popover/popover.component.ts
index 2946debb..22bfa224 100644
--- a/src/components/popover/popover.component.ts
+++ b/src/components/popover/popover.component.ts
@@ -4,6 +4,7 @@ import {
AfterViewInit,
Output,
EventEmitter,
+ ViewChild,
ViewChildren,
ElementRef,
Renderer,
@@ -13,6 +14,8 @@ import {
import {NgSwitch, NgSwitchWhen} from '@angular/common';
+import {KeyAction} from '../../../config-serializer/config-items/KeyAction';
+
import {KeypressTabComponent} from './tab/keypress-tab.component';
import {LayerTabComponent} from './tab/layer-tab.component';
import {MouseTabComponent} from './tab/mouse-tab.component';
@@ -20,6 +23,8 @@ import {MacroTabComponent} from './tab/macro-tab.component';
import {KeymapTabComponent} from './tab/keymap-tab.component';
import {NoneTabComponent} from './tab/none-tab.component';
+import {KeyActionSaver} from './key-action-saver';
+
@Component({
moduleId: module.id,
selector: 'popover',
@@ -70,12 +75,12 @@ import {NoneTabComponent} from './tab/none-tab.component';
@@ -86,7 +91,7 @@ import {NoneTabComponent} from './tab/none-tab.component';
`,
- styles: [ require('./popover.component.scss') ],
+ styles: [require('./popover.component.scss')],
host: { 'class': 'popover' },
directives:
[
@@ -101,8 +106,12 @@ import {NoneTabComponent} from './tab/none-tab.component';
]
})
export class PopoverComponent implements OnInit, AfterViewInit {
+
@Output() cancel = new EventEmitter();
+ @Output() remap = new EventEmitter();
+
@ViewChildren('keypress,layer,mouse,macro,keymap,none') liElementRefs: QueryList;
+ @ViewChild('tab') selectedTab: KeyActionSaver;
private activeListItemIndex: number;
@@ -122,7 +131,13 @@ export class PopoverComponent implements OnInit, AfterViewInit {
}
onRemapKey(): void {
-
+ try {
+ let keyAction = this.selectedTab.toKeyAction();
+ this.remap.emit(keyAction);
+ } catch (e) {
+ // TODO: show error dialog
+ console.error(e);
+ }
}
onListItemClick(index: number): void {
diff --git a/src/components/popover/tab/keymap-tab.component.ts b/src/components/popover/tab/keymap-tab.component.ts
index 913d46bf..e6a4283b 100644
--- a/src/components/popover/tab/keymap-tab.component.ts
+++ b/src/components/popover/tab/keymap-tab.component.ts
@@ -3,6 +3,8 @@ import { Component, OnInit } from '@angular/core';
import {UhkConfigurationService} from '../../../services/uhk-configuration.service';
import {Keymap} from '../../../../config-serializer/config-items/Keymap';
import {SvgKeyboardComponent} from '../../svg-keyboard.component';
+import {KeyActionSaver} from '../key-action-saver';
+import {SwitchKeymapAction} from '../../../../config-serializer/config-items/SwitchKeymapAction';
@Component({
moduleId: module.id,
@@ -28,7 +30,7 @@ import {SvgKeyboardComponent} from '../../svg-keyboard.component';
styles: [require('./keymap-tab.component.scss')],
directives: [SvgKeyboardComponent]
})
-export class KeymapTabComponent implements OnInit {
+export class KeymapTabComponent implements OnInit, KeyActionSaver {
private keymaps: Keymap[];
private selectedKeymapIndex: number;
@@ -40,4 +42,17 @@ export class KeymapTabComponent implements OnInit {
ngOnInit() { }
+ keyActionValid(): boolean {
+ return this.selectedKeymapIndex !== -1;
+ }
+
+ toKeyAction(): SwitchKeymapAction {
+ if (!this.keyActionValid()) {
+ throw new Error('KeyAction is not valid. No selected keymap!');
+ }
+ let keymapAction = new SwitchKeymapAction();
+ keymapAction.keymapId = this.keymaps[this.selectedKeymapIndex].id;
+ return keymapAction;
+ }
+
}
diff --git a/src/components/popover/tab/keypress-tab.component.ts b/src/components/popover/tab/keypress-tab.component.ts
index cf190e43..59c4f61c 100644
--- a/src/components/popover/tab/keypress-tab.component.ts
+++ b/src/components/popover/tab/keypress-tab.component.ts
@@ -2,9 +2,11 @@ import { Component, OnInit } from '@angular/core';
import { CaptureKeystrokeButtonComponent } from '../widgets/capture-keystroke-button.component';
+import { KeyAction } from '../../../../config-serializer/config-items/KeyAction';
import { KeystrokeAction } from '../../../../config-serializer/config-items/KeystrokeAction';
import { KeystrokeModifiersAction } from '../../../../config-serializer/config-items/KeystrokeModifiersAction';
import { KeystrokeWithModifiersAction } from '../../../../config-serializer/config-items/KeystrokeWithModifiersAction';
+import { KeyActionSaver } from '../key-action-saver';
@Component({
moduleId: module.id,
@@ -45,7 +47,7 @@ import { KeystrokeWithModifiersAction } from '../../../../config-serializer/conf
`,
directives: [CaptureKeystrokeButtonComponent]
})
-export class KeypressTabComponent implements OnInit {
+export class KeypressTabComponent implements OnInit, KeyActionSaver {
private leftModifiers: string[];
private rightModifiers: string[];
@@ -63,4 +65,11 @@ export class KeypressTabComponent implements OnInit {
return;
}
+ keyActionValid(): boolean {
+ return false;
+ }
+
+ toKeyAction(): KeyAction {
+ return undefined;
+ }
}
diff --git a/src/components/popover/tab/layer-tab.component.ts b/src/components/popover/tab/layer-tab.component.ts
index 194372b4..542918cf 100644
--- a/src/components/popover/tab/layer-tab.component.ts
+++ b/src/components/popover/tab/layer-tab.component.ts
@@ -1,28 +1,48 @@
import { Component, OnInit } from '@angular/core';
+import { LayerName, SwitchLayerAction } from '../../../../config-serializer/config-items/SwitchLayerAction';
+import { KeyActionSaver } from '../key-action-saver';
+
@Component({
moduleId: module.id,
selector: 'layer-tab',
template:
`
-