Refactor menu internals (#1867)
* Keymaps part@1 move menus * Gather all paths in a module
This commit is contained in:
parent
650ca65e9c
commit
3c1f359198
13 changed files with 476 additions and 414 deletions
27
app/menus/menu.js
Normal file
27
app/menus/menu.js
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// menus
|
||||
const viewMenu = require('./menus/view');
|
||||
const shellMenu = require('./menus/shell');
|
||||
const editMenu = require('./menus/edit');
|
||||
const pluginsMenu = require('./menus/plugins');
|
||||
const windowMenu = require('./menus/window');
|
||||
const helpMenu = require('./menus/help');
|
||||
const darwinMenu = require('./menus/darwin');
|
||||
|
||||
module.exports = (createWindow, updatePlugins) => {
|
||||
const menu = [].concat(
|
||||
shellMenu(createWindow),
|
||||
editMenu(),
|
||||
viewMenu(),
|
||||
pluginsMenu(updatePlugins),
|
||||
windowMenu(),
|
||||
helpMenu()
|
||||
);
|
||||
|
||||
if (process.platform === 'darwin') {
|
||||
menu.unshift(
|
||||
darwinMenu()
|
||||
);
|
||||
}
|
||||
|
||||
return menu;
|
||||
};
|
||||
51
app/menus/menus/darwin.js
Normal file
51
app/menus/menus/darwin.js
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
// This menu label is overrided by OSX to be the appName
|
||||
// The label is set to appName here so it matches actual behavior
|
||||
const {app, shell} = require('electron');
|
||||
const {accelerators} = require('../../accelerators');
|
||||
const {confPath} = require('../../config/paths');
|
||||
|
||||
module.exports = function () {
|
||||
return {
|
||||
label: `${app.getName()}`,
|
||||
submenu: [
|
||||
{
|
||||
role: 'about'
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Preferences...',
|
||||
accelerator: accelerators.preferences,
|
||||
click() {
|
||||
shell.openItem(confPath);
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
role: 'services',
|
||||
submenu: []
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
role: 'hide'
|
||||
},
|
||||
{
|
||||
role: 'hideothers'
|
||||
},
|
||||
{
|
||||
role: 'unhide'
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
role: 'quit'
|
||||
}
|
||||
]
|
||||
};
|
||||
};
|
||||
65
app/menus/menus/edit.js
Normal file
65
app/menus/menus/edit.js
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
const {shell} = require('electron');
|
||||
const {accelerators} = require('../../accelerators');
|
||||
const {confPath} = require('../../config/paths');
|
||||
|
||||
module.exports = function () {
|
||||
const submenu = [
|
||||
{
|
||||
role: 'undo',
|
||||
accelerator: accelerators.undo
|
||||
},
|
||||
{
|
||||
role: 'redo',
|
||||
accelerator: accelerators.redo
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
role: 'cut',
|
||||
accelerator: accelerators.cut
|
||||
},
|
||||
{
|
||||
role: 'copy',
|
||||
accelerator: accelerators.copy
|
||||
},
|
||||
{
|
||||
role: 'paste',
|
||||
accelerator: accelerators.paste
|
||||
},
|
||||
{
|
||||
role: 'selectall',
|
||||
accelerator: accelerators.selectAll
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Clear Buffer',
|
||||
accelerator: accelerators.clear,
|
||||
click(item, focusedWindow) {
|
||||
if (focusedWindow) {
|
||||
focusedWindow.rpc.emit('session clear req');
|
||||
}
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
if (process.platform !== 'darwin') {
|
||||
submenu.push(
|
||||
{type: 'separator'},
|
||||
{
|
||||
label: 'Preferences...',
|
||||
accelerator: accelerators.preferences,
|
||||
click() {
|
||||
shell.openItem(confPath);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
label: 'Edit',
|
||||
submenu
|
||||
};
|
||||
};
|
||||
50
app/menus/menus/help.js
Normal file
50
app/menus/menus/help.js
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
const os = require('os');
|
||||
const {app, shell, dialog} = require('electron');
|
||||
const {icon} = require('../../config/paths');
|
||||
|
||||
module.exports = function () {
|
||||
const submenu = [
|
||||
{
|
||||
label: `${app.getName()} Website`,
|
||||
click() {
|
||||
shell.openExternal('https://hyper.is');
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Report Issue',
|
||||
click() {
|
||||
const body = `
|
||||
<!-- Please succinctly describe your issue and steps to reproduce it. -->
|
||||
-
|
||||
${app.getName()} ${app.getVersion()}
|
||||
Electron ${process.versions.electron}
|
||||
${process.platform} ${process.arch} ${os.release()}`;
|
||||
|
||||
shell.openExternal(`https://github.com/zeit/hyper/issues/new?body=${encodeURIComponent(body)}`);
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
if (process.platform !== 'darwin') {
|
||||
submenu.push(
|
||||
{type: 'separator'},
|
||||
{
|
||||
role: 'about',
|
||||
click() {
|
||||
dialog.showMessageBox({
|
||||
title: `About ${app.getName()}`,
|
||||
message: `${app.getName()} ${app.getVersion()}`,
|
||||
detail: 'Created by Guillermo Rauch',
|
||||
icon,
|
||||
buttons: []
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
role: 'help',
|
||||
submenu
|
||||
};
|
||||
};
|
||||
16
app/menus/menus/plugins.js
Normal file
16
app/menus/menus/plugins.js
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
const {accelerators} = require('../../accelerators');
|
||||
|
||||
module.exports = function (update) {
|
||||
return {
|
||||
label: 'Plugins',
|
||||
submenu: [
|
||||
{
|
||||
label: 'Update',
|
||||
accelerator: accelerators.updatePlugins,
|
||||
click() {
|
||||
update();
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
};
|
||||
67
app/menus/menus/shell.js
Normal file
67
app/menus/menus/shell.js
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
const {accelerators} = require('../../accelerators');
|
||||
|
||||
module.exports = function (createWindow) {
|
||||
const isMac = process.platform === 'darwin';
|
||||
|
||||
return {
|
||||
label: isMac ? 'Shell' : 'File',
|
||||
submenu: [
|
||||
{
|
||||
label: 'New Window',
|
||||
accelerator: accelerators.newWindow,
|
||||
click() {
|
||||
createWindow();
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'New Tab',
|
||||
accelerator: accelerators.newTab,
|
||||
click(item, focusedWindow) {
|
||||
if (focusedWindow) {
|
||||
focusedWindow.rpc.emit('termgroup add req');
|
||||
} else {
|
||||
createWindow();
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Split Vertically',
|
||||
accelerator: accelerators.splitVertically,
|
||||
click(item, focusedWindow) {
|
||||
if (focusedWindow) {
|
||||
focusedWindow.rpc.emit('split request vertical');
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Split Horizontally',
|
||||
accelerator: accelerators.splitHorizontally,
|
||||
click(item, focusedWindow) {
|
||||
if (focusedWindow) {
|
||||
focusedWindow.rpc.emit('split request horizontal');
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Close Session',
|
||||
accelerator: accelerators.closeSession,
|
||||
click(item, focusedWindow) {
|
||||
if (focusedWindow) {
|
||||
focusedWindow.rpc.emit('termgroup close req');
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
label: isMac ? 'Close Window' : 'Quit',
|
||||
role: 'close',
|
||||
accelerator: accelerators.closeWindow
|
||||
}
|
||||
]
|
||||
};
|
||||
};
|
||||
71
app/menus/menus/view.js
Normal file
71
app/menus/menus/view.js
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
const {accelerators} = require('../../accelerators');
|
||||
|
||||
module.exports = function () {
|
||||
return {
|
||||
label: 'View',
|
||||
submenu: [
|
||||
{
|
||||
label: 'Reload',
|
||||
accelerator: accelerators.reload,
|
||||
click(item, focusedWindow) {
|
||||
if (focusedWindow) {
|
||||
focusedWindow.rpc.emit('reload');
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Full Reload',
|
||||
accelerator: accelerators.fullReload,
|
||||
click(item, focusedWindow) {
|
||||
if (focusedWindow) {
|
||||
focusedWindow.reload();
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Developer Tools',
|
||||
accelerator: accelerators.toggleDevTools,
|
||||
click(item, focusedWindow) {
|
||||
if (focusedWindow) {
|
||||
const webContents = focusedWindow.webContents;
|
||||
if (webContents.isDevToolsOpened()) {
|
||||
webContents.closeDevTools();
|
||||
} else {
|
||||
webContents.openDevTools({mode: 'detach'});
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Reset Zoom Level',
|
||||
accelerator: accelerators.resetZoom,
|
||||
click(item, focusedWindow) {
|
||||
if (focusedWindow) {
|
||||
focusedWindow.rpc.emit('reset fontSize req');
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Zoom In',
|
||||
accelerator: accelerators.zoomIn,
|
||||
click(item, focusedWindow) {
|
||||
if (focusedWindow) {
|
||||
focusedWindow.rpc.emit('increase fontSize req');
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Zoom Out',
|
||||
accelerator: accelerators.zoomOut,
|
||||
click(item, focusedWindow) {
|
||||
if (focusedWindow) {
|
||||
focusedWindow.rpc.emit('decrease fontSize req');
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
};
|
||||
78
app/menus/menus/window.js
Normal file
78
app/menus/menus/window.js
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
const {accelerators} = require('../../accelerators');
|
||||
|
||||
module.exports = function () {
|
||||
return {
|
||||
role: 'window',
|
||||
submenu: [
|
||||
{
|
||||
role: 'minimize',
|
||||
accelerator: accelerators.minimize
|
||||
},
|
||||
{
|
||||
role: 'zoom'
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Select Tab',
|
||||
submenu: [
|
||||
{
|
||||
label: 'Previous',
|
||||
accelerator: accelerators.showPreviousTab,
|
||||
click(item, focusedWindow) {
|
||||
if (focusedWindow) {
|
||||
focusedWindow.rpc.emit('move left req');
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Next',
|
||||
accelerator: accelerators.showNextTab,
|
||||
click(item, focusedWindow) {
|
||||
if (focusedWindow) {
|
||||
focusedWindow.rpc.emit('move right req');
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Select Pane',
|
||||
submenu: [
|
||||
{
|
||||
label: 'Previous',
|
||||
accelerator: accelerators.selectNextPane,
|
||||
click(item, focusedWindow) {
|
||||
if (focusedWindow) {
|
||||
focusedWindow.rpc.emit('prev pane req');
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Next',
|
||||
accelerator: accelerators.selectPreviousPane,
|
||||
click(item, focusedWindow) {
|
||||
if (focusedWindow) {
|
||||
focusedWindow.rpc.emit('next pane req');
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
role: 'front'
|
||||
},
|
||||
{
|
||||
role: 'togglefullscreen',
|
||||
accelerators: accelerators.enterFullScreen
|
||||
}
|
||||
]
|
||||
};
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue