Correctly updates new keymap abbrevation in SwitchKeymapActions (#270)
Fixes #269
This commit is contained in:
@@ -69,4 +69,26 @@ export class Keymap {
|
|||||||
toString(): string {
|
toString(): string {
|
||||||
return `<Keymap abbreviation="${this.abbreviation}" name="${this.name}">`;
|
return `<Keymap abbreviation="${this.abbreviation}" name="${this.name}">`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
renameKeymap(oldAbbr: string, newAbbr: string): Keymap {
|
||||||
|
let layers: Layer[];
|
||||||
|
let layerModified = false;
|
||||||
|
this.layers.forEach((layer, index) => {
|
||||||
|
const newLayer = layer.renameKeymap(oldAbbr, newAbbr);
|
||||||
|
if (newLayer !== layer) {
|
||||||
|
if (!layerModified) {
|
||||||
|
layers = this.layers.slice();
|
||||||
|
layerModified = true;
|
||||||
|
}
|
||||||
|
layers[index] = newLayer;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (layerModified) {
|
||||||
|
const newKeymap = Object.assign(new Keymap(), this);
|
||||||
|
newKeymap.layers = layers;
|
||||||
|
return newKeymap;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,4 +42,25 @@ export class Layer {
|
|||||||
return `<Layer>`;
|
return `<Layer>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
renameKeymap(oldAbbr: string, newAbbr: string): Layer {
|
||||||
|
let modules: Module[];
|
||||||
|
let moduleModified = false;
|
||||||
|
this.modules.forEach((module, index) => {
|
||||||
|
const newModule = module.renameKeymap(oldAbbr, newAbbr);
|
||||||
|
if (newModule !== module) {
|
||||||
|
if (!moduleModified) {
|
||||||
|
modules = this.modules.slice();
|
||||||
|
moduleModified = true;
|
||||||
|
}
|
||||||
|
modules[index] = newModule;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (moduleModified) {
|
||||||
|
const newLayer = Object.assign(new Layer(), this);
|
||||||
|
newLayer.modules = modules;
|
||||||
|
return newLayer;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,4 +84,26 @@ export class Module {
|
|||||||
return `<Module id="${this.id}" pointerRole="${this.pointerRole}">`;
|
return `<Module id="${this.id}" pointerRole="${this.pointerRole}">`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
renameKeymap(oldAbbr: string, newAbbr: string): Module {
|
||||||
|
let keyActions: KeyAction[];
|
||||||
|
let keyActionModified = false;
|
||||||
|
this.keyActions.forEach((keyAction, index) => {
|
||||||
|
if (!keyAction) { return; }
|
||||||
|
const newKeyAction = keyAction.renameKeymap(oldAbbr, newAbbr);
|
||||||
|
if (newKeyAction !== keyAction) {
|
||||||
|
if (!keyActionModified) {
|
||||||
|
keyActions = this.keyActions.slice();
|
||||||
|
keyActionModified = true;
|
||||||
|
}
|
||||||
|
keyActions[index] = newKeyAction;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (keyActionModified) {
|
||||||
|
const newModule = Object.assign(new Module(), this);
|
||||||
|
newModule.keyActions = keyActions;
|
||||||
|
return newModule;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,4 +56,7 @@ export abstract class KeyAction {
|
|||||||
abstract toJsonObject(macros?: Macro[]): any;
|
abstract toJsonObject(macros?: Macro[]): any;
|
||||||
abstract toBinary(buffer: UhkBuffer, macros?: Macro[]): any;
|
abstract toBinary(buffer: UhkBuffer, macros?: Macro[]): any;
|
||||||
|
|
||||||
|
renameKeymap(oldAbbr: string, newAbbr: string): KeyAction {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,15 +6,17 @@ export class SwitchKeymapAction extends KeyAction {
|
|||||||
|
|
||||||
keymapAbbreviation: string;
|
keymapAbbreviation: string;
|
||||||
|
|
||||||
constructor(parameter?: SwitchKeymapAction | Keymap) {
|
constructor(parameter?: SwitchKeymapAction | Keymap | string) {
|
||||||
super();
|
super();
|
||||||
if (!parameter) {
|
if (!parameter) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (parameter instanceof SwitchKeymapAction) {
|
if (parameter instanceof SwitchKeymapAction) {
|
||||||
this.keymapAbbreviation = parameter.keymapAbbreviation;
|
this.keymapAbbreviation = parameter.keymapAbbreviation;
|
||||||
} else {
|
} else if (parameter instanceof Keymap) {
|
||||||
this.keymapAbbreviation = parameter.abbreviation;
|
this.keymapAbbreviation = parameter.abbreviation;
|
||||||
|
} else {
|
||||||
|
this.keymapAbbreviation = parameter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,4 +47,11 @@ export class SwitchKeymapAction extends KeyAction {
|
|||||||
toString(): string {
|
toString(): string {
|
||||||
return `<SwitchKeymapAction keymapAbbreviation="${this.keymapAbbreviation}">`;
|
return `<SwitchKeymapAction keymapAbbreviation="${this.keymapAbbreviation}">`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
renameKeymap(oldAbbr: string, newAbbr: string): KeyAction {
|
||||||
|
if (this.keymapAbbreviation !== oldAbbr) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
return new SwitchKeymapAction(newAbbr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import '@ngrx/core/add/operator/select';
|
import '@ngrx/core/add/operator/select';
|
||||||
import { Action } from '@ngrx/store';
|
import { Action } from '@ngrx/store';
|
||||||
|
|
||||||
import 'rxjs/add/operator/map';
|
|
||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
import 'rxjs/add/observable/of';
|
||||||
|
import 'rxjs/add/operator/map';
|
||||||
|
|
||||||
import { Helper as KeyActionHelper, KeyAction } from '../../config-serializer/config-items/key-action';
|
import { Helper as KeyActionHelper, KeyAction, SwitchKeymapAction } from '../../config-serializer/config-items/key-action';
|
||||||
import { Keymap } from '../../config-serializer/config-items/Keymap';
|
import { Keymap } from '../../config-serializer/config-items/Keymap';
|
||||||
import { Macro } from '../../config-serializer/config-items/Macro';
|
import { Macro } from '../../config-serializer/config-items/Macro';
|
||||||
import { UserConfiguration } from '../../config-serializer/config-items/UserConfiguration';
|
import { UserConfiguration } from '../../config-serializer/config-items/UserConfiguration';
|
||||||
@@ -53,6 +54,8 @@ export default function (state = initialState, action: Action): UserConfiguratio
|
|||||||
if (keymap.abbreviation === action.payload.abbr) {
|
if (keymap.abbreviation === action.payload.abbr) {
|
||||||
keymap = Object.assign(new Keymap(), keymap);
|
keymap = Object.assign(new Keymap(), keymap);
|
||||||
keymap.abbreviation = abbr;
|
keymap.abbreviation = abbr;
|
||||||
|
} else {
|
||||||
|
keymap = keymap.renameKeymap(action.payload.abbr, action.payload.newAbbr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return keymap;
|
return keymap;
|
||||||
|
|||||||
Reference in New Issue
Block a user