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

Main View keybindings #463

Merged
merged 9 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
27 changes: 18 additions & 9 deletions assets/default-keybindings.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,39 +87,48 @@
},
{
"command": "app:selectTab-1",
"keys": ["Cmd:1"]
"keys": ["Cmd:1"],
"commandStr":"/screen 1"
},
{
"command": "app:selectTab-2",
"keys": ["Cmd:2"]
"keys": ["Cmd:2"],
"commandStr":"/screen 2"
},
{
"command": "app:selectTab-3",
"keys": ["Cmd:3"]
"keys": ["Cmd:3"],
"commandStr":"/screen 3"
},
{
"command": "app:selectTab-4",
"keys": ["Cmd:4"]
"keys": ["Cmd:4"],
"commandStr":"/screen 4"
},
{
"command": "app:selectTab-5",
"keys": ["Cmd:5"]
"keys": ["Cmd:5"],
"commandStr":"/screen 5"
},
{
"command": "app:selectTab-6",
"keys": ["Cmd:6"]
"keys": ["Cmd:6"],
"commandStr":"/screen 6"
},
{
"command": "app:selectTab-7",
"keys": ["Cmd:7"]
"keys": ["Cmd:7"],
"commandStr":"/screen 7"
},
{
"command": "app:selectTab-8",
"keys": ["Cmd:8"]
"keys": ["Cmd:8"],
"commandStr":"/screen 8"
},
{
"command": "app:selectTab-9",
"keys": ["Cmd:9"]
"keys": ["Cmd:9"],
"commandStr":"/screen 9"
},
{
"command": "app:selectTabLeft",
Expand Down
23 changes: 23 additions & 0 deletions src/app/clientsettings/clientsettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as React from "react";
import * as mobxReact from "mobx-react";
import * as mobx from "mobx";
import { boundMethod } from "autobind-decorator";
import { If } from "tsx-control-statements/components";
import { GlobalModel, GlobalCommandRunner, RemotesModel, getApi } from "@/models";
import { Toggle, InlineSettingsTextEdit, SettingsError, Dropdown } from "@/common/elements";
import { commandRtnHandler, isBlank } from "@/util/util";
Expand All @@ -13,6 +14,25 @@ import * as appconst from "@/app/appconst";
import "./clientsettings.less";
import { MainView } from "../common/elements/mainview";

class ClientSettingsKeybindings extends React.Component<{}, {}> {
componentDidMount() {
let clientSettingsViewModel = GlobalModel.clientSettingsViewModel;
let keybindManager = GlobalModel.keybindManager;
keybindManager.registerKeybinding("mainview", "clientsettings", "generic:cancel", (waveEvent) => {
clientSettingsViewModel.closeView();
return true;
});
}

componentWillUnmount() {
GlobalModel.keybindManager.unregisterDomain("clientsettings");
}

render() {
return null;
}
}

@mobxReact.observer
class ClientSettingsView extends React.Component<{ model: RemotesModel }, { hoveredItemId: string }> {
errorMessage: OV<string> = mobx.observable.box(null, { name: "ClientSettings-errorMessage" });
Expand Down Expand Up @@ -168,6 +188,9 @@ class ClientSettingsView extends React.Component<{ model: RemotesModel }, { hove

return (
<MainView className="clientsettings-view" title="Client Settings" onClose={this.handleClose}>
<If condition={!isHidden}>
<ClientSettingsKeybindings></ClientSettingsKeybindings>
</If>
<div className="content">
<div className="settings-field">
<div className="settings-label">Term Font Size</div>
Expand Down
22 changes: 22 additions & 0 deletions src/app/connections/connections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,25 @@ import * as util from "@/util/util";
import "./connections.less";
import { MainView } from "../common/elements/mainview";

class ConnectionsKeybindings extends React.Component<{}, {}> {
componentDidMount() {
let connectionViewModel = GlobalModel.connectionViewModel;
let keybindManager = GlobalModel.keybindManager;
keybindManager.registerKeybinding("mainview", "connections", "generic:cancel", (waveEvent) => {
connectionViewModel.closeView();
return true;
});
}

componentWillUnmount() {
GlobalModel.keybindManager.unregisterDomain("connections");
}

render() {
return null;
}
}

@mobxReact.observer
class ConnectionsView extends React.Component<{ model: RemotesModel }, { hoveredItemId: string }> {
tableRef: React.RefObject<any> = React.createRef();
Expand Down Expand Up @@ -127,6 +146,9 @@ class ConnectionsView extends React.Component<{ model: RemotesModel }, { hovered

return (
<MainView className="connections-view" title="Connections" onClose={this.handleClose}>
<If condition={!isHidden}>
<ConnectionsKeybindings></ConnectionsKeybindings>
</If>
<table
className="connections-table"
cellSpacing="0"
Expand Down
24 changes: 24 additions & 0 deletions src/app/history/history.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,27 @@ class HistoryCmdStr extends React.Component<
}
}

class HistoryKeybindings extends React.Component<{}, {}> {
@boundMethod
componentDidMount() {
let historyViewModel = GlobalModel.historyViewModel;
let keybindManager = GlobalModel.keybindManager;
keybindManager.registerKeybinding("mainview", "history", "generic:cancel", (waveEvent) => {
historyViewModel.handleUserClose();
return true;
});
}

@boundMethod
componentWillUnmount() {
GlobalModel.keybindManager.unregisterDomain("history");
}

render() {
return null;
}
}

@mobxReact.observer
class HistoryView extends React.Component<{}, {}> {
tableRef: React.RefObject<any> = React.createRef();
Expand Down Expand Up @@ -448,6 +469,9 @@ class HistoryView extends React.Component<{}, {}> {

return (
<MainView className="history-view" title="History" onClose={this.handleClose}>
<If condition={!isHidden}>
<HistoryKeybindings></HistoryKeybindings>
</If>
<div key="search" className="history-search">
<div className="main-search field">
<TextField
Expand Down
68 changes: 68 additions & 0 deletions src/app/workspace/workspaceview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as mobx from "mobx";
import cn from "classnames";
import dayjs from "dayjs";
import localizedFormat from "dayjs/plugin/localizedFormat";
import { If } from "tsx-control-statements/components";
import { GlobalModel } from "@/models";
import { CmdInput } from "./cmdinput/cmdinput";
import { ScreenView } from "./screen/screenview";
Expand All @@ -17,6 +18,70 @@ import "./workspace.less";

dayjs.extend(localizedFormat);

class SessionKeybindings extends React.Component<{}, {}> {
componentDidMount() {
let keybindManager = GlobalModel.keybindManager;
keybindManager.registerKeybinding("mainview", "session", "generic:cancel", (waveEvent) => {
GlobalModel.handleSessionCancel();
return true;
});
keybindManager.registerKeybinding("mainview", "session", "app:toggleSidebar", (waveEvent) => {
GlobalModel.handleToggleSidebar();
return true;
});
keybindManager.registerKeybinding("mainview", "session", "app:newTab", (waveEvent) => {
GlobalModel.onNewTab();
return true;
});
keybindManager.registerKeybinding("mainview", "session", "app:closeCurrentTab", (waveEvent) => {
GlobalModel.onCloseCurrentTab();
return true;
});
for (let index = 1; index <= 9; index++) {
keybindManager.registerKeybinding("mainview", "session", "app:selectTab-" + index, null);
}
keybindManager.registerKeybinding("mainview", "session", "app:selectTabLeft", (waveEvent) => {
GlobalModel.onBracketCmd(-1);
return true;
});
keybindManager.registerKeybinding("mainview", "session", "app:selectTabRight", (waveEvent) => {
GlobalModel.onBracketCmd(1);
return true;
});
keybindManager.registerKeybinding("pane", "session", "app:selectLineAbove", (waveEvent) => {
GlobalModel.onMetaArrowUp();
return true;
});
keybindManager.registerKeybinding("pane", "session", "app:selectLineBelow", (waveEvent) => {
GlobalModel.onMetaArrowDown();
return true;
});
keybindManager.registerKeybinding("pane", "session", "app:restartCommand", (waveEvent) => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this organization make sense? for what is pane vs what is main view?

GlobalModel.onRestartCommand();
return true;
});
keybindManager.registerKeybinding("pane", "session", "app:restartLastCommand", (waveEvent) => {
GlobalModel.onRestartLastCommand();
return true;
});
keybindManager.registerKeybinding("pane", "session", "app:focusSelectedLine", (waveEvent) => {
GlobalModel.onFocusSelectedLine();
return true;
});
keybindManager.registerKeybinding("pane", "session", "app:deleteActiveLine", (waveEvent) => {
return GlobalModel.handleDeleteActiveLine();
});
}

componentWillUnmount() {
GlobalModel.keybindManager.unregisterDomain("session");
}

render() {
return null;
}
}

@mobxReact.observer
class WorkspaceView extends React.Component<{}, {}> {
render() {
Expand Down Expand Up @@ -51,6 +116,9 @@ class WorkspaceView extends React.Component<{}, {}> {
width: `${width}px`,
}}
>
<If condition={!isHidden}>
<SessionKeybindings></SessionKeybindings>
</If>
<ScreenTabs key={"tabs-" + session.sessionId} session={session} />
<ErrorBoundary>
<ScreenView key={"screenview-" + session.sessionId} session={session} screen={activeScreen} />
Expand Down
53 changes: 0 additions & 53 deletions src/electron/emain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,59 +359,6 @@ function createMainWindow(clientData: ClientDataType | null): Electron.BrowserWi
if (input.type != "keyDown") {
return;
}
const mods = getMods(input);
if (checkKeyPressed(waveEvent, "Cmd:t")) {
win.webContents.send("t-cmd", mods);
e.preventDefault();
return;
}
if (checkKeyPressed(waveEvent, "Cmd:r")) {
e.preventDefault();
win.webContents.send("r-cmd", mods);
return;
}
if (checkKeyPressed(waveEvent, "Cmd:l")) {
win.webContents.send("l-cmd", mods);
e.preventDefault();
return;
}
if (checkKeyPressed(waveEvent, "Cmd:w")) {
e.preventDefault();
win.webContents.send("w-cmd", mods);
return;
}
if (checkKeyPressed(waveEvent, "Cmd:ArrowUp") || checkKeyPressed(waveEvent, "Cmd:ArrowDown")) {
if (checkKeyPressed(waveEvent, "Cmd:ArrowUp")) {
win.webContents.send("meta-arrowup");
} else {
win.webContents.send("meta-arrowdown");
}
e.preventDefault();
return;
}
if (checkKeyPressed(waveEvent, "Cmd:PageUp") || checkKeyPressed(waveEvent, "Cmd:PageDown")) {
if (checkKeyPressed(waveEvent, "Cmd:PageUp")) {
win.webContents.send("meta-pageup");
} else {
win.webContents.send("meta-pagedown");
}
e.preventDefault();
return;
}
if (input.code.startsWith("Digit") && input.meta && !input.control) {
const digitNum = parseInt(input.code.substring(5));
if (isNaN(digitNum) || digitNum < 1 || digitNum > 9) {
return;
}
e.preventDefault();
win.webContents.send("digit-cmd", { digit: digitNum }, mods);
}
if (checkKeyPressed(waveEvent, "Cmd:[") || checkKeyPressed(waveEvent, "Cmd:]")) {
const rel = checkKeyPressed(waveEvent, "Cmd:]") ? 1 : -1;
win.webContents.send("bracket-cmd", { relative: rel }, mods);
e.preventDefault();
return;
}
});
win.webContents.on("will-navigate", shNavHandler);
win.webContents.on("will-frame-navigate", shFrameNavHandler);
Expand Down
10 changes: 0 additions & 10 deletions src/electron/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,7 @@ contextBridge.exposeInMainWorld("api", {
installAppUpdate: () => ipcRenderer.send("install-app-update"),
getAppUpdateStatus: () => ipcRenderer.sendSync("get-app-update-status"),
onAppUpdateStatus: (callback) => ipcRenderer.on("app-update-status", (_, val) => callback(val)),
onTCmd: (callback) => ipcRenderer.on("t-cmd", callback),
onLCmd: (callback) => ipcRenderer.on("l-cmd", callback),
onWCmd: (callback) => ipcRenderer.on("w-cmd", callback),
onRCmd: (callback) => ipcRenderer.on("r-cmd", callback),
onZoomChanged: (callback) => ipcRenderer.on("zoom-changed", callback),
onMetaArrowUp: (callback) => ipcRenderer.on("meta-arrowup", callback),
onMetaArrowDown: (callback) => ipcRenderer.on("meta-arrowdown", callback),
onMetaPageUp: (callback) => ipcRenderer.on("meta-pageup", callback),
onMetaPageDown: (callback) => ipcRenderer.on("meta-pagedown", callback),
onBracketCmd: (callback) => ipcRenderer.on("bracket-cmd", callback),
onDigitCmd: (callback) => ipcRenderer.on("digit-cmd", callback),
onMenuItemAbout: (callback) => ipcRenderer.on("menu-item-about", callback),
contextScreen: (screenOpts, position) => ipcRenderer.send("context-screen", screenOpts, position),
contextEditMenu: (position, opts) => ipcRenderer.send("context-editmenu", position, opts),
Expand Down
9 changes: 0 additions & 9 deletions src/models/clientsettingsview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@ class ClientSettingsViewModel {
this.globalModel.activeMainView.set("clientsettings");
})();
}

handleDocKeyDown(e: any): void {
const waveEvent = adaptFromReactOrNativeKeyEvent(e);
if (checkKeyPressed(waveEvent, "Escape")) {
e.preventDefault();
this.closeView();
return;
}
}
}

export { ClientSettingsViewModel };
9 changes: 0 additions & 9 deletions src/models/connectionsview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@ class ConnectionsViewModel {
this.globalModel.activeMainView.set("connections");
})();
}

handleDocKeyDown(e: any): void {
const waveEvent = adaptFromReactOrNativeKeyEvent(e);
if (checkKeyPressed(waveEvent, "Escape")) {
e.preventDefault();
this.closeView();
return;
}
}
}

export { ConnectionsViewModel };
9 changes: 2 additions & 7 deletions src/models/historyview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,8 @@ class HistoryViewModel {
GlobalCommandRunner.historyView(this._getSearchParams(0, 0));
}

handleDocKeyDown(e: any): void {
const waveEvent = adaptFromReactOrNativeKeyEvent(e);
if (checkKeyPressed(waveEvent, "Escape")) {
e.preventDefault();
this.closeView();
return;
}
handleUserClose() {
this.closeView();
}

showHistoryView(data: HistoryViewDataType): void {
Expand Down
Loading
Loading