| 2 | import React from 'react'; |
| 3 | |
| 4 | export default class InputService extends React.Component { |
| 5 | constructor(props) { |
| 6 | super(props); |
| 7 | this.state = {}; |
| 8 | } |
| 9 | |
| 10 | |
| 11 | componentWillMount() { |
| 12 | document.addEventListener("keydown", this.handleKey.bind(this)); |
| 13 | document.addEventListener("keyup", this.handleKeyUp.bind(this)); |
| 14 | } |
| 15 | |
| 16 | componentWillUnmount() { |
| 17 | document.removeEventListener("keydown", this.handleKey.bind(this)); |
| 18 | document.removeEventListener("keyup", this.handleKeyUp.bind(this)); |
| 19 | } |
| 20 | |
| 21 | handleKey(event) { |
| 22 | window.service.keysPressed[event.key]=1; |
| 23 | |
| 24 | if(this.isKeyPressed("Control")) |
| 25 | { |
| 26 | if(event.key == 's'){ |
| 27 | if(window.service.project!=null) |
| 28 | window.service.menuUI.saveProjectClicked(); |
| 29 | } |
| 30 | |
| 31 | if(event.key == 'c' && document.activeElement.id=="body"){ |
| 32 | if(window.service.project!=null) |
| 33 | window.service.copySelection(); |
| 34 | } |
| 35 | |
| 36 | if(event.key == 'v' && document.activeElement.id=="body"){ |
| 37 | if(window.service.project!=null) |
| 38 | window.service.pasteSelection(); |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | handleKeyUp(event) |
| 44 | { |
| 45 | window.service.keysPressed[event.key]=0; |
| 46 | |
| 47 | if(document.activeElement!=null && document.activeElement.id=="body") |
| 48 | { |
| 49 | if(event.key == 'Delete'){ |
| 50 | if(window.service.selectedObject!=null) |
| 51 | { |
| 52 | window.service.sceneUI.findAndDeleteRecursive(null); |
| 53 | |
| 54 | for (let i in window.service.selectedObjects) |
| 55 | { |
| 56 | window.service.sceneUI.findAndDeleteRecursive2(null, window.service.selectedObjects[i]); |
| 57 | } |
| 58 | |
| 59 | window.service.selectedObjects = {}; |
| 60 | } |
| 61 | window.service.hierarchyUI.selectObject(null); |
nothing calls this directly
no outgoing calls
no test coverage detected