Use ids in key actions instead of references (#239)

Partially reverts e48fdea
This commit is contained in:
József Farkas
2016-12-30 11:51:46 +01:00
committed by GitHub
parent 6a7efcc2b1
commit 9b2aa188e6
13 changed files with 165 additions and 164 deletions

View File

@@ -59,7 +59,8 @@ export class KeymapTabComponent implements OnInit, OnChanges, Tab {
}
const switchKeymapAction: SwitchKeymapAction = <SwitchKeymapAction>keyAction;
this.selectedKeymap = switchKeymapAction.keymap;
this.selectedKeymap = this.keymaps
.find((keymap: Keymap) => keymap.abbreviation === switchKeymapAction.keymapAbbreviation);
}
toKeyAction(): SwitchKeymapAction {
@@ -68,7 +69,7 @@ export class KeymapTabComponent implements OnInit, OnChanges, Tab {
}
const keymapAction = new SwitchKeymapAction();
keymapAction.keymap = this.selectedKeymap;
keymapAction.keymapAbbreviation = this.selectedKeymap.abbreviation;
return keymapAction;
}
}

View File

@@ -61,7 +61,7 @@ export class MacroTabComponent implements OnInit, OnChanges, OnDestroy, Tab {
return false;
}
const playMacroAction: PlayMacroAction = <PlayMacroAction>keyAction;
this.selectedMacroIndex = this.macros.findIndex(macro => playMacroAction.macro === macro);
this.selectedMacroIndex = this.macros.findIndex(macro => playMacroAction.macroId === macro.id);
return true;
}
@@ -71,7 +71,7 @@ export class MacroTabComponent implements OnInit, OnChanges, OnDestroy, Tab {
}
const keymapAction = new PlayMacroAction();
keymapAction.macro = this.macros[this.selectedMacroIndex];
keymapAction.macroId = this.macros[this.selectedMacroIndex].id;
return keymapAction;
}

View File

