Skip to content

Commit

Permalink
Add a context menu for cut/copy/paste #50
Browse files Browse the repository at this point in the history
  • Loading branch information
jessedp committed Jun 30, 2020
1 parent a82a935 commit 2f97e67
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions app/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export default class MenuBuilder {
process.env.DEBUG_PROD === 'true'
) {
this.setupDevelopmentEnvironment();
} else {
this.addContextMenu();
}

const template =
Expand All @@ -27,12 +29,54 @@ export default class MenuBuilder {
return menu;
}

addContextMenu() {
this.mainWindow.webContents.on('context-menu', () => {
Menu.buildFromTemplate([
{
label: 'Cut',
role: 'cut',
click: () => {
console.log('cut');
}
},
{
label: 'Copy',
role: 'copy',
click: () => {
console.log('paste');
}
},
{
label: 'Paste',
role: 'paste',
click: () => {
console.log('copy');
}
}
]).popup(this.mainWindow);
});
}

setupDevelopmentEnvironment() {
this.mainWindow.openDevTools();
this.mainWindow.webContents.on('context-menu', (e, props) => {
const { x, y } = props;

Menu.buildFromTemplate([
{
label: 'Paste',
role: 'paste',
click: () => {
console.log('copy');
}
},
{
label: 'Copy',
role: 'copy',
click: () => {
console.log('paste');
}
},
{
label: 'Inspect element',
click: () => {
Expand Down

0 comments on commit 2f97e67

Please sign in to comment.