2019-12-06 19:17:34 +01:00
|
|
|
/*
|
|
|
|
Copyright 2016 OpenMarket Ltd
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2021-05-27 15:39:26 +02:00
|
|
|
const { app, shell, Menu } = require('electron');
|
2021-04-26 15:50:18 +02:00
|
|
|
const { _t } = require('./language-helper');
|
2019-12-06 19:17:34 +01:00
|
|
|
|
2021-06-04 05:56:02 +02:00
|
|
|
const isMac = process.platform === 'darwin';
|
|
|
|
|
2021-04-26 14:58:29 +02:00
|
|
|
function buildMenuTemplate() {
|
|
|
|
// Menu template from http://electron.atom.io/docs/api/menu/, edited
|
|
|
|
const template = [
|
2019-12-06 19:17:34 +01:00
|
|
|
{
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('Edit'),
|
2021-04-26 14:58:29 +02:00
|
|
|
accelerator: 'e',
|
2019-12-06 19:17:34 +01:00
|
|
|
submenu: [
|
2021-04-26 15:14:35 +02:00
|
|
|
{
|
|
|
|
role: 'undo',
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('Undo'),
|
2021-04-26 15:14:35 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
role: 'redo',
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('Redo'),
|
2021-04-26 15:14:35 +02:00
|
|
|
},
|
2021-04-26 14:58:29 +02:00
|
|
|
{ type: 'separator' },
|
2021-04-26 15:14:35 +02:00
|
|
|
{
|
|
|
|
role: 'cut',
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('Cut'),
|
2021-04-26 15:14:35 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
role: 'copy',
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('Copy'),
|
2021-04-26 15:14:35 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
role: 'paste',
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('Paste'),
|
2021-04-26 15:14:35 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
role: 'pasteandmatchstyle',
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('Paste and Match Style'),
|
2021-04-26 15:14:35 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
role: 'delete',
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('Delete'),
|
2021-04-26 15:14:35 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
role: 'selectall',
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('Select All'),
|
2021-04-26 15:14:35 +02:00
|
|
|
},
|
2019-12-06 19:17:34 +01:00
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('View'),
|
2021-04-26 14:58:29 +02:00
|
|
|
accelerator: 'V',
|
|
|
|
submenu: [
|
|
|
|
{ type: 'separator' },
|
2021-06-05 01:08:07 +02:00
|
|
|
{
|
|
|
|
role: 'resetzoom',
|
|
|
|
accelerator: 'CmdOrCtrl+Num0',
|
|
|
|
visible: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
role: 'zoomin',
|
|
|
|
accelerator: 'CmdOrCtrl+NumAdd',
|
|
|
|
visible: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
role: 'zoomout',
|
|
|
|
accelerator: 'CmdOrCtrl+NumSub',
|
|
|
|
visible: false,
|
|
|
|
},
|
2021-04-26 15:14:35 +02:00
|
|
|
{
|
|
|
|
role: 'resetzoom',
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('Actual Size'),
|
2021-04-26 15:14:35 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
role: 'zoomin',
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('Zoom In'),
|
2021-04-26 15:14:35 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
role: 'zoomout',
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('Zoom Out'),
|
2021-04-26 15:14:35 +02:00
|
|
|
},
|
2021-04-26 14:58:29 +02:00
|
|
|
{ type: 'separator' },
|
2021-06-04 05:56:02 +02:00
|
|
|
// in macOS the Preferences menu item goes in the first menu
|
|
|
|
...(!isMac ? [{
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('Preferences'),
|
2021-04-26 14:58:29 +02:00
|
|
|
click() { global.mainWindow.webContents.send('preferences'); },
|
2021-06-04 05:56:02 +02:00
|
|
|
}] : []),
|
2021-04-26 15:14:35 +02:00
|
|
|
{
|
|
|
|
role: 'togglefullscreen',
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('Toggle Full Screen'),
|
2021-04-26 15:14:35 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
role: 'toggledevtools',
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('Toggle Developer Tools'),
|
2021-04-26 15:14:35 +02:00
|
|
|
},
|
2021-04-26 14:58:29 +02:00
|
|
|
],
|
2019-12-06 19:17:34 +01:00
|
|
|
},
|
|
|
|
{
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('Window'),
|
2021-04-26 14:58:29 +02:00
|
|
|
accelerator: 'w',
|
|
|
|
role: 'window',
|
|
|
|
submenu: [
|
2021-04-26 15:14:35 +02:00
|
|
|
{
|
|
|
|
role: 'minimize',
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('Minimize'),
|
2021-04-26 15:14:35 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
role: 'close',
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('Close'),
|
2021-04-26 15:14:35 +02:00
|
|
|
},
|
2021-04-26 14:58:29 +02:00
|
|
|
],
|
2019-12-06 19:17:34 +01:00
|
|
|
},
|
|
|
|
{
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('Help'),
|
2021-04-26 14:58:29 +02:00
|
|
|
accelerator: 'h',
|
|
|
|
role: 'help',
|
|
|
|
submenu: [
|
|
|
|
{
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('Element Help'),
|
2021-04-26 14:58:29 +02:00
|
|
|
click() { shell.openExternal('https://element.io/help'); },
|
|
|
|
},
|
|
|
|
],
|
2019-12-06 19:17:34 +01:00
|
|
|
},
|
|
|
|
];
|
2021-04-26 14:58:29 +02:00
|
|
|
|
|
|
|
// macOS has specific menu conventions...
|
2021-06-04 05:56:02 +02:00
|
|
|
if (isMac) {
|
2021-04-26 14:58:29 +02:00
|
|
|
template.unshift({
|
|
|
|
// first macOS menu is the name of the app
|
2021-04-26 18:12:13 +02:00
|
|
|
role: 'appMenu',
|
2021-04-26 14:58:29 +02:00
|
|
|
label: app.name,
|
|
|
|
submenu: [
|
2021-04-26 15:14:35 +02:00
|
|
|
{
|
|
|
|
role: 'about',
|
2021-06-04 06:07:19 +02:00
|
|
|
label: _t('About') + ' ' + app.name,
|
2021-04-26 15:14:35 +02:00
|
|
|
},
|
2021-04-26 14:58:29 +02:00
|
|
|
{ type: 'separator' },
|
2021-06-04 05:56:02 +02:00
|
|
|
{
|
2021-06-04 06:07:19 +02:00
|
|
|
label: _t('Preferences') + '…',
|
2021-06-04 05:56:02 +02:00
|
|
|
accelerator: 'Command+,', // Mac-only accelerator
|
|
|
|
click() { global.mainWindow.webContents.send('preferences'); },
|
2021-04-26 15:14:35 +02:00
|
|
|
},
|
2021-04-26 14:58:29 +02:00
|
|
|
{ type: 'separator' },
|
|
|
|
{
|
|
|
|
role: 'services',
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('Services'),
|
2021-04-26 14:58:29 +02:00
|
|
|
submenu: [],
|
|
|
|
},
|
|
|
|
{ type: 'separator' },
|
2021-04-26 15:14:35 +02:00
|
|
|
{
|
|
|
|
role: 'hide',
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('Hide'),
|
2021-04-26 15:14:35 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
role: 'hideothers',
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('Hide Others'),
|
2021-04-26 15:14:35 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
role: 'unhide',
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('Unhide'),
|
2021-04-26 15:14:35 +02:00
|
|
|
},
|
2021-04-26 14:58:29 +02:00
|
|
|
{ type: 'separator' },
|
2021-04-26 15:14:35 +02:00
|
|
|
{
|
|
|
|
role: 'quit',
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('Quit'),
|
2021-04-26 15:14:35 +02:00
|
|
|
},
|
2021-04-26 14:58:29 +02:00
|
|
|
],
|
|
|
|
});
|
|
|
|
// Edit menu.
|
|
|
|
// This has a 'speech' section on macOS
|
|
|
|
template[1].submenu.push(
|
|
|
|
{ type: 'separator' },
|
|
|
|
{
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('Speech'),
|
2021-04-26 14:58:29 +02:00
|
|
|
submenu: [
|
2021-04-26 15:14:35 +02:00
|
|
|
{
|
|
|
|
role: 'startspeaking',
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('Start Speaking'),
|
2021-04-26 15:14:35 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
role: 'stopspeaking',
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('Stop Speaking'),
|
2021-04-26 15:14:35 +02:00
|
|
|
},
|
2021-04-26 14:58:29 +02:00
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
// Window menu.
|
|
|
|
// This also has specific functionality on macOS
|
|
|
|
template[3].submenu = [
|
|
|
|
{
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('Close'),
|
2021-04-26 14:58:29 +02:00
|
|
|
accelerator: 'CmdOrCtrl+W',
|
|
|
|
role: 'close',
|
|
|
|
},
|
|
|
|
{
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('Minimize'),
|
2021-04-26 14:58:29 +02:00
|
|
|
accelerator: 'CmdOrCtrl+M',
|
|
|
|
role: 'minimize',
|
|
|
|
},
|
|
|
|
{
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('Zoom'),
|
2021-04-26 14:58:29 +02:00
|
|
|
role: 'zoom',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'separator',
|
|
|
|
},
|
|
|
|
{
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('Bring All to Front'),
|
2021-04-26 14:58:29 +02:00
|
|
|
role: 'front',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
template.unshift({
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('File'),
|
2021-04-26 14:58:29 +02:00
|
|
|
accelerator: 'f',
|
|
|
|
submenu: [
|
|
|
|
// For some reason, 'about' does not seem to work on windows.
|
|
|
|
/*{
|
2021-04-26 15:14:35 +02:00
|
|
|
role: 'about',
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('About'),
|
2021-04-26 14:58:29 +02:00
|
|
|
},*/
|
2021-04-26 15:14:35 +02:00
|
|
|
{
|
|
|
|
role: 'quit',
|
2021-04-26 15:50:18 +02:00
|
|
|
label: _t('Quit'),
|
2021-04-26 15:14:35 +02:00
|
|
|
},
|
2021-04-26 14:58:29 +02:00
|
|
|
],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return Menu.buildFromTemplate(template);
|
2019-12-06 19:17:34 +01:00
|
|
|
}
|
|
|
|
|
2021-04-26 14:58:29 +02:00
|
|
|
module.exports = buildMenuTemplate;
|
2019-12-06 19:17:34 +01:00
|
|
|
|