From 6fb8e56963c466ba7ef7310b4f272905803b6322 Mon Sep 17 00:00:00 2001 From: Attila Csanyi Date: Wed, 18 Oct 2017 22:40:09 +0200 Subject: [PATCH] Add captured press keystroke for macros (closes #324) (#427) * update npm lock file (#425) * feat(capture): make capture keystroke button reusable as make itself render a link or button (closes #324) * review: re-style bootstrap link button template of capture component like a button * review: use same bootstrap btn-link styles for "Add macro action" as in case of "Add captured keystroke" --- .../macro/list/macro-list.component.html | 16 +++++----- .../macro/list/macro-list.component.scss | 6 +++- .../macro/list/macro-list.component.ts | 29 +++++++++++++++++-- .../capture-keystroke-button.component.html | 27 +++++++++-------- .../capture-keystroke-button.component.scss | 8 ++++- .../capture-keystroke-button.component.ts | 4 ++- packages/uhk-web/src/styles/common.scss | 10 +++++++ 7 files changed, 76 insertions(+), 24 deletions(-) diff --git a/packages/uhk-web/src/app/components/macro/list/macro-list.component.html b/packages/uhk-web/src/app/components/macro/list/macro-list.component.html index c6db3039..00e41235 100644 --- a/packages/uhk-web/src/app/components/macro/list/macro-list.component.html +++ b/packages/uhk-web/src/app/components/macro/list/macro-list.component.html @@ -25,13 +25,15 @@
- - Add macro action - - - Add captured keystroke - + + + + + +
- \ No newline at end of file + diff --git a/packages/uhk-web/src/app/components/macro/list/macro-list.component.scss b/packages/uhk-web/src/app/components/macro/list/macro-list.component.scss index 98c6ad91..d8c0bf88 100644 --- a/packages/uhk-web/src/app/components/macro/list/macro-list.component.scss +++ b/packages/uhk-web/src/app/components/macro/list/macro-list.component.scss @@ -1,4 +1,5 @@ @import '../../../../styles/variables'; +@import '../../../../styles/common'; :host { display: flex; @@ -112,7 +113,6 @@ h1 { &--link { width: 50%; float: left; - padding: 10px 5px; text-align: center; color: $icon-hover; @@ -124,6 +124,10 @@ h1 { text-decoration: none; background: #e6e6e6; } + + button.btn-link { + @extend %btn-link; + } } .fa-circle { diff --git a/packages/uhk-web/src/app/components/macro/list/macro-list.component.ts b/packages/uhk-web/src/app/components/macro/list/macro-list.component.ts index ae41d72d..748a38f2 100644 --- a/packages/uhk-web/src/app/components/macro/list/macro-list.component.ts +++ b/packages/uhk-web/src/app/components/macro/list/macro-list.component.ts @@ -1,8 +1,9 @@ import { Component, EventEmitter, Input, Output, QueryList, ViewChildren, forwardRef } from '@angular/core'; import { animate, state, style, transition, trigger } from '@angular/animations'; import { DragulaService } from 'ng2-dragula/ng2-dragula'; -import { Macro, MacroAction } from 'uhk-common'; +import { Macro, MacroAction, KeyMacroAction, KeystrokeAction, MacroSubAction } from 'uhk-common'; +import { MapperService } from '../../../services/mapper.service'; import { MacroItemComponent } from '../item'; @Component({ @@ -46,7 +47,10 @@ export class MacroListComponent { private activeEdit: number = undefined; private dragIndex: number; - constructor(dragulaService: DragulaService) { + constructor( + private mapper: MapperService, + private dragulaService: DragulaService + ) { /* tslint:disable:no-unused-variable: Used by Dragula. */ dragulaService.setOptions('macroActions', { moves: function (el: any, container: any, handle: any) { @@ -121,6 +125,27 @@ export class MacroListComponent { this.hideActiveEditor(); } + onKeysCapture(event: { code: number, left: boolean[], right: boolean[] }) { + const keyMacroAction = Object.assign(new KeyMacroAction(), this.toKeyAction(event)); + keyMacroAction.action = MacroSubAction.press; + + this.add.emit({ + macroId: this.macro.id, + action: keyMacroAction + }); + } + + private toKeyAction(event: { code: number, left: boolean[], right: boolean[] }): KeystrokeAction { + const keystrokeAction: KeystrokeAction = new KeystrokeAction(); + keystrokeAction.scancode = event.code; + keystrokeAction.modifierMask = 0; + const modifiers = event.left.concat(event.right).map(x => x ? 1 : 0); + for (let i = 0; i < modifiers.length; ++i) { + keystrokeAction.modifierMask |= modifiers[i] << this.mapper.modifierMapper(i); + } + return keystrokeAction; + } + private hideActiveEditor() { if (this.activeEdit !== undefined) { this.macroItems.toArray()[this.activeEdit].cancelEdit(); diff --git a/packages/uhk-web/src/app/components/popover/widgets/capture-keystroke/capture-keystroke-button.component.html b/packages/uhk-web/src/app/components/popover/widgets/capture-keystroke/capture-keystroke-button.component.html index f9df04bf..e739e608 100644 --- a/packages/uhk-web/src/app/components/popover/widgets/capture-keystroke/capture-keystroke-button.component.html +++ b/packages/uhk-web/src/app/components/popover/widgets/capture-keystroke/capture-keystroke-button.component.html @@ -1,12 +1,15 @@ - \ No newline at end of file +