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

Add profiles to shell and context menus #7304

Merged
merged 1 commit into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions app/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
const fn = commands[command];
if (fn) {
Expand Down
6 changes: 5 additions & 1 deletion app/menus/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ export const createMenu = (
};
const menu = [
...(process.platform === 'darwin' ? [darwinMenu(commandKeys, execCommand, showAbout)] : []),
shellMenu(commandKeys, execCommand),
shellMenu(
commandKeys,
execCommand,
getConfig().profiles.map((p) => p.name)
),
editMenu(commandKeys, execCommand),
viewMenu(commandKeys, execCommand),
toolsMenu(commandKeys, execCommand),
Expand Down
34 changes: 33 additions & 1 deletion app/menus/menus/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import type {BrowserWindow, MenuItemConstructorOptions} from 'electron';

export default (
commandKeys: Record<string, string>,
execCommand: (command: string, focusedWindow?: BrowserWindow) => void
execCommand: (command: string, focusedWindow?: BrowserWindow) => void,
profiles: string[]
): MenuItemConstructorOptions => {
const isMac = process.platform === 'darwin';

Expand Down Expand Up @@ -43,6 +44,37 @@ export default (
{
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',
accelerator: commandKeys['pane:close'],
Expand Down
7 changes: 6 additions & 1 deletion app/ui/contextmenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import shellMenu from '../menus/menus/shell';
import {execCommand} from '../commands';
import {getDecoratedKeymaps} from '../plugins';
import type {MenuItemConstructorOptions, BrowserWindow} from 'electron';
import {getProfiles} from '../config';
const separator: MenuItemConstructorOptions = {type: 'separator'};

const getCommandKeys = (keymaps: Record<string, string[]>): Record<string, string> =>
Expand All @@ -25,7 +26,11 @@ export default (
selection: string
) => {
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));
return _edit
.concat(separator, _shell)
Expand Down