1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-23 18:53:36 +02:00

Desktop: Fixes #4010: Add history backward and forward commands to keymap and menus

This commit is contained in:
Laurent Cozic 2020-10-31 12:46:55 +00:00
parent 4502414934
commit 154163bd6c
2 changed files with 40 additions and 71 deletions

View File

@ -118,6 +118,8 @@ const commandNames:string[] = [
'showNoteContentProperties', 'showNoteContentProperties',
'copyDevCommand', 'copyDevCommand',
'openProfileDirectory', 'openProfileDirectory',
'historyBackward',
'historyForward',
]; ];
function menuItemSetChecked(id:string, checked:boolean) { function menuItemSetChecked(id:string, checked:boolean) {
@ -249,10 +251,8 @@ function useMenu(props:Props) {
menuItemDic.focusElementNoteBody, menuItemDic.focusElementNoteBody,
]; ];
let toolsItems:any[] = [];
const importItems = []; const importItems = [];
const exportItems = []; const exportItems = [];
const toolsItemsFirst = [];
const templateItems:any[] = []; const templateItems:any[] = [];
const ioService = InteropService.instance(); const ioService = InteropService.instance();
const ioModules = ioService.modules(); const ioModules = ioService.modules();
@ -299,16 +299,18 @@ function useMenu(props:Props) {
}, },
}; };
const separator = () => {
return {
type: 'separator',
};
};
const newNoteItem = menuItemDic.newNote; const newNoteItem = menuItemDic.newNote;
const newTodoItem = menuItemDic.newTodo; const newTodoItem = menuItemDic.newTodo;
const newFolderItem = menuItemDic.newFolder; const newFolderItem = menuItemDic.newFolder;
const newSubFolderItem = menuItemDic.newSubFolder; const newSubFolderItem = menuItemDic.newSubFolder;
const printItem = menuItemDic.print; const printItem = menuItemDic.print;
toolsItemsFirst.push(syncStatusItem, {
type: 'separator',
});
templateItems.push({ templateItems.push({
label: _('Create note from template'), label: _('Create note from template'),
click: () => { click: () => {
@ -342,18 +344,22 @@ function useMenu(props:Props) {
}, },
}); });
let toolsItems:any[] = [];
// we need this workaround, because on macOS the menu is different // we need this workaround, because on macOS the menu is different
const toolsItemsWindowsLinux:any[] = toolsItemsFirst.concat([{ const toolsItemsWindowsLinux:any[] = [
label: _('Options'), {
visible: !shim.isMac(), label: _('Options'),
accelerator: !shim.isMac() && keymapService.getAccelerator('config'), accelerator: keymapService.getAccelerator('config'),
click: () => { click: () => {
props.dispatch({ props.dispatch({
type: 'NAV_GO', type: 'NAV_GO',
routeName: 'Config', routeName: 'Config',
}); });
},
}, },
} as any]); separator(),
];
// the following menu items will be available for all OS under Tools // the following menu items will be available for all OS under Tools
const toolsItemsAll = [{ const toolsItemsAll = [{
@ -451,9 +457,7 @@ function useMenu(props:Props) {
menuItemDic.synchronize, menuItemDic.synchronize,
shim.isMac() ? syncStatusItem : noItem, { shim.isMac() ? noItem : printItem, {
type: 'separator',
}, shim.isMac() ? noItem : printItem, {
type: 'separator', type: 'separator',
platforms: ['darwin'], platforms: ['darwin'],
}, },
@ -518,12 +522,6 @@ function useMenu(props:Props) {
}); });
} }
const separator = () => {
return {
type: 'separator',
};
};
const rootMenus:any = { const rootMenus:any = {
edit: { edit: {
id: 'edit', id: 'edit',
@ -586,11 +584,6 @@ function useMenu(props:Props) {
}, },
}, },
separator(), separator(),
{
label: _('Focus'),
submenu: focusItems,
},
separator(),
{ {
label: _('Actual Size'), label: _('Actual Size'),
click: () => { click: () => {
@ -623,6 +616,18 @@ function useMenu(props:Props) {
accelerator: 'CommandOrControl+-', accelerator: 'CommandOrControl+-',
}], }],
}, },
go: {
label: _('&Go'),
submenu: [
menuItemDic.historyBackward,
menuItemDic.historyForward,
separator(),
{
label: _('Focus'),
submenu: focusItems,
},
],
},
note: { note: {
label: _('&Note'), label: _('&Note'),
submenu: [ submenu: [
@ -655,6 +660,8 @@ function useMenu(props:Props) {
click: () => _checkForUpdates(), click: () => _checkForUpdates(),
}, },
separator(), separator(),
syncStatusItem,
separator(),
{ {
id: 'help:toggleDevTools', id: 'help:toggleDevTools',
label: _('Toggle development tools'), label: _('Toggle development tools'),
@ -709,6 +716,7 @@ function useMenu(props:Props) {
const pluginMenuItems = PluginManager.instance().menuItems(); const pluginMenuItems = PluginManager.instance().menuItems();
for (const item of pluginMenuItems) { for (const item of pluginMenuItems) {
const itemParent = rootMenus[item.parent] ? rootMenus[item.parent] : 'tools'; const itemParent = rootMenus[item.parent] ? rootMenus[item.parent] : 'tools';
itemParent.submenu.push(separator());
itemParent.submenu.push(item); itemParent.submenu.push(item);
} }
} }
@ -741,6 +749,7 @@ function useMenu(props:Props) {
rootMenus.file, rootMenus.file,
rootMenus.edit, rootMenus.edit,
rootMenus.view, rootMenus.view,
rootMenus.go,
rootMenus.note, rootMenus.note,
rootMenus.tools, rootMenus.tools,
rootMenus.help, rootMenus.help,
@ -748,46 +757,6 @@ function useMenu(props:Props) {
if (shim.isMac()) template.splice(0, 0, rootMenus.macOsApp); if (shim.isMac()) template.splice(0, 0, rootMenus.macOsApp);
// TODO
// function isEmptyMenu(template:any[]) {
// for (let i = 0; i < template.length; i++) {
// const t = template[i];
// if (t.type !== 'separator') return false;
// }
// return true;
// }
// function removeUnwantedItems(template:any[], screen:string) {
// const platform = shim.platformName();
// let output = [];
// for (let i = 0; i < template.length; i++) {
// const t = Object.assign({}, template[i]);
// if (t.screens && t.screens.indexOf(screen) < 0) continue;
// if (t.platforms && t.platforms.indexOf(platform) < 0) continue;
// if (t.submenu) t.submenu = removeUnwantedItems(t.submenu, screen);
// if (('submenu' in t) && isEmptyMenu(t.submenu)) continue;
// output.push(t);
// }
// // Remove empty separator for now empty sections
// const temp = [];
// let previous = null;
// for (let i = 0; i < output.length; i++) {
// const t = Object.assign({}, output[i]);
// if (t.type === 'separator') {
// if (!previous) continue;
// if (previous.type === 'separator') continue;
// }
// temp.push(t);
// previous = t;
// }
// output = temp;
// return output;
// }
if (props.routeName !== 'Main') { if (props.routeName !== 'Main') {
setMenu(Menu.buildFromTemplate([ setMenu(Menu.buildFromTemplate([
{ {

View File

@ -557,7 +557,7 @@ GotoAnything.manifest = {
menuItems: [ menuItems: [
{ {
name: 'main', name: 'main',
parent: 'tools', parent: 'go',
label: _('Goto Anything...'), label: _('Goto Anything...'),
accelerator: () => KeymapService.instance().getAccelerator('gotoAnything'), accelerator: () => KeymapService.instance().getAccelerator('gotoAnything'),
screens: ['Main'], screens: ['Main'],