本文整理汇总了TypeScript中electron.Menu.append方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Menu.append方法的具体用法?TypeScript Menu.append怎么用?TypeScript Menu.append使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类electron.Menu
的用法示例。
在下文中一共展示了Menu.append方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
session.plugins.getAllPlugins().forEach(plugin => {
var subMenuItem = new Electron.MenuItem({
label: plugin.pluginName,
click: () => {
plugin.showDevTools();
}});
subMenu.append(subMenuItem);
});
示例2: Menu
(event: Electron.IpcMessageEvent, items: ReadonlyArray<any>) => {
const menu = new Menu()
const menuItems = items.map((item, i) => {
return new MenuItem({
label: item.label,
click: () => event.sender.send('contextual-menu-action', i),
type: item.type,
enabled: item.enabled,
})
})
for (const item of menuItems) {
menu.append(item)
}
const window = BrowserWindow.fromWebContents(event.sender)
menu.popup(window, { async: true })
}
示例3: Menu
(event: Electron.IpcMessageEvent, items: ReadonlyArray<any>) => {
const menu = new Menu()
const menuItems = items.map((item, i) => {
return new MenuItem({
label: item.label,
click: () => event.sender.send('contextual-menu-action', i),
type: item.type,
enabled: item.enabled,
})
})
for (const item of menuItems) {
menu.append(item)
}
const window = BrowserWindow.fromWebContents(event.sender)
// TODO: read https://github.com/desktop/desktop/issues/1003
// to clean up this sin against T Y P E S
const anyMenu: any = menu
anyMenu.popup(window, { async: true })
}
示例4: _rebuildContextMenu
private _rebuildContextMenu(): void {
var contextMenu = new Electron.Menu();
this._sessionManager.getSessions()
.forEach((session) => {
var subMenu = new Electron.Menu();
session.plugins.getAllPlugins().forEach(plugin => {
var subMenuItem = new Electron.MenuItem({
label: plugin.pluginName,
click: () => {
plugin.showDevTools();
}});
subMenu.append(subMenuItem);
});
var sessionItem = new Electron.MenuItem({
label: session.name,
submenu: subMenu
});
contextMenu.append(sessionItem);
});
var menuItem = new Electron.MenuItem({
label: "Quit",
click: () => {
Electron.app.quit();
}
});
contextMenu.append(menuItem);
this._trayMenu.setToolTip('This is my application.');
this._trayMenu.setContextMenu(contextMenu);
}
示例5: createMenu
function createMenu(): Electron.Menu {
let main = new Menu();
let scheduleMenu = new Menu();
let newSchedule = new MenuItem({
label: 'New',
accelerator: 'CmdOrCtrl+N',
click(item, focusedWindow) { createNewSchedule(); }
});
scheduleMenu.append(newSchedule);
let open = new MenuItem({
label: 'Open',
accelerator: 'CmdOrCtrl+O',
click(item, focusedWindow) { openScheduleFileDialog(); }
});
scheduleMenu.append(open);
let merge = new MenuItem({
label: 'Merge',
accelerator: 'CmdOrCtrl+M',
click(item, focusedWindow) {
if (focusedWindow) {
dialog.showOpenDialog(focusedWindow, {
filters: [{ name: 'Schedules', extensions: ['json']}],
properties: ['openFile'],
}, (filenames: string[]) => {
if (filenames && filenames[0]) {
fs.readFile(filenames[0], 'utf8', (err, data) => {
if (err) throw err;
let new_schedule: Schedule = JSON.parse(data);
getCurrentSchedule((schedule) => {
schedule.series = schedule.series.concat(new_schedule.series);
mainWindow.webContents.send('open-schedule', schedule);
});
});
}
});
}
}
});
scheduleMenu.append(merge);
save = new MenuItem({
label: 'Save',
enabled: false,
accelerator: 'CmdOrCtrl+S',
click(item, focusedWindow) {
if (focusedWindow) {
getCurrentSchedule((schedule) => {
if (currentFile) {
fs.writeFile(currentFile, JSON.stringify(schedule, null, 2), 'utf8', (err) => {
if (err) throw err;
});
}
});
}
}
});
scheduleMenu.append(save);
let saveAs = new MenuItem({
label: 'Save As...',
accelerator: 'CmdOrCtrl+Shift+S',
click(item, focusedWindow) {
if (focusedWindow) {
getCurrentSchedule((schedule) => {
dialog.showSaveDialog(focusedWindow, {
filters: [{ name: 'Schedules', extensions: ['json']}],
}, (filename: string) => {
if (filename) {
fs.writeFile(filename, JSON.stringify(schedule, null, 2), 'utf8', (err) => {
if (err) throw err;
});
}
});
});
}
}
});
scheduleMenu.append(saveAs);
main.append(new MenuItem({
label: 'Schedule',
submenu: scheduleMenu
}));
let generateMenu = new Menu();
let posterWrapper = (window: Electron.BrowserWindow, month: number) => {
dialog.showSaveDialog(window, {
filters: [{ name: 'PDF', extensions: ['pdf']}],
}, (filename: string) => {
if (filename) {
renderPoster(filename, month);
}
});
};
let poster = new MenuItem({
label: 'Poster',
submenu: [
{
label: 'August', accelerator: 'F8',
click(item, focusedWindow) { posterWrapper(focusedWindow, 7); }
},
{
label: 'September', accelerator: 'F9',
click(item, focusedWindow) { posterWrapper(focusedWindow, 8); }
//.........这里部分代码省略.........