Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS: make the menu more like a macOS menu #1348

Merged
merged 4 commits into from
Apr 1, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
260 changes: 169 additions & 91 deletions ElectronClient/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ class Application extends BaseApplication {

const importItems = [];
const exportItems = [];
const preferencesItems = [];
const toolsItemsFirst = [];
const ioService = new InteropService();
const ioModules = ioService.modules();
for (let i = 0; i < ioModules.length; i++) {
Expand Down Expand Up @@ -385,49 +387,161 @@ class Application extends BaseApplication {
}
});

/* We need a dummy entry, otherwise the ternary operator to show a
* menu item only on a specific OS does not work. */
const noItem = {
type: 'separator',
visible: false
}

const syncStatusItem = {
label: _('Synchronisation status'),
click: () => {
this.dispatch({
type: 'NAV_GO',
routeName: 'Status',
});
}
}

const newNoteItem = {
label: _('New note'),
accelerator: 'CommandOrControl+N',
screens: ['Main'],
click: () => {
this.dispatch({
type: 'WINDOW_COMMAND',
name: 'newNote',
});
}
}

const newTodoItem = {
label: _('New to-do'),
accelerator: 'CommandOrControl+T',
screens: ['Main'],
click: () => {
this.dispatch({
type: 'WINDOW_COMMAND',
name: 'newTodo',
});
}
}

const newNotebookItem = {
label: _('New notebook'),
screens: ['Main'],
click: () => {
this.dispatch({
type: 'WINDOW_COMMAND',
name: 'newNotebook',
});
}
}

const printItem = {
label: _('Print'),
accelerator: 'CommandOrControl+P',
screens: ['Main'],
click: () => {
this.dispatch({
type: 'WINDOW_COMMAND',
name: 'print',
});
}
}

preferencesItems.push({
label: _('General Options'),
accelerator: 'CommandOrControl+,',
click: () => {
this.dispatch({
type: 'NAV_GO',
routeName: 'Config',
});
}
}, {
label: _('Encryption options'),
click: () => {
this.dispatch({
type: 'NAV_GO',
routeName: 'EncryptionConfig',
});
}
}, {
label: _('Web clipper options'),
click: () => {
this.dispatch({
type: 'NAV_GO',
routeName: 'ClipperConfig',
});
}
});

toolsItemsFirst.push(syncStatusItem, {
type: 'separator',
screens: ['Main'],
});

const toolsItems = toolsItemsFirst.concat(preferencesItems);

function _checkForUpdates(ctx) {
bridge().checkForUpdates(false, bridge().window(), ctx.checkForUpdateLoggerPath(), { includePreReleases: Setting.value('autoUpdate.includePreReleases') });
}

function _showAbout() {
const p = packageInfo;
let message = [
p.description,
'',
'Copyright © 2016-2019 Laurent Cozic',
_('%s %s (%s, %s)', p.name, p.version, Setting.value('env'), process.platform),
];
bridge().showInfoMessageBox(message.join('\n'), {
icon: bridge().electronApp().buildDir() + '/icons/32x32.png',
});
}

