-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwindow-button.js
48 lines (42 loc) · 1.24 KB
/
window-button.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { Component } from 'react'
import { Base } from 'pulse-editor/buttons'
import { ipcRenderer } from 'electron'
import { func } from 'prop-types'
import isMac from 'pulse-editor/built/utils/is-mac'
import Icon from 'react-icons/lib/fa/plus-circle'
export default class CreateButton extends Component {
static contextTypes = {
setShortcut: func.isRequired,
removeShortcut: func.isRequired,
writeValue: func.isRequired,
setFileName: func.isRequired
}
componentDidMount () {
ipcRenderer.on('shortcut-press', this.createWindow)
this.context.setShortcut({
ctrlKey: !isMac(),
metaKey: isMac(),
altKey: true,
shiftKey: false,
keyName: 'n',
updater: selected => selected,
handler: event => {
this.createWindow()
return event.selection
}
})
}
componentWillUnmount () {
this.context.removeShortcut({ keyName: 'n' })
ipcRenderer.removeListener('shortcut-press', this.createWindow)
}
createWindow = () => ipcRenderer.send('create-new-window')
handleClick = () => this.createWindow()
render = () => (
<Base onClick={this.handleClick} name='open'>
<span title='New Window [CMD+ALT+N]'>
<Icon /> New Window
</span>
</Base>
)
}