Fix 560 delete bind play macro action when macro delete (#576)
* fix(config): delete KeyAction binding of deleted macro * refactor: use sorter import * fix(macro): read the macro id from route params * fix(keyAction): use NoneAction in keyAction mapping
This commit is contained in:
committed by
László Monda
parent
e545c9d67b
commit
1a413c824e
@@ -7,6 +7,7 @@ import { SwitchLayerAction } from './switch-layer-action';
|
|||||||
import { SwitchKeymapAction, UnresolvedSwitchKeymapAction } from './switch-keymap-action';
|
import { SwitchKeymapAction, UnresolvedSwitchKeymapAction } from './switch-keymap-action';
|
||||||
import { MouseAction } from './mouse-action';
|
import { MouseAction } from './mouse-action';
|
||||||
import { PlayMacroAction } from './play-macro-action';
|
import { PlayMacroAction } from './play-macro-action';
|
||||||
|
import { NoneAction } from './none-action';
|
||||||
|
|
||||||
export class Helper {
|
export class Helper {
|
||||||
|
|
||||||
@@ -77,6 +78,8 @@ export class Helper {
|
|||||||
return new MouseAction().fromJsonObject(keyAction);
|
return new MouseAction().fromJsonObject(keyAction);
|
||||||
case keyActionType.PlayMacroAction:
|
case keyActionType.PlayMacroAction:
|
||||||
return new PlayMacroAction().fromJsonObject(keyAction, macros);
|
return new PlayMacroAction().fromJsonObject(keyAction, macros);
|
||||||
|
case keyActionType.NoneAction:
|
||||||
|
return new NoneAction();
|
||||||
default:
|
default:
|
||||||
throw `Invalid KeyAction.keyActionType: "${keyAction.keyActionType}"`;
|
throw `Invalid KeyAction.keyActionType: "${keyAction.keyActionType}"`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,5 +13,5 @@
|
|||||||
</ng-template>
|
</ng-template>
|
||||||
|
|
||||||
<div *ngIf="!macro" class="not-found">
|
<div *ngIf="!macro" class="not-found">
|
||||||
There is no macro with id {{ route.params.select('id') | async }}.
|
There is no macro with id {{ macroId }}.
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { Subscription } from 'rxjs/Subscription';
|
|||||||
import 'rxjs/add/operator/pluck';
|
import 'rxjs/add/operator/pluck';
|
||||||
|
|
||||||
import { MacroActions } from '../../../store/actions';
|
import { MacroActions } from '../../../store/actions';
|
||||||
import { AppState } from '../../../store/index';
|
import { AppState } from '../../../store';
|
||||||
import { getMacro } from '../../../store/reducers/user-configuration';
|
import { getMacro } from '../../../store/reducers/user-configuration';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -21,13 +21,17 @@ import { getMacro } from '../../../store/reducers/user-configuration';
|
|||||||
export class MacroEditComponent implements OnDestroy {
|
export class MacroEditComponent implements OnDestroy {
|
||||||
macro: Macro;
|
macro: Macro;
|
||||||
isNew: boolean;
|
isNew: boolean;
|
||||||
|
macroId: number;
|
||||||
|
|
||||||
private subscription: Subscription;
|
private subscription: Subscription;
|
||||||
constructor(private store: Store<AppState>, public route: ActivatedRoute) {
|
constructor(private store: Store<AppState>, public route: ActivatedRoute) {
|
||||||
this.subscription = route
|
this.subscription = route
|
||||||
.params
|
.params
|
||||||
.pluck<{}, string>('id')
|
.pluck<{}, string>('id')
|
||||||
.switchMap((id: string) => store.let(getMacro(+id)))
|
.switchMap((id: string) => {
|
||||||
|
this.macroId = +id;
|
||||||
|
return store.let(getMacro(this.macroId));
|
||||||
|
})
|
||||||
.subscribe((macro: Macro) => {
|
.subscribe((macro: Macro) => {
|
||||||
this.macro = macro;
|
this.macro = macro;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { Store } from '@ngrx/store';
|
|||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
|
||||||
import { Notification } from 'uhk-common';
|
import { Notification } from 'uhk-common';
|
||||||
import { AppState, getUndoableNotification } from '../../store/index';
|
import { AppState, getUndoableNotification } from '../../store';
|
||||||
import { DismissUndoNotificationAction, UndoLastAction } from '../../store/actions/app';
|
import { DismissUndoNotificationAction, UndoLastAction } from '../../store/actions/app';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
|||||||
@@ -4,7 +4,18 @@ import { Observable } from 'rxjs/Observable';
|
|||||||
import 'rxjs/add/observable/of';
|
import 'rxjs/add/observable/of';
|
||||||
import 'rxjs/add/operator/map';
|
import 'rxjs/add/operator/map';
|
||||||
|
|
||||||
import { KeyAction, KeyActionHelper, Keymap, Layer, Macro, Module, SwitchLayerAction, UserConfiguration } from 'uhk-common';
|
import {
|
||||||
|
KeyAction,
|
||||||
|
KeyActionHelper,
|
||||||
|
Keymap,
|
||||||
|
Layer,
|
||||||
|
Macro,
|
||||||
|
Module,
|
||||||
|
NoneAction,
|
||||||
|
PlayMacroAction,
|
||||||
|
SwitchLayerAction,
|
||||||
|
UserConfiguration
|
||||||
|
} from 'uhk-common';
|
||||||
import { KeymapActions, MacroActions } from '../actions';
|
import { KeymapActions, MacroActions } from '../actions';
|
||||||
import { AppState } from '../index';
|
import { AppState } from '../index';
|
||||||
import { ActionTypes } from '../actions/user-config';
|
import { ActionTypes } from '../actions/user-config';
|
||||||
@@ -210,9 +221,34 @@ export function reducer(state = initialState, action: Action & { payload?: any }
|
|||||||
changedUserConfiguration.macros = insertItemInNameOrder(state.macros, newMacro, macro => macro.id !== newMacro.id);
|
changedUserConfiguration.macros = insertItemInNameOrder(state.macros, newMacro, macro => macro.id !== newMacro.id);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case MacroActions.REMOVE:
|
case MacroActions.REMOVE:
|
||||||
changedUserConfiguration.macros = state.macros.filter((macro: Macro) => macro.id !== action.payload);
|
const macroId = action.payload;
|
||||||
|
changedUserConfiguration.macros = state.macros.filter((macro: Macro) => macro.id !== macroId);
|
||||||
|
|
||||||
|
for (let k = 0; k < changedUserConfiguration.keymaps.length; k++) {
|
||||||
|
const keymap = changedUserConfiguration.keymaps[k];
|
||||||
|
let hasChanges = false;
|
||||||
|
|
||||||
|
for (const layer of keymap.layers) {
|
||||||
|
for (const module of layer.modules) {
|
||||||
|
for (let ka = 0; ka < module.keyActions.length; ka++) {
|
||||||
|
const keyAction = module.keyActions[ka];
|
||||||
|
|
||||||
|
if (keyAction instanceof PlayMacroAction && keyAction.macroId === macroId) {
|
||||||
|
hasChanges = true;
|
||||||
|
module.keyActions[ka] = new NoneAction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasChanges) {
|
||||||
|
changedUserConfiguration.keymaps[k] = new Keymap(keymap);
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MacroActions.ADD_ACTION:
|
case MacroActions.ADD_ACTION:
|
||||||
changedUserConfiguration.macros = state.macros.map((macro: Macro) => {
|
changedUserConfiguration.macros = state.macros.map((macro: Macro) => {
|
||||||
if (macro.id === action.payload.id) {
|
if (macro.id === action.payload.id) {
|
||||||
|
|||||||
Reference in New Issue
Block a user