signal-desktop/app/menu.js
Vangelis c0c4730bad Added top level menu shortcuts, pull labels from messages.json (#1702)
* Added top level menu shortcuts (Fixes #1688 and #1695).

The ampersand (&) character in front of a letter in a menu label
indicates that the letter that follows '&' will be used as a keyboard
shortcut letter to access this menu. In Windows/Linux, the default
shortcut combination is Alt+<letter>.

* Use non-hardcoded menu labels.

The menu labels were hardcoded in English.
We should not be using plain strings right in the source code, but
pulling them from the `messages.json` files instead.
2017-11-07 15:14:20 -08:00

214 lines
3.7 KiB
JavaScript

function createTemplate(options, messages) {
const showDebugLog = options.showDebugLog;
const showAbout = options.showAbout;
const openReleaseNotes = options.openReleaseNotes;
const openNewBugForm = options.openNewBugForm;
const openSupportPage = options.openSupportPage;
const openForums = options.openForums;
let template = [{
label: messages.mainMenuFile.message,
submenu: [
{
role: 'quit',
},
]
},
{
label: messages.mainMenuEdit.message,
submenu: [
{
role: 'undo',
},
{
role: 'redo',
},
{
type: 'separator',
},
{
role: 'cut',
},
{
role: 'copy',
},
{
role: 'paste',
},
{
role: 'pasteandmatchstyle',
},
{
role: 'delete',
},
{
role: 'selectall',
}
]
},
{
label: messages.mainMenuView.message,
submenu: [
{
role: 'resetzoom',
},
{
role: 'zoomin',
},
{
role: 'zoomout',
},
{
type: 'separator',
},
{
role: 'togglefullscreen',
},
{
type: 'separator',
},
{
label: messages.debugLog.message,
click: showDebugLog,
},
{
type: 'separator',
},
{
role: 'toggledevtools',
},
]
},
{
label: messages.mainMenuWindow.message,
role: 'window',
submenu: [
{
role: 'minimize',
},
]
},
{
label: messages.mainMenuHelp.message,
role: 'help',
submenu: [
{
label: messages.goToReleaseNotes.message,
click: openReleaseNotes,
},
{
type: 'separator',
},
{
label: messages.goToForums.message,
click: openForums,
},
{
label: messages.goToSupportPage.message,
click: openSupportPage,
},
{
label: messages.fileABug.message,
click: openNewBugForm,
},
{
type: 'separator',
},
{
label: messages.aboutSignalDesktop.message,
click: showAbout,
},
]
}];
if (process.platform === 'darwin') {
return updateForMac(template, messages, options);
}
return template;
}
function updateForMac(template, messages, options) {
const showWindow = options.showWindow;
const showAbout = options.showAbout;
// Remove About item and separator from Help menu, since it's on the first menu
template[4].submenu.pop();
template[4].submenu.pop();
// Replace File menu
template.shift();
template.unshift({
submenu: [
{
label: messages.aboutSignalDesktop.message,
click: showAbout,
},
{
type: 'separator',
},
{
role: 'hide',
},
{
role: 'hideothers',
},
{
role: 'unhide',
},
{
type: 'separator',
},
{
role: 'quit',
},
]
});
// Add to Edit menu
template[1].submenu.push(
{
type: 'separator'
},
{
label: messages.speech.message,
submenu: [
{
role: 'startspeaking',
},
{
role: 'stopspeaking',
},
]
}
);
// Add to Window menu
template[3].submenu = [
{
accelerator: 'CmdOrCtrl+W',
role: 'close',
},
{
accelerator: 'CmdOrCtrl+M',
role: 'minimize',
},
{
role: 'zoom',
},
{
label: messages.show.message,
click: showWindow,
},
{
type: 'separator',
},
{
role: 'front',
},
];
return template;
}
module.exports = createTemplate;