diff --git a/crates/app/src/keymap.rs b/crates/app/src/keymap.rs index 9e520ef..91c1cc4 100644 --- a/crates/app/src/keymap.rs +++ b/crates/app/src/keymap.rs @@ -210,6 +210,14 @@ actions! { /// The cue plate's font and size -- a person's own preference, kept /// beside the theme and not the project, and opened the same way. SubtitleStyle, + /// The settings page: PROJECT rows (resolution, fps, sample-rate, HDR + /// tonemap, the mix) beside EDITOR rows (proxies, auto-proxies, subtitle + /// font) -- one door, two clearly-headed sections, per the split rule + /// that "anything that changes the rendered output or lives in the + /// project file is PROJECT; anything about this machine, this person, + /// this window is EDITOR." Always answerable, same as `Theme`: it is + /// about the editor and the project's own numbers, not about a clip. + Settings, } impl ActionId { @@ -290,6 +298,7 @@ impl ActionId { ActionId::ShowActions => "All actions and their keys…", ActionId::Screenshot => "Save the frame on screen as a PNG", ActionId::SubtitleStyle => "Subtitle style: font and size…", + ActionId::Settings => "Settings: project and editor…", } } @@ -368,6 +377,7 @@ impl ActionId { ActionId::ShowActions => "show-actions", ActionId::Screenshot => "screenshot", ActionId::SubtitleStyle => "subtitle-style", + ActionId::Settings => "settings", } } @@ -448,7 +458,10 @@ impl ActionId { | ActionId::SubtitleStyle // ...and whether that window fills the screen: a way of looking, // same as the zoom and the theme beside it. - | ActionId::Fullscreen => Category::View, + | ActionId::Fullscreen + // The settings page: it changes no clip and no lane, only the + // project's own numbers and this window's preferences. + | ActionId::Settings => Category::View, ActionId::Cut | ActionId::Regroup | ActionId::Detach @@ -1205,6 +1218,10 @@ impl Keymap { // opened as often as the theme, not a switch thrown once a // session. b(ActionId::SubtitleStyle, "y", false), + // The consumer-editor convention (Cmd/Ctrl+,) -- free here: + // bare "," is WalkCutPrev, and nothing else answers to the + // ctrl chord. + b(ActionId::Settings, ",", true), ], } } @@ -1483,7 +1500,7 @@ mod tests { #[test] fn every_default_stroke_reaches_its_action() { let k = Keymap::defaults(); - assert_eq!(k.entries().len(), 73); + assert_eq!(k.entries().len(), 74); // The cut odometer: bare walks one, `<`/`>` (what shift+,/shift+. // actually type) strides ten. assert_eq!(k.lookup(".", false), Some(ActionId::WalkCutNext)); diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 336b2c5..9787a67 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -500,6 +500,11 @@ struct Player { /// pointer: a stroke or a click meant for a row must not also cut the /// timeline. keys_open: bool, + /// The settings page is up (`?` overlay's sibling, but a latch rather + /// than a hold -- it carries clickable rows, not a glance-and-release + /// list). Cleared by [`Player::close_card`], the one reset list every + /// opener routes through. + settings_open: bool, /// What has been typed into the card's search box, which is the card's own /// input exactly as the export card's digits are (nothing in it takes /// focus, so the root's key handler is the field). Emptied every time the @@ -794,6 +799,13 @@ fn main() { // The subtitle style the last session picked, same silence on a missing // or unreadable file. let (sub_family, sub_text) = load_subtitle_style(); + // The auto-proxies default the last session left the switch at, before + // any project's own line ([`engine::edith::Document::auto_proxy`]) + // overrides it the moment one opens. + let auto_proxies_on = player::library::load_auto_proxies_pref(); + // The Proxies default the last session left the switch at, same + // before-any-project-line precedence as the auto-proxies default above. + let proxies_on = player::library::load_proxies_pref(); // Nothing named on the command line is read here. The first file makes the // timeline -- a `.edith` restores a whole one, anything else *is* one -- // and the rest are imports like any other: rows in the library, dragged @@ -867,8 +879,8 @@ fn main() { volume_dragging: false, // What a session comes up at, so the first one opened is // pushed the values it already holds. - proxies_on: false, - auto_proxies_on: true, + proxies_on, + auto_proxies_on, // Only ever used with a timeline; 30 keeps the empty // timecode reading in frames rather than in NaN. fps: 30., @@ -944,6 +956,7 @@ fn main() { autosave_armed: false, keymap: keymap.clone(), keys_open: false, + settings_open: false, keys_search: String::new(), keys_scroll: ScrollHandle::new(), lanes_scroll: ScrollHandle::new(), diff --git a/crates/app/src/oracle.rs b/crates/app/src/oracle.rs index 61073ec..47bc295 100644 --- a/crates/app/src/oracle.rs +++ b/crates/app/src/oracle.rs @@ -102,9 +102,20 @@ pub(crate) fn enable(action: ActionId, ctx: Ctx) -> Enable { // touching no timeline, live through an export the same way. // ...and the cue plate's own font and size: a reading preference like the // theme, never burned into an export, live the same way. + // + // Settings is not in this list, on purpose: it opens the same modal slot + // the exporting card owns (`Player::open_settings`, one card at a time), + // so a permission this oracle granted here would be a permission nobody + // could ever observe. It is refused below, with every other card. if action == ActionId::Theme || action == ActionId::Fullscreen || action == ActionId::SubtitleStyle { return Enable::Yes; } + if action == ActionId::Settings { + return match ctx.exporting { + true => Enable::No("an export is running"), + false => Enable::Yes, + }; + } if action == ActionId::ShowActions { return match ctx.exporting { true => Enable::No("an export is running"), diff --git a/crates/app/src/player/actions.rs b/crates/app/src/player/actions.rs index 22385fd..8e72d42 100644 --- a/crates/app/src/player/actions.rs +++ b/crates/app/src/player/actions.rs @@ -163,6 +163,7 @@ impl Player { // the key handler is what answers this one while there is. ActionId::CancelExport => {} ActionId::ShowActions => self.show_actions(cx), + ActionId::Settings => self.open_settings(cx), ActionId::Screenshot => self.take_screenshot(cx), // Cut machinery (DESIGN.md §6): the subject cut is the marked // clip ([`Selection::anchor`]) -- the oracle already refused diff --git a/crates/app/src/player/cards.rs b/crates/app/src/player/cards.rs index 0e82abd..7429808 100644 --- a/crates/app/src/player/cards.rs +++ b/crates/app/src/player/cards.rs @@ -853,6 +853,23 @@ impl Player { /// Nothing here is a clip's or even the project's -- it never reaches the /// export, which never burns a cue into the picture -- so like the mix /// card it opens with no timeline required and nothing to refuse. + /// Opens the settings page (PROJECT rows beside EDITOR rows, + /// `ui::settings_stance`): the one door for "edit project and editor + /// settings" -- refused while an export is running, same as every other + /// card here, since the exporting card owns this same modal slot + /// (`oracle.rs` agrees: `ActionId::Settings` is `No` there too, for the + /// same reason). + pub(crate) fn open_settings(&mut self, cx: &mut Context) { + if self.exporting().is_some() { + return; + } + // One card at a time -- `close_card`'s own rule. + self.close_card(); + self.settings_open = true; + self.context_menu = None; + cx.notify(); + } + pub(crate) fn open_subtitle_style(&mut self, cx: &mut Context) { // One card at a time -- `close_card`'s own rule. self.close_card(); @@ -1240,7 +1257,20 @@ impl Player { } pub(crate) fn modal(&self) -> bool { + self.card_open() || self.exporting().is_some() + } + + /// Whether an actual card owns the screen -- [`Player::modal`] minus the + /// exporting flag, which is a *state* an action can still be refused + /// over (spoken by the oracle) rather than a surface sitting on top of + /// the keyboard the way every card here does. The darkroom's key guard + /// ([`ui::stance`]'s `on_key_down`) reads this one instead of `modal()` + /// so a bare export in progress, with no card actually open, still lets + /// a keystroke reach `enable()`/`act()` and be answered -- Yes, or a + /// spoken `No` -- instead of being swallowed before either is asked. + pub(crate) fn card_open(&self) -> bool { self.keys_open + || self.settings_open || self.export_open || self.eq_open.is_some() || self.color_open.is_some() @@ -1249,7 +1279,6 @@ impl Player { || self.silence_open.is_some() || self.mix_open || self.subtitle_style_open - || self.exporting().is_some() } /// The pointer's way out of whatever card is up: what every scrim's press @@ -1262,6 +1291,7 @@ impl Player { /// "the" card and closing all of them are the same act. pub(crate) fn close_card(&mut self) { self.keys_open = false; + self.settings_open = false; self.keys_search.clear(); self.rebinding = None; self.export_open = false; diff --git a/crates/app/src/player/library.rs b/crates/app/src/player/library.rs index eca5388..b7ce130 100644 --- a/crates/app/src/player/library.rs +++ b/crates/app/src/player/library.rs @@ -9,6 +9,69 @@ const AUTOSAVE_DEBOUNCE: Duration = Duration::from_secs(5); /// periodic half of "debounced + periodic". const AUTOSAVE_PERIOD: Duration = Duration::from_secs(60); +/// Where the auto-proxies *default* survives, beside the keybindings and the +/// theme, same corner-cut persistence as [`crate::subs::subtitle_style_path`]: +/// a torn write costs this one preference and nothing else. +/// +/// This is the window's own answer, not the project's: a project that was +/// saved with the switch set already carries its own line +/// ([`engine::edith::Document::auto_proxy`]) and always wins once one is +/// open ([`Player::install_project`]) -- this file is only ever read before +/// that, which is what makes it the difference between "the switch reverts to +/// On on every relaunch" and "the switch stayed how it was left". +pub(crate) fn auto_proxies_pref_path() -> PathBuf { + crate::keymap::Keymap::config_path().with_file_name("auto-proxies") +} + +/// `On` unless the file says `off`; missing, unreadable or garbled all read as +/// `On`, the same default the field has always started at -- a preference +/// file is not the user's work, so a bad one is worth no message at startup. +pub(crate) fn load_auto_proxies_pref() -> bool { + match std::fs::read_to_string(auto_proxies_pref_path()) { + Ok(text) => text.trim() != "off", + Err(_) => true, + } +} + +/// Writes the pick whole, the way [`crate::ui::theme::save`] writes the +/// palette. +pub(crate) fn save_auto_proxies_pref(on: bool) -> std::io::Result<()> { + let path = auto_proxies_pref_path(); + if let Some(dir) = path.parent() { + std::fs::create_dir_all(dir)?; + } + std::fs::write(path, if on { "on\n" } else { "off\n" }) +} + +/// Where the Proxies *default* survives -- Proxies' own sibling of +/// [`auto_proxies_pref_path`], same corner-cut persistence. +/// +/// This is the window's own answer, not the project's: a project saved with +/// the switch set carries its own line and always wins once one is open +/// ([`Player::install_project`]) -- this file is only ever read before that. +pub(crate) fn proxies_pref_path() -> PathBuf { + crate::keymap::Keymap::config_path().with_file_name("proxies") +} + +/// `Off` unless the file says `on`; missing, unreadable or garbled all read as +/// `Off`, the same default the field has always started at -- a preference +/// file is not the user's work, so a bad one is worth no message at startup. +pub(crate) fn load_proxies_pref() -> bool { + match std::fs::read_to_string(proxies_pref_path()) { + Ok(text) => text.trim() == "on", + Err(_) => false, + } +} + +/// Writes the pick whole, the way [`save_auto_proxies_pref`] does. +pub(crate) fn save_proxies_pref(on: bool) -> std::io::Result<()> { + let path = proxies_pref_path(); + if let Some(dir) = path.parent() { + std::fs::create_dir_all(dir)?; + } + std::fs::write(path, if on { "on\n" } else { "off\n" }) +} + impl Player { /// The one way a library row reaches the timeline: the Add button and a row /// dragged onto a lane both come here, so there is a single answer to what @@ -738,6 +801,14 @@ impl Player { (true, n, m) => format!("PROXIES ON — cutting on {n}, {m} still being made"), }; eprintln!("{text}"); + // Kept for the next launch, not only the next project -- the same + // reason auto-proxies keeps one ([`save_auto_proxies_pref`]). + if let Err(e) = save_proxies_pref(on) { + let path = proxies_pref_path(); + self.notify_user( + format!("PROXIES DEFAULT COULD NOT BE KEPT — {} — {e}", path.display()).into(), + ); + } self.notify_user(text.into()); // The switch reseeks the session, and the wait for that picture is what // this clears -- with nothing open there is no open to wait for, and a @@ -770,6 +841,15 @@ impl Player { false => "AUTO PROXIES OFF — no import makes one; Proxies on is what asks for them", }; eprintln!("{text}"); + // Kept for the next launch, not only the next project -- a flip made + // with nothing open, or a project never saved after it, used to + // vanish the moment the window closed ([`load_auto_proxies_pref`]). + if let Err(e) = save_auto_proxies_pref(on) { + let path = auto_proxies_pref_path(); + self.notify_user( + format!("AUTO PROXIES DEFAULT COULD NOT BE KEPT — {} — {e}", path.display()).into(), + ); + } self.notify_user(text.into()); cx.notify(); } diff --git a/crates/app/src/tests/cards.rs b/crates/app/src/tests/cards.rs index 9a0632d..cd36b4c 100644 --- a/crates/app/src/tests/cards.rs +++ b/crates/app/src/tests/cards.rs @@ -25,7 +25,7 @@ fn no_overlaid_state_in_the_stance_goes_modal_without_painting_something() { ); } let guard_at = stance - .find("if this.rebinding.is_some() || this.overlaid() {") + .find("if this.rebinding.is_some()\n || this.card_open()") .expect("the stance's modal guard"); let guard = &stance[guard_at..guard_at + 1600]; for field in ["this.context_menu = None", "this.library_menu = None", "this.picker = None"] { @@ -43,8 +43,15 @@ fn every_modal_field_has_a_mounted_surface_somewhere_in_the_darkroom() { // rather than hand-copied -- a hand-copied list is exactly the shape // that let three cards go modal with nothing mounted (GAP 2): the field // was in `modal()` and nowhere in this test. - let modal_body = fn_body("modal"); - let mut fields = Vec::new(); + // `modal()` itself is now just `card_open() || exporting().is_some()` + // ([`Player::card_open`], split out so the darkroom's key guard can read + // "a card is open" without also reading "an export is running" -- see + // `ui::stance`'s guard and `an_export_alone_does_not_lock_the_stances_keyboard` + // below) -- so the card fields this test pins live in `card_open()` now, + // with `exporting` added by hand since `modal()`'s own body names it + // directly rather than through a field this splitter would find. + let modal_body = fn_body("card_open"); + let mut fields = vec!["exporting".to_string()]; for chunk in modal_body.split("self.").skip(1) { let name: String = chunk .chars() @@ -75,6 +82,7 @@ fn every_modal_field_has_a_mounted_surface_somewhere_in_the_darkroom() { "silence_open" => "silence_card(", "mix_open" => "mix_card(", "subtitle_style_open" => "subtitle_style_card(", + "settings_open" => "settings_stance::render(", other => panic!( "Player::modal() now reads `self.{other}` with no entry in this test's \ mount_for map -- add one naming the function that mounts its surface in \ @@ -95,6 +103,47 @@ fn every_modal_field_has_a_mounted_surface_somewhere_in_the_darkroom() { } } +/// D2's class: an action refused while a modal is up used to be sworn to +/// silence, because the stance's own key guard ate the keystroke before +/// `enable()`/`act()` ever saw it -- driven live with `ctrl+,` mid-export +/// (no card open, only `exporting()` true): no notice plate, ledger reading +/// `—`. `ActionId::Settings`'s own refusal string (`oracle.rs`) was sound and +/// simply never reachable. +/// +/// The fix lives in the guard, not in Settings alone (the charter this test +/// pins is explicit that a per-action patch would leave every *other* action +/// refused during a bare export equally mute): [`Player::card_open`] is +/// `modal()` with `exporting()` split out, and the stance's guard now reads +/// `card_open()` -- never `overlaid()`/`modal()` directly, both of which +/// still fold `exporting()` back in for the surfaces that are meant to keep +/// blocking imports and edits during an export ([`Player::modal`]'s own +/// doc comment). This is a source scan, the same kind the guard above it +/// already is: this binary has no `TestAppContext` to actually press `ctrl+,` +/// mid-export and read the notice plate back. +#[test] +fn the_stances_key_guard_does_not_swallow_a_bare_export_before_the_oracle_is_asked() { + let stance = src_text("ui/stance.rs"); + let guard_at = stance + .find("if this.rebinding.is_some()\n || this.card_open()") + .expect("the stance's modal guard moved -- update this test's search string"); + let guard_line = &stance[guard_at..guard_at + 200]; + assert!( + !guard_line.contains("overlaid()") && !guard_line.contains("this.modal()"), + "the stance's key guard reads overlaid()/modal() again, which folds `exporting()` \ + back in and re-mutes every refusal an export-only moment should be able to speak (D2)" + ); + // The split itself: card_open() must never grow an exporting read of its + // own, or the guard above -- which trusts card_open() to mean "an actual + // card/menu/rebind owns the keyboard" -- silently regains the same mute. + let card_open_body = fn_body("card_open"); + assert!( + !card_open_body.contains("exporting"), + "Player::card_open() now reads `exporting` -- that reintroduces the swallow \ + `the_stances_key_guard_does_not_swallow_a_bare_export_before_the_oracle_is_asked` \ + exists to keep out; `modal()` is where `exporting()` belongs" + ); +} + #[test] fn a_bare_escape_leaves_player_fullscreen_before_anything_under_it() { // Fires while the picture-only layout is up, on the same bare escape diff --git a/crates/app/src/tests/editing.rs b/crates/app/src/tests/editing.rs index b0c430b..e11801c 100644 --- a/crates/app/src/tests/editing.rs +++ b/crates/app/src/tests/editing.rs @@ -899,7 +899,11 @@ fn the_clip_menu_dims_what_the_playhead_is_not_on_and_stays_in_the_window() { // word to the user's own config file, which is why it is one of the // actions besides the cancel that stay live here. Fullscreen is the // same kind of thing: the platform's own window toggle, touching no - // edit list either. + // edit list either. Settings is NOT among them, on purpose: it opens + // the same modal slot the exporting card is already standing in + // (`Player::open_settings`), so a permission granted here would be + // one nobody could ever act on -- driven and confirmed: both the `,` + // chord and the spine glyph leave the exporting card on screen. let allowed = action == ActionId::CancelExport || action == ActionId::Theme || action == ActionId::Fullscreen diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index 4b2b2d8..aa90a93 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -2175,3 +2175,100 @@ fn every_darkroom_menu_sizes_its_list_against_the_floor_room_not_the_raw_viewpor assert!(sizings > 0, "{file} no longer opens any menu -- update this guard"); } } + +/// The settings page's own organising rule: PROJECT rows open only the +/// doors that write into the `.edith` file ([`Player::open_picker`], +/// [`Player::open_mix`]), and EDITOR rows open only the doors that do not +/// ([`Player::toggle_proxies`], [`Player::toggle_auto_proxies`], +/// [`Player::open_subtitle_style`]) -- never the config-file writers +/// (`ui::dock_stance::config_path`/`ui::theme::config_path`/ +/// `keymap::Keymap::config_path`) directly, which every editor-side row +/// already routes around through its own opener. A row wired to the wrong +/// section's opener is exactly the regression a page organised around two +/// headings invites; this pins each half to its own doors so the two lists +/// cannot cross. +#[test] +fn settings_project_and_editor_sections_open_disjoint_doors() { + let source = src_text("ui/settings_stance.rs"); + let project_start = source.find("fn project_section(").expect("the project section"); + let editor_start = source.find("fn editor_section(").expect("the editor section"); + let render_start = source.find("pub(crate) fn render(").expect("the page's render fn"); + assert!(project_start < editor_start && editor_start < render_start, "the three fns moved; this scan is blind"); + let project_body = &source[project_start..editor_start]; + let editor_body = &source[editor_start..render_start]; + + for door in ["open_picker(", "open_mix("] { + assert!(project_body.contains(door), "PROJECT section no longer opens {door} -- update this guard"); + assert!( + !editor_body.contains(door), + "EDITOR section opens {door}, a project-file door -- that value belongs in PROJECT, not here" + ); + } + for door in ["toggle_proxies(", "toggle_auto_proxies(", "open_subtitle_style("] { + assert!(editor_body.contains(door), "EDITOR section no longer opens {door} -- update this guard"); + assert!( + !project_body.contains(door), + "PROJECT section opens {door}, an editor-only door -- that value belongs in EDITOR, not here" + ); + } + // Neither section writes a config file straight from a row: both go + // through an opener, which is the one place a config-file write (the + // subtitle style card's Save, this window's next project load) is + // allowed to live. + for path_fn in ["dock_stance::config_path", "theme::config_path", "Keymap::config_path"] { + assert!(!project_body.contains(path_fn), "PROJECT section touches {path_fn} directly"); + assert!(!editor_body.contains(path_fn), "EDITOR section touches {path_fn} directly"); + } +} + +/// D1's own class, pinned per row rather than per section: a row's hint can +/// claim a `~/.config/edith` default (the section header claims nothing on +/// its own since [`settings_project_and_editor_sections_open_disjoint_doors`]'s +/// commit, so a lying section head no longer slips past a reviewer -- but a +/// lying *row* hint did, on Proxies, because nothing scanned row text at all). +/// For every row whose own hint text names that file, this requires the +/// matching `save_*_pref`/`load_*_pref` pair to actually exist in +/// `player/library.rs` -- the exact gap Proxies shipped with: a hint promising +/// a default the row's own door never wrote. +#[test] +fn settings_row_hints_naming_config_edith_have_a_matching_pref_pair() { + let source = src_text("ui/settings_stance.rs"); + let library = src_text("player/library.rs"); + // (row id, the stem its pref functions are named after) + for (row_id, stem) in [("settings-proxies", "proxies"), ("settings-auto-proxies", "auto_proxies")] { + let row_start = source.find(&format!("\"{row_id}\"")).unwrap_or_else(|| panic!("{row_id} row moved or renamed -- update this guard")); + let row_end = source[row_start..].find(",\n ))").map_or(source.len(), |i| row_start + i); + let row_text = &source[row_start..row_end]; + if !row_text.contains("~/.config/edith") { + continue; + } + for prefix in ["save_", "load_"] { + let fn_name = format!("{prefix}{stem}_pref"); + assert!( + library.contains(&format!("fn {fn_name}(")), + "{row_id}'s hint claims a ~/.config/edith default but \ + player/library.rs has no `{fn_name}` -- the hint promises \ + storage the row does not have" + ); + } + } +} + +/// With no project open, a PROJECT row must not fall back to a bare noun +/// ("Size"/"Rate"/"HDR") standing in the value slot -- it reads as a value +/// while carrying none. This binary has no `TestAppContext` to actually +/// render the page with `player.session` empty, so this is a source scan +/// for the fallback strings the bug shipped as, same as the guard above it. +#[test] +fn settings_project_rows_have_no_bare_noun_placeholder() { + let source = src_text("ui/settings_stance.rs"); + let project_start = source.find("fn project_section(").expect("the project section"); + let editor_start = source.find("fn editor_section(").expect("the editor section"); + let project_body = &source[project_start..editor_start]; + for placeholder in ["\"Size\".to_string()", "\"Rate\".to_string()", "\"HDR\".to_string()"] { + assert!( + !project_body.contains(placeholder), + "a PROJECT row fell back to the bare noun {placeholder} -- it reads as a value with no project open" + ); + } +} diff --git a/crates/app/src/tests/media.rs b/crates/app/src/tests/media.rs index 8680495..0f79725 100644 --- a/crates/app/src/tests/media.rs +++ b/crates/app/src/tests/media.rs @@ -5,6 +5,7 @@ use super::*; use crate::subs::{ load_subtitle_style, save_subtitle_style, sub_line_h_for, subtitle_style_path, SUB_SIZE_RANGE, }; +use crate::player::library::{auto_proxies_pref_path, load_auto_proxies_pref, save_auto_proxies_pref}; use crate::ui::preview::{bgra_to_rgba, screenshot_path}; /// The import line's own state machine, driven the way a repaint drives @@ -951,6 +952,46 @@ fn the_subtitle_style_file_round_trips_or_falls_back_to_defaults() { std::fs::remove_dir_all(&dir).ok(); } +/// The auto-proxies default, round-tripped through a scratch config +/// directory the same way the subtitle style is above -- the door D1 wired +/// it through, so this is what the settings page header can now honestly +/// call the same claim it makes about Proxies: a project's own line always +/// beats this one once one is open ([`engine::edith::Document::auto_proxy`]), +/// but with nothing open (or nothing saved since the flip) this is what a +/// relaunch reads instead of the field's hardcoded `true`. +#[test] +fn the_auto_proxies_default_round_trips_through_its_own_config_file_or_falls_back_to_on() { + let dir = std::env::temp_dir().join(format!( + "edith-auto-proxies-pref-test-{}-{}", + std::process::id(), + std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .unwrap() + .as_nanos() + )); + std::fs::create_dir_all(&dir).unwrap(); + // Scoped to this test alone, the same guarantee the subtitle-style test + // above makes for the same env var. + unsafe { std::env::set_var("XDG_CONFIG_HOME", &dir) }; + + // Nothing written yet: On, the field's own long-standing default. + assert!(load_auto_proxies_pref(), "a missing file must read as On"); + + save_auto_proxies_pref(false).unwrap(); + assert!(!load_auto_proxies_pref(), "off must round-trip"); + + save_auto_proxies_pref(true).unwrap(); + assert!(load_auto_proxies_pref(), "on must round-trip too, not just off"); + + // Garbled bytes -- a stray edit, or a future dialect -- read as On rather + // than failing a startup on someone else's edit of the file. + std::fs::write(auto_proxies_pref_path(), "not on or off\n").unwrap(); + assert!(load_auto_proxies_pref(), "unreadable content must fall back to On"); + + unsafe { std::env::remove_var("XDG_CONFIG_HOME") }; + std::fs::remove_dir_all(&dir).ok(); +} + /// The cue's line height scales with its size, on the same ratio the defaults /// draw at -- a bigger plate wants more room per line, not letters growing /// inside an unchanged one. diff --git a/crates/app/src/ui/mod.rs b/crates/app/src/ui/mod.rs index 3c824ca..4741449 100644 --- a/crates/app/src/ui/mod.rs +++ b/crates/app/src/ui/mod.rs @@ -10,6 +10,7 @@ pub mod inspector; pub mod library; pub mod overlays; pub mod preview; +pub mod settings_stance; pub mod spine_stance; pub mod stance; pub mod theme; diff --git a/crates/app/src/ui/settings_stance.rs b/crates/app/src/ui/settings_stance.rs new file mode 100644 index 0000000..98bf4a7 --- /dev/null +++ b/crates/app/src/ui/settings_stance.rs @@ -0,0 +1,302 @@ +//! The settings page (user complaint: "we should have a settings page that +//! we can edit project and editor settings"). Two clearly-headed sections, +//! per the split rule a rubric pass settled: +//! +//! - PROJECT: anything that changes the rendered output or is stored in the +//! `.edith` file -- resolution, fps, sample-rate, the HDR tonemap, the mix. +//! - EDITOR: anything about this machine, this person, this window -- +//! proxies/auto-proxies (this window's decode/import policy, mirrored into +//! the project like the resolution row above it once one is open -- +//! [`engine::PlaybackSession::set_proxies`] -- but with a window-level +//! default, `false`/`true`, that answers before any project is, exactly as +//! [`inspector.rs`]'s own legacy row already does) and the subtitle font +//! (a reading preference, kept in `~/.config/edith` like the theme beside +//! it, per [`crate::load_subtitle_style`], and never written into a +//! project at all). +//! +//! Every row here reuses an opener or a picker this editor already has +//! ([`Player::open_picker`], [`Player::open_mix`], [`Player::open_subtitle_style`], +//! [`Player::toggle_proxies`], [`Player::toggle_auto_proxies`]) -- no new card +//! body, no second source of truth for what a value is or how it is set. +//! Values apply live through those same doors; there is no Apply button here +//! to be inconsistent with the rest of the room. +//! +//! Seams left for other builders (this task's scope boundary): the HDR +//! mastering-display target row (a monitor fact, not in `inspector.rs`'s own +//! project section yet) has no row here either -- it plugs into +//! `project_section` below, beside the tonemap row it is the pair of. A +//! finer fps/sample-rate/tone picker is the same builder's to extend; this +//! page only ever asks for [`Pick::Fps`]/[`Pick::SampleRate`]/[`Pick::Tone`] +//! exactly as `inspector.rs`'s legacy panel already does. + +use crate::*; +use crate::ui::type_scale; + +/// A 9px uppercase Archivo section head, `ink3` -- [`dock_stance::section_head`]'s +/// exact shape, repeated rather than imported across a `pub(crate)` seam for +/// one nine-line function. +fn section_head(text: impl Into) -> impl IntoElement { + let style = type_scale::head(); + div() + .flex_none() + .pt(px(4.)) + .font(style.font) + .text_size(style.size) + .text_color(rgb(INK3())) + .child(text.into()) +} + +/// One row: a ≤16-char label, its current value in mono (units carried, +/// never a bare number -- the density rule this task's charter names), and +/// a hover hint carrying the sentence a label must not. [`dock_stance::ghost_verb`]'s +/// anatomy, with a live value where that row has a chord badge -- this room +/// is a picker's own door, not a keystroke's. +fn row( + id: &'static str, + label_text: &'static str, + value: impl Into, + hint: &'static str, + player: &Player, + on_click: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static, +) -> impl IntoElement { + row_ink(id, label_text, value, hint, player, on_click, INK1()) +} + +/// [`row`] with the value's ink chosen by the caller -- [`INK4`] for a value +/// that is not really a value yet (nothing to show until a project opens), +/// so it reads as absent rather than as a fifth real setting. +fn row_ink( + id: &'static str, + label_text: &'static str, + value: impl Into, + hint: &'static str, + player: &Player, + on_click: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static, + value_ink: u32, +) -> impl IntoElement { + let value: SharedString = value.into(); + let hint: SharedString = hint.into(); + let label_style = type_scale::label(type_scale::LABEL_ROW_PX, gpui::FontWeight::MEDIUM); + let value_style = type_scale::mono(type_scale::LABEL_ROW_PX, gpui::FontWeight::MEDIUM); + let exporting = player.exporting().is_some(); + div() + .id(id) + .flex_none() + .flex() + .items_center() + .justify_between() + .h(px(CONTROL_H)) + .px(px(8.)) + .rounded(px(3.)) + .tooltip(move |_, cx| cx.new(|_| Tip(hint.clone())).into()) + .when(exporting, |d| d.opacity(0.4).cursor_not_allowed()) + .when(!exporting, |d| { + d.cursor_pointer().hover(|s| s.bg(rgb(DARK_RAISED()))).on_click(on_click) + }) + .child( + div() + .font(label_style.font) + .text_size(label_style.size) + .text_color(rgb(INK2())) + .child(label_text), + ) + .child( + div() + .flex_none() + .font(value_style.font) + .text_size(value_style.size) + .text_color(rgb(value_ink)) + .child(value), + ) +} + +/// PROJECT: the canvas every clip is composed onto, the rate it is cut at, +/// the HDR rendition it is watched in, and the mix everything sums into -- +/// [`inspector.rs`]'s own four-plus-Mix list, ported rather than +/// reimplemented (same `Pick`/`open_mix` doors). +fn project_section(player: &Player, cx: &mut Context) -> impl IntoElement { + // corner-cut: no genuine default resolution or fps exists before either + // a project opens or a pick is made, so the empty state is a bare dash + // in INK4 -- quieter than a real value, never a noun that reads as one + // (the "Size"/"Rate"/"HDR" placeholders this row used to fall back to). + let resolution = player.session.as_ref().map(PlaybackSession::resolution); + let (res_val, res_ink) = match resolution.or(player.pending_settings.0) { + Some((_, h)) => (format!("{h}p"), INK1()), + None => ("—".to_string(), INK4()), + }; + let (fps_val, fps_ink) = match (player.session.is_some(), player.pending_settings.1) { + (true, _) => (format!("{} fps", fps_label(player.fps)), INK1()), + (false, Some(fps)) => (format!("{} fps", fps_label(fps)), INK1()), + (false, None) => ("—".to_string(), INK4()), + }; + // Sample rate keeps its "Source" fallback: unlike resolution/fps it + // states a real behaviour (derives from the first audio source) rather + // than standing in for a value with nothing behind it. + let rate_val = match player.session.as_ref().map_or(player.pending_settings.2, |s| s.sample_rate()) { + Some(rate) => format!("{rate} Hz"), + None => "Source".to_string(), + }; + let (tone_val, tone_ink) = match &player.session { + Some(session) => (format!("HDR {}", tone_label(session.tone())), INK1()), + None => ("—".to_string(), INK4()), + }; + div() + .flex_none() + .flex() + .flex_col() + .gap(px(2.)) + .child(section_head("PROJECT · stored in the .edith file")) + .child(row_ink( + "settings-resolution", + "Resolution", + res_val, + "the canvas every clip is composed onto, and the size the export comes out at", + player, + cx.listener(|this, event: &ClickEvent, _, cx| this.open_picker(Pick::Resolution, event.position(), cx)), + res_ink, + )) + .child(row_ink( + "settings-fps", + "Frame rate", + fps_val, + "the rate the whole timeline is cut and written at", + player, + cx.listener(|this, event: &ClickEvent, _, cx| this.open_picker(Pick::Fps, event.position(), cx)), + fps_ink, + )) + .child(row( + "settings-sample-rate", + "Sample rate", + rate_val, + "the rate the project's own sound mix is run at; source derives it from the first audio source", + player, + cx.listener(|this, event: &ClickEvent, _, cx| this.open_picker(Pick::SampleRate, event.position(), cx)), + )) + // hook: the mastering-display target (a monitor peak-nits fact, not + // yet in `inspector.rs`'s own project section) is this row's pair -- + // another builder's row, plugged in right here once it exists. + .child(row_ink( + "settings-tonemap", + "HDR tonemap", + tone_val, + "which rendition HDR media is watched in; SDR media is untouched", + player, + cx.listener(|this, event: &ClickEvent, _, cx| this.open_picker(Pick::Tone, event.position(), cx)), + tone_ink, + )) + .child(row( + "settings-mix", + "Mix", + "Tracks…", + "a fader per track and the limiter over the sum of them", + player, + cx.listener(|this, _: &ClickEvent, _, cx| this.open_mix(None, cx)), + )) +} + +/// EDITOR: this window's own decode/import policy and this person's own +/// reading preference. The subtitle font never touches the `.edith` file; +/// the proxy switches do mirror into it once a project is open (they are +/// project state too), but default from the window rather than a project +/// pick, which is what keeps them answerable with nothing open. +fn editor_section(player: &Player, cx: &mut Context) -> impl IntoElement { + div() + .flex_none() + .flex() + .flex_col() + .gap(px(2.)) + .child(section_head("EDITOR · this machine, this window")) + .child(row( + "settings-proxies", + "Proxies", + match player.proxies_on { + true => format!("On{}", player.proxy_tail()), + false => "Off".to_string(), + }, + "cuts on small stand-ins of the big films; the sound and every export stay the film's own -- default kept in ~/.config/edith, the pick for an open project in its own .edith", + player, + cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_proxies(cx)), + )) + .child(row( + "settings-auto-proxies", + "Auto proxies", + if player.auto_proxies_on { "On" } else { "Off" }, + "makes a stand-in for every big film as it is imported -- default kept in ~/.config/edith, the pick for an open project in its own .edith", + player, + cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_auto_proxies(cx)), + )) + .child(row( + "settings-subtitle-style", + "Subtitle font", + "Font…", + "the cue plate's own font and size -- kept in ~/.config/edith, never in a project", + player, + cx.listener(|this, _: &ClickEvent, _, cx| this.open_subtitle_style(cx)), + )) +} + +/// The page itself: a modal card, the same drag-scrim-and-click-away shape +/// every other card in this room takes ([`crate::ui::cards`]'s +/// eq/color/transform/speed cards) -- closed by a click away or `esc`, +/// through [`Player::close_card`], exactly like them. +pub(crate) fn render(player: &Player, cx: &mut Context) -> impl IntoElement { + drag_scrim(cx) + .flex() + .justify_center() + .items_center() + .bg(rgba(SCRIM())) + .on_mouse_down( + MouseButton::Left, + cx.listener(|this, _: &MouseDownEvent, _, cx| { + this.close_card(); + cx.notify(); + cx.stop_propagation(); + }), + ) + .child( + div() + .id("settings-card") + .w_full() + .max_w(px(360.)) + .max_h(relative(0.86)) + .on_mouse_down(MouseButton::Left, swallow) + .flex() + .flex_col() + .gap(px(8.)) + .p(px(12.)) + .rounded(px(6.)) + .bg(rgb(DARK_PANEL())) + .border_1() + .border_color(rgba(DARK_SEAM())) + .child({ + let head = type_scale::head(); + div() + .flex_none() + .flex() + .justify_between() + .items_baseline() + .font(head.font) + .text_size(head.size) + .text_color(rgb(INK3())) + .child("SETTINGS") + .child( + div() + .font(type_scale::mono(type_scale::CHORD_METADATA_MIN_PX, gpui::FontWeight::MEDIUM).font) + .text_size(px(type_scale::CHORD_METADATA_MIN_PX)) + .text_color(rgb(INK3())) + .child(player.keymap.display(ActionId::Settings)), + ) + }) + .child( + div() + .id("settings-rows") + .min_h(px(0.)) + .overflow_y_scroll() + .flex() + .flex_col() + .gap(px(10.)) + .child(project_section(player, cx)) + .child(editor_section(player, cx)), + ), + ) +} diff --git a/crates/app/src/ui/spine_stance.rs b/crates/app/src/ui/spine_stance.rs index bb2d96d..545ee62 100644 --- a/crates/app/src/ui/spine_stance.rs +++ b/crates/app/src/ui/spine_stance.rs @@ -312,5 +312,11 @@ pub(crate) fn render(player: &Player, cx: &mut Context) -> impl IntoElem glyph("spine-fullscreen", "FS", ActionId::Fullscreen, false, true, player, cx), )) .child(glyph("spine-screenshot", "Sh", ActionId::Screenshot, false, true, player, cx)) + // The settings page's own visible door (user complaint: "some + // options are only reachable via keyboard shortcut") -- a chord + // alone is a defect class this room has hit repeatedly, so this + // glyph sits beside the other once-a-session ROOM acts even though + // its chord (`^,`) is a preference, not a mnemonic. + .child(glyph("spine-settings", "St", ActionId::Settings, player.settings_open, true, player, cx)) .child(div().flex_1()) } diff --git a/crates/app/src/ui/stance.rs b/crates/app/src/ui/stance.rs index 0c6883a..8504b5a 100644 --- a/crates/app/src/ui/stance.rs +++ b/crates/app/src/ui/stance.rs @@ -11,6 +11,7 @@ use crate::*; use crate::ui::bench_stance; use crate::ui::dock_stance; +use crate::ui::settings_stance; use crate::ui::timeband_stance; use crate::ui::spine_stance; use crate::ui::type_scale::{self, Typeset}; @@ -754,14 +755,32 @@ pub(crate) fn render( return; } // Same modal guard the legacy handler's rebinding/keys_open/ - // export_open/exporting/colour/transform/speed/EQ/silence/mix/ + // export_open/colour/transform/speed/EQ/silence/mix/ // subtitle-style/menu chain (`render.rs`) amounts to, read as // one bool instead of re-copied field by field: while a card, a // rebind capture, or a menu owns the keyboard, the darkroom // stance yields to it exactly as the legacy tree does. This is // the fix for the stance's `Home`-inside-the-Colour-card // misfire. - if this.rebinding.is_some() || this.overlaid() { + // + // `exporting()` alone is deliberately left out of this list + // (`Player::card_open` is `modal()` minus it): a running export + // draws no card of its own to own the keyboard for, and a key + // caught here never reaches `enable()`/`act()` below, so a + // refusal the oracle would have spoken (`ActionId::Settings` + // among them) never got said -- the room went silent instead. + // Letting an export-only moment fall through costs nothing this + // guard exists for: every action the oracle would still refuse + // during an export says so through `act()`'s own `Enable::No` + // branch, and the six it leaves live (Theme, Fullscreen, + // SubtitleStyle, CancelExport, ...) are exactly the ones meant + // to keep working. + if this.rebinding.is_some() + || this.card_open() + || this.context_menu.is_some() + || this.library_menu.is_some() + || this.picker.is_some() + { // Escape is every card's own way out (`Player::close_card`, // the same list `overlaid`/`modal` read) -- blocking every // key while a card is open must not also lock the card open. @@ -843,6 +862,7 @@ pub(crate) fn render( el.child(notice_plate(n, bench_h)) }) .when(player.keys_open, |el| el.child(keys_overlay(player))) + .when(player.settings_open, |el| el.child(settings_stance::render(player, cx))) // The two menus (DESIGN §9: "verbs of the thing under the // cursor", plate styling, the same scrim-and-row component // the legacy tree already uses -- `library.rs`'s own doc diff --git a/crates/engine/src/playback.rs b/crates/engine/src/playback.rs index 269ff7e..cf55f8d 100644 --- a/crates/engine/src/playback.rs +++ b/crates/engine/src/playback.rs @@ -4514,3 +4514,4 @@ mod tests { assert_eq!(next.index, first.index, "paused: same timeline position before and after"); } } +