docs: add Menu
module tutorials (#47268)
* docs: add `Menu` module tutorials * link API docs to new tutorials * removed unreferenced fiddles * add wording for new types * fix import sort errors * delete accelerator.md * fixes
This commit is contained in:
parent
17dba93587
commit
cc9ca4bee2
39 changed files with 1240 additions and 1472 deletions
32
docs/fiddles/menus/context-menu/web-contents/main.js
Normal file
32
docs/fiddles/menus/context-menu/web-contents/main.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
const { app, BrowserWindow, Menu } = require('electron/main')
|
||||
|
||||
function createWindow () {
|
||||
const win = new BrowserWindow()
|
||||
// highlight-start
|
||||
const menu = Menu.buildFromTemplate([
|
||||
{ role: 'copy' },
|
||||
{ role: 'cut' },
|
||||
{ role: 'paste' },
|
||||
{ role: 'selectall' }
|
||||
])
|
||||
win.webContents.on('context-menu', (_event, params) => {
|
||||
// only show the context menu if the element is editable
|
||||
if (params.isEditable) {
|
||||
menu.popup()
|
||||
}
|
||||
})
|
||||
// highlight-end
|
||||
win.loadFile('index.html')
|
||||
}
|
||||
|
||||
app.whenReady().then(() => {
|
||||
createWindow()
|
||||
|
||||
app.on('activate', function () {
|
||||
if (BrowserWindow.getAllWindows().length === 0) createWindow()
|
||||
})
|
||||
})
|
||||
|
||||
app.on('window-all-closed', function () {
|
||||
if (process.platform !== 'darwin') app.quit()
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue