|
|
const { Menu, MenuItem } = require( 'electron' ); |
|
|
|
|
|
module.exports = function ( { view } ) { |
|
|
view.webContents.on( 'context-menu', ( event, params ) => { |
|
|
const menu = new Menu(); |
|
|
|
|
|
const copy = new MenuItem( { label: 'Copy', role: 'copy' } ); |
|
|
|
|
|
if ( ! params.isEditable ) { |
|
|
|
|
|
menu.append( copy ); |
|
|
} else { |
|
|
|
|
|
for ( const suggestion of params.dictionarySuggestions ) { |
|
|
menu.append( |
|
|
new MenuItem( { |
|
|
label: suggestion, |
|
|
click: () => view.webContents.replaceMisspelling( suggestion ), |
|
|
} ) |
|
|
); |
|
|
} |
|
|
|
|
|
|
|
|
if ( params.misspelledWord ) { |
|
|
menu.append( new MenuItem( { type: 'separator' } ) ); |
|
|
menu.append( |
|
|
new MenuItem( { |
|
|
label: 'Add to Dictionary', |
|
|
click: () => |
|
|
view.webContents.session.addWordToSpellCheckerDictionary( params.misspelledWord ), |
|
|
} ) |
|
|
); |
|
|
} |
|
|
|
|
|
|
|
|
const cut = new MenuItem( { label: 'Cut', role: 'cut' } ); |
|
|
const paste = new MenuItem( { label: 'Paste', role: 'paste' } ); |
|
|
const selectAll = new MenuItem( { label: 'Select All', role: 'selectAll' } ); |
|
|
|
|
|
const menuItems = [ selectAll, cut, copy, paste ]; |
|
|
|
|
|
if ( params && params.dictionarySuggestions && params.dictionarySuggestions.length > 0 ) { |
|
|
menu.append( new MenuItem( { type: 'separator' } ) ); |
|
|
} |
|
|
|
|
|
for ( const item of menuItems ) { |
|
|
menu.append( item ); |
|
|
} |
|
|
} |
|
|
|
|
|
menu.popup(); |
|
|
} ); |
|
|
}; |
|
|
|