Skip to content

Commit

Permalink
A native context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
felixrieseberg committed Aug 31, 2017
1 parent c199638 commit 7aa7fc8
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/renderer/renderer.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,45 @@
const loadMonaco = require('monaco-loader')
const { remote } = require('electron')
const { Menu, app } = remote

loadMonaco().then((monaco) => {
const element = document.querySelector('#container')
const options = {
language: 'javascript',
theme: 'vs-dark',
automaticLayout: true
automaticLayout: true,
// We'll make our own
contextmenu: false
}

const editor = monaco.editor.create(element, options)

// Context menu
const template = [
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
{
label: 'Minimize Window',
click (item, browserWindow, event) {
browserWindow.minimize()
}
},
{
type: 'separator'
},
{
label: 'Quit',
click () {
app.quit()
}
}
]

const menu = Menu.buildFromTemplate(template)

window.addEventListener('contextmenu', (e) => {
e.preventDefault()
menu.popup(remote.getCurrentWindow())
}, false)
})

0 comments on commit 7aa7fc8

Please sign in to comment.