docs: add Menu
module tutorials (#47761)
* 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 Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Erick Zhao <ezhao@slack-corp.com>
This commit is contained in:
parent
e2689400aa
commit
280f643862
39 changed files with 1240 additions and 1472 deletions
46
docs/fiddles/menus/dock-menu/main.js
Normal file
46
docs/fiddles/menus/dock-menu/main.js
Normal file
|
@ -0,0 +1,46 @@
|
|||
const { app, BrowserWindow, Menu } = require('electron/main')
|
||||
const { shell } = require('electron/common')
|
||||
|
||||
function createWindow () {
|
||||
const win = new BrowserWindow()
|
||||
win.loadFile('index.html')
|
||||
}
|
||||
|
||||
function closeAllWindows () {
|
||||
const wins = BrowserWindow.getAllWindows()
|
||||
for (const win of wins) {
|
||||
win.close()
|
||||
}
|
||||
}
|
||||
|
||||
app.whenReady().then(() => {
|
||||
createWindow()
|
||||
|
||||
const dockMenu = Menu.buildFromTemplate([
|
||||
{
|
||||
label: 'New Window',
|
||||
click: () => { createWindow() }
|
||||
},
|
||||
{
|
||||
label: 'Close All Windows',
|
||||
click: () => { closeAllWindows() }
|
||||
},
|
||||
{
|
||||
label: 'Open Electron Docs',
|
||||
click: () => {
|
||||
shell.openExternal('https://electronjs.org/docs')
|
||||
}
|
||||
}
|
||||
// add more menu options to the array
|
||||
])
|
||||
|
||||
app.dock.setMenu(dockMenu)
|
||||
|
||||
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