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"
This commit is contained in:
Attila Csanyi
2017-10-18 22:40:09 +02:00
committed by László Monda
parent 8c652a427f
commit 6fb8e56963
7 changed files with 76 additions and 24 deletions
@@ -25,12 +25,14 @@
</div> </div>
<div class="list-group add-new__action-container" [@toggler]="(!showNew) ? 'active' : 'inactive'"> <div class="list-group add-new__action-container" [@toggler]="(!showNew) ? 'active' : 'inactive'">
<div class="list-group-item action--item add-new__action-item no-reorder clearfix"> <div class="list-group-item action--item add-new__action-item no-reorder clearfix">
<a class="add-new__action-item--link" (click)="showNewAction()"> <span class="add-new__action-item--link" (click)="showNewAction()">
<i class="fa fa-plus"></i> Add macro action <button type="button" class="btn btn-link">
</a> <i class="fa fa-plus"></i> Add macro action
<a class="add-new__action-item--link"> </button>
<i class="fa fa fa-circle"></i> Add captured keystroke </span>
</a> <span class="add-new__action-item--link">
<capture-keystroke-button captureText="Add captured keystroke" isLink="true" (capture)="onKeysCapture($event)" ></capture-keystroke-button>
</span>
</div> </div>
</div> </div>
</div> </div>
@@ -1,4 +1,5 @@
@import '../../../../styles/variables'; @import '../../../../styles/variables';
@import '../../../../styles/common';
:host { :host {
display: flex; display: flex;
@@ -112,7 +113,6 @@ h1 {
&--link { &--link {
width: 50%; width: 50%;
float: left; float: left;
padding: 10px 5px;
text-align: center; text-align: center;
color: $icon-hover; color: $icon-hover;
@@ -124,6 +124,10 @@ h1 {
text-decoration: none; text-decoration: none;
background: #e6e6e6; background: #e6e6e6;
} }
button.btn-link {
@extend %btn-link;
}
} }
.fa-circle { .fa-circle {
@@ -1,8 +1,9 @@
import { Component, EventEmitter, Input, Output, QueryList, ViewChildren, forwardRef } from '@angular/core'; import { Component, EventEmitter, Input, Output, QueryList, ViewChildren, forwardRef } from '@angular/core';
import { animate, state, style, transition, trigger } from '@angular/animations'; import { animate, state, style, transition, trigger } from '@angular/animations';
import { DragulaService } from 'ng2-dragula/ng2-dragula'; 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'; import { MacroItemComponent } from '../item';
@Component({ @Component({
@@ -46,7 +47,10 @@ export class MacroListComponent {
private activeEdit: number = undefined; private activeEdit: number = undefined;
private dragIndex: number; private dragIndex: number;
constructor(dragulaService: DragulaService) { constructor(
private mapper: MapperService,
private dragulaService: DragulaService
) {
/* tslint:disable:no-unused-variable: Used by Dragula. */ /* tslint:disable:no-unused-variable: Used by Dragula. */
dragulaService.setOptions('macroActions', { dragulaService.setOptions('macroActions', {
moves: function (el: any, container: any, handle: any) { moves: function (el: any, container: any, handle: any) {
@@ -121,6 +125,27 @@ export class MacroListComponent {
this.hideActiveEditor(); 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() { private hideActiveEditor() {
if (this.activeEdit !== undefined) { if (this.activeEdit !== undefined) {
this.macroItems.toArray()[this.activeEdit].cancelEdit(); this.macroItems.toArray()[this.activeEdit].cancelEdit();
@@ -1,12 +1,15 @@
<button type="button" class="btn btn-sm btn--capture-keystroke" <button type="button" [ngClass]="{
[ngClass]="{'btn-default': !record, 'btn-info': record}" 'btn btn-sm btn--capture-keystroke': !isLink,
(click)="start()" 'btn-link link--capture-keystroke': isLink,
> 'btn-default': !record && !isLink,
<i class="fa fa-circle"></i> 'btn-info': record && !isLink
<ng-template [ngIf]="!record"> }" (click)="start()">
Capture keystroke <i class="fa fa-circle"></i>
</ng-template>
<ng-template [ngIf]="record"> <ng-template [ngIf]="!record">
Capturing ... {{ captureText }}
</ng-template> </ng-template>
</button>
<ng-template [ngIf]="record">
Capturing ...
</ng-template>
@@ -1,8 +1,14 @@
button { @import '../../../../../styles/common';
.btn--capture-keystroke {
display: inline-block; display: inline-block;
margin: 0 0 0 0.25rem; margin: 0 0 0 0.25rem;
} }
.link--capture-keystroke {
@extend %btn-link;
}
.fa-circle { .fa-circle {
color: #c00; color: #c00;
} }
@@ -1,4 +1,4 @@
import { Component, EventEmitter, HostListener, Output } from '@angular/core'; import { Component, EventEmitter, HostListener, Output, Input } from '@angular/core';
import { CaptureService } from '../../../../services/capture.service'; import { CaptureService } from '../../../../services/capture.service';
@Component({ @Component({
@@ -7,6 +7,8 @@ import { CaptureService } from '../../../../services/capture.service';
styleUrls: ['./capture-keystroke-button.component.scss'] styleUrls: ['./capture-keystroke-button.component.scss']
}) })
export class CaptureKeystrokeButtonComponent { export class CaptureKeystrokeButtonComponent {
@Input() isLink = false;
@Input() captureText = 'Capture keystroke';
@Output() capture = new EventEmitter<any>(); @Output() capture = new EventEmitter<any>();
record: boolean; record: boolean;
+10
View File
@@ -0,0 +1,10 @@
%btn-link {
padding: 7px 0px;
text-decoration: none;
border: 0;
width: 100%;
&:focus {
outline: none;
}
}