edith
Clone
https://git.tahinli.com/Tahinli/edith.git
0 watching·0 forks·Rust·18.3 MiB·ff99ad6·Tahinli·6 days ago·1055 commits
| 1 | //! The keymap: which stroke means which action, and the file it survives in. |
| 2 | //! |
| 3 | //! ```text |
| 4 | //! edith-keys 2 |
| 5 | //! play space |
| 6 | //! delete x |
| 7 | //! delete delete |
| 8 | //! save ctrl+s |
| 9 | //! ``` |
| 10 | //! |
| 11 | //! One line per binding, so an action bound to two strokes is two lines and the |
| 12 | //! format needs no list syntax. A chord is `key` with any of `ctrl+`, `shift+` and |
| 13 | //! `alt+` in front of it, in any order, where `key` is |
| 14 | //! exactly what gpui reports for the stroke (`escape`, not `esc`) -- the lookup |
| 15 | //! compares against that string and nothing translates in between. What a |
| 16 | //! *person* reads is [`Keymap::display`]'s business, and only there. |
| 17 | //! |
| 18 | //! The parser is strict and everything it cannot use names its 1-based line, |
| 19 | //! like the project file. Only the first line refuses the whole file: a binding |
| 20 | //! line the parser cannot use is *dropped*, named in the notice, and every other |
| 21 | //! line still stands -- one unusable line is not a reason to throw away the |
| 22 | //! rebinds around it. A missing file is not corrupt either -- it means nobody |
| 23 | //! has changed a key yet, and the defaults stand. |
| 24 | //! |
| 25 | //! Writing mirrors `engine::edith::save`: `.part`, fsync, rename, directory |
| 26 | //! fsync, so an interrupted save cannot cost the bindings that were already |
| 27 | //! there. |
| 28 | |
| 29 | // The UI consumes this module in a later step; until then nothing calls it and |
| 30 | // every item here reads as dead. |
| 31 | #![allow(dead_code)] |
| 32 | |
| 33 | use std::ffi::OsString; |
| 34 | use std::io::Write; |
| 35 | use std::path::{Path, PathBuf}; |
| 36 | |
| 37 | /// First line, exactly. The version is part of it, as in the project file. |
| 38 | const MAGIC: &str = "edith-keys 2"; |
| 39 | |
| 40 | /// The action list, written once: the enum and the display-order array come out |
| 41 | /// of the same names, so an action added here is in [`ActionId::ALL`] by |
| 42 | /// construction. It used to be two lists, and a variant added to one of them |
| 43 | /// compiled, passed every test, and was simply missing from the keys card -- |
| 44 | /// the pointer-unreachable action this editor opened with. |
| 45 | macro_rules! actions { |
| 46 | ($($(#[$note:meta])* $variant:ident),+ $(,)?) => { |
| 47 | /// Everything a stroke can ask for. Not the mouse's actions: only what a |
| 48 | /// key can reach is bindable. |
| 49 | #[derive(Clone, Copy, PartialEq, Eq, Debug)] |
| 50 | pub enum ActionId { |
| 51 | $($(#[$note])* $variant,)+ |
| 52 | } |
| 53 | |
| 54 | impl ActionId { |
| 55 | /// The angle a number key switches to (1 to 9). |
| 56 | pub fn angle_number(self) -> Option<usize> { |
| 57 | match self { |
| 58 | ActionId::Angle1 => Some(1), |
| 59 | ActionId::Angle2 => Some(2), |
| 60 | ActionId::Angle3 => Some(3), |
| 61 | ActionId::Angle4 => Some(4), |
| 62 | ActionId::Angle5 => Some(5), |
| 63 | ActionId::Angle6 => Some(6), |
| 64 | ActionId::Angle7 => Some(7), |
| 65 | ActionId::Angle8 => Some(8), |
| 66 | ActionId::Angle9 => Some(9), |
| 67 | _ => None, |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | impl ActionId { |
| 73 | /// Display order everywhere -- the editor lists them in it and |
| 74 | /// [`Keymap::defaults`] binds them in it. Derived from the list |
| 75 | /// above, so there is no second place to forget. |
| 76 | pub const ALL: [ActionId; [$(stringify!($variant)),+].len()] = |
| 77 | [$(ActionId::$variant),+]; |
| 78 | } |
| 79 | }; |
| 80 | } |
| 81 | |
| 82 | actions! { |
| 83 | Play, |
| 84 | /// Whether the active session -- the timeline or a library preview -- |
| 85 | /// restarts from the top on reaching its end instead of stopping there. |
| 86 | /// Live exactly where Play is: a transport with nothing under it has |
| 87 | /// nothing to loop either. |
| 88 | Loop, |
| 89 | /// Plays from a short lead-in before the playhead to a short run-on after |
| 90 | /// it, then puts the playhead back where it started (Premiere's Play Around). |
| 91 | PlayAround, |
| 92 | StepBack, |
| 93 | StepForward, |
| 94 | JumpBack, |
| 95 | JumpForward, |
| 96 | GoStart, |
| 97 | GoEnd, |
| 98 | /// Types a time (`1:23`, `83.5`, `00:01:23:12`, `+2s`, `-10f`) and the playhead jumps there. |
| 99 | GoToTime, |
| 100 | /// The two that put the playhead on a *source* sync point -- the frames a |
| 101 | /// cut may be placed on for an export to copy the film's own coded pictures |
| 102 | /// instead of decoding and coding every one of them again. Playback keys by |
| 103 | /// what they do (they move the playhead and nothing else) and editing keys |
| 104 | /// by what they are for. |
| 105 | PrevSyncPoint, |
| 106 | NextSyncPoint, |
| 107 | /// Walks to the next cut (DESIGN.md §6): the odometer the cut readout |
| 108 | /// counts against. |
| 109 | WalkCutNext, |
| 110 | /// The pair's other half, one cut earlier. |
| 111 | WalkCutPrev, |
| 112 | /// [`ActionId::WalkCutNext`]'s stride-ten (DESIGN.md §6's "shift"): its |
| 113 | /// own action, not a modifier read off `WalkCutNext`, because gpui 0.2.2 |
| 114 | /// never delivers a shift modifier alongside `.`/`,` (see [`Chord`]'s |
| 115 | /// doc) -- the *only* channel a stroke has back to [`Player::act`] is |
| 116 | /// which [`ActionId`] the keymap resolved it to, so the stride the |
| 117 | /// platform can't spell as a modifier is spelled as its own bound key |
| 118 | /// (`>`, what shift+. actually types) instead. |
| 119 | WalkCutNext10, |
| 120 | /// The pair's other half (`<`, what shift+, actually types). |
| 121 | WalkCutPrev10, |
| 122 | /// Drops a comment marker at the playhead (`engine::project::Marker`): a name, a |
| 123 | /// note and a colour, listed on the markers card. Bare `m` is the mute, so it |
| 124 | /// takes the alt rung of the same letter. |
| 125 | AddMarker, |
| 126 | /// Drops a comment marker at the frame the ruler menu was opened on. |
| 127 | MarkerHere, |
| 128 | /// Renames the marker the ruler menu was opened on: the markers card opens with its name |
| 129 | /// being typed ([`Player::begin_marker_edit`]). |
| 130 | RenameMarker, |
| 131 | /// Takes the marker the ruler menu was opened on off the list. |
| 132 | DeleteMarker, |
| 133 | /// Moves the playhead to the frame the ruler (or empty-track) menu was opened on. |
| 134 | PlayheadHere, |
| 135 | /// Walks the playhead to the next comment marker, after the playhead. |
| 136 | NextMarker, |
| 137 | /// The pair's other half, the marker before the playhead. |
| 138 | PrevMarker, |
| 139 | /// Opens the markers card: every marker with its time, name, note and colour. |
| 140 | Markers, |
| 141 | /// Marks the playhead as an export's in point. The out point wraps around |
| 142 | /// it if the mark lands past the current out ([`ordered_range`]). |
| 143 | SetIn, |
| 144 | /// The out point's pair. Ordered the same way against whatever in point |
| 145 | /// stands already. |
| 146 | SetOut, |
| 147 | /// Drops the mark: an export goes back to the whole timeline. |
| 148 | ClearRange, |
| 149 | /// Pre-renders the In-Out range into the render cache, which plays back as finished frames. |
| 150 | RenderInOut, |
| 151 | /// Pre-renders the whole timeline into the render cache. |
| 152 | RenderAll, |
| 153 | /// Stops the render preview running now and removes its partial file. |
| 154 | CancelRender, |
| 155 | /// Deletes every render-cache file. |
| 156 | DeleteRenderFiles, |
| 157 | /// The J/K/L shuttle (DESIGN.md §10.2). J plays backward, and again steps |
| 158 | /// the rate through 2x and 4x. |
| 159 | ShuttleBack, |
| 160 | /// K: pauses whatever is playing. |
| 161 | ShuttleStop, |
| 162 | /// L: plays forward, and again steps the rate through 2x and 4x. |
| 163 | ShuttleForward, |
| 164 | Export, |
| 165 | Save, |
| 166 | /// Reloads the open project from its file on disk, as the window follows it |
| 167 | /// when another writer saves it ([`crate::Player::reload_request`]). Menu and |
| 168 | /// palette only: no stroke, since a key that throws away edits is one that |
| 169 | /// is pressed by accident. |
| 170 | ReloadProject, |
| 171 | /// File > New > Project…: a small dialog (name, folder, size, rate) that starts a project |
| 172 | /// the first footage then fills. Menu, palette and the welcome screen's button. |
| 173 | NewProject, |
| 174 | /// File > Save version: a named full copy of the project beside it, kept to go back to |
| 175 | /// ([`engine::versions`]). Menu and palette only. |
| 176 | SaveVersion, |
| 177 | /// File > Save as template…: the settings, and optionally the clips, as a reusable template. |
| 178 | SaveTemplate, |
| 179 | /// File > Export captions: the timeline's captions written as an SRT or WebVTT file beside |
| 180 | /// the export folder's default name ([`engine::subtitle::write_srt`]). Menu and palette only. |
| 181 | ExportCaptions, |
| 182 | /// File > Versions: the saved versions, and Restore for one (a single undo step). |
| 183 | Versions, |
| 184 | /// File > Collect media: copies every used source into one folder and relinks the project |
| 185 | /// to the copies ([`engine::collect`]). |
| 186 | CollectMedia, |
| 187 | /// File > Project notes: a free-text note kept in the project, several lines allowed. |
| 188 | ProjectNotes, |
| 189 | /// File > Export timeline as > OpenTimelineIO, Final Cut Pro XML or EDL: writes the active |
| 190 | /// sequence to the default export folder, named after the project ([`engine::interchange`]). |
| 191 | ExportTimelineOtio, |
| 192 | ExportTimelineFcpxml, |
| 193 | ExportTimelineEdl, |
| 194 | /// File > Import timeline (OTIO): reads an OpenTimelineIO file as a new sequence of the project. |
| 195 | ImportTimelineOtio, |
| 196 | Copy, |
| 197 | Paste, |
| 198 | /// Three-point insert (DESIGN.md §10.2): the library item being previewed -- |
| 199 | /// its marked in..out, or the whole of it -- goes in at the playhead, cutting |
| 200 | /// the clip there and rippling the later ones on the lanes it lands on. With |
| 201 | /// timeline marks set, their length is the duration. F9, as in Resolve: |
| 202 | /// `,` and `.` already walk the cuts. |
| 203 | InsertSource, |
| 204 | /// Three-point overwrite: the same source range laid over what is at the |
| 205 | /// playhead for its length, trimming or splitting it. Nothing moves. F10. |
| 206 | OverwriteSource, |
| 207 | Cut, |
| 208 | Regroup, |
| 209 | Detach, |
| 210 | Group, |
| 211 | Select, |
| 212 | SelectNext, |
| 213 | SelectPrev, |
| 214 | /// Every placement on every lane in one selection -- the companion of the |
| 215 | /// ctrl-click that builds a selection by hand, for the times everything |
| 216 | /// wants selecting at once. |
| 217 | SelectAll, |
| 218 | /// Bare escape with nothing else claiming it: empties a multi-clip |
| 219 | /// selection without touching picks, cards or fullscreen. |
| 220 | Deselect, |
| 221 | Delete, |
| 222 | Lift, |
| 223 | Color, |
| 224 | /// Where a clip sits, how big and which way up |
| 225 | /// ([`crate::transform_ui::TRANSFORM_BANDS`]) -- the geometry twin of |
| 226 | /// [`ActionId::Color`], filed right beside it. |
| 227 | Transform, |
| 228 | /// Opens the effects card: the clip's stack of blurs, keys and masks. |
| 229 | Effects, |
| 230 | /// The stopwatch on the transform card's placement: a key on the playhead |
| 231 | /// holding what the clip shows there, or the one that is there taken off. |
| 232 | KeyPlacement, |
| 233 | /// [`ActionId::KeyPlacement`] for the opacity. |
| 234 | KeyOpacity, |
| 235 | /// [`ActionId::KeyPlacement`] for the grade, on the colour card. |
| 236 | KeyColor, |
| 237 | /// Steps the easing of the key on the playhead: linear, ease in, ease out, |
| 238 | /// ease in-out, hold. |
| 239 | KeyEasing, |
| 240 | Fit, |
| 241 | Resolution, |
| 242 | ZoomIn, |
| 243 | ZoomOut, |
| 244 | ZoomFit, |
| 245 | /// Fits the timeline view to the selected clips' span, with a small margin. |
| 246 | ZoomToSelection, |
| 247 | /// Every track to Small height (the Timeline menu's "All tracks" rows; a lane's own |
| 248 | /// header menu sets one track, see `oracle::lane_items`). |
| 249 | TrackSmall, |
| 250 | /// Every track to Medium height, the height a track starts at. |
| 251 | TrackMedium, |
| 252 | /// Every track to Large height, for thumbnails and waveforms in full. |
| 253 | TrackLarge, |
| 254 | /// Every track one size shorter, from its own size. |
| 255 | TracksSmaller, |
| 256 | /// Every track one size taller, from its own size. |
| 257 | TracksLarger, |
| 258 | /// The viewer's zoom list: Fit, 25, 50, 100, 200%. View state, saved with the project's view. |
| 259 | ViewZoom, |
| 260 | /// The viewer's playback quality list: Full, Half, Quarter. |
| 261 | PlaybackQuality, |
| 262 | /// Safe-area rectangles and centre cross over the picture. |
| 263 | GuideStyle, |
| 264 | /// The aspect mask list: none, 9:16, 1:1, 4:5. |
| 265 | GuideMask, |
| 266 | Undo, |
| 267 | Redo, |
| 268 | /// Edit > History: the card that lists the undo steps and jumps to any of them. |
| 269 | History, |
| 270 | AddVideoLane, |
| 271 | AddAudioLane, |
| 272 | RemoveVideoLane, |
| 273 | RemoveAudioLane, |
| 274 | AddSubtitleLane, |
| 275 | RemoveSubtitleLane, |
| 276 | /// The palette's own door: a file's subtitle tracks read into the list the |
| 277 | /// panel shows, which is where a lane's words are dragged *from*. Adding a |
| 278 | /// track to that list places nothing -- the pair above it is what makes the |
| 279 | /// timeline row a caption can land on. |
| 280 | ImportSubtitles, |
| 281 | /// The dock's own `Import media` verb (MOCK-SPEC "Dock" IMPORT section): |
| 282 | /// the file chooser, same door [`crate::Player::pick_and_import`] and a |
| 283 | /// drop on the window already use. |
| 284 | AddFiles, |
| 285 | /// The dock's `Paste path` verb: imports whatever file the OS clipboard |
| 286 | /// names ([`crate::Player::paste_file_path`]). |
| 287 | PasteFilePath, |
| 288 | /// File > Open project…: asks for a `.edith` project and opens it, with the |
| 289 | /// same unsaved-changes question a recent project asks ([`crate::Player::pick_open_project`]). |
| 290 | /// The welcome screen's Open project button is the same door. |
| 291 | OpenProject, |
| 292 | ToggleMute, |
| 293 | VolumeUp, |
| 294 | VolumeDown, |
| 295 | Equalizer, |
| 296 | Speed, |
| 297 | /// The speed card's ramp shapes, laid across the clip the card would open on |
| 298 | /// without opening it ([`crate::audio_cards::RampPreset`]): real time easing |
| 299 | /// up to double... |
| 300 | SpeedRampUp, |
| 301 | /// ...double easing down to real time... |
| 302 | SpeedRampDown, |
| 303 | /// ...slow-fast-slow, the classic speed ramp... |
| 304 | SpeedRampSlowFastSlow, |
| 305 | /// ...and fast-slow-fast, the hero shot. |
| 306 | SpeedRampFastSlowFast, |
| 307 | /// Puts a key on the clip's speed ramp at the playhead, at the speed the ramp |
| 308 | /// runs there. |
| 309 | SpeedRampKey, |
| 310 | /// Takes the clip's speed ramp off, back to its constant speed. |
| 311 | SpeedRampClear, |
| 312 | Silence, |
| 313 | /// The Tools card on Normalize: the mix (or each track) to a loudness target, the true peak |
| 314 | /// held under a ceiling ([`engine::normalize`]). |
| 315 | Normalize, |
| 316 | /// The Tools card on Captions: listen to the sound, put the words on a caption track. |
| 317 | Captions, |
| 318 | /// The Tools card on Fillers: the ums and uhs found, checked, cut out as one step. |
| 319 | Fillers, |
| 320 | /// Cuts the words picked in the transcript out of every lane, closing the hole: one undo |
| 321 | /// step. The transcript's own Cut button and the Delete key there do the same. |
| 322 | CutSelectedWords, |
| 323 | /// The Tools card on Voiceover: text spoken by piper and placed at the playhead. |
| 324 | Voiceover, |
| 325 | /// Timeline > Record voice-over: records from the audio input onto an audio lane at the |
| 326 | /// playhead, as one undo step. Menu and palette only. |
| 327 | RecordVoiceover, |
| 328 | /// Paints a sliding waveform of this audio clip onto a video lane, so the |
| 329 | /// sound is a picture on the same timeline — preview and export both. |
| 330 | Visualizer, |
| 331 | /// Listens to a sound clip for its beat and marks the beats as comment markers. |
| 332 | MarkBeats, |
| 333 | Reframe, |
| 334 | TrackMask, |
| 335 | /// Folds the selected clips (and their linked partners) into a new sequence and leaves |
| 336 | /// one compound clip where they were ([`engine::Project::nest`]). |
| 337 | NestClips, |
| 338 | /// Puts a compound clip's contents back on the timeline ([`engine::Project::break_apart`]). |
| 339 | BreakApart, |
| 340 | /// Opens the selected compound clip's sequence for editing. |
| 341 | OpenCompound, |
| 342 | /// Back to the sequence the compound clip was opened from. |
| 343 | CloseCompound, |
| 344 | /// A new empty sequence, opened. |
| 345 | NewSequence, |
| 346 | /// A copy of the sequence being edited, opened. |
| 347 | DuplicateSequence, |
| 348 | /// Retypes the open sequence's name on its tab. |
| 349 | RenameSequence, |
| 350 | /// Deletes the open sequence (never the last, never one a compound clip plays). |
| 351 | DeleteSequence, |
| 352 | /// Makes a multicam clip of the media selected in the library, synced by their sound |
| 353 | /// ([`engine::PlaybackSession::make_multicam_at`]). |
| 354 | CreateMulticam, |
| 355 | /// Replaces the multicam clip with the plain camera clips it plays. |
| 356 | FlattenMulticam, |
| 357 | /// Shows or hides the angle monitor beside the picture: a grid of the multicam clip's angles |
| 358 | /// at the playhead, each one a button that switches the picture to it. |
| 359 | ToggleAngleMonitor, |
| 360 | ToggleOutputWindow, |
| 361 | OutputDisplay, |
| 362 | /// Switches the multicam clip under the playhead to angle 1..9 from the playhead on (a razor |
| 363 | /// cut and the new angle on the right half, one undo step). Live while the angle monitor is. |
| 364 | Angle1, |
| 365 | Angle2, |
| 366 | Angle3, |
| 367 | Angle4, |
| 368 | Angle5, |
| 369 | Angle6, |
| 370 | Angle7, |
| 371 | Angle8, |
| 372 | Angle9, |
| 373 | /// Retypes a track's name on its head (the track's right-click menu; double-click too). |
| 374 | RenameLane, |
| 375 | /// Crossfades the selected audio clip into its neighbour ([`Project::crossfade`]): |
| 376 | /// two adjacent clips picked on one lane, or a single pick faded into the |
| 377 | /// clip right after it. |
| 378 | Crossfade, |
| 379 | /// No-aim trim of the subject cut's in point, frame detents, at any zoom |
| 380 | /// (DESIGN.md §6), on its designed bare `[`. [`ActionId::SelectPrev`] |
| 381 | /// moved to `{` (what shift+[ actually types) to free it -- see |
| 382 | /// keymap.rs's own defaults. |
| 383 | TrimIn, |
| 384 | /// The pair's other half, the subject cut's out point, on its designed |
| 385 | /// bare `]` -- [`ActionId::SelectNext`] moved to `}` (what shift+] |
| 386 | /// actually types) for the same reason. |
| 387 | TrimOut, |
| 388 | /// Loop-trim: loops around the subject cut while trimming it (DESIGN.md |
| 389 | /// §6, "the modernized Avid trim mode"). |
| 390 | LoopTrim, |
| 391 | /// The keyboard's own version of the pointer's drag-the-edge-to-a-spot |
| 392 | /// trim (debt #42: trim used to be pointer-only): snaps the subject |
| 393 | /// cut's in point straight to the playhead, one press, one undo step -- |
| 394 | /// [`ActionId::TrimIn`]'s frame-detent nudge covers the other case. Bare |
| 395 | /// `[`/`{`/ctrl+`[` are all spoken for (nudge, select-prev, sync point), |
| 396 | /// so this takes the next rung of the same bracket family: ctrl held on |
| 397 | /// the shifted bracket, `ctrl+{` (what ctrl+shift+[ actually types). |
| 398 | TrimInToPlayhead, |
| 399 | /// The pair's other half, the subject cut's out point, on `ctrl+}`. |
| 400 | TrimOutToPlayhead, |
| 401 | /// The ripple version of [`ActionId::TrimInToPlayhead`], on `q`: the same edge moves to the |
| 402 | /// playhead, and the hole it leaves closes so the clips after it move up (Premiere's ripple trim). |
| 403 | RippleTrimInToPlayhead, |
| 404 | /// The ripple version of [`ActionId::TrimOutToPlayhead`], on `w`: the out point moves to the |
| 405 | /// playhead and what follows moves with it. |
| 406 | RippleTrimOutToPlayhead, |
| 407 | /// **Roll**: moves the cut after the subject clip one frame earlier, |
| 408 | /// the clip's out point and its neighbour's in point together, so the |
| 409 | /// timeline keeps its length ([`Project::roll`]). The pointer's version |
| 410 | /// is shift-drag on a clip edge. |
| 411 | RollBack, |
| 412 | /// Roll's other direction: the cut one frame later. |
| 413 | RollForward, |
| 414 | /// **Slip**: the subject clip shows one frame earlier of its source, |
| 415 | /// keeping its place and length ([`Project::slip`]). The pointer's |
| 416 | /// version is shift-drag on the clip. |
| 417 | SlipBack, |
| 418 | /// Slip's other direction: one frame later of the source. |
| 419 | SlipForward, |
| 420 | /// **Slide**: the subject clip moves one frame earlier between its |
| 421 | /// neighbours, which give and take the frame ([`Project::slide`]). The |
| 422 | /// pointer's version is shift+alt-drag on the clip. |
| 423 | SlideBack, |
| 424 | /// Slide's other direction: one frame later. |
| 425 | SlideForward, |
| 426 | /// Dissolves the selected video clip into its neighbour |
| 427 | /// ([`Project::set_transition_out`]): two adjacent clips picked on one |
| 428 | /// lane, or a single pick dissolved into the clip right after it. A |
| 429 | /// second press on a clip that already dissolves removes it instead. |
| 430 | Dissolve, |
| 431 | /// The `Transition*` family sets how the selected video clip's join with |
| 432 | /// its neighbour is drawn ([`engine::transitions::TransitionKind`]), making |
| 433 | /// the join (one second) if the clip has none: the command palette's door |
| 434 | /// to the picker the Clip tab shows. Unbound by default. |
| 435 | TransitionDissolve, |
| 436 | TransitionDipBlack, |
| 437 | TransitionDipWhite, |
| 438 | TransitionWipeLeft, |
| 439 | TransitionWipeRight, |
| 440 | TransitionWipeUp, |
| 441 | TransitionWipeDown, |
| 442 | TransitionSlideLeft, |
| 443 | TransitionSlideRight, |
| 444 | TransitionSlideUp, |
| 445 | TransitionSlideDown, |
| 446 | TransitionPushLeft, |
| 447 | TransitionPushRight, |
| 448 | TransitionPushUp, |
| 449 | TransitionPushDown, |
| 450 | TransitionZoom, |
| 451 | /// Plays the selected clip (and its group) backward, or forward again |
| 452 | /// ([`engine::PlaybackSession::set_reverse`]): picture and sound, composing |
| 453 | /// with the clip's rate. Menu, palette and `ctrl+alt+r`. |
| 454 | Reverse, |
| 455 | /// Switches the selected clip on or off ([`engine::PlaybackSession::set_enabled`]): a |
| 456 | /// switched-off clip stays on the timeline, drawn dimmed, and is skipped by picture and sound. |
| 457 | ClipEnabled, |
| 458 | /// Opens the colour label list for the selected clip ([`engine::project::LABELS`]). |
| 459 | ClipLabel, |
| 460 | /// Puts a solid colour, a gradient, a countdown, colour bars or an adjustment layer on the |
| 461 | /// timeline at the playhead ([`engine::generate`]): a clip with no file behind it. |
| 462 | NewSolid, |
| 463 | NewGradient, |
| 464 | NewCountdown, |
| 465 | NewBars, |
| 466 | /// A 1 kHz test tone on an audio lane (File > New > Tone). |
| 467 | NewTone, |
| 468 | /// Colour bars on V and a tone on A, linked (File > New > Bars and tone). |
| 469 | NewBarsAndTone, |
| 470 | NewAdjustment, |
| 471 | NewRectangle, |
| 472 | NewEllipse, |
| 473 | NewLine, |
| 474 | NewArrow, |
| 475 | /// A title card at the playhead, opened for typing ([`Player::new_title`]). |
| 476 | NewTitle, |
| 477 | /// Makes a bin in the media library, named in place ([`Player::new_bin`]); the picked media go in it. |
| 478 | NewBin, |
| 479 | /// Makes a bin inside the bin picked in the media library (one level of nesting). |
| 480 | NewBinInside, |
| 481 | /// Retypes the name of the bin picked in the media library. |
| 482 | RenameBin, |
| 483 | /// Removes the bin picked in the media library; what it held stays, one level up. |
| 484 | RemoveBin, |
| 485 | /// Stars or unstars the picked media ([`Player::toggle_favourite`]). |
| 486 | ToggleFavourite, |
| 487 | /// Opens the list of bins to file the picked media in. |
| 488 | MoveToBin, |
| 489 | /// The media list shows only the starred sources. |
| 490 | ShowFavourites, |
| 491 | /// The media list shows every source. |
| 492 | ShowAllMedia, |
| 493 | Mix, |
| 494 | /// One-click voice cleanup of the audio track the selection (or the mix |
| 495 | /// card) names: gate, noise reduction, compressor and de-esser at medium |
| 496 | /// strength, one undo step ([`engine::voice`]). |
| 497 | CleanVoice, |
| 498 | /// The mix card with the picked track's dynamics section unfolded. |
| 499 | VoiceDynamics, |
| 500 | ToggleSnap, |
| 501 | ToggleSubtitles, |
| 502 | /// Draws the audio clips' waveforms, or leaves them as flat bars with their names. |
| 503 | ToggleWaveforms, |
| 504 | ToggleScrubAudio, |
| 505 | CompareOff, |
| 506 | CompareSplit, |
| 507 | CompareSide, |
| 508 | AutoColour, |
| 509 | SaveLook, |
| 510 | /// Cut on the stand-ins or on the films themselves |
| 511 | /// ([`engine::proxy`]): what the picture is decoded from, and nothing |
| 512 | /// else -- the sound and every export stay the film's whichever way it |
| 513 | /// is set. |
| 514 | ToggleProxies, |
| 515 | /// Whether a film that wants a stand-in gets one made as it is imported |
| 516 | /// ([`engine::proxy::wanted`]): what is *encoded*, where the switch above |
| 517 | /// is what is decoded. With it off the switch above is also the ask -- it |
| 518 | /// starts the ones the project is missing. |
| 519 | ToggleAutoProxies, |
| 520 | /// The window's own colours, which belong to the person looking at them and |
| 521 | /// not to the project: a list of the palettes, opened here and from the |
| 522 | /// toolbar's Theme button. It was a build feature once, which made it a |
| 523 | /// choice only whoever compiled the binary could make. |
| 524 | Theme, |
| 525 | /// The accent colour the window is painted with, as a list beside the Theme one: kept |
| 526 | /// for every project like the theme, so it belongs to the person and not to the timeline. |
| 527 | AccentColour, |
| 528 | /// The whole window, borderless over the screen: a player's own control, |
| 529 | /// on the platform's own toggle ([`gpui::Window::toggle_fullscreen`]). |
| 530 | Fullscreen, |
| 531 | CancelExport, |
| 532 | /// Opens the actions card -- the list every other action is on. A door of |
| 533 | /// its own, because a card reachable only by a button in the panel is one a |
| 534 | /// hand on the keyboard has to leave the keyboard for. |
| 535 | ShowActions, |
| 536 | /// The shortcuts sheet (DESIGN.md §10.2's `?` and F1): swings the dock to |
| 537 | /// its KEYS tab, and a second press swings it back. Its own action, not |
| 538 | /// [`ActionId::ShowActions`], which is the command search's door. |
| 539 | ShowKeys, |
| 540 | /// The About dialog: name, version and what edith is. Opens from Help. |
| 541 | About, |
| 542 | /// Saves the frame on screen to a PNG: whatever is showing, the timeline's |
| 543 | /// own picture or a library preview's, since both write through the one |
| 544 | /// `self.image` the atlas already holds. |
| 545 | Screenshot, |
| 546 | /// The cue plate's font and size -- a person's own preference, kept |
| 547 | /// beside the theme and not the project, and opened the same way. |
| 548 | SubtitleStyle, |
| 549 | /// The settings page: PROJECT rows (resolution, fps, sample-rate, HDR |
| 550 | /// tonemap, the mix) beside EDITOR rows (proxies, auto-proxies, subtitle |
| 551 | /// font) -- one door, two clearly-headed sections, per the split rule |
| 552 | /// that "anything that changes the rendered output or lives in the |
| 553 | /// project file is PROJECT; anything about this machine, this person, |
| 554 | /// this window is EDITOR." Always answerable, same as `Theme`: it is |
| 555 | /// about the editor and the project's own numbers, not about a clip. |
| 556 | Settings, |
| 557 | /// Moves the keyboard ring onto the dock (`ui::stance::Surface::Dock`, |
| 558 | /// the cycle's first stop): the door into keyboard-only navigation |
| 559 | /// (`ui::stance`'s Tab/Shift-Tab ring), which nothing else in the app |
| 560 | /// opens. Bare Tab stays [`ActionId::Select`] at the root the whole time |
| 561 | /// -- this only starts the ring, it never steals the clip-selection key. |
| 562 | /// Closes the gap under the playhead (or the picked one): everything after it on the track, and on its linked take, moves up. One undo step. |
| 563 | CloseGap, |
| 564 | /// Holds the frame under the playhead as a still of the default length, pushing the rest later. |
| 565 | Freeze, |
| 566 | /// Pastes the copied clip's colour, effects, transform, speed and sound onto the selected clips. |
| 567 | PasteAttributes, |
| 568 | /// The copied clip's grade onto the selected clips. |
| 569 | PasteColor, |
| 570 | /// The copied clip's effect stack onto the selected clips. |
| 571 | PasteEffects, |
| 572 | /// The copied clip's placement, size and fit onto the selected clips. |
| 573 | PasteTransform, |
| 574 | /// The copied clip's rate, ramp and direction onto the selected clips. |
| 575 | PasteSpeed, |
| 576 | /// The copied clip's gain and equalizer onto the selected clips. |
| 577 | PasteAudio, |
| 578 | /// Opens the source of the clip under the playhead in the library preview, parked on the frame the playhead shows. |
| 579 | MatchFrame, |
| 580 | /// Replaces the clip under the playhead with the selected library item, keeping its place and duration. |
| 581 | ReplaceEdit, |
| 582 | /// Selects every clip from the playhead onward on the selected clip's track. |
| 583 | SelectForward, |
| 584 | /// Selects every clip from the playhead onward on every track. |
| 585 | SelectForwardAll, |
| 586 | /// Split edit: moves the audio edge of the take to the playhead, the picture's staying put (an L-cut after the cut, a J-cut before). |
| 587 | ExtendAudio, |
| 588 | /// Split edit: moves the picture edge of the take to the playhead, the sound's staying put. |
| 589 | ExtendVideo, |
| 590 | /// Moves the selected clips one frame earlier. |
| 591 | NudgeBack, |
| 592 | /// Moves the selected clips one frame later. |
| 593 | NudgeForward, |
| 594 | /// Moves the selected clips ten frames earlier. |
| 595 | NudgeBack10, |
| 596 | /// Moves the selected clips ten frames later. |
| 597 | NudgeForward10, |
| 598 | FocusPanels, |
| 599 | } |
| 600 | |
| 601 | impl ActionId { |
| 602 | /// The transition kind a `Transition*` action sets. |
| 603 | pub fn transition_kind(self) -> Option<engine::transitions::TransitionKind> { |
| 604 | use engine::transitions::{Dir, TransitionKind}; |
| 605 | Some(match self { |
| 606 | ActionId::TransitionDissolve => TransitionKind::Dissolve, |
| 607 | ActionId::TransitionDipBlack => TransitionKind::DipBlack, |
| 608 | ActionId::TransitionDipWhite => TransitionKind::DipWhite, |
| 609 | ActionId::TransitionWipeLeft => TransitionKind::Wipe(Dir::Left), |
| 610 | ActionId::TransitionWipeRight => TransitionKind::Wipe(Dir::Right), |
| 611 | ActionId::TransitionWipeUp => TransitionKind::Wipe(Dir::Up), |
| 612 | ActionId::TransitionWipeDown => TransitionKind::Wipe(Dir::Down), |
| 613 | ActionId::TransitionSlideLeft => TransitionKind::Slide(Dir::Left), |
| 614 | ActionId::TransitionSlideRight => TransitionKind::Slide(Dir::Right), |
| 615 | ActionId::TransitionSlideUp => TransitionKind::Slide(Dir::Up), |
| 616 | ActionId::TransitionSlideDown => TransitionKind::Slide(Dir::Down), |
| 617 | ActionId::TransitionPushLeft => TransitionKind::Push(Dir::Left), |
| 618 | ActionId::TransitionPushRight => TransitionKind::Push(Dir::Right), |
| 619 | ActionId::TransitionPushUp => TransitionKind::Push(Dir::Up), |
| 620 | ActionId::TransitionPushDown => TransitionKind::Push(Dir::Down), |
| 621 | ActionId::TransitionZoom => TransitionKind::Zoom, |
| 622 | _ => return None, |
| 623 | }) |
| 624 | } |
| 625 | |
| 626 | /// What a person calls it. |
| 627 | pub fn label(self) -> &'static str { |
| 628 | match self { |
| 629 | ActionId::Play => "Play / Pause", |
| 630 | ActionId::Loop => "Loop playback", |
| 631 | ActionId::PlayAround => "Play around playhead", |
| 632 | ActionId::StepBack => "One frame back", |
| 633 | ActionId::StepForward => "One frame forward", |
| 634 | ActionId::JumpBack => "One second back", |
| 635 | ActionId::JumpForward => "One second forward", |
| 636 | ActionId::GoStart => "Go to start", |
| 637 | ActionId::GoEnd => "Go to end", |
| 638 | ActionId::GoToTime => "Go to time\u{2026}", |
| 639 | ActionId::PrevSyncPoint => "Previous sync point", |
| 640 | ActionId::NextSyncPoint => "Next sync point", |
| 641 | ActionId::WalkCutNext => "Next cut", |
| 642 | ActionId::WalkCutPrev => "Previous cut", |
| 643 | ActionId::WalkCutNext10 => "Jump 10 cuts forward", |
| 644 | ActionId::WalkCutPrev10 => "Jump 10 cuts back", |
| 645 | ActionId::AddMarker => "Add marker", |
| 646 | ActionId::MarkerHere => "Add marker here", |
| 647 | ActionId::RenameMarker => "Rename marker\u{2026}", |
| 648 | ActionId::DeleteMarker => "Delete marker", |
| 649 | ActionId::PlayheadHere => "Move playhead here", |
| 650 | ActionId::NextMarker => "Next marker", |
| 651 | ActionId::PrevMarker => "Previous marker", |
| 652 | ActionId::Markers => "Markers…", |
| 653 | ActionId::SetIn => "Mark in", |
| 654 | ActionId::SetOut => "Mark out", |
| 655 | ActionId::ClearRange => "Clear range", |
| 656 | ActionId::RenderInOut => "Render in to out", |
| 657 | ActionId::RenderAll => "Render whole timeline", |
| 658 | ActionId::CancelRender => "Cancel render", |
| 659 | ActionId::DeleteRenderFiles => "Delete render files", |
| 660 | ActionId::ShuttleBack => "Shuttle back", |
| 661 | ActionId::ShuttleStop => "Pause shuttle", |
| 662 | ActionId::ShuttleForward => "Shuttle forward", |
| 663 | ActionId::Export => "Export", |
| 664 | ActionId::Save => "Save", |
| 665 | ActionId::ReloadProject => "Reload project from disk", |
| 666 | ActionId::NewProject => "New project…", |
| 667 | ActionId::SaveVersion => "Save version…", |
| 668 | ActionId::SaveTemplate => "Save as template…", |
| 669 | ActionId::ExportCaptions => "Export captions…", |
| 670 | ActionId::Versions => "Versions…", |
| 671 | ActionId::CollectMedia => "Collect media…", |
| 672 | ActionId::ProjectNotes => "Project notes…", |
| 673 | ActionId::ExportTimelineOtio => "OpenTimelineIO…", |
| 674 | ActionId::ExportTimelineFcpxml => "Final Cut Pro XML…", |
| 675 | ActionId::ExportTimelineEdl => "EDL…", |
| 676 | ActionId::ImportTimelineOtio => "Import OpenTimelineIO…", |
| 677 | ActionId::Copy => "Copy", |
| 678 | ActionId::Paste => "Paste", |
| 679 | ActionId::InsertSource => "Insert source at playhead", |
| 680 | ActionId::OverwriteSource => "Overwrite source at playhead", |
| 681 | ActionId::Cut => "Split", |
| 682 | ActionId::Regroup => "Join clips back", |
| 683 | // Neither half's action: it takes the *pair* apart, and the menu |
| 684 | // that offers it hangs on whichever half was right-clicked -- worded |
| 685 | // from the picture's side it read as a video item on an audio clip. |
| 686 | ActionId::Detach => "Unlink audio and video", |
| 687 | ActionId::Group => "Group", |
| 688 | ActionId::Select => "Select clip at playhead", |
| 689 | ActionId::SelectNext => "Select next clip", |
| 690 | ActionId::SelectPrev => "Select previous clip", |
| 691 | ActionId::SelectAll => "Select all", |
| 692 | ActionId::Deselect => "Deselect", |
| 693 | ActionId::Delete => "Delete", |
| 694 | ActionId::Lift => "Lift", |
| 695 | ActionId::Color => "Colour…", |
| 696 | ActionId::Transform => "Transform…", |
| 697 | ActionId::Effects => "Effects…", |
| 698 | ActionId::KeyPlacement => "Add position key here", |
| 699 | ActionId::KeyOpacity => "Add opacity key here", |
| 700 | ActionId::KeyColor => "Add colour key here", |
| 701 | ActionId::KeyEasing => "Key easing…", |
| 702 | ActionId::Fit => "Fit to frame…", |
| 703 | ActionId::Resolution => "Project resolution…", |
| 704 | ActionId::ZoomIn => "Zoom in", |
| 705 | ActionId::ZoomOut => "Zoom out", |
| 706 | ActionId::ZoomFit => "Fit timeline", |
| 707 | ActionId::ZoomToSelection => "Zoom to selection", |
| 708 | ActionId::TrackSmall => "All tracks: Small", |
| 709 | ActionId::TrackMedium => "All tracks: Medium", |
| 710 | ActionId::TrackLarge => "All tracks: Large", |
| 711 | ActionId::TracksSmaller => "Make tracks smaller", |
| 712 | ActionId::TracksLarger => "Make tracks larger", |
| 713 | ActionId::ViewZoom => "Viewer zoom…", |
| 714 | ActionId::PlaybackQuality => "Playback quality…", |
| 715 | ActionId::GuideStyle => "Guides…", |
| 716 | ActionId::GuideMask => "Frame mask…", |
| 717 | ActionId::Undo => "Undo", |
| 718 | ActionId::Redo => "Redo", |
| 719 | ActionId::History => "History…", |
| 720 | ActionId::AddVideoLane => "Add video track", |
| 721 | ActionId::AddAudioLane => "Add audio track", |
| 722 | ActionId::RemoveVideoLane => "Remove video track", |
| 723 | ActionId::RemoveAudioLane => "Remove audio track", |
| 724 | ActionId::AddSubtitleLane => "Add subtitle track", |
| 725 | ActionId::RemoveSubtitleLane => "Remove subtitle track", |
| 726 | ActionId::ImportSubtitles => "Add subtitles…", |
| 727 | ActionId::AddFiles => "Import media…", |
| 728 | ActionId::OpenProject => "Open project…", |
| 729 | ActionId::PasteFilePath => "Paste path", |
| 730 | ActionId::ToggleMute => "Mute / Unmute", |
| 731 | ActionId::VolumeUp => "Volume up", |
| 732 | ActionId::VolumeDown => "Volume down", |
| 733 | ActionId::Equalizer => "Equalizer…", |
| 734 | ActionId::Speed => "Speed…", |
| 735 | ActionId::SpeedRampUp => "Speed ramp up", |
| 736 | ActionId::SpeedRampDown => "Speed ramp down", |
| 737 | ActionId::SpeedRampSlowFastSlow => "Speed ramp slow-fast-slow", |
| 738 | ActionId::SpeedRampFastSlowFast => "Speed ramp fast-slow-fast", |
| 739 | ActionId::SpeedRampKey => "Add speed key here", |
| 740 | ActionId::SpeedRampClear => "Clear speed ramp", |
| 741 | ActionId::Silence => "Silences…", |
| 742 | ActionId::MarkBeats => "Mark the beats…", |
| 743 | ActionId::Normalize => "Normalize loudness…", |
| 744 | ActionId::Captions => "Generate captions", |
| 745 | ActionId::Fillers => "Remove fillers…", |
| 746 | ActionId::CutSelectedWords => "Cut selected words", |
| 747 | ActionId::Voiceover => "Voiceover from text…", |
| 748 | ActionId::RecordVoiceover => "Record voice-over…", |
| 749 | ActionId::Visualizer => "Create visualizer", |
| 750 | ActionId::Reframe => "Auto reframe", |
| 751 | ActionId::TrackMask => "Track mask", |
| 752 | ActionId::NestClips => "Nest into compound clip", |
| 753 | ActionId::BreakApart => "Break apart compound clip", |
| 754 | ActionId::OpenCompound => "Open compound clip", |
| 755 | ActionId::CloseCompound => "Back to parent sequence", |
| 756 | ActionId::NewBin => "New bin", |
| 757 | ActionId::NewBinInside => "New bin inside", |
| 758 | ActionId::RenameBin => "Rename bin", |
| 759 | ActionId::RemoveBin => "Remove bin", |
| 760 | ActionId::ToggleFavourite => "Favourite media", |
| 761 | ActionId::MoveToBin => "Move media to bin…", |
| 762 | ActionId::ShowFavourites => "Show favourite media", |
| 763 | ActionId::ShowAllMedia => "Show all media", |
| 764 | ActionId::NewSequence => "New sequence", |
| 765 | ActionId::DuplicateSequence => "Duplicate sequence", |
| 766 | ActionId::RenameSequence => "Rename sequence", |
| 767 | ActionId::DeleteSequence => "Delete sequence", |
| 768 | ActionId::CreateMulticam => "Create multicam from media…", |
| 769 | ActionId::FlattenMulticam => "Flatten multicam clip", |
| 770 | ActionId::ToggleAngleMonitor => "Angle monitor", |
| 771 | ActionId::ToggleOutputWindow => "Video output window", |
| 772 | ActionId::OutputDisplay => "Output display…", |
| 773 | ActionId::Angle1 => "Switch to angle 1–9", |
| 774 | ActionId::Angle2 => "Switch to angle 2", |
| 775 | ActionId::Angle3 => "Switch to angle 3", |
| 776 | ActionId::Angle4 => "Switch to angle 4", |
| 777 | ActionId::Angle5 => "Switch to angle 5", |
| 778 | ActionId::Angle6 => "Switch to angle 6", |
| 779 | ActionId::Angle7 => "Switch to angle 7", |
| 780 | ActionId::Angle8 => "Switch to angle 8", |
| 781 | ActionId::Angle9 => "Switch to angle 9", |
| 782 | ActionId::RenameLane => "Rename track", |
| 783 | ActionId::Crossfade => "Crossfade audio", |
| 784 | ActionId::TrimIn => "Trim in", |
| 785 | ActionId::TrimOut => "Trim out", |
| 786 | ActionId::LoopTrim => "Loop while trimming", |
| 787 | ActionId::TrimInToPlayhead => "Trim start to playhead", |
| 788 | ActionId::TrimOutToPlayhead => "Trim end to playhead", |
| 789 | ActionId::RippleTrimInToPlayhead => "Ripple start to playhead", |
| 790 | ActionId::RippleTrimOutToPlayhead => "Ripple end to playhead", |
| 791 | ActionId::RollBack => "Move cut earlier", |
| 792 | ActionId::RollForward => "Move cut later", |
| 793 | ActionId::SlipBack => "Slip back", |
| 794 | ActionId::SlipForward => "Slip forward", |
| 795 | ActionId::SlideBack => "Slide back", |
| 796 | ActionId::SlideForward => "Slide forward", |
| 797 | ActionId::Dissolve => "Dissolve", |
| 798 | ActionId::TransitionDissolve => "Dissolve at a cut", |
| 799 | ActionId::TransitionDipBlack => "Dip to black", |
| 800 | ActionId::TransitionDipWhite => "Dip to white", |
| 801 | ActionId::TransitionWipeLeft => "Wipe left", |
| 802 | ActionId::TransitionWipeRight => "Wipe right", |
| 803 | ActionId::TransitionWipeUp => "Wipe up", |
| 804 | ActionId::TransitionWipeDown => "Wipe down", |
| 805 | ActionId::TransitionSlideLeft => "Slide left", |
| 806 | ActionId::TransitionSlideRight => "Slide right", |
| 807 | ActionId::TransitionSlideUp => "Slide up", |
| 808 | ActionId::TransitionSlideDown => "Slide down", |
| 809 | ActionId::TransitionPushLeft => "Push left", |
| 810 | ActionId::TransitionPushRight => "Push right", |
| 811 | ActionId::TransitionPushUp => "Push up", |
| 812 | ActionId::TransitionPushDown => "Push down", |
| 813 | ActionId::TransitionZoom => "Zoom", |
| 814 | ActionId::Reverse => "Reverse clip", |
| 815 | ActionId::ClipEnabled => "Clip enabled", |
| 816 | ActionId::ClipLabel => "Clip label", |
| 817 | ActionId::NewSolid => "Solid colour", |
| 818 | ActionId::NewGradient => "Gradient", |
| 819 | ActionId::NewCountdown => "Countdown", |
| 820 | ActionId::NewBars => "Colour bars", |
| 821 | ActionId::NewTone => "Tone", |
| 822 | ActionId::NewBarsAndTone => "Bars and tone", |
| 823 | ActionId::NewAdjustment => "Adjustment layer", |
| 824 | ActionId::NewRectangle => "Rectangle shape", |
| 825 | ActionId::NewEllipse => "Ellipse shape", |
| 826 | ActionId::NewLine => "Line shape", |
| 827 | ActionId::NewArrow => "Arrow shape", |
| 828 | ActionId::NewTitle => "Add title", |
| 829 | ActionId::Mix => "Mix…", |
| 830 | ActionId::CleanVoice => "Clean voice", |
| 831 | ActionId::VoiceDynamics => "Voice dynamics…", |
| 832 | ActionId::ToggleSnap => "Snap", |
| 833 | ActionId::ToggleSubtitles => "Subtitles", |
| 834 | ActionId::ToggleWaveforms => "Audio waveforms", |
| 835 | ActionId::ToggleScrubAudio => "Audio scrubbing", |
| 836 | ActionId::CompareOff => "Compare: off", |
| 837 | ActionId::CompareSplit => "Compare: split", |
| 838 | ActionId::CompareSide => "Compare: side by side", |
| 839 | ActionId::AutoColour => "Auto colour", |
| 840 | ActionId::SaveLook => "Save colour as look\u{2026}", |
| 841 | ActionId::ToggleProxies => "Use proxies for playback", |
| 842 | ActionId::ToggleAutoProxies => "Make proxies on import", |
| 843 | ActionId::Theme => "Theme…", |
| 844 | ActionId::AccentColour => "Accent colour…", |
| 845 | ActionId::Fullscreen => "Fullscreen", |
| 846 | ActionId::CancelExport => "Cancel export", |
| 847 | ActionId::ShowActions => "Search commands…", |
| 848 | ActionId::ShowKeys => "Keyboard shortcuts", |
| 849 | ActionId::About => "About edith…", |
| 850 | ActionId::Screenshot => "Save frame as PNG", |
| 851 | ActionId::SubtitleStyle => "Subtitle style…", |
| 852 | ActionId::Settings => "Settings…", |
| 853 | ActionId::CloseGap => "Close gap", |
| 854 | ActionId::Freeze => "Freeze frame", |
| 855 | ActionId::PasteAttributes => "Paste all attributes", |
| 856 | ActionId::PasteColor => "Paste colour", |
| 857 | ActionId::PasteEffects => "Paste effects", |
| 858 | ActionId::PasteTransform => "Paste transform", |
| 859 | ActionId::PasteSpeed => "Paste speed", |
| 860 | ActionId::PasteAudio => "Paste audio", |
| 861 | ActionId::MatchFrame => "Match frame", |
| 862 | ActionId::ReplaceEdit => "Replace edit", |
| 863 | ActionId::SelectForward => "Select track forward", |
| 864 | ActionId::SelectForwardAll => "Select all tracks forward", |
| 865 | ActionId::ExtendAudio => "Extend audio to playhead", |
| 866 | ActionId::ExtendVideo => "Extend video to playhead", |
| 867 | ActionId::NudgeBack => "Nudge back", |
| 868 | ActionId::NudgeForward => "Nudge forward", |
| 869 | ActionId::NudgeBack10 => "Nudge back ten frames", |
| 870 | ActionId::NudgeForward10 => "Nudge forward ten frames", |
| 871 | ActionId::FocusPanels => "Next panel", |
| 872 | } |
| 873 | } |
| 874 | |
| 875 | /// What the file calls it: ASCII, no spaces, one spelling per variant and |
| 876 | /// never the label, which is free to be reworded. |
| 877 | fn name(self) -> &'static str { |
| 878 | match self { |
| 879 | ActionId::Play => "play", |
| 880 | ActionId::Loop => "loop", |
| 881 | ActionId::PlayAround => "play-around", |
| 882 | ActionId::StepBack => "step-back", |
| 883 | ActionId::StepForward => "step-forward", |
| 884 | ActionId::JumpBack => "jump-back", |
| 885 | ActionId::JumpForward => "jump-forward", |
| 886 | ActionId::GoStart => "go-start", |
| 887 | ActionId::GoEnd => "go-end", |
| 888 | ActionId::GoToTime => "go-to-time", |
| 889 | ActionId::PrevSyncPoint => "prev-sync-point", |
| 890 | ActionId::NextSyncPoint => "next-sync-point", |
| 891 | ActionId::AddMarker => "add-marker", |
| 892 | ActionId::MarkerHere => "marker-here", |
| 893 | ActionId::RenameMarker => "rename-marker", |
| 894 | ActionId::DeleteMarker => "delete-marker", |
| 895 | ActionId::PlayheadHere => "playhead-here", |
| 896 | ActionId::NextMarker => "next-marker", |
| 897 | ActionId::PrevMarker => "prev-marker", |
| 898 | ActionId::Markers => "markers", |
| 899 | ActionId::WalkCutNext => "walk-cut-next", |
| 900 | ActionId::WalkCutPrev => "walk-cut-prev", |
| 901 | ActionId::WalkCutNext10 => "walk-cut-next-10", |
| 902 | ActionId::WalkCutPrev10 => "walk-cut-prev-10", |
| 903 | ActionId::SetIn => "set-in", |
| 904 | ActionId::SetOut => "set-out", |
| 905 | ActionId::ClearRange => "clear-range", |
| 906 | ActionId::RenderInOut => "render-in-out", |
| 907 | ActionId::RenderAll => "render-all", |
| 908 | ActionId::CancelRender => "cancel-render", |
| 909 | ActionId::DeleteRenderFiles => "delete-render-files", |
| 910 | ActionId::ShuttleBack => "shuttle-back", |
| 911 | ActionId::ShuttleStop => "shuttle-stop", |
| 912 | ActionId::ShuttleForward => "shuttle-forward", |
| 913 | ActionId::Export => "export", |
| 914 | ActionId::Save => "save", |
| 915 | ActionId::ReloadProject => "reload-project", |
| 916 | ActionId::NewProject => "new-project", |
| 917 | ActionId::SaveVersion => "save-version", |
| 918 | ActionId::SaveTemplate => "save-template", |
| 919 | ActionId::ExportCaptions => "export-captions", |
| 920 | ActionId::Versions => "versions", |
| 921 | ActionId::CollectMedia => "collect-media", |
| 922 | ActionId::ProjectNotes => "project-notes", |
| 923 | ActionId::ExportTimelineOtio => "export-timeline-otio", |
| 924 | ActionId::ExportTimelineFcpxml => "export-timeline-fcpxml", |
| 925 | ActionId::ExportTimelineEdl => "export-timeline-edl", |
| 926 | ActionId::ImportTimelineOtio => "import-timeline-otio", |
| 927 | ActionId::Copy => "copy", |
| 928 | ActionId::Paste => "paste", |
| 929 | ActionId::InsertSource => "insert-source", |
| 930 | ActionId::OverwriteSource => "overwrite-source", |
| 931 | ActionId::Cut => "cut", |
| 932 | ActionId::Regroup => "regroup", |
| 933 | ActionId::Detach => "detach", |
| 934 | ActionId::Group => "group", |
| 935 | ActionId::Select => "select", |
| 936 | ActionId::SelectNext => "select-next", |
| 937 | ActionId::SelectPrev => "select-prev", |
| 938 | ActionId::SelectAll => "select-all", |
| 939 | ActionId::Deselect => "deselect", |
| 940 | ActionId::Delete => "delete", |
| 941 | ActionId::Lift => "lift", |
| 942 | ActionId::Color => "color", |
| 943 | ActionId::Transform => "transform", |
| 944 | ActionId::Effects => "effects", |
| 945 | ActionId::KeyPlacement => "key-placement", |
| 946 | ActionId::KeyOpacity => "key-opacity", |
| 947 | ActionId::KeyColor => "key-color", |
| 948 | ActionId::KeyEasing => "key-easing", |
| 949 | ActionId::Fit => "fit", |
| 950 | ActionId::Resolution => "resolution", |
| 951 | ActionId::ZoomIn => "zoom-in", |
| 952 | ActionId::ZoomOut => "zoom-out", |
| 953 | ActionId::ZoomFit => "zoom-fit", |
| 954 | ActionId::ZoomToSelection => "zoom-to-selection", |
| 955 | ActionId::TrackSmall => "track-small", |
| 956 | ActionId::TrackMedium => "track-medium", |
| 957 | ActionId::TrackLarge => "track-large", |
| 958 | ActionId::TracksSmaller => "tracks-smaller", |
| 959 | ActionId::TracksLarger => "tracks-larger", |
| 960 | ActionId::ViewZoom => "view-zoom", |
| 961 | ActionId::PlaybackQuality => "playback-quality", |
| 962 | ActionId::GuideStyle => "guide-style", |
| 963 | ActionId::GuideMask => "guide-mask", |
| 964 | ActionId::Undo => "undo", |
| 965 | ActionId::Redo => "redo", |
| 966 | ActionId::History => "history", |
| 967 | ActionId::AddVideoLane => "add-video-lane", |
| 968 | ActionId::AddAudioLane => "add-audio-lane", |
| 969 | ActionId::RemoveVideoLane => "remove-video-lane", |
| 970 | ActionId::RemoveAudioLane => "remove-audio-lane", |
| 971 | ActionId::AddSubtitleLane => "add-subtitle-lane", |
| 972 | ActionId::RemoveSubtitleLane => "remove-subtitle-lane", |
| 973 | ActionId::ImportSubtitles => "import-subtitles", |
| 974 | ActionId::AddFiles => "add-files", |
| 975 | ActionId::OpenProject => "open-project", |
| 976 | ActionId::PasteFilePath => "paste-file-path", |
| 977 | ActionId::ToggleMute => "toggle-mute", |
| 978 | ActionId::VolumeUp => "volume-up", |
| 979 | ActionId::VolumeDown => "volume-down", |
| 980 | ActionId::Equalizer => "equalizer", |
| 981 | ActionId::Speed => "speed", |
| 982 | ActionId::SpeedRampUp => "speed-ramp-up", |
| 983 | ActionId::SpeedRampDown => "speed-ramp-down", |
| 984 | ActionId::SpeedRampSlowFastSlow => "speed-ramp-slow-fast-slow", |
| 985 | ActionId::SpeedRampFastSlowFast => "speed-ramp-fast-slow-fast", |
| 986 | ActionId::SpeedRampKey => "speed-ramp-key", |
| 987 | ActionId::SpeedRampClear => "speed-ramp-clear", |
| 988 | ActionId::Silence => "silence", |
| 989 | ActionId::Normalize => "normalize", |
| 990 | ActionId::Captions => "generate-captions", |
| 991 | ActionId::Fillers => "remove-fillers", |
| 992 | ActionId::CutSelectedWords => "cut-selected-words", |
| 993 | ActionId::Voiceover => "voiceover", |
| 994 | ActionId::RecordVoiceover => "record-voiceover", |
| 995 | ActionId::Visualizer => "visualizer", |
| 996 | ActionId::MarkBeats => "mark-beats", |
| 997 | ActionId::Reframe => "reframe", |
| 998 | ActionId::TrackMask => "track-mask", |
| 999 | ActionId::NestClips => "nest-clips", |
| 1000 | ActionId::BreakApart => "break-apart", |
| 1001 | ActionId::OpenCompound => "open-compound", |
| 1002 | ActionId::CloseCompound => "close-compound", |
| 1003 | ActionId::NewBin => "new-bin", |
| 1004 | ActionId::NewBinInside => "new-bin-inside", |
| 1005 | ActionId::RenameBin => "rename-bin", |
| 1006 | ActionId::RemoveBin => "remove-bin", |
| 1007 | ActionId::ToggleFavourite => "toggle-favourite", |
| 1008 | ActionId::MoveToBin => "move-to-bin", |
| 1009 | ActionId::ShowFavourites => "show-favourites", |
| 1010 | ActionId::ShowAllMedia => "show-all-media", |
| 1011 | ActionId::NewSequence => "new-sequence", |
| 1012 | ActionId::DuplicateSequence => "duplicate-sequence", |
| 1013 | ActionId::RenameSequence => "rename-sequence", |
| 1014 | ActionId::DeleteSequence => "delete-sequence", |
| 1015 | ActionId::CreateMulticam => "create-multicam", |
| 1016 | ActionId::FlattenMulticam => "flatten-multicam", |
| 1017 | ActionId::ToggleAngleMonitor => "toggle-angle-monitor", |
| 1018 | ActionId::ToggleOutputWindow => "toggle-output-window", |
| 1019 | ActionId::OutputDisplay => "output-display", |
| 1020 | ActionId::Angle1 => "angle-1", |
| 1021 | ActionId::Angle2 => "angle-2", |
| 1022 | ActionId::Angle3 => "angle-3", |
| 1023 | ActionId::Angle4 => "angle-4", |
| 1024 | ActionId::Angle5 => "angle-5", |
| 1025 | ActionId::Angle6 => "angle-6", |
| 1026 | ActionId::Angle7 => "angle-7", |
| 1027 | ActionId::Angle8 => "angle-8", |
| 1028 | ActionId::Angle9 => "angle-9", |
| 1029 | ActionId::RenameLane => "rename-lane", |
| 1030 | ActionId::Crossfade => "crossfade", |
| 1031 | ActionId::TrimIn => "trim-in", |
| 1032 | ActionId::TrimOut => "trim-out", |
| 1033 | ActionId::LoopTrim => "loop-trim", |
| 1034 | ActionId::TrimInToPlayhead => "trim-in-to-playhead", |
| 1035 | ActionId::TrimOutToPlayhead => "trim-out-to-playhead", |
| 1036 | ActionId::RippleTrimInToPlayhead => "ripple-trim-in-to-playhead", |
| 1037 | ActionId::RippleTrimOutToPlayhead => "ripple-trim-out-to-playhead", |
| 1038 | ActionId::RollBack => "roll-back", |
| 1039 | ActionId::RollForward => "roll-forward", |
| 1040 | ActionId::SlipBack => "slip-back", |
| 1041 | ActionId::SlipForward => "slip-forward", |
| 1042 | ActionId::SlideBack => "slide-back", |
| 1043 | ActionId::SlideForward => "slide-forward", |
| 1044 | ActionId::Dissolve => "dissolve", |
| 1045 | ActionId::TransitionDissolve => "transition-dissolve", |
| 1046 | ActionId::TransitionDipBlack => "transition-dip-black", |
| 1047 | ActionId::TransitionDipWhite => "transition-dip-white", |
| 1048 | ActionId::TransitionWipeLeft => "transition-wipe-left", |
| 1049 | ActionId::TransitionWipeRight => "transition-wipe-right", |
| 1050 | ActionId::TransitionWipeUp => "transition-wipe-up", |
| 1051 | ActionId::TransitionWipeDown => "transition-wipe-down", |
| 1052 | ActionId::TransitionSlideLeft => "transition-slide-left", |
| 1053 | ActionId::TransitionSlideRight => "transition-slide-right", |
| 1054 | ActionId::TransitionSlideUp => "transition-slide-up", |
| 1055 | ActionId::TransitionSlideDown => "transition-slide-down", |
| 1056 | ActionId::TransitionPushLeft => "transition-push-left", |
| 1057 | ActionId::TransitionPushRight => "transition-push-right", |
| 1058 | ActionId::TransitionPushUp => "transition-push-up", |
| 1059 | ActionId::TransitionPushDown => "transition-push-down", |
| 1060 | ActionId::TransitionZoom => "transition-zoom", |
| 1061 | ActionId::Reverse => "reverse", |
| 1062 | ActionId::ClipEnabled => "clip-enabled", |
| 1063 | ActionId::ClipLabel => "clip-label", |
| 1064 | ActionId::NewSolid => "new-solid", |
| 1065 | ActionId::NewGradient => "new-gradient", |
| 1066 | ActionId::NewCountdown => "new-countdown", |
| 1067 | ActionId::NewBars => "new-bars", |
| 1068 | ActionId::NewTone => "new-tone", |
| 1069 | ActionId::NewBarsAndTone => "new-bars-and-tone", |
| 1070 | ActionId::NewAdjustment => "new-adjustment", |
| 1071 | ActionId::NewRectangle => "new-rectangle", |
| 1072 | ActionId::NewEllipse => "new-ellipse", |
| 1073 | ActionId::NewLine => "new-line", |
| 1074 | ActionId::NewArrow => "new-arrow", |
| 1075 | ActionId::NewTitle => "new-title", |
| 1076 | ActionId::Mix => "mix", |
| 1077 | ActionId::CleanVoice => "clean-voice", |
| 1078 | ActionId::VoiceDynamics => "voice-dynamics", |
| 1079 | ActionId::ToggleSnap => "toggle-snap", |
| 1080 | ActionId::ToggleSubtitles => "toggle-subtitles", |
| 1081 | ActionId::ToggleWaveforms => "toggle-waveforms", |
| 1082 | ActionId::ToggleScrubAudio => "toggle-scrub-audio", |
| 1083 | ActionId::CompareOff => "compare-off", |
| 1084 | ActionId::CompareSplit => "compare-split", |
| 1085 | ActionId::CompareSide => "compare-side", |
| 1086 | ActionId::AutoColour => "auto-colour", |
| 1087 | ActionId::SaveLook => "save-look", |
| 1088 | ActionId::ToggleProxies => "toggle-proxies", |
| 1089 | ActionId::ToggleAutoProxies => "toggle-auto-proxies", |
| 1090 | ActionId::Theme => "theme", |
| 1091 | ActionId::AccentColour => "accent-colour", |
| 1092 | ActionId::Fullscreen => "fullscreen", |
| 1093 | ActionId::CancelExport => "cancel-export", |
| 1094 | ActionId::ShowActions => "show-actions", |
| 1095 | ActionId::ShowKeys => "show-keys", |
| 1096 | ActionId::About => "about", |
| 1097 | ActionId::Screenshot => "screenshot", |
| 1098 | ActionId::SubtitleStyle => "subtitle-style", |
| 1099 | ActionId::Settings => "settings", |
| 1100 | ActionId::CloseGap => "close-gap", |
| 1101 | ActionId::Freeze => "freeze", |
| 1102 | ActionId::PasteAttributes => "paste-attributes", |
| 1103 | ActionId::PasteColor => "paste-color", |
| 1104 | ActionId::PasteEffects => "paste-effects", |
| 1105 | ActionId::PasteTransform => "paste-transform", |
| 1106 | ActionId::PasteSpeed => "paste-speed", |
| 1107 | ActionId::PasteAudio => "paste-audio", |
| 1108 | ActionId::MatchFrame => "match-frame", |
| 1109 | ActionId::ReplaceEdit => "replace-edit", |
| 1110 | ActionId::SelectForward => "select-forward", |
| 1111 | ActionId::SelectForwardAll => "select-forward-all", |
| 1112 | ActionId::ExtendAudio => "extend-audio", |
| 1113 | ActionId::ExtendVideo => "extend-video", |
| 1114 | ActionId::NudgeBack => "nudge-back", |
| 1115 | ActionId::NudgeForward => "nudge-forward", |
| 1116 | ActionId::NudgeBack10 => "nudge-back-10", |
| 1117 | ActionId::NudgeForward10 => "nudge-forward-10", |
| 1118 | ActionId::FocusPanels => "focus-panels", |
| 1119 | } |
| 1120 | } |
| 1121 | |
| 1122 | fn from_name(name: &str) -> Option<Self> { |
| 1123 | // "cycle-key-ease" is what a keys file written before the cycle became a choice calls it. |
| 1124 | let name = if name == "cycle-key-ease" { "key-easing" } else { name }; |
| 1125 | Self::ALL.into_iter().find(|a| a.name() == name) |
| 1126 | } |
| 1127 | |
| 1128 | /// Which heading the keys menu files it under. Every action has one, so a |
| 1129 | /// new action is listed the moment it exists -- there is no second list to |
| 1130 | /// forget. |
| 1131 | pub fn category(self) -> Category { |
| 1132 | match self { |
| 1133 | ActionId::Play |
| 1134 | | ActionId::Loop |
| 1135 | | ActionId::PlayAround |
| 1136 | | ActionId::StepBack |
| 1137 | | ActionId::StepForward |
| 1138 | | ActionId::JumpBack |
| 1139 | | ActionId::JumpForward |
| 1140 | | ActionId::GoStart |
| 1141 | | ActionId::GoEnd |
| 1142 | | ActionId::GoToTime |
| 1143 | | ActionId::PrevSyncPoint |
| 1144 | | ActionId::NextSyncPoint |
| 1145 | | ActionId::WalkCutNext |
| 1146 | | ActionId::WalkCutPrev |
| 1147 | | ActionId::WalkCutNext10 |
| 1148 | | ActionId::WalkCutPrev10 |
| 1149 | | ActionId::ShuttleBack |
| 1150 | | ActionId::ShuttleStop |
| 1151 | | ActionId::PlayheadHere |
| 1152 | | ActionId::ShuttleForward => Category::Playback, |
| 1153 | // Marks and markers: the one place a range or a saved point is set and |
| 1154 | // listed, so the palette and the menus find them together. |
| 1155 | ActionId::SetIn |
| 1156 | | ActionId::SetOut |
| 1157 | | ActionId::ClearRange |
| 1158 | | ActionId::RenderInOut |
| 1159 | | ActionId::RenderAll |
| 1160 | | ActionId::CancelRender |
| 1161 | | ActionId::DeleteRenderFiles |
| 1162 | | ActionId::AddMarker |
| 1163 | | ActionId::MarkerHere |
| 1164 | | ActionId::RenameMarker |
| 1165 | | ActionId::DeleteMarker |
| 1166 | | ActionId::Markers |
| 1167 | | ActionId::NextMarker |
| 1168 | | ActionId::PrevMarker => Category::Marking, |
| 1169 | ActionId::Copy |
| 1170 | | ActionId::Paste |
| 1171 | | ActionId::Select |
| 1172 | | ActionId::SelectNext |
| 1173 | | ActionId::SelectPrev |
| 1174 | | ActionId::SelectAll |
| 1175 | | ActionId::Deselect |
| 1176 | | ActionId::Delete |
| 1177 | | ActionId::Lift |
| 1178 | | ActionId::Color |
| 1179 | | ActionId::AutoColour |
| 1180 | | ActionId::SaveLook |
| 1181 | | ActionId::Transform |
| 1182 | | ActionId::Effects |
| 1183 | | ActionId::KeyPlacement |
| 1184 | | ActionId::KeyOpacity |
| 1185 | | ActionId::KeyColor |
| 1186 | | ActionId::KeyEasing |
| 1187 | | ActionId::Fit |
| 1188 | // A rate is the clip's, not the sound's: it re-times the picture |
| 1189 | // and the sound together, and the card opens on whichever half was |
| 1190 | // clicked. |
| 1191 | | ActionId::Speed |
| 1192 | | ActionId::SpeedRampUp |
| 1193 | | ActionId::SpeedRampDown |
| 1194 | | ActionId::SpeedRampSlowFastSlow |
| 1195 | | ActionId::SpeedRampFastSlowFast |
| 1196 | | ActionId::SpeedRampKey |
| 1197 | | ActionId::SpeedRampClear |
| 1198 | // The scan reads a clip's sound, but what it does is edit the |
| 1199 | // timeline the clip is on -- it is a clip card like the three |
| 1200 | // above it, opened on whichever half was picked. |
| 1201 | | ActionId::Reframe |
| 1202 | | ActionId::TrackMask |
| 1203 | | ActionId::NestClips |
| 1204 | | ActionId::BreakApart |
| 1205 | | ActionId::CloseCompound |
| 1206 | | ActionId::OpenCompound |
| 1207 | | ActionId::CreateMulticam |
| 1208 | | ActionId::FlattenMulticam |
| 1209 | | ActionId::Angle1 |
| 1210 | | ActionId::Angle2 |
| 1211 | | ActionId::Angle3 |
| 1212 | | ActionId::Angle4 |
| 1213 | | ActionId::Angle5 |
| 1214 | | ActionId::Angle6 |
| 1215 | | ActionId::Angle7 |
| 1216 | | ActionId::Angle8 |
| 1217 | | ActionId::Angle9 |
| 1218 | | ActionId::Crossfade |
| 1219 | | ActionId::TrimIn |
| 1220 | | ActionId::TrimOut |
| 1221 | | ActionId::LoopTrim |
| 1222 | | ActionId::TrimInToPlayhead |
| 1223 | | ActionId::TrimOutToPlayhead |
| 1224 | | ActionId::RippleTrimInToPlayhead |
| 1225 | | ActionId::RippleTrimOutToPlayhead |
| 1226 | | ActionId::RollBack |
| 1227 | | ActionId::RollForward |
| 1228 | | ActionId::SlipBack |
| 1229 | | ActionId::SlipForward |
| 1230 | | ActionId::SlideBack |
| 1231 | | ActionId::SlideForward |
| 1232 | | ActionId::Dissolve |
| 1233 | | ActionId::TransitionDissolve |
| 1234 | | ActionId::TransitionDipBlack |
| 1235 | | ActionId::TransitionDipWhite |
| 1236 | | ActionId::TransitionWipeLeft |
| 1237 | | ActionId::TransitionWipeRight |
| 1238 | | ActionId::TransitionWipeUp |
| 1239 | | ActionId::TransitionWipeDown |
| 1240 | | ActionId::TransitionSlideLeft |
| 1241 | | ActionId::TransitionSlideRight |
| 1242 | | ActionId::TransitionSlideUp |
| 1243 | | ActionId::TransitionSlideDown |
| 1244 | | ActionId::TransitionPushLeft |
| 1245 | | ActionId::TransitionPushRight |
| 1246 | | ActionId::TransitionPushUp |
| 1247 | | ActionId::TransitionPushDown |
| 1248 | | ActionId::TransitionZoom |
| 1249 | | ActionId::PasteAttributes |
| 1250 | | ActionId::PasteColor |
| 1251 | | ActionId::PasteEffects |
| 1252 | | ActionId::PasteTransform |
| 1253 | | ActionId::PasteSpeed |
| 1254 | | ActionId::PasteAudio |
| 1255 | | ActionId::SelectForward |
| 1256 | | ActionId::SelectForwardAll |
| 1257 | | ActionId::ExtendAudio |
| 1258 | | ActionId::ExtendVideo |
| 1259 | | ActionId::NudgeBack |
| 1260 | | ActionId::NudgeForward |
| 1261 | | ActionId::NudgeBack10 |
| 1262 | | ActionId::NudgeForward10 |
| 1263 | | ActionId::Reverse |
| 1264 | | ActionId::ClipEnabled |
| 1265 | | ActionId::ClipLabel |
| 1266 | | ActionId::NewSolid |
| 1267 | | ActionId::NewGradient |
| 1268 | | ActionId::NewCountdown |
| 1269 | | ActionId::NewBars |
| 1270 | | ActionId::NewTone |
| 1271 | | ActionId::NewBarsAndTone |
| 1272 | | ActionId::NewAdjustment |
| 1273 | | ActionId::NewRectangle |
| 1274 | | ActionId::NewEllipse |
| 1275 | | ActionId::NewLine |
| 1276 | | ActionId::NewArrow |
| 1277 | | ActionId::NewTitle => Category::Clips, |
| 1278 | // The project's own picture size is not a clip's business, and not |
| 1279 | // a file operation either: it is what the viewer is looking at. |
| 1280 | // Neither is how much of the timeline the panel shows: a zoom edits |
| 1281 | // nothing, it magnifies. |
| 1282 | // ...and whether the cues are drawn over that picture: a subtitle |
| 1283 | // edits nothing either, it is part of what is being watched. |
| 1284 | ActionId::Resolution |
| 1285 | | ActionId::ZoomIn |
| 1286 | | ActionId::ZoomOut |
| 1287 | | ActionId::ZoomFit |
| 1288 | | ActionId::ZoomToSelection |
| 1289 | // How tall the tracks are drawn: a view of the timeline, not an edit. |
| 1290 | | ActionId::TrackSmall |
| 1291 | | ActionId::TrackMedium |
| 1292 | | ActionId::TrackLarge |
| 1293 | | ActionId::TracksSmaller |
| 1294 | | ActionId::TracksLarger |
| 1295 | // The viewer's own look: how big, how sharp while playing, which guides. |
| 1296 | | ActionId::ViewZoom |
| 1297 | | ActionId::PlaybackQuality |
| 1298 | | ActionId::GuideStyle |
| 1299 | | ActionId::GuideMask |
| 1300 | | ActionId::ToggleSubtitles |
| 1301 | | ActionId::ToggleWaveforms |
| 1302 | | ActionId::ToggleScrubAudio |
| 1303 | | ActionId::CompareOff |
| 1304 | | ActionId::CompareSplit |
| 1305 | | ActionId::CompareSide |
| 1306 | // ...and the angle monitor: a second way of looking at the footage. |
| 1307 | | ActionId::ToggleAngleMonitor |
| 1308 | // ...and the video output window and its display: a second window onto the same |
| 1309 | // picture, which edits nothing and saves nothing. |
| 1310 | | ActionId::ToggleOutputWindow |
| 1311 | | ActionId::OutputDisplay |
| 1312 | // ...and which file the picture is decoded from, which changes |
| 1313 | // nothing that is saved and nothing that is exported: a stand-in |
| 1314 | // is what one watches while cutting, not what one delivers. |
| 1315 | | ActionId::ToggleProxies |
| 1316 | // ...and whether those stand-ins are made without being asked: the |
| 1317 | // other half of the same switch, filed beside it so a card reader |
| 1318 | // meets the pair the panel shows as a pair. |
| 1319 | | ActionId::ToggleAutoProxies |
| 1320 | // ...and what the whole window is painted in: it edits nothing at |
| 1321 | // all, it is what one is looking *with*. |
| 1322 | | ActionId::Theme |
| 1323 | | ActionId::AccentColour |
| 1324 | // ...and what the cue plate is drawn in: a person's own reading |
| 1325 | // preference, same as the theme beside it. |
| 1326 | | ActionId::SubtitleStyle |
| 1327 | // ...and whether that window fills the screen: a way of looking, |
| 1328 | // same as the zoom and the theme beside it. |
| 1329 | | ActionId::Fullscreen |
| 1330 | // The settings page: it changes no clip and no lane, only the |
| 1331 | // project's own numbers and this window's preferences. |
| 1332 | | ActionId::Settings |
| 1333 | // Moves the ring, not a clip or a lane: the same "how one is |
| 1334 | // looking/reaching, not what is being edited" shape as the rest |
| 1335 | // of this heading. |
| 1336 | | ActionId::FocusPanels |
| 1337 | | ActionId::About |
| 1338 | | ActionId::ShowKeys => Category::View, |
| 1339 | ActionId::InsertSource |
| 1340 | | ActionId::OverwriteSource |
| 1341 | | ActionId::CloseGap |
| 1342 | | ActionId::Freeze |
| 1343 | | ActionId::CutSelectedWords |
| 1344 | | ActionId::MatchFrame |
| 1345 | | ActionId::ReplaceEdit |
| 1346 | | ActionId::Cut |
| 1347 | | ActionId::Regroup |
| 1348 | | ActionId::Detach |
| 1349 | | ActionId::Group |
| 1350 | | ActionId::Undo |
| 1351 | | ActionId::Redo |
| 1352 | | ActionId::History |
| 1353 | | ActionId::AddVideoLane |
| 1354 | | ActionId::AddAudioLane |
| 1355 | | ActionId::RemoveVideoLane |
| 1356 | // Not a view setting despite being a pointer aid: it decides where |
| 1357 | // a drag actually lands, which is an edit and not a magnification. |
| 1358 | | ActionId::ToggleSnap |
| 1359 | // A marker is saved with the project and travels with the picture |
| 1360 | // through every cut, the way a title does: an edit, and the card |
| 1361 | // that lists them is the project's own list. |
| 1362 | // The subtitle pair is a track pair like the lanes above it: what |
| 1363 | // they add is on the timeline and goes into the file an export |
| 1364 | // writes, where the toggle two headings down only decides whether |
| 1365 | // this window draws it. |
| 1366 | | ActionId::AddSubtitleLane |
| 1367 | | ActionId::RemoveSubtitleLane |
| 1368 | // ...and the door that fills the palette those lanes are dragged |
| 1369 | // from: it edits no lane, but what it brings in is the project's |
| 1370 | // and is saved with it, which is not a view setting. |
| 1371 | | ActionId::ImportSubtitles |
| 1372 | | ActionId::NewSequence |
| 1373 | | ActionId::DuplicateSequence |
| 1374 | | ActionId::RenameSequence |
| 1375 | | ActionId::DeleteSequence |
| 1376 | | ActionId::RenameLane |
| 1377 | | ActionId::RemoveAudioLane => Category::Editing, |
| 1378 | ActionId::ToggleMute |
| 1379 | | ActionId::VolumeUp |
| 1380 | | ActionId::VolumeDown |
| 1381 | | ActionId::Equalizer |
| 1382 | // The mix is the project's sound -- what every track plays at and |
| 1383 | // what the whole of it is held under -- where the three above it |
| 1384 | // are this machine's monitoring. Both are audio, and the card says |
| 1385 | // which is which. |
| 1386 | | ActionId::Mix |
| 1387 | | ActionId::CleanVoice |
| 1388 | | ActionId::VoiceDynamics |
| 1389 | // The creator tools: they listen to or write the project's sound (and the |
| 1390 | // words said in it), and open one card each. |
| 1391 | | ActionId::Normalize |
| 1392 | | ActionId::Captions |
| 1393 | | ActionId::Fillers |
| 1394 | | ActionId::Silence |
| 1395 | | ActionId::MarkBeats |
| 1396 | | ActionId::Visualizer |
| 1397 | | ActionId::Voiceover |
| 1398 | | ActionId::RecordVoiceover => Category::Audio, |
| 1399 | // Under the heading the panel button sits in, beside the save and |
| 1400 | // the export it stands next to on screen. |
| 1401 | ActionId::Save |
| 1402 | | ActionId::ReloadProject |
| 1403 | | ActionId::NewProject |
| 1404 | | ActionId::SaveVersion |
| 1405 | | ActionId::SaveTemplate |
| 1406 | | ActionId::ExportCaptions |
| 1407 | | ActionId::Versions |
| 1408 | | ActionId::CollectMedia |
| 1409 | | ActionId::ProjectNotes |
| 1410 | | ActionId::ExportTimelineOtio |
| 1411 | | ActionId::ExportTimelineFcpxml |
| 1412 | | ActionId::ExportTimelineEdl |
| 1413 | | ActionId::Export |
| 1414 | | ActionId::CancelExport |
| 1415 | | ActionId::ShowActions |
| 1416 | // It writes a file like the three above it, and touches no edit |
| 1417 | // list -- what an export's own allow-list already means it stays |
| 1418 | // out of, not what puts it in this heading. |
| 1419 | | ActionId::Screenshot |
| 1420 | // The dock's import pair brings a file *in*, the same heading a |
| 1421 | // file going *out* (Export, Save) already sits under. |
| 1422 | | ActionId::AddFiles |
| 1423 | | ActionId::ImportTimelineOtio |
| 1424 | | ActionId::PasteFilePath |
| 1425 | | ActionId::OpenProject |
| 1426 | // ...and the library's own housekeeping sits beside them: how the media that came |
| 1427 | // in is filed and found again. |
| 1428 | | ActionId::NewBin |
| 1429 | | ActionId::NewBinInside |
| 1430 | | ActionId::RenameBin |
| 1431 | | ActionId::RemoveBin |
| 1432 | | ActionId::ToggleFavourite |
| 1433 | | ActionId::MoveToBin |
| 1434 | | ActionId::ShowFavourites |
| 1435 | | ActionId::ShowAllMedia => Category::File, |
| 1436 | } |
| 1437 | } |
| 1438 | } |
| 1439 | |
| 1440 | /// A heading in the keys menu, and the order the headings come in. |
| 1441 | #[derive(Clone, Copy, PartialEq, Eq, Debug)] |
| 1442 | pub enum Category { |
| 1443 | Playback, |
| 1444 | Marking, |
| 1445 | Editing, |
| 1446 | Clips, |
| 1447 | Audio, |
| 1448 | File, |
| 1449 | View, |
| 1450 | } |
| 1451 | |
| 1452 | impl Category { |
| 1453 | pub const ALL: [Category; 7] = [ |
| 1454 | Category::Playback, |
| 1455 | Category::Marking, |
| 1456 | Category::Editing, |
| 1457 | Category::Clips, |
| 1458 | Category::Audio, |
| 1459 | Category::File, |
| 1460 | Category::View, |
| 1461 | ]; |
| 1462 | |
| 1463 | pub fn label(self) -> &'static str { |
| 1464 | match self { |
| 1465 | Category::Playback => "Playback", |
| 1466 | Category::Marking => "Marking", |
| 1467 | Category::Editing => "Editing", |
| 1468 | Category::Clips => "Clips", |
| 1469 | Category::Audio => "Audio", |
| 1470 | Category::File => "File", |
| 1471 | Category::View => "View", |
| 1472 | } |
| 1473 | } |
| 1474 | } |
| 1475 | |
| 1476 | /// A stroke that works but nobody may rebind: the modal cards read the keyboard |
| 1477 | /// themselves, and what closes a card must not be a thing a user can take away. |
| 1478 | /// Listed here anyway, because the keys menu shows every stroke that works -- |
| 1479 | /// `no_stroke_is_missing_from_the_keys_menu` reads the key handler's own source |
| 1480 | /// and fails on any key that reaches neither this table nor a binding. |
| 1481 | pub struct Fixed { |
| 1482 | /// As a person reads it, which for a single key is [`Chord::pretty`]'s |
| 1483 | /// spelling and for a family of keys is the family (`0–9`). A `String` |
| 1484 | /// because one of them is generated: the codec row's keys are the export |
| 1485 | /// card's own table, not a line typed a second time here. |
| 1486 | pub chord: String, |
| 1487 | pub label: &'static str, |
| 1488 | pub category: Category, |
| 1489 | /// What a hand with only a mouse does instead. Every stroke here is |
| 1490 | /// card-local, and a card whose rows only a keyboard can reach is half this |
| 1491 | /// editor's users locked out of it, so each row names the thing on its card |
| 1492 | /// -- `every_action_is_reachable_without_the_keyboard` looks each id up in |
| 1493 | /// the render's own source. |
| 1494 | pub reach: Reach, |
| 1495 | } |
| 1496 | |
| 1497 | /// The pointer's answer to a fixed stroke. |
| 1498 | #[derive(Clone, Copy, PartialEq, Eq, Debug)] |
| 1499 | pub enum Reach { |
| 1500 | /// The id of the element on the card that does the same thing by click or |
| 1501 | /// by drag. |
| 1502 | Click(&'static str), |
| 1503 | /// Not an action a pointer takes: the way *out* of a card, and the hold |
| 1504 | /// that only repeats what a drag already does continuously. A variant |
| 1505 | /// rather than an omission, so a row with nothing to click is a decision |
| 1506 | /// somebody wrote down instead of a line missing from a list. |
| 1507 | Gesture, |
| 1508 | } |
| 1509 | |
| 1510 | /// The words a person types for a shown key, besides the glyph itself, so the |
| 1511 | /// keys menu's search finds `↵` by "enter" and `↑` by "up". Each token of a |
| 1512 | /// shown chord (`↑ ↓ ↵`, `← / →`) is looked up; a token with no alias adds |
| 1513 | /// nothing. |
| 1514 | pub(crate) fn search_aliases(shown: &str) -> String { |
| 1515 | const ALIASES: [(&str, &str); 6] = [ |
| 1516 | ("↵", "enter return"), |
| 1517 | ("↑", "up arrow"), |
| 1518 | ("↓", "down arrow"), |
| 1519 | ("←", "left arrow"), |
| 1520 | ("→", "right arrow"), |
| 1521 | ("Esc", "escape"), |
| 1522 | ]; |
| 1523 | shown |
| 1524 | .split(|c: char| c.is_whitespace() || c == '+' || c == '/') |
| 1525 | .filter_map(|token| { |
| 1526 | ALIASES |
| 1527 | .iter() |
| 1528 | .find(|(glyph, _)| *glyph == token) |
| 1529 | .map(|(_, words)| *words) |
| 1530 | }) |
| 1531 | .collect::<Vec<_>>() |
| 1532 | .join(" ") |
| 1533 | } |
| 1534 | |
| 1535 | pub static FIXED:std::sync::LazyLock<[Fixed; 36]> = std::sync::LazyLock::new(|| { |
| 1536 | [ |
| 1537 | // Not a chord at all but a way of pressing one, and the only place the |
| 1538 | // editor can say so: holding a key that moves a *value* runs it, and |
| 1539 | // holding anything else still does what one press did. |
| 1540 | Fixed { |
| 1541 | chord: "hold ← → ↑ ↓".into(), |
| 1542 | label: "Hold a key to adjust", |
| 1543 | category: Category::View, |
| 1544 | reach: Reach::Gesture, |
| 1545 | }, |
| 1546 | Fixed { |
| 1547 | chord: "Esc".into(), |
| 1548 | label: "Close a menu or card, or cancel", |
| 1549 | category: Category::View, |
| 1550 | reach: Reach::Gesture, |
| 1551 | }, |
| 1552 | // An open choice list is driven by the keyboard as well as clicked: the |
| 1553 | // list is the door to a setting, and a door only a pointer opens is one |
| 1554 | // half of this editor's users cannot use. |
| 1555 | Fixed { |
| 1556 | chord: "↑ ↓ ↵".into(), |
| 1557 | label: "Move through an open choice list, and take the row", |
| 1558 | category: Category::View, |
| 1559 | reach: Reach::Click("picker-row"), |
| 1560 | }, |
| 1561 | Fixed { |
| 1562 | chord: "N".into(), |
| 1563 | label: "Say the export budget: 850k, 6.5M, 6.5 or 1.2G of file", |
| 1564 | category: Category::File, |
| 1565 | reach: Reach::Click("export-c-bitrate"), |
| 1566 | }, |
| 1567 | Fixed { |
| 1568 | chord: "− / + / ← →".into(), |
| 1569 | label: "Move the export budget — shift steps whole megabits", |
| 1570 | category: Category::File, |
| 1571 | reach: Reach::Click("export-c-bitrate"), |
| 1572 | }, |
| 1573 | Fixed { |
| 1574 | chord: "0–9".into(), |
| 1575 | label: "Type into an open field — the budget, or a clip's duration", |
| 1576 | category: Category::File, |
| 1577 | reach: Reach::Click("export-c-bitrate"), |
| 1578 | }, |
| 1579 | Fixed { |
| 1580 | chord: "Backspace".into(), |
| 1581 | label: "Erase a character in the budget or duration field", |
| 1582 | category: Category::File, |
| 1583 | reach: Reach::Click("export-c-bitrate"), |
| 1584 | }, |
| 1585 | Fixed { |
| 1586 | chord: "D".into(), |
| 1587 | label: "Choose where the export is written", |
| 1588 | category: Category::File, |
| 1589 | reach: Reach::Click("export-destination"), |
| 1590 | }, |
| 1591 | Fixed { |
| 1592 | chord: "↵".into(), |
| 1593 | label: "Start the export — or take the budget being typed", |
| 1594 | category: Category::File, |
| 1595 | reach: Reach::Click("export-confirm"), |
| 1596 | }, |
| 1597 | // The equalizer card's own input, for the same reason the export card has |
| 1598 | // its own: a band nothing but a drag can reach is a band half the users of |
| 1599 | // this editor cannot move at all. Card-local, so none of them is bindable. |
| 1600 | Fixed { |
| 1601 | chord: "Tab, Shift+Tab".into(), |
| 1602 | label: "Select an equalizer band", |
| 1603 | category: Category::Audio, |
| 1604 | reach: Reach::Click("eq-graph"), |
| 1605 | }, |
| 1606 | Fixed { |
| 1607 | chord: "↑".into(), |
| 1608 | label: "Raise the selected band 1 dB", |
| 1609 | category: Category::Audio, |
| 1610 | reach: Reach::Click("eq-gain-field"), |
| 1611 | }, |
| 1612 | Fixed { |
| 1613 | chord: "↓".into(), |
| 1614 | label: "Lower the selected band 1 dB", |
| 1615 | category: Category::Audio, |
| 1616 | reach: Reach::Click("eq-gain-field"), |
| 1617 | }, |
| 1618 | Fixed { |
| 1619 | chord: "← / →".into(), |
| 1620 | label: "Move the selected band down or up in frequency", |
| 1621 | category: Category::Audio, |
| 1622 | reach: Reach::Click("eq-freq-field"), |
| 1623 | }, |
| 1624 | Fixed { |
| 1625 | chord: "Shift+← / →".into(), |
| 1626 | label: "Widen or narrow the selected band (its Q)", |
| 1627 | category: Category::Audio, |
| 1628 | reach: Reach::Click("eq-q-field"), |
| 1629 | }, |
| 1630 | Fixed { |
| 1631 | chord: "A".into(), |
| 1632 | label: "Add an equalizer band beside the selected one", |
| 1633 | category: Category::Audio, |
| 1634 | reach: Reach::Click("eq-add"), |
| 1635 | }, |
| 1636 | Fixed { |
| 1637 | chord: "X".into(), |
| 1638 | label: "Remove the selected equalizer band", |
| 1639 | category: Category::Audio, |
| 1640 | reach: Reach::Click("eq-remove"), |
| 1641 | }, |
| 1642 | Fixed { |
| 1643 | chord: "F".into(), |
| 1644 | label: "Flatten the selected band (double-click does the same)", |
| 1645 | category: Category::Audio, |
| 1646 | reach: Reach::Click("eq-flat-band"), |
| 1647 | }, |
| 1648 | Fixed { |
| 1649 | chord: "R".into(), |
| 1650 | label: "Flatten every band", |
| 1651 | category: Category::Audio, |
| 1652 | reach: Reach::Click("eq-reset"), |
| 1653 | }, |
| 1654 | Fixed { |
| 1655 | chord: "S".into(), |
| 1656 | label: "Show or hide the spectrum behind the curve", |
| 1657 | category: Category::Audio, |
| 1658 | reach: Reach::Click("eq-spectrum"), |
| 1659 | }, |
| 1660 | // The colour card's own three, which mean nothing outside it -- the same |
| 1661 | // card-local input the export card's digits are. |
| 1662 | Fixed { |
| 1663 | chord: "↑ / ↓".into(), |
| 1664 | label: "Select a colour slider", |
| 1665 | category: Category::Clips, |
| 1666 | reach: Reach::Click("color-row"), |
| 1667 | }, |
| 1668 | Fixed { |
| 1669 | chord: "← / →".into(), |
| 1670 | label: "Move the selected colour slider", |
| 1671 | category: Category::Clips, |
| 1672 | reach: Reach::Click("color-bar"), |
| 1673 | }, |
| 1674 | Fixed { |
| 1675 | chord: "R".into(), |
| 1676 | label: "Take the colour grade off the clip", |
| 1677 | category: Category::Clips, |
| 1678 | reach: Reach::Click("color-reset"), |
| 1679 | }, |
| 1680 | // The transform card's own three, the same shape as the colour card's: |
| 1681 | // up/down pick a band (position, scale, rotate, crop), left/right move |
| 1682 | // it, and `r` resets to identity. |
| 1683 | Fixed { |
| 1684 | chord: "↑ / ↓".into(), |
| 1685 | label: "Select a transform band", |
| 1686 | category: Category::Clips, |
| 1687 | reach: Reach::Click("transform-row"), |
| 1688 | }, |
| 1689 | Fixed { |
| 1690 | chord: "← / →".into(), |
| 1691 | label: "Move the selected transform band", |
| 1692 | category: Category::Clips, |
| 1693 | reach: Reach::Click("transform-bar"), |
| 1694 | }, |
| 1695 | Fixed { |
| 1696 | chord: "R".into(), |
| 1697 | label: "Take the transform off the clip", |
| 1698 | category: Category::Clips, |
| 1699 | reach: Reach::Click("transform-reset"), |
| 1700 | }, |
| 1701 | // The silence card's two apply keys. Card-local like every stroke above -- |
| 1702 | // they mean nothing while it is closed -- but the card is the one place in |
| 1703 | // this editor where a key rewrites forty places at once, so both of them |
| 1704 | // are listed rather than hidden in the card's own hint line. |
| 1705 | Fixed { |
| 1706 | chord: "↵".into(), |
| 1707 | label: "Cut every silence the card found", |
| 1708 | category: Category::Clips, |
| 1709 | reach: Reach::Click("silence-apply"), |
| 1710 | }, |
| 1711 | Fixed { |
| 1712 | chord: "F".into(), |
| 1713 | label: "Speed the silences up instead of cutting them", |
| 1714 | category: Category::Clips, |
| 1715 | reach: Reach::Click("silence-apply"), |
| 1716 | }, |
| 1717 | Fixed { |
| 1718 | chord: "K".into(), |
| 1719 | label: "Keep only the silences the card found", |
| 1720 | category: Category::Clips, |
| 1721 | reach: Reach::Click("silence-keep-only"), |
| 1722 | }, |
| 1723 | // The markers card's own three: up/down select a marker, `↵` renames it |
| 1724 | // and shift+`↵` edits its note (`↵` then saves what was typed, esc gives it up). |
| 1725 | Fixed { |
| 1726 | chord: "↑ / ↓".into(), |
| 1727 | label: "Select marker", |
| 1728 | category: Category::Editing, |
| 1729 | reach: Reach::Click("markers-row"), |
| 1730 | }, |
| 1731 | Fixed { |
| 1732 | chord: "↵".into(), |
| 1733 | label: "Rename marker", |
| 1734 | category: Category::Editing, |
| 1735 | reach: Reach::Click("markers-name"), |
| 1736 | }, |
| 1737 | Fixed { |
| 1738 | chord: "Shift+↵".into(), |
| 1739 | label: "Edit marker note", |
| 1740 | category: Category::Editing, |
| 1741 | reach: Reach::Click("markers-note"), |
| 1742 | }, |
| 1743 | // The pointer's trims on the timeline, in plain words: nothing on |
| 1744 | // screen says that shift turns an edge drag into a roll or a body drag |
| 1745 | // into a slip, so the sheet does. The status bar says the same while |
| 1746 | // the pointer rests on a clip (`ui/bench_stance/clip.rs`). |
| 1747 | Fixed { |
| 1748 | chord: "drag edge".into(), |
| 1749 | label: "Trim: lengthen or shorten the clip from that edge", |
| 1750 | category: Category::Editing, |
| 1751 | reach: Reach::Gesture, |
| 1752 | }, |
| 1753 | Fixed { |
| 1754 | chord: "Shift+drag edge".into(), |
| 1755 | label: "Roll the cut: both clips change, the timeline keeps its length", |
| 1756 | category: Category::Editing, |
| 1757 | reach: Reach::Gesture, |
| 1758 | }, |
| 1759 | Fixed { |
| 1760 | chord: "Shift+drag clip".into(), |
| 1761 | label: "Slip: show other footage of the file in the same place", |
| 1762 | category: Category::Editing, |
| 1763 | reach: Reach::Gesture, |
| 1764 | }, |
| 1765 | Fixed { |
| 1766 | chord: "Shift+Alt+drag clip".into(), |
| 1767 | label: "Slide: move the clip between its neighbours, which give and take", |
| 1768 | category: Category::Editing, |
| 1769 | reach: Reach::Gesture, |
| 1770 | }, |
| 1771 | Fixed { |
| 1772 | chord: "Alt+drag".into(), |
| 1773 | label: "Move or trim with snapping off, for that drag only", |
| 1774 | category: Category::Editing, |
| 1775 | reach: Reach::Gesture, |
| 1776 | }, |
| 1777 | ] |
| 1778 | }); |
| 1779 | |
| 1780 | /// A stroke as the key handler sees it: gpui's key name plus the three |
| 1781 | /// modifiers this editor binds, `ctrl`, `shift` and `alt`. |
| 1782 | /// |
| 1783 | /// Shift is kept on letters: gpui 0.2.2 reports `ctrl+shift+i` as the key `i` |
| 1784 | /// with both held, so it is a different stroke from `ctrl+i`. It is not kept on |
| 1785 | /// symbols: gpui clears shift for any single-char key whose upper and lower |
| 1786 | /// case are the same (linux/platform.rs:909-917), so a shifted symbol arrives |
| 1787 | /// as the glyph it types -- shift+/ is `?`, shift+. is `>`. Those are bound on |
| 1788 | /// the literal key, with no shift, which is why `?` needs no modifier at all. |
| 1789 | #[derive(Clone, PartialEq, Eq, Debug)] |
| 1790 | pub struct Chord { |
| 1791 | pub key: String, |
| 1792 | pub ctrl: bool, |
| 1793 | pub shift: bool, |
| 1794 | pub alt: bool, |
| 1795 | } |
| 1796 | |
| 1797 | impl Chord { |
| 1798 | /// The file's spelling, and the only one [`parse`] accepts back: the |
| 1799 | /// modifiers in one fixed order, then the key. |
| 1800 | fn text(&self) -> String { |
| 1801 | let mut out = String::new(); |
| 1802 | if self.ctrl { |
| 1803 | out.push_str("ctrl+"); |
| 1804 | } |
| 1805 | if self.shift { |
| 1806 | out.push_str("shift+"); |
| 1807 | } |
| 1808 | if self.alt { |
| 1809 | out.push_str("alt+"); |
| 1810 | } |
| 1811 | out.push_str(&self.key); |
| 1812 | out |
| 1813 | } |
| 1814 | |
| 1815 | /// The spelling a person reads, as DESIGN.md §10.2 writes it: `Ctrl+Shift+I`, |
| 1816 | /// `Alt+1`, `Delete`, `F11`, `←`. Modifiers are capitalised, a letter is a |
| 1817 | /// capital, and named keys are title case ([`Chord::shown_key`]). Display |
| 1818 | /// only: the file keeps gpui's lowercase names. Public because a keybindings |
| 1819 | /// row shows one chord, where [`Keymap::display`] shows every chord an action |
| 1820 | /// answers to. |
| 1821 | pub fn pretty(&self) -> String { |
| 1822 | let mut out = String::new(); |
| 1823 | if self.ctrl { |
| 1824 | out.push_str("Ctrl+"); |
| 1825 | } |
| 1826 | if self.shift { |
| 1827 | out.push_str("Shift+"); |
| 1828 | } |
| 1829 | if self.alt { |
| 1830 | out.push_str("Alt+"); |
| 1831 | } |
| 1832 | out.push_str(&Self::shown_key(&self.key)); |
| 1833 | out |
| 1834 | } |
| 1835 | |
| 1836 | /// One key as a person reads it. Named keys are title case (`Delete`, |
| 1837 | /// `PageUp`, `Esc`), `enter` is `↵`, the arrows are glyphs, function keys |
| 1838 | /// are `F1`..`F12`, and a single letter is its capital. Symbols and anything |
| 1839 | /// else are left as gpui names them. |
| 1840 | fn shown_key(key: &str) -> String { |
| 1841 | if let Some(n) = key |
| 1842 | .strip_prefix('f') |
| 1843 | .and_then(|n| n.parse::<u8>().ok()) |
| 1844 | .filter(|n| (1..=12).contains(n)) |
| 1845 | { |
| 1846 | return format!("F{n}"); |
| 1847 | } |
| 1848 | match key { |
| 1849 | "escape" => "Esc".to_string(), |
| 1850 | "enter" => "↵".to_string(), |
| 1851 | "left" => "←".to_string(), |
| 1852 | "right" => "→".to_string(), |
| 1853 | "up" => "↑".to_string(), |
| 1854 | "down" => "↓".to_string(), |
| 1855 | "backspace" => "Backspace".to_string(), |
| 1856 | "delete" => "Delete".to_string(), |
| 1857 | "space" => "Space".to_string(), |
| 1858 | "home" => "Home".to_string(), |
| 1859 | "end" => "End".to_string(), |
| 1860 | "pageup" => "PageUp".to_string(), |
| 1861 | "pagedown" => "PageDown".to_string(), |
| 1862 | "tab" => "Tab".to_string(), |
| 1863 | key if key.len() == 1 && key.as_bytes()[0].is_ascii_alphabetic() => { |
| 1864 | key.to_ascii_uppercase() |
| 1865 | } |
| 1866 | key => key.to_string(), |
| 1867 | } |
| 1868 | } |
| 1869 | |
| 1870 | /// The spelling a badge reads. It is the same spelling as |
| 1871 | /// [`Chord::pretty`], so a hint in the status bar, the transport and the |
| 1872 | /// toolbar all say `Ctrl+K`, `Space`, `Delete`. The old short forms (`^K`, |
| 1873 | /// `Spc`, `Del`) were dropped so one key never has two spellings on screen. |
| 1874 | pub fn compact(&self) -> String { |
| 1875 | self.pretty() |
| 1876 | } |
| 1877 | |
| 1878 | /// Whether the file can carry this stroke and read it back as itself. gpui |
| 1879 | /// reports strokes this format cannot spell -- shift+= arrives as the key |
| 1880 | /// `"+"`, which is the chord grammar's own separator -- and binding one |
| 1881 | /// would write a line the next load has to drop. Asked before a capture is |
| 1882 | /// taken, so a stroke that cannot be saved is refused while the user is |
| 1883 | /// still looking at the row. |
| 1884 | pub fn bindable(&self) -> bool { |
| 1885 | Chord::parse(&self.text(), 0).is_ok_and(|round_trip| round_trip == *self) |
| 1886 | } |
| 1887 | |
| 1888 | /// Strict: each of `ctrl+`, `shift+` and `alt+` at most once, in any order, |
| 1889 | /// then a key gpui could have reported. A spelling this cannot emit back |
| 1890 | /// unchanged is refused rather than normalised, because the round-trip is |
| 1891 | /// what makes the file editable by hand at all -- `shift+ctrl+i` is read as |
| 1892 | /// `ctrl+shift+i` and written back that way, but `Ctrl+i` is refused. |
| 1893 | fn parse(text: &str, n: usize) -> Result<Self, String> { |
| 1894 | let (mut ctrl, mut shift, mut alt) = (false, false, false); |
| 1895 | let mut rest = text; |
| 1896 | loop { |
| 1897 | if !ctrl && let Some(r) = rest.strip_prefix("ctrl+") { |
| 1898 | ctrl = true; |
| 1899 | rest = r; |
| 1900 | } else if !shift && let Some(r) = rest.strip_prefix("shift+") { |
| 1901 | shift = true; |
| 1902 | rest = r; |
| 1903 | } else if !alt && let Some(r) = rest.strip_prefix("alt+") { |
| 1904 | alt = true; |
| 1905 | rest = r; |
| 1906 | } else { |
| 1907 | break; |
| 1908 | } |
| 1909 | } |
| 1910 | if rest.is_empty() |
| 1911 | || rest.contains(' ') |
| 1912 | || rest.contains('+') |
| 1913 | || rest.chars().any(|c| c.is_ascii_uppercase()) |
| 1914 | { |
| 1915 | return Err(format!("line {n}: {text:?} is not a chord")); |
| 1916 | } |
| 1917 | Ok(Chord { |
| 1918 | key: rest.to_string(), |
| 1919 | ctrl, |
| 1920 | shift, |
| 1921 | alt, |
| 1922 | }) |
| 1923 | } |
| 1924 | } |
| 1925 | |
| 1926 | /// One stroke, one action. Two strokes for the same action are two bindings. |
| 1927 | #[derive(Clone, PartialEq, Eq, Debug)] |
| 1928 | pub struct Binding { |
| 1929 | pub action: ActionId, |
| 1930 | pub chord: Chord, |
| 1931 | } |
| 1932 | |
| 1933 | /// Every binding in force, in display order. No chord appears twice -- that is |
| 1934 | /// the invariant [`parse`] defends, and it is what lets [`Keymap::lookup`] |
| 1935 | /// answer with the first match. |
| 1936 | #[derive(Clone, PartialEq, Eq, Debug)] |
| 1937 | pub struct Keymap { |
| 1938 | bindings: Vec<Binding>, |
| 1939 | } |
| 1940 | |
| 1941 | impl Keymap { |
| 1942 | /// The bindings the editor ships with, in the order the editor lists them: |
| 1943 | /// DESIGN.md §10.2's table, row for row. `defaults_are_the_proposed_keys` |
| 1944 | /// pins every row, so a change here is a change to that table first. |
| 1945 | pub fn defaults() -> Self { |
| 1946 | let b = |action, text: &str| Binding { |
| 1947 | action, |
| 1948 | chord: Chord::parse(text, 0).expect("a default chord is a chord"), |
| 1949 | }; |
| 1950 | Keymap { |
| 1951 | bindings: vec![ |
| 1952 | // File |
| 1953 | b(ActionId::Export, "e"), |
| 1954 | b(ActionId::Save, "ctrl+s"), |
| 1955 | b(ActionId::AddFiles, "ctrl+i"), |
| 1956 | b(ActionId::OpenProject, "ctrl+o"), |
| 1957 | // PasteFilePath: menu only, no chord. |
| 1958 | b(ActionId::CancelExport, "ctrl+escape"), |
| 1959 | b(ActionId::ShowActions, "ctrl+k"), |
| 1960 | // View |
| 1961 | b(ActionId::ShowKeys, "?"), |
| 1962 | b(ActionId::ShowKeys, "f1"), |
| 1963 | // File |
| 1964 | b(ActionId::Screenshot, "f12"), |
| 1965 | // Playback |
| 1966 | b(ActionId::Play, "space"), |
| 1967 | b(ActionId::Loop, "r"), |
| 1968 | b(ActionId::PlayAround, "shift+k"), |
| 1969 | b(ActionId::StepBack, "left"), |
| 1970 | b(ActionId::StepForward, "right"), |
| 1971 | b(ActionId::JumpBack, "ctrl+left"), |
| 1972 | b(ActionId::JumpForward, "ctrl+right"), |
| 1973 | b(ActionId::GoStart, "home"), |
| 1974 | b(ActionId::GoEnd, "end"), |
| 1975 | // Free: Ctrl+G is Group. |
| 1976 | b(ActionId::GoToTime, "ctrl+j"), |
| 1977 | b(ActionId::PrevSyncPoint, "ctrl+["), |
| 1978 | b(ActionId::NextSyncPoint, "ctrl+]"), |
| 1979 | b(ActionId::WalkCutNext, "down"), |
| 1980 | b(ActionId::WalkCutNext, "."), |
| 1981 | b(ActionId::WalkCutPrev, "up"), |
| 1982 | b(ActionId::WalkCutPrev, ","), |
| 1983 | b(ActionId::WalkCutNext10, ">"), |
| 1984 | b(ActionId::WalkCutPrev10, "<"), |
| 1985 | b(ActionId::NextMarker, "shift+m"), |
| 1986 | b(ActionId::PrevMarker, "ctrl+shift+m"), |
| 1987 | b(ActionId::SetIn, "i"), |
| 1988 | b(ActionId::SetOut, "o"), |
| 1989 | b(ActionId::ClearRange, "ctrl+u"), |
| 1990 | b(ActionId::RenderInOut, "enter"), |
| 1991 | b(ActionId::ShuttleBack, "j"), |
| 1992 | b(ActionId::ShuttleStop, "k"), |
| 1993 | b(ActionId::ShuttleForward, "l"), |
| 1994 | // Editing |
| 1995 | b(ActionId::InsertSource, "f9"), |
| 1996 | b(ActionId::OverwriteSource, "f10"), |
| 1997 | b(ActionId::Cut, "s"), |
| 1998 | b(ActionId::Regroup, "g"), |
| 1999 | b(ActionId::Detach, "d"), |
| 2000 | b(ActionId::Group, "ctrl+g"), |
| 2001 | b(ActionId::Undo, "ctrl+z"), |
| 2002 | b(ActionId::Redo, "ctrl+y"), |
| 2003 | b(ActionId::Redo, "ctrl+shift+z"), |
| 2004 | // AddVideoLane: menu only, no chord. |
| 2005 | // AddAudioLane: menu only, no chord. |
| 2006 | // RemoveVideoLane: menu only, no chord. |
| 2007 | // RemoveAudioLane: menu only, no chord. |
| 2008 | // AddSubtitleLane: menu only, no chord. |
| 2009 | // RemoveSubtitleLane: menu only, no chord. |
| 2010 | b(ActionId::ImportSubtitles, "ctrl+shift+i"), |
| 2011 | b(ActionId::ToggleSnap, "n"), |
| 2012 | b(ActionId::AddMarker, "alt+m"), |
| 2013 | b(ActionId::Markers, "alt+8"), |
| 2014 | // Clips |
| 2015 | b(ActionId::Copy, "ctrl+c"), |
| 2016 | b(ActionId::Paste, "ctrl+v"), |
| 2017 | b(ActionId::Select, "tab"), |
| 2018 | b(ActionId::SelectNext, "}"), |
| 2019 | b(ActionId::SelectPrev, "{"), |
| 2020 | b(ActionId::SelectAll, "ctrl+a"), |
| 2021 | b(ActionId::Deselect, "escape"), |
| 2022 | b(ActionId::Delete, "delete"), |
| 2023 | b(ActionId::Delete, "backspace"), |
| 2024 | b(ActionId::Lift, ";"), |
| 2025 | b(ActionId::Color, "alt+2"), |
| 2026 | b(ActionId::Transform, "alt+3"), |
| 2027 | b(ActionId::Fit, "alt+7"), |
| 2028 | b(ActionId::Speed, "alt+1"), |
| 2029 | b(ActionId::Silence, "alt+5"), |
| 2030 | b(ActionId::MarkBeats, "alt+b"), |
| 2031 | b(ActionId::Visualizer, "alt+6"), |
| 2032 | b(ActionId::Angle1, "1"), |
| 2033 | b(ActionId::Angle2, "2"), |
| 2034 | b(ActionId::Angle3, "3"), |
| 2035 | b(ActionId::Angle4, "4"), |
| 2036 | b(ActionId::Angle5, "5"), |
| 2037 | b(ActionId::Angle6, "6"), |
| 2038 | b(ActionId::Angle7, "7"), |
| 2039 | b(ActionId::Angle8, "8"), |
| 2040 | b(ActionId::Angle9, "9"), |
| 2041 | b(ActionId::Crossfade, "ctrl+f"), |
| 2042 | b(ActionId::TrimIn, "["), |
| 2043 | b(ActionId::TrimOut, "]"), |
| 2044 | b(ActionId::LoopTrim, "/"), |
| 2045 | b(ActionId::RippleTrimInToPlayhead, "q"), |
| 2046 | b(ActionId::RippleTrimOutToPlayhead, "w"), |
| 2047 | b(ActionId::TrimInToPlayhead, "alt+q"), |
| 2048 | b(ActionId::TrimOutToPlayhead, "alt+w"), |
| 2049 | b(ActionId::RollBack, "alt+["), |
| 2050 | b(ActionId::RollForward, "alt+]"), |
| 2051 | b(ActionId::SlipBack, "alt+,"), |
| 2052 | b(ActionId::SlipForward, "alt+."), |
| 2053 | b(ActionId::SlideBack, "alt+left"), |
| 2054 | b(ActionId::SlideForward, "alt+right"), |
| 2055 | b(ActionId::Dissolve, "ctrl+d"), |
| 2056 | b(ActionId::Reverse, "ctrl+alt+r"), |
| 2057 | b(ActionId::ClipEnabled, "shift+e"), |
| 2058 | b(ActionId::NewTitle, "alt+t"), |
| 2059 | // ClipLabel, NewSolid, NewGradient, NewCountdown, NewBars, NewTone, NewBarsAndTone, NewAdjustment: menu only, no chord. |
| 2060 | // Audio |
| 2061 | b(ActionId::ToggleMute, "m"), |
| 2062 | b(ActionId::VolumeUp, "pageup"), |
| 2063 | b(ActionId::VolumeDown, "pagedown"), |
| 2064 | b(ActionId::Equalizer, "alt+4"), |
| 2065 | b(ActionId::Mix, "f"), |
| 2066 | b(ActionId::Mix, "alt+x"), |
| 2067 | b(ActionId::Effects, "alt+e"), |
| 2068 | b(ActionId::CleanVoice, "alt+9"), |
| 2069 | b(ActionId::VoiceDynamics, "alt+0"), |
| 2070 | // View |
| 2071 | b(ActionId::Resolution, "ctrl+r"), |
| 2072 | b(ActionId::ZoomIn, "="), |
| 2073 | b(ActionId::ZoomIn, "ctrl+="), |
| 2074 | b(ActionId::ZoomOut, "-"), |
| 2075 | b(ActionId::ZoomOut, "ctrl+-"), |
| 2076 | b(ActionId::ZoomFit, "\\"), |
| 2077 | b(ActionId::ZoomFit, "ctrl+0"), |
| 2078 | b(ActionId::TracksLarger, "alt+="), |
| 2079 | b(ActionId::TracksSmaller, "alt+-"), |
| 2080 | // Free: the shifted Z, next to the fit keys. |
| 2081 | b(ActionId::ZoomToSelection, "shift+z"), |
| 2082 | b(ActionId::ToggleSubtitles, "t"), |
| 2083 | b(ActionId::ToggleAngleMonitor, "alt+a"), |
| 2084 | b(ActionId::ToggleProxies, "ctrl+p"), |
| 2085 | // ToggleAutoProxies: menu only, no chord. |
| 2086 | b(ActionId::Normalize, "alt+n"), |
| 2087 | b(ActionId::Captions, "alt+c"), |
| 2088 | b(ActionId::Fillers, "alt+u"), |
| 2089 | b(ActionId::Voiceover, "alt+v"), |
| 2090 | // Theme: menu only, no chord. |
| 2091 | b(ActionId::Fullscreen, "f11"), |
| 2092 | b(ActionId::SubtitleStyle, "y"), |
| 2093 | b(ActionId::Settings, "ctrl+,"), |
| 2094 | b(ActionId::CloseGap, "shift+delete"), |
| 2095 | b(ActionId::Freeze, "shift+r"), |
| 2096 | b(ActionId::PasteAttributes, "ctrl+alt+v"), |
| 2097 | b(ActionId::MatchFrame, "shift+f"), |
| 2098 | b(ActionId::ReplaceEdit, "f8"), |
| 2099 | b(ActionId::SelectForward, "alt+y"), |
| 2100 | b(ActionId::SelectForwardAll, "shift+a"), |
| 2101 | b(ActionId::ExtendAudio, "shift+alt+l"), |
| 2102 | b(ActionId::ExtendVideo, "shift+alt+j"), |
| 2103 | b(ActionId::NudgeBack, "ctrl+alt+left"), |
| 2104 | b(ActionId::NudgeForward, "ctrl+alt+right"), |
| 2105 | b(ActionId::NudgeBack10, "ctrl+shift+alt+left"), |
| 2106 | b(ActionId::NudgeForward10, "ctrl+shift+alt+right"), |
| 2107 | b(ActionId::FocusPanels, "f6"), |
| 2108 | ], |
| 2109 | } |
| 2110 | } |
| 2111 | |
| 2112 | /// What a stroke means, if anything. `key` is gpui's key name and the three |
| 2113 | /// modifiers are the ones the key handler reads. A stroke matches only a |
| 2114 | /// binding with the same modifiers, so `i` and `ctrl+shift+i` are two. |
| 2115 | pub fn lookup(&self, key: &str, ctrl: bool, shift: bool, alt: bool) -> Option<ActionId> { |
| 2116 | self.bindings |
| 2117 | .iter() |
| 2118 | .find(|b| { |
| 2119 | b.chord.key == key |
| 2120 | && b.chord.ctrl == ctrl |
| 2121 | && b.chord.shift == shift |
| 2122 | && b.chord.alt == alt |
| 2123 | }) |
| 2124 | .map(|b| b.action) |
| 2125 | } |
| 2126 | |
| 2127 | /// Every stroke that reaches an action, each in display form, in binding order. Empty when |
| 2128 | /// nothing reaches it; a reference sheet shows that as an empty key cell. |
| 2129 | pub fn strokes(&self, action: ActionId) -> Vec<String> { |
| 2130 | self.bindings.iter().filter(|b| b.action == action).map(|b| b.chord.pretty()).collect() |
| 2131 | } |
| 2132 | |
| 2133 | /// Every stroke that reaches an action, as one readable phrase: `X or |
| 2134 | /// Delete`. An action nobody can reach says so rather than reading blank. |
| 2135 | pub fn display(&self, action: ActionId) -> String { |
| 2136 | let strokes = self.strokes(action); |
| 2137 | if strokes.is_empty() { |
| 2138 | "unbound".to_string() |
| 2139 | } else { |
| 2140 | strokes.join(" or ") |
| 2141 | } |
| 2142 | } |
| 2143 | |
| 2144 | /// The primary chord for `action`, compact ([`Chord::compact`]) -- a |
| 2145 | /// badge that has room for one token, not [`Keymap::display`]'s sentence. |
| 2146 | /// The first bound stroke wins (`defaults`' own insertion order, and |
| 2147 | /// [`parse`]'s "no chord appears twice" leaves at most one anyway); an |
| 2148 | /// action with no stroke reads `--` rather than the unbound sentence, |
| 2149 | /// since a badge is not a warning. |
| 2150 | pub fn chord(&self, action: ActionId) -> String { |
| 2151 | self.bindings |
| 2152 | .iter() |
| 2153 | .find(|b| b.action == action) |
| 2154 | .map(|b| b.chord.compact()) |
| 2155 | .unwrap_or_else(|| "--".to_string()) |
| 2156 | } |
| 2157 | |
| 2158 | /// The first stroke for `action` in display form (`Delete`, `Ctrl+Z`), for |
| 2159 | /// a control with room for one key only. [`Keymap::display`] lists every |
| 2160 | /// stroke; a toolbar shows the one a person would press. |
| 2161 | pub fn primary(&self, action: ActionId) -> String { |
| 2162 | self.bindings |
| 2163 | .iter() |
| 2164 | .find(|b| b.action == action) |
| 2165 | .map(|b| b.chord.pretty()) |
| 2166 | .unwrap_or_else(|| "unbound".to_string()) |
| 2167 | } |
| 2168 | |
| 2169 | /// Every binding, in display order. |
| 2170 | pub fn entries(&self) -> &[Binding] { |
| 2171 | &self.bindings |
| 2172 | } |
| 2173 | |
| 2174 | /// The other binding that already holds `chord`, if any. The Keys page asks |
| 2175 | /// this before it moves a stroke, so the conflict is named rather than |
| 2176 | /// silently stolen. |
| 2177 | pub(crate) fn holder(&self, chord: &Chord, except: usize) -> Option<usize> { |
| 2178 | self.bindings |
| 2179 | .iter() |
| 2180 | .enumerate() |
| 2181 | .find(|(i, b)| *i != except && b.chord == *chord) |
| 2182 | .map(|(i, _)| i) |
| 2183 | } |
| 2184 | |
| 2185 | /// Puts `chord` on the binding at `index`. A stroke another binding holds |
| 2186 | /// goes to that binding in exchange for the one `index` gives up, so no |
| 2187 | /// chord ever appears twice -- the invariant [`Keymap::lookup`] answers by. |
| 2188 | pub(crate) fn swap_in(&mut self, index: usize, chord: Chord) { |
| 2189 | let old = self.bindings[index].chord.clone(); |
| 2190 | if let Some(other) = self.holder(&chord, index) { |
| 2191 | self.bindings[other].chord = old; |
| 2192 | } |
| 2193 | self.bindings[index].chord = chord; |
| 2194 | } |
| 2195 | |
| 2196 | /// Whether `action` carries exactly its shipped strokes. `shipped` is |
| 2197 | /// [`Keymap::defaults`], passed in so a page asking once per row parses the |
| 2198 | /// defaults once per frame rather than once per row. |
| 2199 | pub(crate) fn is_default(&self, action: ActionId, shipped: &Keymap) -> bool { |
| 2200 | let now: Vec<&Chord> = self |
| 2201 | .bindings |
| 2202 | .iter() |
| 2203 | .filter(|b| b.action == action) |
| 2204 | .map(|b| &b.chord) |
| 2205 | .collect(); |
| 2206 | let want: Vec<&Chord> = shipped |
| 2207 | .bindings |
| 2208 | .iter() |
| 2209 | .filter(|b| b.action == action) |
| 2210 | .map(|b| &b.chord) |
| 2211 | .collect(); |
| 2212 | now.len() == want.len() && want.iter().all(|c| now.contains(c)) |
| 2213 | } |
| 2214 | |
| 2215 | /// Restores `action` to its shipped strokes, in their shipped place in the |
| 2216 | /// list. A shipped stroke another action now holds is taken back from it; |
| 2217 | /// the actions that lost one are returned so the page can say so. |
| 2218 | pub(crate) fn reset_action(&mut self, action: ActionId) -> Vec<ActionId> { |
| 2219 | let shipped: Vec<Chord> = Keymap::defaults() |
| 2220 | .bindings |
| 2221 | .into_iter() |
| 2222 | .filter(|b| b.action == action) |
| 2223 | .map(|b| b.chord) |
| 2224 | .collect(); |
| 2225 | let mut displaced = Vec::new(); |
| 2226 | self.bindings.retain(|b| { |
| 2227 | let taken = b.action != action && shipped.contains(&b.chord); |
| 2228 | if taken && !displaced.contains(&b.action) { |
| 2229 | displaced.push(b.action); |
| 2230 | } |
| 2231 | !taken |
| 2232 | }); |
| 2233 | // Taken back first, so the position read next is where the action's |
| 2234 | // own strokes sit in the list after that. |
| 2235 | let at = self |
| 2236 | .bindings |
| 2237 | .iter() |
| 2238 | .position(|b| b.action == action) |
| 2239 | .unwrap_or(self.bindings.len()); |
| 2240 | self.bindings.retain(|b| b.action != action); |
| 2241 | for (k, chord) in shipped.into_iter().enumerate() { |
| 2242 | self.bindings.insert(at + k, Binding { action, chord }); |
| 2243 | } |
| 2244 | displaced |
| 2245 | } |
| 2246 | |
| 2247 | /// The keymap in force, and what to tell the user if the file could not be |
| 2248 | /// used. A file that is merely absent is the normal case and says nothing; |
| 2249 | /// anything else -- unreadable, or a line this parser refuses -- falls back |
| 2250 | /// to the defaults *and* is reported, because a keymap silently not applied |
| 2251 | /// is a keyboard that has quietly changed under the user. |
| 2252 | pub fn load() -> (Self, Option<String>) { |
| 2253 | Self::load_from(&Self::config_path()) |
| 2254 | } |
| 2255 | |
| 2256 | /// All of [`Keymap::load`] but the path, which the config directory decides |
| 2257 | /// and a test must not be allowed to. |
| 2258 | fn load_from(path: &Path) -> (Self, Option<String>) { |
| 2259 | let text = match std::fs::read_to_string(path) { |
| 2260 | Ok(text) => text, |
| 2261 | Err(e) if e.kind() == std::io::ErrorKind::NotFound => return (Self::defaults(), None), |
| 2262 | Err(e) => { |
| 2263 | return ( |
| 2264 | Self::defaults(), |
| 2265 | Some(format!( |
| 2266 | "Keybindings ignored — {}: {e} — the defaults are in force", |
| 2267 | path.display() |
| 2268 | )), |
| 2269 | ); |
| 2270 | } |
| 2271 | }; |
| 2272 | match parse(&text) { |
| 2273 | Ok((keymap, dropped)) if dropped.is_empty() => (keymap, None), |
| 2274 | // The lines it could use are in force; the ones it could not are |
| 2275 | // named, and only those are lost. |
| 2276 | Ok((keymap, dropped)) => ( |
| 2277 | keymap, |
| 2278 | Some(format!( |
| 2279 | "Keybindings part-read — {}, {} — those strokes are unbound", |
| 2280 | path.display(), |
| 2281 | dropped.join("; ") |
| 2282 | )), |
| 2283 | ), |
| 2284 | Err(e) => ( |
| 2285 | Self::defaults(), |
| 2286 | Some(format!( |
| 2287 | "Keybindings ignored — {}, {e} — the defaults are in force", |
| 2288 | path.display() |
| 2289 | )), |
| 2290 | ), |
| 2291 | } |
| 2292 | } |
| 2293 | |
| 2294 | /// Writes the keymap, atomically, creating the config directory if this is |
| 2295 | /// the first save. Until the rename the previous bindings are still the |
| 2296 | /// whole truth on disk. |
| 2297 | pub fn save(&self) -> std::io::Result<()> { |
| 2298 | self.save_to(&Self::config_path()) |
| 2299 | } |
| 2300 | |
| 2301 | /// All of [`Keymap::save`] but the path, for the same reason as |
| 2302 | /// [`Keymap::load_from`]. |
| 2303 | fn save_to(&self, path: &Path) -> std::io::Result<()> { |
| 2304 | let dir = path.parent().unwrap_or(Path::new(".")).to_path_buf(); |
| 2305 | std::fs::create_dir_all(&dir)?; |
| 2306 | let mut part = path.to_path_buf().into_os_string(); |
| 2307 | part.push(".part"); |
| 2308 | let part = PathBuf::from(part); |
| 2309 | let result = std::fs::File::create(&part) |
| 2310 | .and_then(|mut f| { |
| 2311 | f.write_all(emit(self).as_bytes())?; |
| 2312 | f.sync_all() |
| 2313 | }) |
| 2314 | .and_then(|()| std::fs::rename(&part, path)) |
| 2315 | .and_then(|()| std::fs::File::open(&dir)?.sync_all()); |
| 2316 | if result.is_err() { |
| 2317 | let _ = std::fs::remove_file(&part); |
| 2318 | } |
| 2319 | result |
| 2320 | } |
| 2321 | |
| 2322 | /// Where the bindings live: the XDG config directory, or `~/.config` when |
| 2323 | /// the desktop has not named one. |
| 2324 | pub fn config_path() -> PathBuf { |
| 2325 | config_path_in(xdg_config_home(), std::env::var_os("HOME")) |
| 2326 | } |
| 2327 | } |
| 2328 | |
| 2329 | #[cfg(test)] |
| 2330 | thread_local! { |
| 2331 | /// The test-only stand-in for `$XDG_CONFIG_HOME`, scoped to the test's own |
| 2332 | /// thread so no other test sees it. Set through [`set_test_config_home`]. |
| 2333 | static TEST_CONFIG_HOME: std::cell::RefCell<Option<PathBuf>> = const { std::cell::RefCell::new(None) }; |
| 2334 | } |
| 2335 | |
| 2336 | /// Points every config file at `dir` for the calling test thread, or back at the |
| 2337 | /// real environment with `None`. Stands in for setting `XDG_CONFIG_HOME`, which |
| 2338 | /// Rust 2024 no longer lets safe code change it. |
| 2339 | #[cfg(test)] |
| 2340 | pub(crate) fn set_test_config_home(dir: Option<PathBuf>) { |
| 2341 | TEST_CONFIG_HOME.with(|c| *c.borrow_mut() = dir); |
| 2342 | } |
| 2343 | |
| 2344 | /// The XDG config directory as the environment (or a test) names it, if any. |
| 2345 | pub(crate) fn xdg_config_home() -> Option<OsString> { |
| 2346 | #[cfg(test)] |
| 2347 | if let Some(dir) = TEST_CONFIG_HOME.with(|c| c.borrow().clone()) { |
| 2348 | return Some(dir.into_os_string()); |
| 2349 | } |
| 2350 | std::env::var_os("XDG_CONFIG_HOME") |
| 2351 | } |
| 2352 | |
| 2353 | /// The path rule, with the environment handed in so it can be checked. An |
| 2354 | /// `XDG_CONFIG_HOME` that is empty is one the spec says to ignore; with no |
| 2355 | /// `HOME` either there is nowhere but here, and a relative path is still better |
| 2356 | /// than dropping the file in `/`. |
| 2357 | fn config_path_in(xdg: Option<OsString>, home: Option<OsString>) -> PathBuf { |
| 2358 | let dir = xdg |
| 2359 | .filter(|v| !v.is_empty()) |
| 2360 | .map(PathBuf::from) |
| 2361 | .or_else(|| { |
| 2362 | home.filter(|v| !v.is_empty()) |
| 2363 | .map(|h| PathBuf::from(h).join(".config")) |
| 2364 | }) |
| 2365 | .unwrap_or_else(|| PathBuf::from(".config")); |
| 2366 | dir.join("edith").join("keybindings") |
| 2367 | } |
| 2368 | |
| 2369 | fn emit(keymap: &Keymap) -> String { |
| 2370 | let mut out = String::from(MAGIC); |
| 2371 | out.push('\n'); |
| 2372 | for b in &keymap.bindings { |
| 2373 | out.push_str(b.action.name()); |
| 2374 | out.push(' '); |
| 2375 | out.push_str(&b.chord.text()); |
| 2376 | out.push('\n'); |
| 2377 | } |
| 2378 | out |
| 2379 | } |
| 2380 | |
| 2381 | /// First line of the files the build before shift and alt wrote. Still read; |
| 2382 | /// see [`V1_DEFAULTS`]. |
| 2383 | const MAGIC_V1: &str = "edith-keys 1"; |
| 2384 | |
| 2385 | /// The chords the build before shift and alt defaulted each action to, for |
| 2386 | /// every action whose stroke has since moved. A `edith-keys 1` file that holds |
| 2387 | /// exactly these for an action is one nobody rebound, and that action takes |
| 2388 | /// today's defaults. Anything else in such a file is somebody's own choice and |
| 2389 | /// is kept. An action that did not exist then (the shuttle, the shortcuts |
| 2390 | /// sheet) has no entries here, so its absence is what gets the default. |
| 2391 | const V1_DEFAULTS: &[(ActionId, &[&str])] = &[ |
| 2392 | (ActionId::AddFiles, &["ctrl+o"]), |
| 2393 | (ActionId::PasteFilePath, &["ctrl+l"]), |
| 2394 | (ActionId::ShowActions, &["?"]), |
| 2395 | (ActionId::ShowKeys, &[]), |
| 2396 | (ActionId::Screenshot, &["w"]), |
| 2397 | (ActionId::WalkCutNext, &["."]), |
| 2398 | (ActionId::WalkCutPrev, &[","]), |
| 2399 | (ActionId::ShuttleBack, &[]), |
| 2400 | (ActionId::ShuttleStop, &[]), |
| 2401 | (ActionId::ShuttleForward, &[]), |
| 2402 | (ActionId::Undo, &["z", "ctrl+z"]), |
| 2403 | (ActionId::AddVideoLane, &["v"]), |
| 2404 | (ActionId::AddAudioLane, &["a"]), |
| 2405 | (ActionId::RemoveVideoLane, &["ctrl+b"]), |
| 2406 | (ActionId::RemoveAudioLane, &["ctrl+q"]), |
| 2407 | (ActionId::AddSubtitleLane, &["c"]), |
| 2408 | (ActionId::RemoveSubtitleLane, &["ctrl+t"]), |
| 2409 | (ActionId::ImportSubtitles, &["ctrl+i"]), |
| 2410 | (ActionId::Delete, &["x", "delete"]), |
| 2411 | (ActionId::Lift, &["l"]), |
| 2412 | (ActionId::Color, &["k"]), |
| 2413 | (ActionId::Transform, &["ctrl+k"]), |
| 2414 | (ActionId::Fit, &["p"]), |
| 2415 | (ActionId::Speed, &["j"]), |
| 2416 | (ActionId::Silence, &["u"]), |
| 2417 | (ActionId::Visualizer, &["h"]), |
| 2418 | (ActionId::Reframe, &[]), |
| 2419 | (ActionId::TrackMask, &[]), |
| 2420 | (ActionId::TrimInToPlayhead, &["ctrl+{"]), |
| 2421 | (ActionId::TrimOutToPlayhead, &["ctrl+}"]), |
| 2422 | (ActionId::Dissolve, &["ctrl+x"]), |
| 2423 | (ActionId::VolumeUp, &["="]), |
| 2424 | (ActionId::VolumeDown, &["-"]), |
| 2425 | (ActionId::Equalizer, &["q"]), |
| 2426 | (ActionId::ZoomIn, &["ctrl+="]), |
| 2427 | (ActionId::ZoomOut, &["ctrl+-"]), |
| 2428 | (ActionId::ZoomFit, &["ctrl+0"]), |
| 2429 | (ActionId::ToggleAutoProxies, &["ctrl+m"]), |
| 2430 | (ActionId::Theme, &["ctrl+h"]), |
| 2431 | ]; |
| 2432 | |
| 2433 | /// Moves a `edith-keys 1` file onto today's defaults, action by action (see |
| 2434 | /// [`V1_DEFAULTS`]). The lines it keeps go first, so a stroke a kept line holds |
| 2435 | /// is never taken away from it by a default; a default whose stroke is held |
| 2436 | /// stays unbound instead. |
| 2437 | fn migrate_v1(file: Vec<Binding>) -> Vec<Binding> { |
| 2438 | let mut out: Vec<Binding> = Vec::new(); |
| 2439 | let mut replaced: Vec<ActionId> = Vec::new(); |
| 2440 | for action in ActionId::ALL { |
| 2441 | let held: Vec<Binding> = file |
| 2442 | .iter() |
| 2443 | .filter(|b| b.action == action) |
| 2444 | .cloned() |
| 2445 | .collect(); |
| 2446 | let mut have: Vec<String> = held.iter().map(|b| b.chord.text()).collect(); |
| 2447 | have.sort(); |
| 2448 | let untouched = V1_DEFAULTS |
| 2449 | .iter() |
| 2450 | .find(|(a, _)| *a == action) |
| 2451 | .is_some_and(|(_, old)| { |
| 2452 | let mut want: Vec<String> = old.iter().map(|s| s.to_string()).collect(); |
| 2453 | want.sort(); |
| 2454 | have == want |
| 2455 | }); |
| 2456 | if untouched { |
| 2457 | replaced.push(action); |
| 2458 | } else { |
| 2459 | out.extend(held); |
| 2460 | } |
| 2461 | } |
| 2462 | for default in Keymap::defaults().bindings { |
| 2463 | if replaced.contains(&default.action) && !out.iter().any(|b| b.chord == default.chord) { |
| 2464 | out.push(default); |
| 2465 | } |
| 2466 | } |
| 2467 | out |
| 2468 | } |
| 2469 | |
| 2470 | /// The magic line is the whole of what makes this a keybindings file, so it is |
| 2471 | /// the only thing refused outright. A *binding* line this parser cannot use is |
| 2472 | /// dropped instead, and named in the returned warnings: one unusable line used |
| 2473 | /// to cost every other rebind in the file, which is the user's data. What |
| 2474 | /// survives is still exactly what emits back, so the by-hand round-trip holds |
| 2475 | /// for every line that is kept. |
| 2476 | fn parse(text: &str) -> Result<(Keymap, Vec<String>), String> { |
| 2477 | // One trailing newline terminates the last line rather than starting an |
| 2478 | // empty one; a second is an empty line and is refused below. |
| 2479 | let body = text.strip_suffix('\n').unwrap_or(text); |
| 2480 | let mut lines = body.split('\n').enumerate(); |
| 2481 | let (_, first) = lines.next().unwrap_or((0, "")); |
| 2482 | let migrating = match first { |
| 2483 | MAGIC => false, |
| 2484 | MAGIC_V1 => true, |
| 2485 | _ => { |
| 2486 | return Err(match first.strip_prefix("edith-keys ") { |
| 2487 | Some(v) => format!("line 1: unsupported version {v}"), |
| 2488 | None => "line 1: not a keybindings file".to_string(), |
| 2489 | }); |
| 2490 | } |
| 2491 | }; |
| 2492 | |
| 2493 | let mut bindings: Vec<Binding> = Vec::new(); |
| 2494 | let mut dropped: Vec<String> = Vec::new(); |
| 2495 | for (i, line) in lines { |
| 2496 | let n = i + 1; |
| 2497 | let Some((name, chord)) = line.split_once(' ') else { |
| 2498 | dropped.push(format!("line {n}: {line:?} is not `<action> <chord>`")); |
| 2499 | continue; |
| 2500 | }; |
| 2501 | let Some(action) = ActionId::from_name(name) else { |
| 2502 | dropped.push(format!("line {n}: unknown action {name:?}")); |
| 2503 | continue; |
| 2504 | }; |
| 2505 | let chord = match Chord::parse(chord, n) { |
| 2506 | Ok(chord) => chord, |
| 2507 | Err(e) => { |
| 2508 | dropped.push(e); |
| 2509 | continue; |
| 2510 | } |
| 2511 | }; |
| 2512 | // One stroke, one meaning: the second line to claim it would be the |
| 2513 | // dead one, and which of them died would depend on line order. The |
| 2514 | // first line keeps the stroke, which is the order the file reads in. |
| 2515 | if let Some(held) = bindings.iter().find(|b| b.chord == chord) { |
| 2516 | dropped.push(format!( |
| 2517 | "line {n}: {} is already {}'s", |
| 2518 | chord.text(), |
| 2519 | held.action.name() |
| 2520 | )); |
| 2521 | continue; |
| 2522 | } |
| 2523 | bindings.push(Binding { action, chord }); |
| 2524 | } |
| 2525 | let bindings = if migrating { |
| 2526 | migrate_v1(bindings) |
| 2527 | } else { |
| 2528 | bindings |
| 2529 | }; |
| 2530 | Ok((Keymap { bindings }, dropped)) |
| 2531 | } |
| 2532 | |
| 2533 | #[cfg(test)] |
| 2534 | mod tests { |
| 2535 | use engine::scratch::Scratch; |
| 2536 | |
| 2537 | use super::{ActionId, Chord, Keymap, V1_DEFAULTS, config_path_in, emit, parse}; |
| 2538 | |
| 2539 | fn chord(key: &str, ctrl: bool) -> Chord { |
| 2540 | Chord { |
| 2541 | key: key.to_string(), |
| 2542 | ctrl, |
| 2543 | shift: false, |
| 2544 | alt: false, |
| 2545 | } |
| 2546 | } |
| 2547 | |
| 2548 | /// A file every line of which the parser could use -- what most assertions |
| 2549 | /// are about. A dropped line here is a failure, not a warning. |
| 2550 | fn whole(text: &str) -> Keymap { |
| 2551 | let (keymap, dropped) = parse(text).expect("a keybindings file"); |
| 2552 | assert!(dropped.is_empty(), "unexpected dropped lines: {dropped:?}"); |
| 2553 | keymap |
| 2554 | } |
| 2555 | |
| 2556 | #[test] |
| 2557 | fn every_default_stroke_reaches_its_action() { |
| 2558 | let k = Keymap::defaults(); |
| 2559 | // Each stroke as the file spells it, read the way the key handler reads it. |
| 2560 | let at = |text: &str| { |
| 2561 | let c = Chord::parse(text, 0).expect("a stroke"); |
| 2562 | k.lookup(&c.key, c.ctrl, c.shift, c.alt) |
| 2563 | }; |
| 2564 | // The cut odometer: bare walks one, `<`/`>` (what shift+,/shift+. actually |
| 2565 | // type) strides ten, and the arrows walk too. |
| 2566 | assert_eq!(at("."), Some(ActionId::WalkCutNext)); |
| 2567 | assert_eq!(at("down"), Some(ActionId::WalkCutNext)); |
| 2568 | assert_eq!(at(","), Some(ActionId::WalkCutPrev)); |
| 2569 | assert_eq!(at("up"), Some(ActionId::WalkCutPrev)); |
| 2570 | assert_eq!(at(">"), Some(ActionId::WalkCutNext10)); |
| 2571 | assert_eq!(at("<"), Some(ActionId::WalkCutPrev10)); |
| 2572 | assert_eq!(at("/"), Some(ActionId::LoopTrim)); |
| 2573 | // The trim pair on its bare brackets, and the playhead trims on Q and W. |
| 2574 | assert_eq!(at("["), Some(ActionId::TrimIn)); |
| 2575 | assert_eq!(at("]"), Some(ActionId::TrimOut)); |
| 2576 | assert_eq!(at("q"), Some(ActionId::RippleTrimInToPlayhead)); |
| 2577 | assert_eq!(at("w"), Some(ActionId::RippleTrimOutToPlayhead)); |
| 2578 | assert_eq!(at("alt+q"), Some(ActionId::TrimInToPlayhead)); |
| 2579 | // The shuttle: J back, K pauses, L plays. |
| 2580 | assert_eq!(at("j"), Some(ActionId::ShuttleBack)); |
| 2581 | assert_eq!(at("k"), Some(ActionId::ShuttleStop)); |
| 2582 | assert_eq!(at("l"), Some(ActionId::ShuttleForward)); |
| 2583 | // The shortcuts sheet is ? and F1; command search is Ctrl+K alone. |
| 2584 | assert_eq!(at("?"), Some(ActionId::ShowKeys)); |
| 2585 | assert_eq!(at("f1"), Some(ActionId::ShowKeys)); |
| 2586 | assert_eq!(at("ctrl+k"), Some(ActionId::ShowActions)); |
| 2587 | assert_eq!(at("f11"), Some(ActionId::Fullscreen)); |
| 2588 | assert_eq!(at("f12"), Some(ActionId::Screenshot)); |
| 2589 | assert_eq!(at("y"), Some(ActionId::SubtitleStyle)); |
| 2590 | assert_eq!(at("ctrl+p"), Some(ActionId::ToggleProxies)); |
| 2591 | // Import media is Ctrl+I; Import subtitles is Ctrl+Shift+I. The shift is |
| 2592 | // part of the stroke, so the two never answer for each other. |
| 2593 | assert_eq!(at("ctrl+i"), Some(ActionId::AddFiles)); |
| 2594 | assert_eq!(at("ctrl+shift+i"), Some(ActionId::ImportSubtitles)); |
| 2595 | assert_eq!(at("ctrl+o"), Some(ActionId::OpenProject)); |
| 2596 | assert_eq!(at("ctrl+l"), None); |
| 2597 | assert_eq!(at("ctrl+h"), None); |
| 2598 | assert_eq!(at("space"), Some(ActionId::Play)); |
| 2599 | // The seek keys: arrows a frame, ctrl arrows a second, the ends of the timeline. |
| 2600 | assert_eq!(at("left"), Some(ActionId::StepBack)); |
| 2601 | assert_eq!(at("right"), Some(ActionId::StepForward)); |
| 2602 | assert_eq!(at("ctrl+left"), Some(ActionId::JumpBack)); |
| 2603 | assert_eq!(at("ctrl+right"), Some(ActionId::JumpForward)); |
| 2604 | assert_eq!(at("home"), Some(ActionId::GoStart)); |
| 2605 | assert_eq!(at("end"), Some(ActionId::GoEnd)); |
| 2606 | // The source's own grid is on ctrl+brackets. |
| 2607 | assert_eq!(at("ctrl+["), Some(ActionId::PrevSyncPoint)); |
| 2608 | assert_eq!(at("ctrl+]"), Some(ActionId::NextSyncPoint)); |
| 2609 | assert_eq!(at("i"), Some(ActionId::SetIn)); |
| 2610 | assert_eq!(at("o"), Some(ActionId::SetOut)); |
| 2611 | assert_eq!(at("ctrl+u"), Some(ActionId::ClearRange)); |
| 2612 | assert_eq!(at("e"), Some(ActionId::Export)); |
| 2613 | assert_eq!(at("ctrl+s"), Some(ActionId::Save)); |
| 2614 | assert_eq!(at("ctrl+escape"), Some(ActionId::CancelExport)); |
| 2615 | assert_eq!(at("escape"), Some(ActionId::Deselect)); |
| 2616 | // Editing and clips. |
| 2617 | assert_eq!(at("ctrl+c"), Some(ActionId::Copy)); |
| 2618 | assert_eq!(at("ctrl+v"), Some(ActionId::Paste)); |
| 2619 | assert_eq!(at("s"), Some(ActionId::Cut)); |
| 2620 | assert_eq!(at("g"), Some(ActionId::Regroup)); |
| 2621 | assert_eq!(at("d"), Some(ActionId::Detach)); |
| 2622 | assert_eq!(at("ctrl+g"), Some(ActionId::Group)); |
| 2623 | assert_eq!(at("tab"), Some(ActionId::Select)); |
| 2624 | assert_eq!(at("}"), Some(ActionId::SelectNext)); |
| 2625 | assert_eq!(at("{"), Some(ActionId::SelectPrev)); |
| 2626 | assert_eq!(at("ctrl+a"), Some(ActionId::SelectAll)); |
| 2627 | assert_eq!(at("delete"), Some(ActionId::Delete)); |
| 2628 | assert_eq!(at("backspace"), Some(ActionId::Delete)); |
| 2629 | assert_eq!(at(";"), Some(ActionId::Lift)); |
| 2630 | assert_eq!(at("alt+1"), Some(ActionId::Speed)); |
| 2631 | assert_eq!(at("alt+2"), Some(ActionId::Color)); |
| 2632 | assert_eq!(at("alt+3"), Some(ActionId::Transform)); |
| 2633 | assert_eq!(at("alt+4"), Some(ActionId::Equalizer)); |
| 2634 | assert_eq!(at("alt+5"), Some(ActionId::Silence)); |
| 2635 | assert_eq!(at("alt+6"), Some(ActionId::Visualizer)); |
| 2636 | assert_eq!(at("alt+7"), Some(ActionId::Fit)); |
| 2637 | assert_eq!(at("ctrl+alt+r"), Some(ActionId::Reverse)); |
| 2638 | assert_eq!(at("alt+9"), Some(ActionId::CleanVoice)); |
| 2639 | assert_eq!(at("alt+0"), Some(ActionId::VoiceDynamics)); |
| 2640 | assert_eq!(at("ctrl+f"), Some(ActionId::Crossfade)); |
| 2641 | assert_eq!(at("ctrl+d"), Some(ActionId::Dissolve)); |
| 2642 | assert_eq!(at("ctrl+z"), Some(ActionId::Undo)); |
| 2643 | assert_eq!(at("ctrl+y"), Some(ActionId::Redo)); |
| 2644 | assert_eq!(at("ctrl+shift+z"), Some(ActionId::Redo)); |
| 2645 | // Audio and view. |
| 2646 | assert_eq!(at("m"), Some(ActionId::ToggleMute)); |
| 2647 | assert_eq!(at("pageup"), Some(ActionId::VolumeUp)); |
| 2648 | assert_eq!(at("pagedown"), Some(ActionId::VolumeDown)); |
| 2649 | assert_eq!(at("f"), Some(ActionId::Mix)); |
| 2650 | assert_eq!(at("ctrl+r"), Some(ActionId::Resolution)); |
| 2651 | assert_eq!(at("="), Some(ActionId::ZoomIn)); |
| 2652 | assert_eq!(at("ctrl+="), Some(ActionId::ZoomIn)); |
| 2653 | assert_eq!(at("-"), Some(ActionId::ZoomOut)); |
| 2654 | assert_eq!(at("ctrl+-"), Some(ActionId::ZoomOut)); |
| 2655 | assert_eq!(at("\\"), Some(ActionId::ZoomFit)); |
| 2656 | assert_eq!(at("ctrl+0"), Some(ActionId::ZoomFit)); |
| 2657 | assert_eq!(at("t"), Some(ActionId::ToggleSubtitles)); |
| 2658 | assert_eq!(at("n"), Some(ActionId::ToggleSnap)); |
| 2659 | assert_eq!(at("ctrl+,"), Some(ActionId::Settings)); |
| 2660 | // What the old defaults answered to and the new ones give up: a bare |
| 2661 | // letter that destroys, the old volume keys, and the moved clip keys. |
| 2662 | // A bare `+` is the grammar's own separator, so it is not a stroke at all. |
| 2663 | assert!(Chord::parse("+", 0).is_err()); |
| 2664 | for gone in ["z", "x", "a", "v", "c", "h", "shift+l", "alt+l", "ctrl+e"] { |
| 2665 | assert_eq!(at(gone), None, "{gone} should be unbound"); |
| 2666 | } |
| 2667 | // Nothing is bound twice, or lookup's first match would be a coin toss. |
| 2668 | assert_eq!(k.entries().len(), 136); |
| 2669 | for (i, a) in k.entries().iter().enumerate() { |
| 2670 | assert!( |
| 2671 | !k.entries()[i + 1..].iter().any(|b| b.chord == a.chord), |
| 2672 | "{:?} bound twice", |
| 2673 | a.chord |
| 2674 | ); |
| 2675 | } |
| 2676 | } |
| 2677 | |
| 2678 | #[test] |
| 2679 | fn a_file_survives_the_round_trip_exactly() { |
| 2680 | let text = emit(&Keymap::defaults()); |
| 2681 | assert!(text.starts_with("edith-keys 2\n")); |
| 2682 | assert!(text.contains("play space\n")); |
| 2683 | assert!(text.contains("save ctrl+s\n")); |
| 2684 | assert!(text.contains("cancel-export ctrl+escape\n")); |
| 2685 | // Both directions: the file this writes is the file it reads back, and |
| 2686 | // a file read in comes out byte for byte as it went. |
| 2687 | assert_eq!(whole(&text), Keymap::defaults()); |
| 2688 | assert_eq!(emit(&whole(&text)), text); |
| 2689 | let handwritten = "edith-keys 2\nundo ctrl+z\nplay space\n"; |
| 2690 | assert_eq!(emit(&whole(handwritten)), handwritten); |
| 2691 | // A keymap that binds nothing is legal -- and unusable, which is the |
| 2692 | // user's business, not the parser's. |
| 2693 | assert_eq!(whole("edith-keys 2\n").entries(), &[]); |
| 2694 | } |
| 2695 | |
| 2696 | #[test] |
| 2697 | fn every_refusal_names_its_line() { |
| 2698 | // Only the first line refuses the whole file. |
| 2699 | let err = |text: &str| parse(text).unwrap_err(); |
| 2700 | assert_eq!(err(""), "line 1: not a keybindings file"); |
| 2701 | assert_eq!(err("nonsense\n"), "line 1: not a keybindings file"); |
| 2702 | assert_eq!(err("edith-keys 3\n"), "line 1: unsupported version 3"); |
| 2703 | |
| 2704 | // Every other kind of bad line costs that line and nothing else. |
| 2705 | let dropped = |text: &str| parse(text).unwrap().1; |
| 2706 | assert_eq!( |
| 2707 | dropped("edith-keys 2\nfly space\n"), |
| 2708 | ["line 2: unknown action \"fly\""] |
| 2709 | ); |
| 2710 | assert_eq!( |
| 2711 | dropped("edith-keys 2\nplay space\nplayspace\n"), |
| 2712 | ["line 3: \"playspace\" is not `<action> <chord>`"] |
| 2713 | ); |
| 2714 | // An empty line is not optional whitespace, it is a line. |
| 2715 | assert_eq!( |
| 2716 | dropped("edith-keys 2\n\n"), |
| 2717 | ["line 2: \"\" is not `<action> <chord>`"] |
| 2718 | ); |
| 2719 | assert_eq!( |
| 2720 | dropped("edith-keys 2\nplay ctrl+shift+shift+x\n"), |
| 2721 | ["line 2: \"ctrl+shift+shift+x\" is not a chord"] |
| 2722 | ); |
| 2723 | assert_eq!( |
| 2724 | dropped("edith-keys 2\nplay ctrl+\n"), |
| 2725 | ["line 2: \"ctrl+\" is not a chord"] |
| 2726 | ); |
| 2727 | // gpui reports lowercase key names, so an uppercase one would simply |
| 2728 | // never match -- dropped rather than quietly dead. |
| 2729 | assert_eq!( |
| 2730 | dropped("edith-keys 2\nplay X\n"), |
| 2731 | ["line 2: \"X\" is not a chord"] |
| 2732 | ); |
| 2733 | // The same stroke twice: whichever line lost would depend on order, so |
| 2734 | // the second one is the one that goes. |
| 2735 | assert_eq!( |
| 2736 | dropped("edith-keys 2\nplay space\ncut space\n"), |
| 2737 | ["line 3: space is already play's"] |
| 2738 | ); |
| 2739 | } |
| 2740 | |
| 2741 | /// The rebind data-loss path: one line the parser cannot use must not cost |
| 2742 | /// the rebinds around it (a `capture` of shift+= wrote `play +`, and the |
| 2743 | /// next load threw the whole file away and went back to the defaults). |
| 2744 | #[test] |
| 2745 | fn one_bad_line_costs_only_that_line() { |
| 2746 | let text = "edith-keys 2\nplay +\nexport ctrl+w\ncut j\n"; |
| 2747 | let (keymap, dropped) = parse(text).expect("the magic line is still good"); |
| 2748 | assert_eq!(dropped, ["line 2: \"+\" is not a chord"]); |
| 2749 | // The lines around it are in force, which is the whole point. |
| 2750 | assert_eq!( |
| 2751 | keymap.lookup("w", true, false, false), |
| 2752 | Some(ActionId::Export) |
| 2753 | ); |
| 2754 | assert_eq!(keymap.lookup("j", false, false, false), Some(ActionId::Cut)); |
| 2755 | // ...and the one that went is unbound, not silently something else. |
| 2756 | assert_eq!(keymap.display(ActionId::Play), "unbound"); |
| 2757 | // What survives still round-trips: the kept lines emit back as read. |
| 2758 | assert_eq!(emit(&keymap), "edith-keys 2\nexport ctrl+w\ncut j\n"); |
| 2759 | |
| 2760 | // The notice names the line and the file, and the defaults do *not* |
| 2761 | // take over -- that was the data loss. |
| 2762 | let dir = Scratch::dir("edith-keymap-drop"); |
| 2763 | let path = dir.join("edith").join("keybindings"); |
| 2764 | std::fs::create_dir_all(path.parent().unwrap()).unwrap(); |
| 2765 | std::fs::write(&path, text).unwrap(); |
| 2766 | let (read, notice) = Keymap::load_from(&path); |
| 2767 | assert_eq!(read, keymap); |
| 2768 | let notice = notice.expect("a part-read file must say so"); |
| 2769 | assert!(notice.contains("line 2:"), "{notice}"); |
| 2770 | assert!(notice.contains("keybindings"), "{notice}"); |
| 2771 | std::fs::remove_dir_all(&dir).ok(); |
| 2772 | } |
| 2773 | |
| 2774 | /// The other half of the same bug: a stroke the file cannot spell is refused |
| 2775 | /// at the capture, before it can ever be written. |
| 2776 | #[test] |
| 2777 | fn only_a_stroke_the_file_can_spell_is_bindable() { |
| 2778 | for (key, ctrl) in [ |
| 2779 | ("space", false), |
| 2780 | ("=", false), |
| 2781 | ("s", true), |
| 2782 | ("escape", false), |
| 2783 | ] { |
| 2784 | assert!(chord(key, ctrl).bindable(), "{key}"); |
| 2785 | } |
| 2786 | // gpui's name for shift+=, and the grammar's own separator. |
| 2787 | assert!(!chord("+", false).bindable()); |
| 2788 | assert!(!chord("+", true).bindable()); |
| 2789 | // The rest of what `Chord::parse` will not take back. |
| 2790 | assert!(!chord("", false).bindable()); |
| 2791 | assert!(!chord("X", false).bindable()); |
| 2792 | assert!(!chord("page up", false).bindable()); |
| 2793 | // A bindable chord is one the file's own grammar can spell: what it |
| 2794 | // writes is what the next load reads, for every stroke that passes |
| 2795 | // here. |
| 2796 | let k = whole("edith-keys 2\nplay ctrl+w\n"); |
| 2797 | assert_eq!(whole(&emit(&k)), k); |
| 2798 | } |
| 2799 | |
| 2800 | #[test] |
| 2801 | fn display_reads_as_a_person_would_say_it() { |
| 2802 | let k = Keymap::defaults(); |
| 2803 | assert_eq!(k.display(ActionId::Play), "Space"); |
| 2804 | assert_eq!(k.display(ActionId::Save), "Ctrl+S"); |
| 2805 | assert_eq!(k.display(ActionId::Delete), "Delete or Backspace"); |
| 2806 | assert_eq!(k.display(ActionId::Undo), "Ctrl+Z"); |
| 2807 | // A toolbar shows one key: the first stroke, not the phrase. |
| 2808 | assert_eq!(k.primary(ActionId::Delete), "Delete"); |
| 2809 | assert_eq!(k.primary(ActionId::Undo), "Ctrl+Z"); |
| 2810 | // The one key whose common name is not gpui's. |
| 2811 | assert_eq!(k.display(ActionId::CancelExport), "Ctrl+Esc"); |
| 2812 | assert_eq!(whole("edith-keys 2\n").display(ActionId::Cut), "unbound"); |
| 2813 | // The label is the editor's column, and never the file's word for it. |
| 2814 | assert_eq!(ActionId::CancelExport.label(), "Cancel export"); |
| 2815 | assert_eq!(k.display(ActionId::ToggleSnap), "N"); |
| 2816 | assert_eq!(k.display(ActionId::ShowActions), "Ctrl+K"); |
| 2817 | assert_eq!(k.display(ActionId::ShowKeys), "? or F1"); |
| 2818 | assert_eq!(k.display(ActionId::ToggleSubtitles), "T"); |
| 2819 | assert_eq!(k.display(ActionId::ZoomIn), "= or Ctrl+="); |
| 2820 | assert_eq!(k.display(ActionId::GoStart), "Home"); |
| 2821 | assert_eq!(k.display(ActionId::StepBack), "←"); |
| 2822 | assert_eq!(k.display(ActionId::VolumeUp), "PageUp"); |
| 2823 | assert_eq!(k.display(ActionId::Fullscreen), "F11"); |
| 2824 | assert_eq!(k.display(ActionId::WalkCutNext), "↓ or ."); |
| 2825 | assert_eq!(k.display(ActionId::SetIn), "I"); |
| 2826 | assert_eq!(k.display(ActionId::ImportSubtitles), "Ctrl+Shift+I"); |
| 2827 | assert_eq!(k.display(ActionId::Speed), "Alt+1"); |
| 2828 | assert_eq!(k.display(ActionId::AddVideoLane), "unbound"); |
| 2829 | } |
| 2830 | |
| 2831 | /// DESIGN §8: a label names the verb. Prose truncates -- the KEYS list |
| 2832 | /// ellipsises it, a menu row's fixed plate cuts it mid-word, a hover plate |
| 2833 | /// the same -- so four words is the whole budget, and what a parenthesis |
| 2834 | /// used to carry (why an action refuses) lives in the refusal string the |
| 2835 | /// oracle and the engine already word. |
| 2836 | #[test] |
| 2837 | fn a_label_names_the_verb_in_four_words() { |
| 2838 | let mut seen: Vec<&'static str> = Vec::new(); |
| 2839 | for action in ActionId::ALL { |
| 2840 | let label = action.label(); |
| 2841 | let words = label.split_whitespace().count(); |
| 2842 | assert!(words <= 4, "{action:?}: {words} words -- {label:?}"); |
| 2843 | // No parenthesis: "(picture)" and "(sound)" were the jargon a menu |
| 2844 | // reader could not place; the names say the kind on their own. |
| 2845 | assert!(!label.contains('('), "{action:?}: a parenthesis -- {label:?}"); |
| 2846 | assert!( |
| 2847 | !label.to_lowercase().starts_with("the "), |
| 2848 | "{action:?}: leads with an article -- {label:?}" |
| 2849 | ); |
| 2850 | assert!(!seen.contains(&label), "two actions both named {label:?}"); |
| 2851 | seen.push(label); |
| 2852 | } |
| 2853 | } |
| 2854 | |
| 2855 | /// [`Keymap::chord`] is the badge's one token, not [`Keymap::display`]'s |
| 2856 | /// sentence: the primary (first-bound) stroke only, spelled as |
| 2857 | /// [`Chord::pretty`] spells it. |
| 2858 | #[test] |
| 2859 | fn chord_is_the_primary_stroke_compact() { |
| 2860 | let k = Keymap::defaults(); |
| 2861 | assert_eq!(k.chord(ActionId::Delete), "Delete"); |
| 2862 | assert_eq!(k.chord(ActionId::Undo), "Ctrl+Z"); |
| 2863 | assert_eq!(k.chord(ActionId::AddFiles), "Ctrl+I"); |
| 2864 | assert_eq!(k.chord(ActionId::ImportSubtitles), "Ctrl+Shift+I"); |
| 2865 | assert_eq!(k.chord(ActionId::CancelExport), "Ctrl+Esc"); |
| 2866 | assert_eq!(k.chord(ActionId::Play), "Space"); |
| 2867 | assert_eq!(k.chord(ActionId::Speed), "Alt+1"); |
| 2868 | assert_eq!(k.chord(ActionId::Settings), "Ctrl+,"); |
| 2869 | assert_eq!(k.chord(ActionId::ShowActions), "Ctrl+K"); |
| 2870 | // Menu-only: no stroke, so the badge reads `--`. |
| 2871 | assert_eq!(k.chord(ActionId::PasteFilePath), "--"); |
| 2872 | assert_eq!(whole("edith-keys 2\n").chord(ActionId::Cut), "--"); |
| 2873 | } |
| 2874 | |
| 2875 | /// The keys search matches a glyph by the word a person says for it, and |
| 2876 | /// `Esc` by its full name. |
| 2877 | #[test] |
| 2878 | fn search_aliases_name_the_glyphs_a_person_would_type() { |
| 2879 | assert_eq!(super::search_aliases("↵"), "enter return"); |
| 2880 | assert_eq!(super::search_aliases("Esc"), "escape"); |
| 2881 | assert_eq!( |
| 2882 | super::search_aliases("↑ ↓ ↵"), |
| 2883 | "up arrow down arrow enter return" |
| 2884 | ); |
| 2885 | assert_eq!(super::search_aliases("← / →"), "left arrow right arrow"); |
| 2886 | assert_eq!(super::search_aliases("N"), ""); |
| 2887 | } |
| 2888 | |
| 2889 | #[test] |
| 2890 | fn a_saved_keymap_comes_back_off_the_disk() { |
| 2891 | // Its own directory, never the real config one: this test writes. |
| 2892 | let dir = Scratch::dir("edith-keymap"); |
| 2893 | let path = dir.join("edith").join("keybindings"); |
| 2894 | // A defaults file with Export's own line swapped for a free stroke -- |
| 2895 | // parsed rather than rebound, since nothing left in the API mutates |
| 2896 | // a `Keymap` in place. |
| 2897 | let text: String = emit(&Keymap::defaults()) |
| 2898 | .lines() |
| 2899 | .filter(|l| !l.starts_with("export ")) |
| 2900 | .chain(std::iter::once("export ctrl+w")) |
| 2901 | .collect::<Vec<_>>() |
| 2902 | .join("\n") |
| 2903 | + "\n"; |
| 2904 | let written = whole(&text); |
| 2905 | // The config directory does not exist yet -- the first save makes it. |
| 2906 | written.save_to(&path).unwrap(); |
| 2907 | let (read, notice) = Keymap::load_from(&path); |
| 2908 | assert_eq!(notice, None); |
| 2909 | assert_eq!(read, written); |
| 2910 | assert_eq!(read.lookup("w", true, false, false), Some(ActionId::Export)); |
| 2911 | assert_eq!(read.lookup("e", false, false, false), None); |
| 2912 | // The rename left nothing half-written behind. |
| 2913 | assert!(!dir.join("edith").join("keybindings.part").exists()); |
| 2914 | // A file that is merely absent is not an error and says nothing. |
| 2915 | let (fresh, notice) = Keymap::load_from(&dir.join("nothing-here")); |
| 2916 | assert_eq!(fresh, Keymap::defaults()); |
| 2917 | assert_eq!(notice, None); |
| 2918 | // A file that is not one at all falls back whole, and names its line. |
| 2919 | std::fs::write(&path, "edith-keys 9\nplay space\n").unwrap(); |
| 2920 | let (fallback, notice) = Keymap::load_from(&path); |
| 2921 | assert_eq!(fallback, Keymap::defaults()); |
| 2922 | let notice = notice.expect("a refused file must say so"); |
| 2923 | assert!(notice.contains("line 1:"), "{notice}"); |
| 2924 | assert!(notice.contains("keybindings"), "{notice}"); |
| 2925 | // One unusable line inside a good file costs that line only -- the |
| 2926 | // defaults do not come back over the rebinds that read fine. |
| 2927 | std::fs::write( |
| 2928 | &path, |
| 2929 | "edith-keys 2\nplay ctrl+shift+shift+x\nexport ctrl+w\n", |
| 2930 | ) |
| 2931 | .unwrap(); |
| 2932 | let (kept, notice) = Keymap::load_from(&path); |
| 2933 | assert_eq!(kept.lookup("w", true, false, false), Some(ActionId::Export)); |
| 2934 | assert_eq!(kept.display(ActionId::Play), "unbound"); |
| 2935 | let notice = notice.expect("a part-read file must say so"); |
| 2936 | assert!(notice.contains("line 2:"), "{notice}"); |
| 2937 | assert!(notice.contains("keybindings"), "{notice}"); |
| 2938 | // Saving over it is a whole replacement, not an edit. |
| 2939 | Keymap::defaults().save_to(&path).unwrap(); |
| 2940 | assert_eq!(Keymap::load_from(&path), (Keymap::defaults(), None)); |
| 2941 | std::fs::remove_dir_all(&dir).ok(); |
| 2942 | } |
| 2943 | |
| 2944 | #[test] |
| 2945 | fn shift_and_alt_round_trip_in_any_order() { |
| 2946 | let c = Chord::parse("shift+ctrl+i", 1).unwrap(); |
| 2947 | assert_eq!( |
| 2948 | c, |
| 2949 | Chord { |
| 2950 | key: "i".into(), |
| 2951 | ctrl: true, |
| 2952 | shift: true, |
| 2953 | alt: false, |
| 2954 | } |
| 2955 | ); |
| 2956 | assert_eq!(c.text(), "ctrl+shift+i"); |
| 2957 | assert_eq!(c.pretty(), "Ctrl+Shift+I"); |
| 2958 | assert_eq!(c.compact(), "Ctrl+Shift+I"); |
| 2959 | let a = Chord::parse("alt+1", 1).unwrap(); |
| 2960 | assert_eq!(a.pretty(), "Alt+1"); |
| 2961 | assert_eq!(a.compact(), "Alt+1"); |
| 2962 | // Each modifier once, a lowercase key last, and nothing else. |
| 2963 | for bad in [ |
| 2964 | "alt+ctrl+alt+1", |
| 2965 | "ctrl+ctrl+x", |
| 2966 | "shift+", |
| 2967 | "ctrl+shift+", |
| 2968 | "Ctrl+i", |
| 2969 | "shift+I", |
| 2970 | ] { |
| 2971 | assert!(Chord::parse(bad, 1).is_err(), "{bad} should be refused"); |
| 2972 | } |
| 2973 | // Read from a file and written back in the one spelling; the same key |
| 2974 | // with and without shift is two strokes. |
| 2975 | let k = whole("edith-keys 2\nimport-subtitles shift+ctrl+i\nadd-files ctrl+i\n"); |
| 2976 | assert_eq!( |
| 2977 | k.lookup("i", true, true, false), |
| 2978 | Some(ActionId::ImportSubtitles) |
| 2979 | ); |
| 2980 | assert_eq!(k.lookup("i", true, false, false), Some(ActionId::AddFiles)); |
| 2981 | assert_eq!(k.lookup("i", false, false, false), None); |
| 2982 | assert_eq!( |
| 2983 | emit(&k), |
| 2984 | "edith-keys 2\nimport-subtitles ctrl+shift+i\nadd-files ctrl+i\n" |
| 2985 | ); |
| 2986 | assert!(c.bindable()); |
| 2987 | assert!( |
| 2988 | !Chord { |
| 2989 | key: "+".into(), |
| 2990 | ctrl: false, |
| 2991 | shift: true, |
| 2992 | alt: false, |
| 2993 | } |
| 2994 | .bindable() |
| 2995 | ); |
| 2996 | } |
| 2997 | |
| 2998 | /// DESIGN.md §10.2's table, row for row: every action's strokes, in order, |
| 2999 | /// as keymap.json's "proposed" column has them, with Delete's Backspace and |
| 3000 | /// ShowActions alone on Ctrl+K as the brief set them. |
| 3001 | #[test] |
| 3002 | fn defaults_are_the_proposed_keys() { |
| 3003 | const PROPOSED: &[(&str, &[&str])] = &[ |
| 3004 | ("Export", &["e"]), |
| 3005 | ("Save", &["ctrl+s"]), |
| 3006 | ("ReloadProject", &[]), |
| 3007 | ("NewProject", &[]), |
| 3008 | ("SaveVersion", &[]), |
| 3009 | ("SaveTemplate", &[]), |
| 3010 | ("ExportCaptions", &[]), |
| 3011 | ("Versions", &[]), |
| 3012 | ("CollectMedia", &[]), |
| 3013 | ("ProjectNotes", &[]), |
| 3014 | ("ExportTimelineOtio", &[]), |
| 3015 | ("ExportTimelineFcpxml", &[]), |
| 3016 | ("ExportTimelineEdl", &[]), |
| 3017 | ("ImportTimelineOtio", &[]), |
| 3018 | ("Normalize", &["alt+n"]), |
| 3019 | ("Captions", &["alt+c"]), |
| 3020 | ("Fillers", &["alt+u"]), |
| 3021 | ("CutSelectedWords", &[]), |
| 3022 | ("Voiceover", &["alt+v"]), |
| 3023 | ("RecordVoiceover", &[]), |
| 3024 | ("AddFiles", &["ctrl+i"]), |
| 3025 | ("OpenProject", &["ctrl+o"]), |
| 3026 | ("PasteFilePath", &[]), |
| 3027 | ("CancelExport", &["ctrl+escape"]), |
| 3028 | ("ShowActions", &["ctrl+k"]), |
| 3029 | ("ShowKeys", &["?", "f1"]), |
| 3030 | ("Screenshot", &["f12"]), |
| 3031 | ("Play", &["space"]), |
| 3032 | ("Loop", &["r"]), |
| 3033 | ("PlayAround", &["shift+k"]), |
| 3034 | ("StepBack", &["left"]), |
| 3035 | ("StepForward", &["right"]), |
| 3036 | ("JumpBack", &["ctrl+left"]), |
| 3037 | ("JumpForward", &["ctrl+right"]), |
| 3038 | ("GoStart", &["home"]), |
| 3039 | ("GoEnd", &["end"]), |
| 3040 | ("GoToTime", &["ctrl+j"]), |
| 3041 | ("PrevSyncPoint", &["ctrl+["]), |
| 3042 | ("NextSyncPoint", &["ctrl+]"]), |
| 3043 | ("WalkCutNext", &["down", "."]), |
| 3044 | ("WalkCutPrev", &["up", ","]), |
| 3045 | ("WalkCutNext10", &[">"]), |
| 3046 | ("WalkCutPrev10", &["<"]), |
| 3047 | ("NextMarker", &["shift+m"]), |
| 3048 | ("PrevMarker", &["ctrl+shift+m"]), |
| 3049 | ("SetIn", &["i"]), |
| 3050 | ("SetOut", &["o"]), |
| 3051 | ("ClearRange", &["ctrl+u"]), |
| 3052 | ("ShuttleBack", &["j"]), |
| 3053 | ("ShuttleStop", &["k"]), |
| 3054 | ("ShuttleForward", &["l"]), |
| 3055 | ("InsertSource", &["f9"]), |
| 3056 | ("OverwriteSource", &["f10"]), |
| 3057 | ("Cut", &["s"]), |
| 3058 | ("Regroup", &["g"]), |
| 3059 | ("Detach", &["d"]), |
| 3060 | ("Group", &["ctrl+g"]), |
| 3061 | ("Undo", &["ctrl+z"]), |
| 3062 | ("Redo", &["ctrl+y", "ctrl+shift+z"]), |
| 3063 | ("History", &[]), |
| 3064 | ("AddVideoLane", &[]), |
| 3065 | ("AddAudioLane", &[]), |
| 3066 | ("RemoveVideoLane", &[]), |
| 3067 | ("RemoveAudioLane", &[]), |
| 3068 | ("AddSubtitleLane", &[]), |
| 3069 | ("RemoveSubtitleLane", &[]), |
| 3070 | ("ImportSubtitles", &["ctrl+shift+i"]), |
| 3071 | ("ToggleSnap", &["n"]), |
| 3072 | ("AddMarker", &["alt+m"]), |
| 3073 | ("Markers", &["alt+8"]), |
| 3074 | ("Copy", &["ctrl+c"]), |
| 3075 | ("Paste", &["ctrl+v"]), |
| 3076 | ("Select", &["tab"]), |
| 3077 | ("SelectNext", &["}"]), |
| 3078 | ("SelectPrev", &["{"]), |
| 3079 | ("SelectAll", &["ctrl+a"]), |
| 3080 | ("Deselect", &["escape"]), |
| 3081 | ("Delete", &["delete", "backspace"]), |
| 3082 | ("Lift", &[";"]), |
| 3083 | ("Color", &["alt+2"]), |
| 3084 | ("Transform", &["alt+3"]), |
| 3085 | ("Effects", &["alt+e"]), |
| 3086 | ("KeyPlacement", &[]), |
| 3087 | ("KeyOpacity", &[]), |
| 3088 | ("KeyColor", &[]), |
| 3089 | ("KeyEasing", &[]), |
| 3090 | ("Fit", &["alt+7"]), |
| 3091 | ("Reverse", &["ctrl+alt+r"]), |
| 3092 | ("ClipEnabled", &["shift+e"]), |
| 3093 | ("ClipLabel", &[]), |
| 3094 | ("NewSolid", &[]), |
| 3095 | ("NewGradient", &[]), |
| 3096 | ("NewCountdown", &[]), |
| 3097 | ("NewBars", &[]), |
| 3098 | ("NewTone", &[]), |
| 3099 | ("NewBarsAndTone", &[]), |
| 3100 | ("NewAdjustment", &[]), |
| 3101 | ("NewRectangle", &[]), |
| 3102 | ("NewEllipse", &[]), |
| 3103 | ("NewLine", &[]), |
| 3104 | ("NewArrow", &[]), |
| 3105 | ("NewTitle", &["alt+t"]), |
| 3106 | ("NewBin", &[]), |
| 3107 | ("NewBinInside", &[]), |
| 3108 | ("RenameBin", &[]), |
| 3109 | ("RemoveBin", &[]), |
| 3110 | ("ToggleFavourite", &[]), |
| 3111 | ("MoveToBin", &[]), |
| 3112 | ("ShowFavourites", &[]), |
| 3113 | ("ShowAllMedia", &[]), |
| 3114 | ("Speed", &["alt+1"]), |
| 3115 | ("SpeedRampUp", &[]), |
| 3116 | ("SpeedRampDown", &[]), |
| 3117 | ("SpeedRampSlowFastSlow", &[]), |
| 3118 | ("SpeedRampFastSlowFast", &[]), |
| 3119 | ("SpeedRampKey", &[]), |
| 3120 | ("SpeedRampClear", &[]), |
| 3121 | ("Silence", &["alt+5"]), |
| 3122 | ("MarkBeats", &["alt+b"]), |
| 3123 | ("Visualizer", &["alt+6"]), |
| 3124 | ("Reframe", &[]), |
| 3125 | ("TrackMask", &[]), |
| 3126 | ("NestClips", &[]), |
| 3127 | ("BreakApart", &[]), |
| 3128 | ("OpenCompound", &[]), |
| 3129 | ("CloseCompound", &[]), |
| 3130 | ("NewSequence", &[]), |
| 3131 | ("DuplicateSequence", &[]), |
| 3132 | ("RenameSequence", &[]), |
| 3133 | ("DeleteSequence", &[]), |
| 3134 | ("CreateMulticam", &[]), |
| 3135 | ("FlattenMulticam", &[]), |
| 3136 | ("ToggleAngleMonitor", &["alt+a"]), |
| 3137 | ("ToggleOutputWindow", &[]), |
| 3138 | ("OutputDisplay", &[]), |
| 3139 | ("Angle1", &["1"]), |
| 3140 | ("Angle2", &["2"]), |
| 3141 | ("Angle3", &["3"]), |
| 3142 | ("Angle4", &["4"]), |
| 3143 | ("Angle5", &["5"]), |
| 3144 | ("Angle6", &["6"]), |
| 3145 | ("Angle7", &["7"]), |
| 3146 | ("Angle8", &["8"]), |
| 3147 | ("Angle9", &["9"]), |
| 3148 | ("RenameLane", &[]), |
| 3149 | ("Crossfade", &["ctrl+f"]), |
| 3150 | ("TrimIn", &["["]), |
| 3151 | ("TrimOut", &["]"]), |
| 3152 | ("LoopTrim", &["/"]), |
| 3153 | ("RippleTrimInToPlayhead", &["q"]), |
| 3154 | ("RippleTrimOutToPlayhead", &["w"]), |
| 3155 | ("TrimInToPlayhead", &["alt+q"]), |
| 3156 | ("TrimOutToPlayhead", &["alt+w"]), |
| 3157 | ("RollBack", &["alt+["]), |
| 3158 | ("RollForward", &["alt+]"]), |
| 3159 | ("SlipBack", &["alt+,"]), |
| 3160 | ("SlipForward", &["alt+."]), |
| 3161 | ("SlideBack", &["alt+left"]), |
| 3162 | ("SlideForward", &["alt+right"]), |
| 3163 | ("Dissolve", &["ctrl+d"]), |
| 3164 | ("TransitionDissolve", &[]), |
| 3165 | ("TransitionDipBlack", &[]), |
| 3166 | ("TransitionDipWhite", &[]), |
| 3167 | ("TransitionWipeLeft", &[]), |
| 3168 | ("TransitionWipeRight", &[]), |
| 3169 | ("TransitionWipeUp", &[]), |
| 3170 | ("TransitionWipeDown", &[]), |
| 3171 | ("TransitionSlideLeft", &[]), |
| 3172 | ("TransitionSlideRight", &[]), |
| 3173 | ("TransitionSlideUp", &[]), |
| 3174 | ("TransitionSlideDown", &[]), |
| 3175 | ("TransitionPushLeft", &[]), |
| 3176 | ("TransitionPushRight", &[]), |
| 3177 | ("TransitionPushUp", &[]), |
| 3178 | ("TransitionPushDown", &[]), |
| 3179 | ("TransitionZoom", &[]), |
| 3180 | ("ToggleMute", &["m"]), |
| 3181 | ("VolumeUp", &["pageup"]), |
| 3182 | ("VolumeDown", &["pagedown"]), |
| 3183 | ("Equalizer", &["alt+4"]), |
| 3184 | ("Mix", &["f", "alt+x"]), |
| 3185 | ("CleanVoice", &["alt+9"]), |
| 3186 | ("VoiceDynamics", &["alt+0"]), |
| 3187 | ("Resolution", &["ctrl+r"]), |
| 3188 | ("ZoomIn", &["=", "ctrl+="]), |
| 3189 | ("ZoomOut", &["-", "ctrl+-"]), |
| 3190 | ("ZoomFit", &["\\", "ctrl+0"]), |
| 3191 | ("ZoomToSelection", &["shift+z"]), |
| 3192 | ("TrackSmall", &[]), |
| 3193 | ("TrackMedium", &[]), |
| 3194 | ("TrackLarge", &[]), |
| 3195 | ("TracksSmaller", &["alt+-"]), |
| 3196 | ("TracksLarger", &["alt+="]), |
| 3197 | ("ViewZoom", &[]), |
| 3198 | ("PlaybackQuality", &[]), |
| 3199 | ("GuideStyle", &[]), |
| 3200 | ("GuideMask", &[]), |
| 3201 | ("ToggleSubtitles", &["t"]), |
| 3202 | ("ToggleWaveforms", &[]), |
| 3203 | ("ToggleScrubAudio", &[]), |
| 3204 | ("CompareOff", &[]), |
| 3205 | ("CompareSplit", &[]), |
| 3206 | ("CompareSide", &[]), |
| 3207 | ("AutoColour", &[]), |
| 3208 | ("SaveLook", &[]), |
| 3209 | ("ToggleProxies", &["ctrl+p"]), |
| 3210 | ("ToggleAutoProxies", &[]), |
| 3211 | ("Theme", &[]), |
| 3212 | ("AccentColour", &[]), |
| 3213 | ("Fullscreen", &["f11"]), |
| 3214 | ("SubtitleStyle", &["y"]), |
| 3215 | ("Settings", &["ctrl+,"]), |
| 3216 | ("CloseGap", &["shift+delete"]), |
| 3217 | ("Freeze", &["shift+r"]), |
| 3218 | ("PasteAttributes", &["ctrl+alt+v"]), |
| 3219 | ("PasteColor", &[]), |
| 3220 | ("PasteEffects", &[]), |
| 3221 | ("PasteTransform", &[]), |
| 3222 | ("PasteSpeed", &[]), |
| 3223 | ("PasteAudio", &[]), |
| 3224 | ("MatchFrame", &["shift+f"]), |
| 3225 | ("ReplaceEdit", &["f8"]), |
| 3226 | ("SelectForward", &["alt+y"]), |
| 3227 | ("SelectForwardAll", &["shift+a"]), |
| 3228 | ("ExtendAudio", &["shift+alt+l"]), |
| 3229 | ("ExtendVideo", &["shift+alt+j"]), |
| 3230 | ("NudgeBack", &["ctrl+alt+left"]), |
| 3231 | ("NudgeForward", &["ctrl+alt+right"]), |
| 3232 | ("NudgeBack10", &["ctrl+shift+alt+left"]), |
| 3233 | ("NudgeForward10", &["ctrl+shift+alt+right"]), |
| 3234 | ("FocusPanels", &["f6"]), |
| 3235 | ("About", &[]), |
| 3236 | ("MarkerHere", &[]), |
| 3237 | ("RenameMarker", &[]), |
| 3238 | ("DeleteMarker", &[]), |
| 3239 | ("PlayheadHere", &[]), |
| 3240 | ("RenderInOut", &["enter"]), |
| 3241 | ("RenderAll", &[]), |
| 3242 | ("CancelRender", &[]), |
| 3243 | ("DeleteRenderFiles", &[]), |
| 3244 | ]; |
| 3245 | let k = Keymap::defaults(); |
| 3246 | assert_eq!(PROPOSED.len(), ActionId::ALL.len()); |
| 3247 | for (name, want) in PROPOSED { |
| 3248 | let action = ActionId::ALL |
| 3249 | .into_iter() |
| 3250 | .find(|a| format!("{a:?}") == *name) |
| 3251 | .unwrap_or_else(|| panic!("{name} is not an action")); |
| 3252 | let have: Vec<String> = k |
| 3253 | .entries() |
| 3254 | .iter() |
| 3255 | .filter(|b| b.action == action) |
| 3256 | .map(|b| b.chord.text()) |
| 3257 | .collect(); |
| 3258 | let want: Vec<String> = want.iter().map(|s| s.to_string()).collect(); |
| 3259 | assert_eq!(have, want, "{name}"); |
| 3260 | } |
| 3261 | } |
| 3262 | |
| 3263 | /// A file the build before shift and alt saved, with that build's defaults |
| 3264 | /// in it, comes back as today's defaults for every action that moved. |
| 3265 | #[test] |
| 3266 | fn a_v1_file_with_the_old_defaults_migrates() { |
| 3267 | let mut text = String::from("edith-keys 1\n"); |
| 3268 | for (action, old) in V1_DEFAULTS { |
| 3269 | for chord in old.iter() { |
| 3270 | text.push_str(&format!("{} {chord}\n", action.name())); |
| 3271 | } |
| 3272 | } |
| 3273 | let migrated = whole(&text); |
| 3274 | let defaults = Keymap::defaults(); |
| 3275 | for (action, _) in V1_DEFAULTS { |
| 3276 | let of = |k: &Keymap| { |
| 3277 | k.entries() |
| 3278 | .iter() |
| 3279 | .filter(|b| b.action == *action) |
| 3280 | .cloned() |
| 3281 | .collect::<Vec<_>>() |
| 3282 | }; |
| 3283 | assert_eq!(of(&migrated), of(&defaults), "{action:?}"); |
| 3284 | } |
| 3285 | assert_eq!(migrated.display(ActionId::Speed), "Alt+1"); |
| 3286 | assert_eq!(migrated.display(ActionId::Delete), "Delete or Backspace"); |
| 3287 | assert_eq!(migrated.display(ActionId::Undo), "Ctrl+Z"); |
| 3288 | assert_eq!(migrated.display(ActionId::ShuttleBack), "J"); |
| 3289 | // Nothing the table does not name was in the file, so nothing else is bound. |
| 3290 | assert_eq!(migrated.display(ActionId::Cut), "unbound"); |
| 3291 | } |
| 3292 | |
| 3293 | /// A rebind in the old format is the person's: it is kept, and a default |
| 3294 | /// whose stroke it takes is left unbound rather than taking the stroke back. |
| 3295 | #[test] |
| 3296 | fn a_v1_rebind_is_kept_and_a_default_it_holds_is_not_taken() { |
| 3297 | let (k, dropped) = parse("edith-keys 1\nspeed x\nlift j\n").unwrap(); |
| 3298 | assert!(dropped.is_empty()); |
| 3299 | assert_eq!(k.display(ActionId::Speed), "X"); |
| 3300 | assert_eq!(k.display(ActionId::Lift), "J"); |
| 3301 | // The shuttle's default is `j`, which the lift line holds. |
| 3302 | assert_eq!(k.display(ActionId::ShuttleBack), "unbound"); |
| 3303 | // A default the file does not touch comes from the defaults. |
| 3304 | assert_eq!(k.display(ActionId::ShuttleStop), "K"); |
| 3305 | } |
| 3306 | |
| 3307 | /// Today's files are never migrated, so an action unbound on purpose stays |
| 3308 | /// unbound after a save and a load. |
| 3309 | #[test] |
| 3310 | fn a_v2_file_keeps_what_its_owner_unbound() { |
| 3311 | let text: String = emit(&Keymap::defaults()) |
| 3312 | .lines() |
| 3313 | .filter(|l| !l.starts_with("shuttle-back ")) |
| 3314 | .collect::<Vec<_>>() |
| 3315 | .join("\n") |
| 3316 | + "\n"; |
| 3317 | let k = whole(&text); |
| 3318 | assert_eq!(k.display(ActionId::ShuttleBack), "unbound"); |
| 3319 | assert_eq!(k.display(ActionId::ShuttleStop), "K"); |
| 3320 | } |
| 3321 | |
| 3322 | #[test] |
| 3323 | fn the_config_path_follows_xdg_then_home() { |
| 3324 | let p = |xdg: Option<&str>, home: Option<&str>| { |
| 3325 | config_path_in(xdg.map(Into::into), home.map(Into::into)) |
| 3326 | }; |
| 3327 | assert_eq!( |
| 3328 | p(Some("/x/config"), Some("/home/u")), |
| 3329 | std::path::Path::new("/x/config/edith/keybindings") |
| 3330 | ); |
| 3331 | assert_eq!( |
| 3332 | p(None, Some("/home/u")), |
| 3333 | std::path::Path::new("/home/u/.config/edith/keybindings") |
| 3334 | ); |
| 3335 | // An empty XDG_CONFIG_HOME is one the spec says to ignore. |
| 3336 | assert_eq!( |
| 3337 | p(Some(""), Some("/home/u")), |
| 3338 | std::path::Path::new("/home/u/.config/edith/keybindings") |
| 3339 | ); |
| 3340 | // Nowhere to put it but here -- still never `/edith/keybindings`. |
| 3341 | assert_eq!( |
| 3342 | p(None, None), |
| 3343 | std::path::Path::new(".config/edith/keybindings") |
| 3344 | ); |
| 3345 | } |
| 3346 | |
| 3347 | fn index_of(keymap: &Keymap, action: ActionId) -> usize { |
| 3348 | keymap |
| 3349 | .entries() |
| 3350 | .iter() |
| 3351 | .position(|b| b.action == action) |
| 3352 | .expect("a shipped action has a binding") |
| 3353 | } |
| 3354 | |
| 3355 | #[test] |
| 3356 | fn a_swap_hands_the_holders_stroke_over_and_never_doubles_a_chord() { |
| 3357 | let mut keymap = Keymap::defaults(); |
| 3358 | let save = index_of(&keymap, ActionId::Save); |
| 3359 | // Save is ctrl+s and AddFiles is ctrl+i: taking ctrl+i for Save must |
| 3360 | // leave AddFiles with the stroke Save gave up. |
| 3361 | assert_eq!( |
| 3362 | keymap.holder(&chord("i", true), save), |
| 3363 | Some(index_of(&keymap, ActionId::AddFiles)) |
| 3364 | ); |
| 3365 | keymap.swap_in(save, chord("i", true)); |
| 3366 | assert_eq!(keymap.lookup("i", true, false, false), Some(ActionId::Save)); |
| 3367 | assert_eq!( |
| 3368 | keymap.lookup("s", true, false, false), |
| 3369 | Some(ActionId::AddFiles) |
| 3370 | ); |
| 3371 | let chords: Vec<&Chord> = keymap.entries().iter().map(|b| &b.chord).collect(); |
| 3372 | for (at, c) in chords.iter().enumerate() { |
| 3373 | assert!(!chords[at + 1..].contains(c), "{c:?} is on two rows"); |
| 3374 | } |
| 3375 | } |
| 3376 | |
| 3377 | #[test] |
| 3378 | fn a_reset_restores_the_shipped_strokes_and_names_whoever_lost_one() { |
| 3379 | let shipped = Keymap::defaults(); |
| 3380 | let mut keymap = Keymap::defaults(); |
| 3381 | assert!(keymap.is_default(ActionId::Save, &shipped)); |
| 3382 | let save = index_of(&keymap, ActionId::Save); |
| 3383 | keymap.swap_in(save, chord("i", true)); |
| 3384 | assert!(!keymap.is_default(ActionId::Save, &shipped)); |
| 3385 | assert!(!keymap.is_default(ActionId::AddFiles, &shipped)); |
| 3386 | let displaced = keymap.reset_action(ActionId::Save); |
| 3387 | assert!(keymap.is_default(ActionId::Save, &shipped)); |
| 3388 | // AddFiles held Save's shipped ctrl+s after the swap, so the reset takes |
| 3389 | // it back and AddFiles is left with nothing -- and says so. |
| 3390 | assert_eq!(displaced, vec![ActionId::AddFiles]); |
| 3391 | assert_eq!(keymap.lookup("i", true, false, false), None); |
| 3392 | assert_eq!(keymap.lookup("s", true, false, false), Some(ActionId::Save)); |
| 3393 | } |
| 3394 | |
| 3395 | #[test] |
| 3396 | fn a_reset_keeps_the_action_in_its_shipped_place() { |
| 3397 | let mut keymap = Keymap::defaults(); |
| 3398 | let before: Vec<ActionId> = keymap.entries().iter().map(|b| b.action).collect(); |
| 3399 | let save = index_of(&keymap, ActionId::Save); |
| 3400 | keymap.swap_in(save, chord("q", true)); |
| 3401 | keymap.reset_action(ActionId::Save); |
| 3402 | let after: Vec<ActionId> = keymap.entries().iter().map(|b| b.action).collect(); |
| 3403 | assert_eq!(before, after); |
| 3404 | } |
| 3405 | } |
| 3406 | |
| 3407 | #[cfg(test)] |
| 3408 | mod nocycle_names { |
| 3409 | use super::*; |
| 3410 | |
| 3411 | /// A keys file written while the action still stepped calls it `cycle-key-ease`. |
| 3412 | #[test] |
| 3413 | fn an_old_keys_file_still_finds_key_easing() { |
| 3414 | assert_eq!(ActionId::from_name("cycle-key-ease"), Some(ActionId::KeyEasing)); |
| 3415 | assert_eq!(ActionId::from_name("key-easing"), Some(ActionId::KeyEasing)); |
| 3416 | } |
| 3417 | } |