const template = [
{
label: _('&File'),
/* Using a dummy entry for macOS here, because first menu
* becomes 'Joplin' and we need a nenu called 'File' later. */
label: shim.isMac() ? '&JoplinMainMenu' : _('&File'),
/* `&` before one of the char in the label name mean, that
* <Alt + F> will open this menu. It's needed becase electron
* opens the first menu on Alt press if no hotkey assigned.
* Issue: https://github.com/laurent22/joplin/issues/934 */
submenu: [{
label: _('New note'),
accelerator: 'CommandOrControl+N',
screens: ['Main'],
click: () => {
this.dispatch({
type: 'WINDOW_COMMAND',
name: 'newNote',
});
}
label: _('About Joplin'),
visible: shim.isMac() ? true : false,
click: () => _showAbout()
}, {
label: _('New to-do'),
accelerator: 'CommandOrControl+T',
screens: ['Main'],
click: () => {
this.dispatch({
type: 'WINDOW_COMMAND',
name: 'newTodo',
});
}
type: 'separator',
visible: shim.isMac() ? true : false
}, {
label: _('New notebook'),
screens: ['Main'],
click: () => {
this.dispatch({
type: 'WINDOW_COMMAND',
name: 'newNotebook',
});
}
label: _('Preferences...'),
visible: shim.isMac() ? true : false,
submenu: preferencesItems
}, {
label: _('Check for updates...'),
visible: shim.isMac() ? true : false,
click: () => _checkForUpdates(this)
}, {
type: 'separator',
visible: shim.isMac() ? true : false
},
shim.isMac() ? noItem : newNoteItem,
shim.isMac() ? noItem : newTodoItem,
shim.isMac() ? noItem : newNotebookItem, {
type: 'separator',
visible: shim.isMac() ? false : true
}, {
label: _('Import'),
visible: shim.isMac() ? false : true,
submenu: importItems,
}, {
label: _('Export'),
visible: shim.isMac() ? false : true,
submenu: exportItems,
}, {
type: 'separator',
Expand All @@ -441,19 +555,9 @@ class Application extends BaseApplication {
name: 'synchronize',
});
}
}, {
}, shim.isMac() ? syncStatusItem : noItem, {
type: 'separator',
}, {
label: _('Print'),
accelerator: 'CommandOrControl+P',
screens: ['Main'],
click: () => {
this.dispatch({
type: 'WINDOW_COMMAND',
name: 'print',
});
}
}, {
}, shim.isMac() ? noItem : printItem, {
type: 'separator',
platforms: ['darwin'],
}, {
Expand All @@ -468,6 +572,25 @@ class Application extends BaseApplication {
accelerator: 'CommandOrControl+Q',
click: () => { bridge().electronApp().quit() }
}]
}, {
label: _('&File'),
visible: shim.isMac() ? true : false,
submenu: [
newNoteItem,
newTodoItem,
newNotebookItem, {
type: 'separator',
}, {
label: _('Import'),
submenu: importItems,
}, {
label: _('Export'),
submenu: exportItems,
}, {
type: 'separator',
},
printItem
]
}, {
label: _('&Edit'),
submenu: [{
Expand Down Expand Up @@ -628,43 +751,8 @@ class Application extends BaseApplication {
}],
}, {
label: _('&Tools'),
submenu: [{
label: _('Synchronisation status'),
click: () => {
this.dispatch({
type: 'NAV_GO',
routeName: 'Status',
});
}
}, {
type: 'separator',
screens: ['Main'],
},{
label: _('Web clipper options'),
click: () => {
this.dispatch({
type: 'NAV_GO',
routeName: 'ClipperConfig',
});
}
},{
label: _('Encryption options'),
click: () => {
this.dispatch({
type: 'NAV_GO',
routeName: 'EncryptionConfig',
});
}
},{
label: _('General Options'),
accelerator: 'CommandOrControl+,',
click: () => {
this.dispatch({
type: 'NAV_GO',
routeName: 'Config',
});
}
}],
visible: shim.isMac() ? false : true,
submenu: toolsItems
}, {
label: _('&Help'),
submenu: [{
Expand All @@ -676,26 +764,16 @@ class Application extends BaseApplication {
click () { bridge().openExternal('https://joplin.cozic.net/donate') }
}, {
label: _('Check for updates...'),
click: () => {
bridge().checkForUpdates(false, bridge().window(), this.checkForUpdateLoggerPath(), { includePreReleases: Setting.value('autoUpdate.includePreReleases') });
}
visible: shim.isMac() ? false : true,
click: () => _checkForUpdates(this)
}, {
type: 'separator',
visible: shim.isMac() ? false : true,
screens: ['Main'],
}, {
label: _('About Joplin'),
click: () => {
const p = packageInfo;
let message = [
p.description,
'',
'Copyright © 2016-2019 Laurent Cozic',
_('%s %s (%s, %s)', p.name, p.version, Setting.value('env'), process.platform),
];
bridge().showInfoMessageBox(message.join('\n'), {
icon: bridge().electronApp().buildDir() + '/icons/32x32.png',
});
}
visible: shim.isMac() ? false : true,
click: () => _showAbout()
}]
},
];
Expand Down