import React, { PropTypes } from 'react' import fetchConfig from 'browser/lib/fetchConfig' import hljsTheme from 'browser/lib/hljsThemes' const electron = require('electron') const ipc = electron.ipcRenderer const remote = electron.remote const ace = window.ace const OSX = global.process.platform === 'darwin' export default class AppSettingTab extends React.Component { constructor (props) { super(props) let keymap = Object.assign({}, remote.getGlobal('keymap')) let config = Object.assign({}, fetchConfig()) let userName = props.user != null ? props.user.name : null this.state = { user: { name: userName, alert: null }, userAlert: null, keymap: keymap, keymapAlert: null, config: config, configAlert: null } } componentDidMount () { this.handleSettingDone = () => { this.setState({keymapAlert: { type: 'success', message: 'Successfully done!' }}) } this.handleSettingError = (err) => { this.setState({keymapAlert: { type: 'error', message: err.message != null ? err.message : 'Error occurs!' }}) } 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) } submitHotKey () { ipc.send('hotkeyUpdated', this.state.keymap) } submitConfig () { ipc.send('configUpdated', this.state.config) } handleSaveButtonClick (e) { this.submitHotKey() } handleConfigSaveButtonClick (e) { this.submitConfig() } handleKeyDown (e) { if (e.keyCode === 13) { this.submitHotKey() } } handleConfigKeyDown (e) { if (e.keyCode === 13) { this.submitConfig() } } handleLineNumberingClick (e) { let config = this.state.config config['preview-line-number'] = e.target.checked this.setState({ config }) } handleDisableDirectWriteClick (e) { let config = this.state.config config['disable-direct-write'] = e.target.checked this.setState({ config }) } render () { let keymapAlert = this.state.keymapAlert let keymapAlertElement = keymapAlert != null ?
{keymapAlert.message}
: null let aceThemeList = ace.require('ace/ext/themelist') let hljsThemeList = hljsTheme() return (0 to 9A to ZF1 to F24~, !, @, #, $, etc.PlusSpaceBackspaceDeleteInsertReturn (or Enter as alias)Up, Down, Left and RightHome and EndPageUp and PageDownEscape (or Esc for short)VolumeUp, VolumeDown and VolumeMuteMediaNextTrack, MediaPreviousTrack, MediaStop and MediaPlayPause