本文整理汇总了TypeScript中electron.Menu类的典型用法代码示例。如果您正苦于以下问题:TypeScript Menu类的具体用法?TypeScript Menu怎么用?TypeScript Menu使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Menu类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Tray
app.on("ready", () => {
// window
MainWindow.getInstance().show()
// tray
const tray = new Tray(`${__dirname}/images/icon.png`)
const menu = Menu.buildFromTemplate([
{label: "Setting", click: () => SettingWindow.getInstance().show()},
{label: "Quit", click: () => app.quit()},
])
tray.setToolTip(app.getName())
tray.setContextMenu(menu)
// menu
Menu.setApplicationMenu(Menu.buildFromTemplate([{
label: "Application",
submenu: [
{ label: "About Application", selector: "orderFrontStandardAboutPanel:" },
{ type: "separator" },
{ label: "Quit", accelerator: "Command+Q", click: () => app.quit() },
]}, {
label: "Edit",
submenu: [
{ label: "Undo", accelerator: "CmdOrCtrl+Z", selector: "undo:" },
{ label: "Redo", accelerator: "Shift+CmdOrCtrl+Z", selector: "redo:" },
{ type: "separator" },
{ label: "Cut", accelerator: "CmdOrCtrl+X", selector: "cut:" },
{ label: "Copy", accelerator: "CmdOrCtrl+C", selector: "copy:" },
{ label: "Paste", accelerator: "CmdOrCtrl+V", selector: "paste:" },
{ label: "Select All", accelerator: "CmdOrCtrl+A", selector: "selectAll:" },
]},
]))
})
示例2:
const setApplicationMenu = () => {
const menus = [editMenuTemplate];
if (env.name !== 'production') {
menus.push(devMenuTemplate);
}
Menu.setApplicationMenu(Menu.buildFromTemplate(menus));
};
示例3: createWindow
export function createWindow() {
const electronScreen = screen;
const size = electronScreen.getPrimaryDisplay().workAreaSize;
// Create the browser window.
win = new BrowserWindow({
width: 1200,
height: 900,
title: pkg.productName,
icon: path.join(__dirname, '../resources/icon.png')
});
Menu.setApplicationMenu(Menu.buildFromTemplate(menuTemplate));
// and load the index.html of the app.
win.loadURL(`file://${__dirname}/index.html`);
// Emitted when the window is closed.
win.on('closed', () => {
// Dereference the window object, usually you would store window
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win = null;
});
}
示例4: registerShortcuts
const __refreshMenu = _.debounce(function () {
Menu.setApplicationMenu(Menu.buildFromTemplate(_.cloneDeep(menuTemplate)));
globalShortcut.unregisterAll();
const mainWindow = shell.getMainWindow();
if (mainWindow.isFocused()) {
menuTemplate.forEach((menuItem) => registerShortcuts(menuItem));
}
}, 100);
示例5: function
var setApplicationMenu = function () {
var menus :Electron.MenuItemOptions[];
menus = [editMenuTemplate];
if (env.name !== 'production') {
menus.push(devMenuTemplate);
}
Menu.setApplicationMenu(Menu.buildFromTemplate(menus));
};
示例6: function
const setMenu = (mainWindow: MainWindow) => {
const buildedMenu = Menu.buildFromTemplate([
{
label: 'File',
submenu: [
{ label: 'New File', accelerator: 'Command+N', click: () => {
FileManager.getInstance().resetFile();
}},
{ label: 'Open...' , accelerator: 'Command+O', click: () => {
FileManager.getInstance().openFile();
}},
{ type: 'separator' },
{ label: 'Save', accelerator: 'Command+S', click: () => {
FileManager.getInstance().saveFile();
}},
{ label: 'Save As...', click: () => {
FileManager.getInstance().saveAsNewFile();
}},
{ type: 'separator' },
{ label: 'Export To PDF', click: () => {
ExportWindow.getInstance().createWindow(MainWindow.getInstance().getText());
}},
{ type: 'separator' },
{ label: 'Quit', accelerator: 'Command+Q', click: () => app.quit() }
]
},
{
label: 'Edit',
submenu: [
{ label: 'Undo', accelerator: 'CmdOrCtrl+Z', selector: 'undo:' },
{ label: 'Redo', accelerator: 'Shift+CmdOrCtrl+Z', selector: 'redo:' },
{ type: 'separator' },
{ label: 'Cut', accelerator: 'CmdOrCtrl+X', selector: 'cut:' },
{ label: 'Copy', accelerator: 'CmdOrCtrl+C', selector: 'copy:' },
{ label: 'Paste', accelerator: 'CmdOrCtrl+V', selector: 'paste:' },
{ label: 'Select All', accelerator: 'CmdOrCtrl+A', selector: 'selectAll:' }
]
},
{
label: 'Play',
submenu: [
{ label: 'Play Slideshow', accelerator: 'Command+P', click: () => PresentationWindow.getInstance().createWindow() }
]
},
{
label: 'View',
submenu: [
{
label: 'Toggle Developer Tools',
accelerator: 'Alt+Command+I',
click: function() { mainWindow.getBrowserWindow().webContents.toggleDevTools(); }
}
]
}
]);
Menu.setApplicationMenu(buildedMenu);
};
示例7: registerShortcuts
const __refreshMenu = _.debounce(function () {
Menu.setApplicationMenu(Menu.buildFromTemplate(_.cloneDeep(menuTemplate)));
const mainWindow = shell.getMainWindow();
if (mainWindow.isFocused()) {
currentShortcuts = {};
menuTemplate.forEach((menuItem) => registerShortcuts(mainWindow, menuItem));
mainWindow.webContents.send("updateShortcuts", JSON.stringify(currentShortcuts));
}
}, 100);
示例8: buildMenu
export function buildMenu() {
let menuItems: Electron.MenuItemConstructorOptions[] = [];
if (process.platform === "win32") {
// サービスをinjectionするようになったらnewはしないけども。
menuItems = new DefaultMenu().build();
}
const menu = Menu.buildFromTemplate(menuItems);
Menu.setApplicationMenu(menu);
}
示例9: addMenuItemClickConnector
socket.on('menu-setApplicationMenu', (menuItems) => {
const menu = Menu.buildFromTemplate(menuItems);
addMenuItemClickConnector(menu.items, (id) => {
socket.emit("menuItemClicked", id);
});
Menu.setApplicationMenu(menu);
});
示例10: build
export function build(mainWin: Electron.BrowserWindow, cfg: config.Config) {
const template = [{
label: 'Menu',
id: 'menu',
submenu: [
{
label: 'Reload',
click: () => mainWin.reload(),
},
{
label: 'Toggle DevTools',
click: () => mainWin.webContents.toggleDevTools(),
},
{
type: 'separator'
},
{
label: 'Quit',
click: () => mainWin.close(),
}
]
},
{
label: 'Thema',
id: 'thema',
submenu: [
{
label: 'Normal',
id: 'thema-normal',
type: 'checkbox',
checked: (cfg.thema == 'thema-normal'),
click: () => {
mainWin.webContents.executeJavaScript("changeThema('thema-normal')")
}
},
{
label: 'Dark',
id: 'thema-dark',
type: 'checkbox',
checked: (cfg.thema == 'thema-dark'),
click: () => {
mainWin.webContents.executeJavaScript("changeThema('thema-dark')")
}
}
]
}];
const menu = electron.Menu.buildFromTemplate(template);
electron.Menu.setApplicationMenu(menu);
return menu;
};