mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
165 lines
5.1 KiB
JavaScript
165 lines
5.1 KiB
JavaScript
import React, { PropTypes } 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'
|
|
|
|
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: 'Successfully applied!'
|
|
}})
|
|
}
|
|
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)
|
|
}
|
|
|
|
handleSaveButtonClick (e) {
|
|
let newConfig = {
|
|
hotkey: this.state.config.hotkey
|
|
}
|
|
|
|
ConfigManager.set(newConfig)
|
|
|
|
store.dispatch({
|
|
type: 'SET_UI',
|
|
config: newConfig
|
|
})
|
|
}
|
|
|
|
handleHintToggleButtonClick (e) {
|
|
this.setState({
|
|
isHotkeyHintOpen: !this.state.isHotkeyHintOpen
|
|
})
|
|
}
|
|
|
|
handleHotkeyChange (e) {
|
|
let { config } = this.state
|
|
config.hotkey = {
|
|
toggleFinder: this.refs.toggleFinder.value,
|
|
toggleMain: this.refs.toggleMain.value
|
|
}
|
|
this.setState({
|
|
config
|
|
})
|
|
}
|
|
|
|
componentDidUpdate () {
|
|
setTimeout(() => {
|
|
this.setState({
|
|
keymapAlert: null
|
|
})
|
|
}, 2500)
|
|
}
|
|
|
|
render () {
|
|
let keymapAlert = this.state.keymapAlert
|
|
let keymapAlertElement = keymapAlert != null
|
|
? <p className={`alert ${keymapAlert.type}`}>
|
|
{keymapAlert.message}
|
|
</p>
|
|
: null
|
|
let { config } = this.state
|
|
|
|
return (
|
|
<div styleName='root'>
|
|
<div styleName='group'>
|
|
<div styleName='group-header'>Hotkey</div>
|
|
<div styleName='group-section'>
|
|
<div styleName='group-section-label'>Toggle Main</div>
|
|
<div styleName='group-section-control'>
|
|
<input styleName='group-section-control-input'
|
|
onChange={(e) => this.handleHotkeyChange(e)}
|
|
ref='toggleMain'
|
|
value={config.hotkey.toggleMain}
|
|
type='text'
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div styleName='group-section'>
|
|
<div styleName='group-section-label'>Toggle Finder (Quick search)</div>
|
|
<div styleName='group-section-control'>
|
|
<input styleName='group-section-control-input'
|
|
onChange={(e) => this.handleHotkeyChange(e)}
|
|
ref='toggleFinder'
|
|
value={config.hotkey.toggleFinder}
|
|
type='text'
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div styleName='group-control'>
|
|
<button styleName='group-control-leftButton'
|
|
onClick={(e) => this.handleHintToggleButtonClick(e)}
|
|
>
|
|
{this.state.isHotkeyHintOpen
|
|
? 'Hide Hint'
|
|
: 'Hint?'
|
|
}
|
|
</button>
|
|
<button styleName='group-control-rightButton'
|
|
onClick={(e) => this.handleSaveButtonClick(e)}>Save
|
|
</button>
|
|
{keymapAlertElement}
|
|
</div>
|
|
{this.state.isHotkeyHintOpen &&
|
|
<div styleName='group-hint'>
|
|
<p>Available Keys</p>
|
|
<ul>
|
|
<li><code>0</code> to <code>9</code></li>
|
|
<li><code>A</code> to <code>Z</code></li>
|
|
<li><code>F1</code> to <code>F24</code></li>
|
|
<li>Punctuations like <code>~</code>, <code>!</code>, <code>@</code>, <code>#</code>, <code>$</code>, etc.</li>
|
|
<li><code>Plus</code></li>
|
|
<li><code>Space</code></li>
|
|
<li><code>Backspace</code></li>
|
|
<li><code>Delete</code></li>
|
|
<li><code>Insert</code></li>
|
|
<li><code>Return</code> (or <code>Enter</code> as alias)</li>
|
|
<li><code>Up</code>, <code>Down</code>, <code>Left</code> and <code>Right</code></li>
|
|
<li><code>Home</code> and <code>End</code></li>
|
|
<li><code>PageUp</code> and <code>PageDown</code></li>
|
|
<li><code>Escape</code> (or <code>Esc</code> for short)</li>
|
|
<li><code>VolumeUp</code>, <code>VolumeDown</code> and <code>VolumeMute</code></li>
|
|
<li><code>MediaNextTrack</code>, <code>MediaPreviousTrack</code>, <code>MediaStop</code> and <code>MediaPlayPause</code></li>
|
|
<li><code>Control</code> (or <code>Ctrl</code> for short)</li>
|
|
<li><code>Shift</code></li>
|
|
</ul>
|
|
</div>
|
|
}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
}
|
|
|
|
HotkeyTab.propTypes = {
|
|
dispatch: PropTypes.func
|
|
}
|
|
|
|
export default CSSModules(HotkeyTab, styles)
|