refactor: Change name of actions (#470)

* style: shorter import in key-macro-action.ts

* refactor: rename 'press' macro key action to 'tap'

* refactor: rename 'hold' macro key action to 'press'

* refactor: rename 'press' macro mouse action to 'click'

* style: fix stylelint
This commit is contained in:
Róbert Kiss
2017-10-26 23:25:19 +02:00
committed by László Monda
parent 133f8be370
commit 6c6e2af047
11 changed files with 71 additions and 65 deletions

View File

@@ -1,6 +1,6 @@
import { KeyMacroAction } from './key-macro-action';
import { binaryDefaultHelper, jsonDefaultHelper } from '../../../../test/serializer-test-helper';
import { MacroSubAction } from './macro-action';
import { MacroKeySubAction } from './macro-action';
import { KeystrokeType } from '../key-action';
describe('key-macro-action', () => {
@@ -12,7 +12,7 @@ describe('key-macro-action', () => {
describe('full serialization', () => {
it('should json match', () => {
const action = new KeyMacroAction();
action.action = MacroSubAction.hold;
action.action = MacroKeySubAction.press;
action.type = KeystrokeType.basic;
action.scancode = 100;
jsonDefaultHelper(action);
@@ -20,7 +20,7 @@ describe('key-macro-action', () => {
it('should binary match', () => {
const action = new KeyMacroAction();
action.action = MacroSubAction.hold;
action.action = MacroKeySubAction.press;
action.type = KeystrokeType.basic;
action.scancode = 100;
binaryDefaultHelper(action);

View File

@@ -1,8 +1,8 @@
import { assertEnum, assertUInt8 } from '../../assert';
import { UhkBuffer } from '../../uhk-buffer';
import { KeyModifiers } from '../key-modifiers';
import { MacroAction, MacroActionId, MacroSubAction, macroActionType } from './macro-action';
import { KeystrokeType } from '../key-action/keystroke-type';
import { MacroAction, MacroActionId, MacroKeySubAction, macroActionType } from './macro-action';
import { KeystrokeType } from '../key-action';
interface JsObjectKeyMacroAction {
macroActionType: string;
@@ -14,8 +14,8 @@ interface JsObjectKeyMacroAction {
export class KeyMacroAction extends MacroAction {
@assertEnum(MacroSubAction)
action: MacroSubAction;
@assertEnum(MacroKeySubAction)
action: MacroKeySubAction;
@assertEnum(KeystrokeType)
type: KeystrokeType;
@@ -39,7 +39,7 @@ export class KeyMacroAction extends MacroAction {
fromJsonObject(jsObject: JsObjectKeyMacroAction): KeyMacroAction {
this.assertMacroActionType(jsObject);
this.action = MacroSubAction[jsObject.action];
this.action = MacroKeySubAction[jsObject.action];
if (jsObject.type === 'media') {
this.type = jsObject.scancode < 256 ? KeystrokeType.shortMedia : KeystrokeType.longMedia;
} else {
@@ -69,7 +69,7 @@ export class KeyMacroAction extends MacroAction {
toJsonObject(): any {
const jsObject: JsObjectKeyMacroAction = {
macroActionType: macroActionType.KeyMacroAction,
action: MacroSubAction[this.action]
action: MacroKeySubAction[this.action]
};
if (this.hasScancode()) {
@@ -121,16 +121,16 @@ export class KeyMacroAction extends MacroAction {
return !!this.modifierMask;
}
isHoldAction(): boolean {
return this.action === MacroSubAction.hold;
isPressAction(): boolean {
return this.action === MacroKeySubAction.press;
}
isPressAction(): boolean {
return this.action === MacroSubAction.press;
isTapAction(): boolean {
return this.action === MacroKeySubAction.tap;
}
isReleaseAction(): boolean {
return this.action === MacroSubAction.release;
return this.action === MacroKeySubAction.release;
}
public getName(): string {

View File

@@ -23,8 +23,14 @@ export enum MacroActionId {
TextMacroAction = 70
}
export enum MacroSubAction {
press = 0,
export enum MacroKeySubAction {
tap = 0,
press = 1,
release = 2
}
export enum MacroMouseSubAction {
click = 0,
hold = 1,
release = 2
}

View File

@@ -1,6 +1,6 @@
import { assertEnum, assertUInt8 } from '../../assert';
import { UhkBuffer } from '../../uhk-buffer';
import { MacroAction, MacroActionId, MacroSubAction, macroActionType } from './macro-action';
import { MacroAction, MacroActionId, MacroMouseSubAction, macroActionType } from './macro-action';
export enum MouseButtons {
Left = 1 << 0,
@@ -15,8 +15,8 @@ interface JsObjectMouseButtonMacroAction {
}
export class MouseButtonMacroAction extends MacroAction {
@assertEnum(MacroSubAction)
action: MacroSubAction;
@assertEnum(MacroMouseSubAction)
action: MacroMouseSubAction;
@assertUInt8
mouseButtonsMask: number;
@@ -32,7 +32,7 @@ export class MouseButtonMacroAction extends MacroAction {
fromJsonObject(jsObject: JsObjectMouseButtonMacroAction): MouseButtonMacroAction {
this.assertMacroActionType(jsObject);
this.action = MacroSubAction[jsObject.action];
this.action = MacroMouseSubAction[jsObject.action];
this.mouseButtonsMask = jsObject.mouseButtonsMask;
return this;
}
@@ -47,7 +47,7 @@ export class MouseButtonMacroAction extends MacroAction {
toJsonObject(): any {
return {
macroActionType: macroActionType.MouseButtonMacroAction,
action: MacroSubAction[this.action],
action: MacroMouseSubAction[this.action],
mouseButtonsMask: this.mouseButtonsMask
};
}
@@ -81,16 +81,16 @@ export class MouseButtonMacroAction extends MacroAction {
return this.mouseButtonsMask !== 0;
}
isOnlyHoldAction(): boolean {
return this.action === MacroSubAction.hold;
isOnlyClickAction(): boolean {
return this.action === MacroMouseSubAction.click;
}
isOnlyPressAction(): boolean {
return this.action === MacroSubAction.press;
isOnlyHoldAction(): boolean {
return this.action === MacroMouseSubAction.hold;
}
isOnlyReleaseAction(): boolean {
return this.action === MacroSubAction.release;
return this.action === MacroMouseSubAction.release;
}
public getName(): string {

View File

@@ -1,16 +1,16 @@
<div class="col-xs-12 macro-key__container">
<div class="col-xs-3 macro-key__types">
<ul class="nav nav-pills nav-stacked">
<li #keyMove [class.active]="activeTab === TabName.Keypress" (click)="selectTab(TabName.Keypress)">
<li #keyMove [class.active]="activeTab === TabName.Tap" (click)="selectTab(TabName.Tap)">
<a>
<i class="fa fa-hand-pointer-o"></i>
<span>Press key</span>
<span>Tap key</span>
</a>
</li>
<li #keyHold [class.active]="activeTab === TabName.Hold" (click)="selectTab(TabName.Hold)">
<li #keyHold [class.active]="activeTab === TabName.Press" (click)="selectTab(TabName.Press)">
<a>
<i class="fa fa-hand-rock-o"></i>
<span>Hold key</span>
<span>Press key</span>
</a>
</li>
<li #keyRelease [class.active]="activeTab === TabName.Release" (click)="selectTab(TabName.Release)">
@@ -23,8 +23,8 @@
</div>
<div class="col-xs-9 macro-key__action-container">
<div class="macro-key__action">
<h4 *ngIf="activeTab === TabName.Keypress">Press key</h4>
<h4 *ngIf="activeTab === TabName.Hold">Hold key</h4>
<h4 *ngIf="activeTab === TabName.Tap">Tap key</h4>
<h4 *ngIf="activeTab === TabName.Press">Press key</h4>
<h4 *ngIf="activeTab === TabName.Release">Release key</h4>
<keypress-tab #keypressTab [defaultKeyAction]="defaultKeyAction" [secondaryRoleEnabled]="false"
(validAction)="validate()"></keypress-tab>

View File

@@ -1,12 +1,12 @@
import { Component, Input, OnInit, ViewChild } from '@angular/core';
import { KeyMacroAction, KeystrokeAction, MacroSubAction } from 'uhk-common';
import { KeyMacroAction, KeystrokeAction, MacroKeySubAction } from 'uhk-common';
import { KeypressTabComponent, Tab } from '../../../../popover/tab';
import { MacroBaseComponent } from '../macro-base.component';
enum TabName {
Keypress,
Hold,
Tap,
Press,
Release
}
@@ -45,22 +45,22 @@ export class MacroKeyTabComponent extends MacroBaseComponent implements OnInit {
getTabName(macroAction: KeyMacroAction): TabName {
if (!macroAction.action) {
return TabName.Keypress;
} else if (macroAction.action === MacroSubAction.hold) {
return TabName.Hold;
} else if (macroAction.action === MacroSubAction.release) {
return TabName.Tap;
} else if (macroAction.action === MacroKeySubAction.press) {
return TabName.Press;
} else if (macroAction.action === MacroKeySubAction.release) {
return TabName.Release;
}
}
getActionType(tab: TabName): MacroSubAction {
getActionType(tab: TabName): MacroKeySubAction {
switch (tab) {
case TabName.Keypress:
return MacroSubAction.press;
case TabName.Hold:
return MacroSubAction.hold;
case TabName.Tap:
return MacroKeySubAction.tap;
case TabName.Press:
return MacroKeySubAction.press;
case TabName.Release:
return MacroSubAction.release;
return MacroKeySubAction.release;
default:
throw new Error('Invalid tab type');
}

View File

@@ -4,7 +4,7 @@ import {
MouseButtonMacroAction,
MoveMouseMacroAction,
ScrollMouseMacroAction,
MacroSubAction
MacroMouseSubAction
} from 'uhk-common';
import { Tab } from '../../../../popover/tab';
import { MacroBaseComponent } from '../macro-base.component';
@@ -48,7 +48,7 @@ export class MacroMouseTabComponent extends MacroBaseComponent implements OnInit
ngOnInit() {
if (!this.macroAction) {
this.macroAction = new MouseButtonMacroAction();
this.macroAction.action = MacroSubAction.press;
this.macroAction.action = MacroMouseSubAction.click;
}
const tabName = this.getTabName(this.macroAction);
this.selectTab(tabName);
@@ -96,14 +96,14 @@ export class MacroMouseTabComponent extends MacroBaseComponent implements OnInit
return this.selectedButtons[index];
}
getAction(tab: TabName): MacroSubAction {
getAction(tab: TabName): MacroMouseSubAction {
switch (tab) {
case TabName.Click:
return MacroSubAction.press;
return MacroMouseSubAction.click;
case TabName.Hold:
return MacroSubAction.hold;
return MacroMouseSubAction.hold;
case TabName.Release:
return MacroSubAction.release;
return MacroMouseSubAction.release;
default:
throw new Error(`Invalid tab name: ${TabName[tab]}`);
}
@@ -111,7 +111,7 @@ export class MacroMouseTabComponent extends MacroBaseComponent implements OnInit
getTabName(action: MouseMacroAction): TabName {
if (action instanceof MouseButtonMacroAction) {
if (!action.action || action.isOnlyPressAction()) {
if (!action.action || action.isOnlyClickAction()) {
return TabName.Click;
} else if (action.isOnlyHoldAction()) {
return TabName.Hold;

View File

@@ -124,14 +124,14 @@ export class MacroItemComponent implements OnInit, OnChanges {
return;
}
if (action.isPressAction()) {
// Press key
if (action.isTapAction()) {
// Tap key
this.iconName = 'hand-pointer';
this.title = 'Press key: ';
} else if (action.isHoldAction()) {
// Hold key
this.title = 'Tap key: ';
} else if (action.isPressAction()) {
// Press key
this.iconName = 'hand-rock';
this.title = 'Hold key: ';
this.title = 'Press key: ';
} else if (action.isReleaseAction()) {
// Release key
this.iconName = 'hand-paper';
@@ -146,7 +146,7 @@ export class MacroItemComponent implements OnInit, OnChanges {
}
if (action.hasModifiers()) {
// Press/hold/release modifiers
// Tap/press/release modifiers
for (let i = KeyModifiers.leftCtrl; i <= KeyModifiers.rightGui; i <<= 1) {
if (action.isModifierActive(i)) {
this.title += ' ' + KeyModifiers[i];
@@ -181,7 +181,7 @@ export class MacroItemComponent implements OnInit, OnChanges {
private setMouseButtonActionContent(action: MouseButtonMacroAction): void {
// Press/hold/release mouse buttons
if (action.isOnlyPressAction()) {
if (action.isOnlyClickAction()) {
this.iconName = 'mouse-pointer';
this.title = 'Click mouse button: ';
} else if (action.isOnlyHoldAction()) {

View File

@@ -1,7 +1,7 @@
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, KeyMacroAction, KeystrokeAction, MacroSubAction } from 'uhk-common';
import { Macro, MacroAction, KeyMacroAction, KeystrokeAction, MacroKeySubAction } from 'uhk-common';
import { MapperService } from '../../../services/mapper.service';
import { MacroItemComponent } from '../item';
@@ -127,7 +127,7 @@ export class MacroListComponent {
onKeysCapture(event: { code: number, left: boolean[], right: boolean[] }) {
const keyMacroAction = Object.assign(new KeyMacroAction(), this.toKeyAction(event));
keyMacroAction.action = MacroSubAction.press;
keyMacroAction.action = MacroKeySubAction.tap;
this.add.emit({
macroId: this.macro.id,

View File

@@ -7072,7 +7072,7 @@
"macroActions": [
{
"macroActionType": "key",
"action": "press",
"action": "tap",
"scancode": 15,
"modifierMask": 1,
"type": "basic"
@@ -7083,7 +7083,7 @@
},
{
"macroActionType": "key",
"action": "press",
"action": "tap",
"scancode": 40,
"type": "basic"
}

View File

@@ -1,5 +1,5 @@
%btn-link {
padding: 7px 0px;
padding: 7px 0;
text-decoration: none;
border: 0;
width: 100%;