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 (
Editor
this.handleConfigKeyDown(e)} type='text'/>
this.handleConfigKeyDown(e)} type='text'/>
type size
Preview
this.handleConfigKeyDown(e)} type='text'/>
this.handleConfigKeyDown(e)} type='text'/>
{ global.process.platform === 'win32' ? (
) : null }
Theme
Hotkey
this.handleKeyDown(e)} valueLink={this.linkState('keymap.toggleMain')} type='text'/>
this.handleKeyDown(e)} valueLink={this.linkState('keymap.toggleFinder')} type='text'/>
{keymapAlertElement}
  • 0 to 9
  • A to Z
  • F1 to F24
  • Punctuations like ~, !, @, #, $, 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
) } } AppSettingTab.propTypes = { user: PropTypes.shape({ name: PropTypes.string }), dispatch: PropTypes.func }