@@ -283,13 +283,14 @@ export class SvgKeyboardKeyComponent implements OnInit, OnChanges, OnDestroy {
} else if (this.keyAction instanceof SwitchKeymapAction) {
let keyAction: SwitchKeymapAction = this.keyAction as SwitchKeymapAction;
this.labelType = LabelTypes.SwitchKeymap;
this.labelSource = keyAction.keymap.abbreviation;
this.labelSource = keyAction.keymapAbbreviation;
} else if (this.keyAction instanceof PlayMacroAction) {
let keyAction: PlayMacroAction = this.keyAction as PlayMacroAction;
const macro: Macro = this.macros.find((macro: Macro) => macro.id === keyAction.macroId);
this.labelType = LabelTypes.IconText;
this.labelSource = {
icon: this.mapper.getIcon('macro'),
text: keyAction.macro.name
text: macro.name
};
} else if (this.keyAction instanceof MouseAction) {
this.labelType = LabelTypes.MouseKey;

View File

@@ -16,7 +16,7 @@
>
<div class="tooltip-arrow"></div>
<div class="tooltip-inner">
<p *ngFor="let item of tooltipData.content">
<p *ngFor="let item of tooltipData.content | async">
{{ item.name }}: {{ item.value }}
</p>
</div>

View File

@@ -12,6 +12,9 @@ import {
SimpleChanges
} from '@angular/core';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/map';
import { Store } from '@ngrx/store';
import { MapperService } from '../../../services/mapper.service';
@@ -35,6 +38,11 @@ import { AppState } from '../../../store';
import { KeymapActions } from '../../../store/actions';
import { PopoverComponent } from '../../popover';
interface NameValuePair {
name: string;
value: string;
}
@Component({
selector: 'svg-keyboard-wrap',
template: require('./svg-keyboard-wrap.component.html'),
@@ -46,14 +54,19 @@ export class SvgKeyboardWrapComponent implements OnInit, OnChanges {
@Input() popoverEnabled: boolean = true;
@Input() tooltipEnabled: boolean = false;
@ViewChild(PopoverComponent, { read: ElementRef}) popover: ElementRef;
@ViewChild(PopoverComponent, { read: ElementRef }) popover: ElementRef;
private popoverShown: boolean;
private keyEditConfig: { moduleId: number, keyId: number };
private popoverInitKeyAction: KeyAction;
private keybindAnimationEnabled: boolean;
private currentLayer: number = 0;
private tooltipData: { posTop: number, posLeft: number, content: { name: string, value: string }[], show: boolean };
private tooltipData: {
posTop: number,
posLeft: number,
content: Observable<NameValuePair[]>,
show: boolean
};
private layers: Layer[];
private keyPosition: ClientRect;
private wrapPosition: ClientRect;
@@ -89,7 +102,7 @@ export class SvgKeyboardWrapComponent implements OnInit, OnChanges {
this.tooltipData = {
posTop: 0,
posLeft: 0,
content: [],
content: Observable.of([]),
show: false
};
}
@@ -139,7 +152,7 @@ export class SvgKeyboardWrapComponent implements OnInit, OnChanges {
}
}
onCapture(moduleId: number, keyId: number, captured: {code: number, left: boolean[], right: boolean[]}): void {
onCapture(moduleId: number, keyId: number, captured: { code: number, left: boolean[], right: boolean[] }): void {
let keystrokeAction: KeystrokeAction = new KeystrokeAction();
const modifiers = captured.left.concat(captured.right).map(x => x ? 1 : 0);
@@ -194,13 +207,30 @@ export class SvgKeyboardWrapComponent implements OnInit, OnChanges {
posTop = position.top + position.height;
}
let content: {
name: string,
value: string
}[] = [];
this.tooltipData = {
posLeft: posLeft,
posTop: posTop,
content: this.getKeyActionContent(keyAction),
show: true
};
}
hideTooltip() {
this.tooltipData.show = false;
}
hidePopover(): void {
this.popoverShown = false;
}
selectLayer(index: number): void {
this.currentLayer = index;
}
private getKeyActionContent(keyAction: KeyAction): Observable<NameValuePair[]> {
if (keyAction instanceof KeystrokeAction) {
const keystrokeAction: KeystrokeAction = keyAction;
const content: NameValuePair[] = [];
content.push({
name: 'Action type',
value: 'Keystroke'
@@ -231,71 +261,79 @@ export class SvgKeyboardWrapComponent implements OnInit, OnChanges {
value: LongPressAction[keystrokeAction.longPressAction]
});
}
return Observable.of(content);
} else if (keyAction instanceof MouseAction) {
const mouseAction: MouseAction = keyAction;
content.push({
name: 'Action type',
value: 'Mouse'
});
content.push({
name: 'Action',
value: camelCaseToSentence(MouseActionParam[mouseAction.mouseAction])
});
const content: NameValuePair[] =
[
{
name: 'Action type',
value: 'Mouse'
},
{
name: 'Action',
value: camelCaseToSentence(MouseActionParam[mouseAction.mouseAction])
}
];
return Observable.of(content);
} else if (keyAction instanceof PlayMacroAction) {
const playMacroAction: PlayMacroAction = keyAction;
content.push({
name: 'Action type',
value: 'Play macro'
});
content.push({
name: 'Macro name',
value: playMacroAction.macro.name.toString()
});
return this.store
.select(appState => appState.macros)
.map(macroState => macroState.entities.find(macro => {
return macro.id === playMacroAction.macroId;
}).name)
.map(macroName => {
const content: NameValuePair[] = [
{
name: 'Action type',
value: 'Play macro'
},
{
name: 'Macro name',
value: macroName
}
];
return content;
});
} else if (keyAction instanceof SwitchKeymapAction) {
const switchKeymapAction: SwitchKeymapAction = keyAction;
content.push({
name: 'Action type',
value: 'Switch keymap'
});
content.push({
name: 'Keymap',
value: switchKeymapAction.keymap.name
});
return this.store
.select(appState => appState.keymaps.entities)
.map(keymaps => keymaps.find(keymap => keymap.abbreviation === switchKeymapAction.keymapAbbreviation).name)
.map(keymapName => {
const content: NameValuePair[] = [
{
name: 'Action type',
value: 'Switch keymap'
},
{
name: 'Keymap',
value: keymapName
}
];
return content;
});
} else if (keyAction instanceof SwitchLayerAction) {
const switchLayerAction: SwitchLayerAction = keyAction;
content.push({
name: 'Action type',
value: 'Switch layer'
});
content.push({
name: 'Layer',
value: capitalizeFirstLetter(LayerName[switchLayerAction.layer])
});
content.push({
name: 'Toogle',
value: switchLayerAction.isLayerToggleable ? 'On' : 'Off'
});
const content: NameValuePair[] =
[
{
name: 'Action type',
value: 'Switch layer'
},
{
name: 'Layer',
value: capitalizeFirstLetter(LayerName[switchLayerAction.layer])
},
{
name: 'Toogle',
value: switchLayerAction.isLayerToggleable ? 'On' : 'Off'
}
];
return Observable.of(content);
}
this.tooltipData = {
posLeft: posLeft,
posTop: posTop,
content,
show: true
};
}
hideTooltip() {
this.tooltipData.show = false;
}
hidePopover(): void {
this.popoverShown = false;
}
selectLayer(index: number): void {
this.currentLayer = index;
return Observable.of([]);
}
}