From f2bf795396cd5e677485f16e81ccc2412a61546d Mon Sep 17 00:00:00 2001 From: shueja <32416547+shueja@users.noreply.github.com> Date: Thu, 11 Apr 2024 10:59:39 -0700 Subject: [PATCH] Add list of keyboard shortcuts to document settings (#447) Co-authored-by: Jacob Trentini --- src-tauri/Cargo.lock | 50 ++++++++ src-tauri/Cargo.toml | 2 +- src-tauri/tauri.conf.json | 3 + .../config/KeyboardShortcutsPanel.tsx | 119 ++++++++++++++++++ src/components/config/SettingsModal.tsx | 5 + src/document/UIStateStore.tsx | 2 +- 6 files changed, 179 insertions(+), 2 deletions(-) create mode 100644 src/components/config/KeyboardShortcutsPanel.tsx diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 286708bb4..034b9bc6b 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1767,6 +1767,17 @@ dependencies = [ "windows-sys 0.42.0", ] +[[package]] +name = "os_info" +version = "3.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "006e42d5b888366f1880eda20371fedde764ed2213dc8496f49622fa0c99cd5e" +dependencies = [ + "log", + "serde", + "winapi", +] + [[package]] name = "overload" version = "0.1.1" @@ -2634,6 +2645,19 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sys-locale" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8a11bd9c338fdba09f7881ab41551932ad42e405f61d01e8406baea71c07aee" +dependencies = [ + "js-sys", + "libc", + "wasm-bindgen", + "web-sys", + "windows-sys 0.45.0", +] + [[package]] name = "system-deps" version = "5.0.0" @@ -2758,6 +2782,7 @@ dependencies = [ "objc", "once_cell", "open", + "os_info", "percent-encoding", "rand 0.8.5", "raw-window-handle", @@ -2769,6 +2794,7 @@ dependencies = [ "serde_repr", "serialize-to-javascript", "state", + "sys-locale", "tar", "tauri-macros", "tauri-runtime", @@ -3575,6 +3601,15 @@ dependencies = [ "windows_x86_64_msvc 0.42.2", ] +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.2", +] + [[package]] name = "windows-sys" version = "0.48.0" @@ -3584,6 +3619,21 @@ dependencies = [ "windows-targets 0.48.5", ] +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + [[package]] name = "windows-targets" version = "0.48.5" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 362bea560..0fa042929 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -15,7 +15,7 @@ license = "BSD-3-Clause" tauri-build = { version = "1.5.1", features = [] } [dependencies] -tauri = { version = "1.6.0", features = [ "window-close", "window-set-title", "path-all", "dialog", "dialog-confirm", "dialog-save", "dialog-open", "dialog-ask", "fs-all", "shell-open", "devtools"] } +tauri = { version = "1.6.0", features = [ "os-all", "window-close", "window-set-title", "path-all", "dialog", "dialog-confirm", "dialog-save", "dialog-open", "dialog-ask", "fs-all", "shell-open", "devtools"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" trajoptlib = { git = "https://github.com/SleipnirGroup/TrajoptLib.git", rev = "e7ae74aa2ef06de734b896305ab31261f1611c69", features = ["sleipnir"] } diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 27c4d5d06..ad1610b01 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -32,6 +32,9 @@ "window": { "setTitle": true, "close": true + }, + "os": { + "all": true } }, "bundle": { diff --git a/src/components/config/KeyboardShortcutsPanel.tsx b/src/components/config/KeyboardShortcutsPanel.tsx new file mode 100644 index 000000000..74dc37b4e --- /dev/null +++ b/src/components/config/KeyboardShortcutsPanel.tsx @@ -0,0 +1,119 @@ +import { Accordion, AccordionDetails, AccordionSummary } from "@mui/material"; +import Paper from "@mui/material/Paper"; +import Table from "@mui/material/Table"; +import TableBody from "@mui/material/TableBody"; +import TableCell from "@mui/material/TableCell"; +import TableContainer from "@mui/material/TableContainer/TableContainer"; +import TableRow from "@mui/material/TableRow/TableRow"; +import { type } from "@tauri-apps/api/os"; +import { Component } from "react"; +import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; + +type Props = object; + +type State = object; + +let isMac = false; +// We don't want to block during the imports stage, especially +// if type() somehow fails. +type().then((type) => { + isMac = type == "Darwin"; +}); +// These default to the Mac ⌘ key because it's easier to replace with Ctrl than vice versa +// All descriptions should be like "Rotate" or "Select", not "Selects" +const shortcuts = { + Path: { + "G, ⌘ + G": "Generate current path", + Space: "Start/stop path playback", + Escape: "Clear sidebar and navbar selection" + }, + "Field View": { + "Left Mouse Drag": "Pan around the field", + "Scroll Wheel, Trackpad Scroll": "Zoom in or out of the field", + "⌘ + Plus": "Zoom in", + "⌘ + Minus": "Zoom out", + "⌘ + 0": "Fit zoom to waypoints" + }, + File: { + "⌘ + N": "New File", + "⌘ + O": "Open File", + "⌘ + Z": "Undo", + "⌘ + Shift + Z, ⌘ + Y": "Redo" + }, + Waypoints: { + "1 through 4": "Select waypoint type in navbar", + "Shift + 1 through Shift + 4": "Change type of selected waypoint", + "Left Mouse Click": + "Add waypoint type selected in navbar at click position", + "Left Arrow, X": "Select previous waypoint in path", + "Right Arrow, Z": "Select next waypoint in path", + "Delete/Backspace": "Delete selected waypoint" + }, + "Selected Waypoint Movement": { + "Left Mouse Drag on Center": "Move Waypoint", + "Left Mouse Drag on Edge": "Rotate Waypoint", + Q: "Rotate 1/32 turn counterclockwise", + E: "Rotate 1/32 turn clockwise", + "Shift + Rotation Key": "Rotate by 1/8 turn instead of 1/32 turn", + W: "Translate 0.1 m up (+Y)", + A: "Translate 0.1 m left (-X)", + S: "Translate 0.1 m down (-Y)", + D: "Translate 0.1 m right (+X)", + "Shift + Translation Key": "Translate by 0.5 m instead of 0.1 m" + } +}; + +class KeyboardShortcutsPanel extends Component { + rowGap = 16; + render() { + return ( +
+ {Object.entries(shortcuts).map((entry) => ( + <> + + }> + {entry[0].toUpperCase()} + + + + + + {Object.entries(entry[1]).map((entry) => ( + + {entry[1]} + + {isMac + ? entry[0] + : entry[0].replaceAll("⌘", "Ctrl")} + + + ))} + +
+
+
+
+ + ))} +
+ ); + } +} +export default KeyboardShortcutsPanel; diff --git a/src/components/config/SettingsModal.tsx b/src/components/config/SettingsModal.tsx index 83bef3156..d672acded 100644 --- a/src/components/config/SettingsModal.tsx +++ b/src/components/config/SettingsModal.tsx @@ -6,6 +6,7 @@ import RobotConfigPanel from "./robotconfig/RobotConfigPanel"; import { Close } from "@mui/icons-material"; import ExportConfigPanel from "./ExportConfigPanel"; import BetasConfigPanel from "./BetasConfigPanel"; +import KeyboardShortcutsPanel from "./KeyboardShortcutsPanel"; type Props = object; @@ -69,6 +70,7 @@ class SettingsModal extends Component { > + uiState.setRobotConfigOpen(false)}> @@ -83,6 +85,9 @@ class SettingsModal extends Component { )} {uiState.settingsTab == 2 && ( + + )} + {uiState.settingsTab == 3 && ( )} diff --git a/src/document/UIStateStore.tsx b/src/document/UIStateStore.tsx index 399c9236f..be7df464e 100644 --- a/src/document/UIStateStore.tsx +++ b/src/document/UIStateStore.tsx @@ -247,7 +247,7 @@ export const ViewItemData = (() => { })(); export const ViewLayerDefaults = ViewItemData.map((layer) => layer.default); export type ViewLayerType = typeof ViewLayers; -export const NUM_SETTINGS_TABS = 3; +export const NUM_SETTINGS_TABS = 4; export const UIStateStore = types .model("UIStateStore", { fieldScalingFactor: 0.02,