import PropTypes from 'prop-types' import React from 'react' import CSSModules from 'browser/lib/CSSModules' import styles from './ConfigTab.styl' import ConfigManager from 'browser/main/lib/ConfigManager' import { store } from 'browser/main/store' import _ from 'lodash' import i18n from 'browser/lib/i18n' const electron = require('electron') const ipc = electron.ipcRenderer class HotkeyTab extends React.Component { constructor(props) { super(props) this.state = { isHotkeyHintOpen: false, config: props.config } } componentDidMount() { this.handleSettingDone = () => { this.setState({ keymapAlert: { type: 'success', message: i18n.__('Successfully applied!') } }) } this.handleSettingError = err => { if ( this.state.config.hotkey.toggleMain === '' || this.state.config.hotkey.toggleMode === '' || this.state.config.hotkey.toggleDirection === '' ) { this.setState({ keymapAlert: { type: 'success', message: i18n.__('Successfully applied!') } }) } else { this.setState({ keymapAlert: { type: 'error', message: err.message != null ? err.message : i18n.__('An error occurred!') } }) } } this.oldHotkey = this.state.config.hotkey ipc.addListener('APP_SETTING_DONE', this.handleSettingDone) ipc.addListener('APP_SETTING_ERROR', this.handleSettingError) } componentWillUnmount() { ipc.removeListener('APP_SETTING_DONE', this.handleSettingDone) ipc.removeListener('APP_SETTING_ERROR', this.handleSettingError) } handleSaveButtonClick(e) { const newConfig = { hotkey: this.state.config.hotkey } ConfigManager.set(newConfig) store.dispatch({ type: 'SET_UI', config: newConfig }) this.clearMessage() this.props.haveToSave() } handleHintToggleButtonClick(e) { this.setState({ isHotkeyHintOpen: !this.state.isHotkeyHintOpen }) } handleHotkeyChange(e) { const { config } = this.state config.hotkey = Object.assign({}, config.hotkey, { toggleMain: this.refs.toggleMain.value, toggleMode: this.refs.toggleMode.value, toggleDirection: this.refs.toggleDirection.value, deleteNote: this.refs.deleteNote.value, pasteSmartly: this.refs.pasteSmartly.value, prettifyMarkdown: this.refs.prettifyMarkdown.value, toggleMenuBar: this.refs.toggleMenuBar.value, insertDate: this.refs.insertDate.value, insertDateTime: this.refs.insertDateTime.value }) this.setState({ config }) if (_.isEqual(this.oldHotkey, config.hotkey)) { this.props.haveToSave() } else { this.props.haveToSave({ tab: 'Hotkey', type: 'warning', message: i18n.__('Unsaved Changes!') }) } } clearMessage() { _.debounce(() => { this.setState({ keymapAlert: null }) }, 2000)() } render() { const keymapAlert = this.state.keymapAlert const keymapAlertElement = keymapAlert != null ? (
{keymapAlert.message}
) : null const { config } = this.state return ({i18n.__('Available Keys')}
0 to 9
A to Z
F1 to F24
~, !,{' '}
@, #, $, etc.
Plus
Space
Backspace
Delete
Insert
Return (or Enter as alias)
Up, Down, Left and{' '}
Right
Home and End
PageUp and PageDown
Escape (or Esc for short)
VolumeUp, VolumeDown and{' '}
VolumeMute
MediaNextTrack, MediaPreviousTrack,{' '}
MediaStop and MediaPlayPause
Control (or Ctrl for short)
Shift