mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-17 05:58:41 -09:00
Add profiles to shell and context menus
This commit is contained in:
parent
bea0270a3b
commit
354c0aa7dd
4 changed files with 57 additions and 3 deletions
|
|
@ -145,6 +145,19 @@ const commands: Record<string, (focusedWindow?: BrowserWindow) => void> = {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Profile specific commands
|
||||||
|
getConfig().profiles.forEach((profile) => {
|
||||||
|
commands[`tab:new:${profile.name}`] = (focusedWindow) => {
|
||||||
|
focusedWindow?.rpc.emit('termgroup add req', {profile: profile.name});
|
||||||
|
};
|
||||||
|
commands[`pane:splitRight:${profile.name}`] = (focusedWindow) => {
|
||||||
|
focusedWindow?.rpc.emit('split request vertical', {profile: profile.name});
|
||||||
|
};
|
||||||
|
commands[`pane:splitDown:${profile.name}`] = (focusedWindow) => {
|
||||||
|
focusedWindow?.rpc.emit('split request horizontal', {profile: profile.name});
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
export const execCommand = (command: string, focusedWindow?: BrowserWindow) => {
|
export const execCommand = (command: string, focusedWindow?: BrowserWindow) => {
|
||||||
const fn = commands[command];
|
const fn = commands[command];
|
||||||
if (fn) {
|
if (fn) {
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,11 @@ export const createMenu = (
|
||||||
};
|
};
|
||||||
const menu = [
|
const menu = [
|
||||||
...(process.platform === 'darwin' ? [darwinMenu(commandKeys, execCommand, showAbout)] : []),
|
...(process.platform === 'darwin' ? [darwinMenu(commandKeys, execCommand, showAbout)] : []),
|
||||||
shellMenu(commandKeys, execCommand),
|
shellMenu(
|
||||||
|
commandKeys,
|
||||||
|
execCommand,
|
||||||
|
getConfig().profiles.map((p) => p.name)
|
||||||
|
),
|
||||||
editMenu(commandKeys, execCommand),
|
editMenu(commandKeys, execCommand),
|
||||||
viewMenu(commandKeys, execCommand),
|
viewMenu(commandKeys, execCommand),
|
||||||
toolsMenu(commandKeys, execCommand),
|
toolsMenu(commandKeys, execCommand),
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@ import type {BrowserWindow, MenuItemConstructorOptions} from 'electron';
|
||||||
|
|
||||||
export default (
|
export default (
|
||||||
commandKeys: Record<string, string>,
|
commandKeys: Record<string, string>,
|
||||||
execCommand: (command: string, focusedWindow?: BrowserWindow) => void
|
execCommand: (command: string, focusedWindow?: BrowserWindow) => void,
|
||||||
|
profiles: string[]
|
||||||
): MenuItemConstructorOptions => {
|
): MenuItemConstructorOptions => {
|
||||||
const isMac = process.platform === 'darwin';
|
const isMac = process.platform === 'darwin';
|
||||||
|
|
||||||
|
|
@ -43,6 +44,37 @@ export default (
|
||||||
{
|
{
|
||||||
type: 'separator'
|
type: 'separator'
|
||||||
},
|
},
|
||||||
|
...profiles.map(
|
||||||
|
(profile): MenuItemConstructorOptions => ({
|
||||||
|
label: profile,
|
||||||
|
submenu: [
|
||||||
|
{
|
||||||
|
label: 'New Tab',
|
||||||
|
click(item, focusedWindow) {
|
||||||
|
execCommand(`tab:new:${profile}`, focusedWindow);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'separator'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Split Down',
|
||||||
|
click(item, focusedWindow) {
|
||||||
|
execCommand(`pane:splitDown:${profile}`, focusedWindow);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Split Right',
|
||||||
|
click(item, focusedWindow) {
|
||||||
|
execCommand(`pane:splitRight:${profile}`, focusedWindow);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
),
|
||||||
|
{
|
||||||
|
type: 'separator'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: 'Close',
|
label: 'Close',
|
||||||
accelerator: commandKeys['pane:close'],
|
accelerator: commandKeys['pane:close'],
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import shellMenu from '../menus/menus/shell';
|
||||||
import {execCommand} from '../commands';
|
import {execCommand} from '../commands';
|
||||||
import {getDecoratedKeymaps} from '../plugins';
|
import {getDecoratedKeymaps} from '../plugins';
|
||||||
import type {MenuItemConstructorOptions, BrowserWindow} from 'electron';
|
import type {MenuItemConstructorOptions, BrowserWindow} from 'electron';
|
||||||
|
import {getProfiles} from '../config';
|
||||||
const separator: MenuItemConstructorOptions = {type: 'separator'};
|
const separator: MenuItemConstructorOptions = {type: 'separator'};
|
||||||
|
|
||||||
const getCommandKeys = (keymaps: Record<string, string[]>): Record<string, string> =>
|
const getCommandKeys = (keymaps: Record<string, string[]>): Record<string, string> =>
|
||||||
|
|
@ -25,7 +26,11 @@ export default (
|
||||||
selection: string
|
selection: string
|
||||||
) => {
|
) => {
|
||||||
const commandKeys = getCommandKeys(getDecoratedKeymaps());
|
const commandKeys = getCommandKeys(getDecoratedKeymaps());
|
||||||
const _shell = shellMenu(commandKeys, execCommand).submenu as MenuItemConstructorOptions[];
|
const _shell = shellMenu(
|
||||||
|
commandKeys,
|
||||||
|
execCommand,
|
||||||
|
getProfiles().map((p) => p.name)
|
||||||
|
).submenu as MenuItemConstructorOptions[];
|
||||||
const _edit = editMenu(commandKeys, execCommand).submenu.filter(filterCutCopy.bind(null, selection));
|
const _edit = editMenu(commandKeys, execCommand).submenu.filter(filterCutCopy.bind(null, selection));
|
||||||
return _edit
|
return _edit
|
||||||
.concat(separator, _shell)
|
.concat(separator, _shell)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue