From 6c6e2af0470c83074abe815920acf56fa1854bdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B3bert=20Kiss?= Date: Thu, 26 Oct 2017 23:25:19 +0200 Subject: [PATCH] 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 --- .../macro-action/key-macro-action.spec.ts | 6 ++--- .../macro-action/key-macro-action.ts | 22 ++++++++-------- .../config-items/macro-action/macro-action.ts | 10 +++++-- .../macro-action/mouse-button-macro-action.ts | 20 +++++++------- .../tab/key/macro-key.component.html | 12 ++++----- .../tab/key/macro-key.component.ts | 26 +++++++++---------- .../tab/mouse/macro-mouse.component.ts | 14 +++++----- .../macro/item/macro-item.component.ts | 16 ++++++------ .../macro/list/macro-list.component.ts | 4 +-- .../uhk-web/src/app/services/user-config.json | 4 +-- packages/uhk-web/src/styles/common.scss | 2 +- 11 files changed, 71 insertions(+), 65 deletions(-) diff --git a/packages/uhk-common/src/config-serializer/config-items/macro-action/key-macro-action.spec.ts b/packages/uhk-common/src/config-serializer/config-items/macro-action/key-macro-action.spec.ts index 80cf8e8d..a663b40d 100644 --- a/packages/uhk-common/src/config-serializer/config-items/macro-action/key-macro-action.spec.ts +++ b/packages/uhk-common/src/config-serializer/config-items/macro-action/key-macro-action.spec.ts @@ -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); diff --git a/packages/uhk-common/src/config-serializer/config-items/macro-action/key-macro-action.ts b/packages/uhk-common/src/config-serializer/config-items/macro-action/key-macro-action.ts index 7ca5e2e1..afb65e2b 100644 --- a/packages/uhk-common/src/config-serializer/config-items/macro-action/key-macro-action.ts +++ b/packages/uhk-common/src/config-serializer/config-items/macro-action/key-macro-action.ts @@ -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 { diff --git a/packages/uhk-common/src/config-serializer/config-items/macro-action/macro-action.ts b/packages/uhk-common/src/config-serializer/config-items/macro-action/macro-action.ts index 7e0f655e..342fae47 100644 --- a/packages/uhk-common/src/config-serializer/config-items/macro-action/macro-action.ts +++ b/packages/uhk-common/src/config-serializer/config-items/macro-action/macro-action.ts @@ -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 } diff --git a/packages/uhk-common/src/config-serializer/config-items/macro-action/mouse-button-macro-action.ts b/packages/uhk-common/src/config-serializer/config-items/macro-action/mouse-button-macro-action.ts index 09b5f0a2..d500ac2b 100644 --- a/packages/uhk-common/src/config-serializer/config-items/macro-action/mouse-button-macro-action.ts +++ b/packages/uhk-common/src/config-serializer/config-items/macro-action/mouse-button-macro-action.ts @@ -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 { diff --git a/packages/uhk-web/src/app/components/macro/action-editor/tab/key/macro-key.component.html b/packages/uhk-web/src/app/components/macro/action-editor/tab/key/macro-key.component.html index 1a1f7f72..ef0b009e 100644 --- a/packages/uhk-web/src/app/components/macro/action-editor/tab/key/macro-key.component.html +++ b/packages/uhk-web/src/app/components/macro/action-editor/tab/key/macro-key.component.html @@ -1,16 +1,16 @@
-

Press key

-

Hold key

+

Tap key

+

Press key

Release key

diff --git a/packages/uhk-web/src/app/components/macro/action-editor/tab/key/macro-key.component.ts b/packages/uhk-web/src/app/components/macro/action-editor/tab/key/macro-key.component.ts index 654e3bbd..110ef2f6 100644 --- a/packages/uhk-web/src/app/components/macro/action-editor/tab/key/macro-key.component.ts +++ b/packages/uhk-web/src/app/components/macro/action-editor/tab/key/macro-key.component.ts @@ -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'); } diff --git a/packages/uhk-web/src/app/components/macro/action-editor/tab/mouse/macro-mouse.component.ts b/packages/uhk-web/src/app/components/macro/action-editor/tab/mouse/macro-mouse.component.ts index 1a04c4e8..3a8f31f9 100644 --- a/packages/uhk-web/src/app/components/macro/action-editor/tab/mouse/macro-mouse.component.ts +++ b/packages/uhk-web/src/app/components/macro/action-editor/tab/mouse/macro-mouse.component.ts @@ -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; diff --git a/packages/uhk-web/src/app/components/macro/item/macro-item.component.ts b/packages/uhk-web/src/app/components/macro/item/macro-item.component.ts index 0b572e5f..38069706 100644 --- a/packages/uhk-web/src/app/components/macro/item/macro-item.component.ts +++ b/packages/uhk-web/src/app/components/macro/item/macro-item.component.ts @@ -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()) { 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 748a38f2..67110f3d 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,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, diff --git a/packages/uhk-web/src/app/services/user-config.json b/packages/uhk-web/src/app/services/user-config.json index d7013dca..63c3ad53 100644 --- a/packages/uhk-web/src/app/services/user-config.json +++ b/packages/uhk-web/src/app/services/user-config.json @@ -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" } diff --git a/packages/uhk-web/src/styles/common.scss b/packages/uhk-web/src/styles/common.scss index c4e316bb..80754c34 100644 --- a/packages/uhk-web/src/styles/common.scss +++ b/packages/uhk-web/src/styles/common.scss @@ -1,5 +1,5 @@ %btn-link { - padding: 7px 0px; + padding: 7px 0; text-decoration: none; border: 0; width: 100%;