forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'worktree-agent-a62f844d48ad5e2ef' into worktree-agent-a81b5077f25858904

Browse files at this commit

d5d7fdfe06a2e6f6336bd4e78c379901053fecf0Ahmet Kaan GümüşParent: a7dd4c5a29af89
crates/app/src/main.rsmodified+126 -17
@@ -1509,9 +1509,12 @@ impl Player {
15091509 /// playhead happens to sit between two cues would read as broken.
15101510 fn toggle_subtitles(&mut self, cx: &mut Context<Self>) {
15111511 self.subs_on = !self.subs_on;
1512+ // Named with its film here too: a notice saying "SUBTITLES ON — eng"
1513+ // over a timeline holding two films' eng tracks names neither.
15121514 let label = self
1513- .subtitle_track()
1514- .map(|track| track.label.clone())
1515+ .session
1516+ .as_ref()
1517+ .and_then(|session| sub_pick_name(session.subtitles(), self.sub_track))
15151518 .unwrap_or_else(|| "nothing imported".to_string());
15161519 self.notice = Some(
15171520 match self.subs_on {
@@ -5313,12 +5316,16 @@ impl Player {
53135316 .truncate()
53145317 .text_size(px(11.))
53155318 .text_color(rgb(INK_DIM))
5316- .child(match self.subs_on {
5317- true => "Subtitles",
5319+ .child(match (self.subs_on, sub_pick_name(tracks, self.sub_track)) {
5320+ // Which of them is on screen, named by its film:
5321+ // the heading over a list of five is where the one
5322+ // being shown is worth saying out loud.
5323+ (true, Some(pick)) => format!("Subtitles — {pick}"),
5324+ (true, None) => "Subtitles".to_string(),
53185325 // The toggle's state where the tracks are listed: a
53195326 // list of subtitles nothing on screen is showing has
53205327 // to say that it is showing none.
5321- false => "Subtitles — hidden",
5328+ (false, _) => "Subtitles — hidden".to_string(),
53225329 }),
53235330 )
53245331 .child(
@@ -8481,17 +8488,31 @@ impl Player {
84818488 fn subtitle_strip(&self, filled: f32) -> Option<impl IntoElement + use<>> {
84828489 let track = self.subtitle_track()?;
84838490 let scale = self.scale;
8484- let label = track.label.clone();
8491+ // The pick with its film on it, not the raw tag: two films' "eng"
8492+ // tracks read alike otherwise, and a header saying "und" names a
8493+ // language nobody speaks.
8494+ let label = sub_pick_name(self.session.as_ref()?.subtitles(), self.sub_track)?;
8495+ // The colour the file's own rows and clips wear, so the strip says
8496+ // whose subtitles these are before the tooltip is asked. `None` for a
8497+ // standalone `.srt` -- nobody's stream, and the first film's colour
8498+ // would be a lie about where it came from.
8499+ let tint = file_tint(self.sources(), &track.path).unwrap_or(SURFACE);
84858500 // The whole of what the row says in words, since a 40 px column can hold
8486- // three characters of it: which track, how many cues, and -- for one
8487- // that could not be read -- the engine's own reason, where the library
8488- // row's grey already says the same thing.
8501+ // three characters of it: which track of which file, how many cues, the
8502+ // file itself in full -- one stem is two films when they are two cuts of
8503+ // it -- and, for a track that could not be read, the engine's own reason,
8504+ // where the library row's grey already says the same thing.
84898505 let tip: SharedString = match track.refused.is_some() {
8490- true => format!("Subtitles: {label} — {}", subtitle_detail(track)),
8506+ true => format!(
8507+ "Subtitles: {label} — {} — {}",
8508+ subtitle_detail(track),
8509+ track.path.display()
8510+ ),
84918511 false => format!(
8492- "Subtitles: {label} — {}, {} hides them",
8512+ "Subtitles: {label} — {}, {} hides them — {}",
84938513 subtitle_detail(track),
8494- self.keymap.display(ActionId::ToggleSubtitles)
8514+ self.keymap.display(ActionId::ToggleSubtitles),
8515+ track.path.display()
84958516 ),
84968517 }
84978518 .into();
@@ -8528,7 +8549,7 @@ impl Player {
85288549 // a centred truncation eats both of its ends.
85298550 .px(px(2.))
85308551 .rounded(px(3.))
8531- .bg(rgb(SURFACE))
8552+ .bg(rgb(tint))
85328553 .text_size(px(9.))
85338554 .text_color(rgb(INK_DIM))
85348555 .truncate()
@@ -9352,9 +9373,10 @@ fn subtitle_detail(track: &engine::subtitle::SubtitleTrack) -> String {
93529373 /// before anything is drawn -- the grouping is the branchy part and it is the
93539374 /// same answer whatever a styling puts around it.
93549375 ///
9355-/// ponytail: nothing draws these yet -- [`Player::subtitle_section`] still
9356-/// lists the flat rows. Ceiling: the model is proven by its tests and by
9357-/// nothing on screen. The upgrade is that section rendering groups instead.
9376+/// ponytail: only [`sub_pick_name`] reads these -- [`Player::subtitle_section`]
9377+/// still *lists* the flat rows, so the grouping shows in what the headers say
9378+/// and not yet in how the list is laid out. The upgrade is that section
9379+/// rendering groups instead.
93589380 #[derive(Debug, PartialEq)]
93599381 #[allow(dead_code)]
93609382 struct SubGroup {
@@ -9428,6 +9450,38 @@ fn subtitle_rows(tracks: &[engine::subtitle::SubtitleTrack]) -> Vec<SubGroup> {
94289450 groups
94299451 }
94309452
9453+/// How the picked track is named wherever the pick is echoed -- the strip
9454+/// header, the section heading, the toggle's own notice. What the track is
9455+/// *and* which file it came out of: two remuxes each carrying an "eng" track
9456+/// give the same word twice, and the file is the only thing that tells them
9457+/// apart. A file that gave several of them numbers them within itself, the way
9458+/// [`row_name`] numbers audio streams, since "eng" twice off one remux is the
9459+/// same problem one file down.
9460+///
9461+/// Goes through [`subtitle_rows`], so the name a header says and the row a
9462+/// person clicked cannot disagree -- and the label is humanised there, so an
9463+/// "und" track is named in words here without being passed through
9464+/// [`lang_human`] twice.
9465+///
9466+/// `None` for an index no track answers to, which is the silence
9467+/// [`Player::subtitle_track`] gives at the same moment.
9468+fn sub_pick_name(tracks: &[engine::subtitle::SubtitleTrack], track: usize) -> Option<String> {
9469+ subtitle_rows(tracks).into_iter().find_map(|group| {
9470+ let row = group.rows.iter().find(|row| row.track == track)?;
9471+ let track = match group.rows.len() > 1 {
9472+ false => row.label.clone(),
9473+ true => format!("{} {}", row.label, row.number),
9474+ };
9475+ // A standalone `.srt` is already named after its own file: "sub.srt —
9476+ // sub" says the one thing twice, and the film is only worth naming
9477+ // where it is not in the label yet.
9478+ Some(match row.label.starts_with(&group.name) {
9479+ true => track,
9480+ false => format!("{track} — {}", group.name),
9481+ })
9482+ })
9483+}
9484+
94319485 /// Where a cue is drawn on the bed: left edge and width in pixels, through the
94329486 /// same [`Scale`] every clip box goes through -- so a cue and the take it is
94339487 /// spoken over line up at every zoom, which is the only reason the strip is
@@ -10008,6 +10062,16 @@ fn file_tint(sources: &[Source], path: &Path) -> Option<u32> {
1000810062 sources
1000910063 .iter()
1001010064 .position(|s| s.path == path)
10065+ .or_else(|| {
10066+ // A source entry is stored symlink-resolved (`Source::new`) and a
10067+ // path from anywhere else -- a subtitle track, a file being
10068+ // dragged -- is stored as it was spelled. `edith assets/film.mkv`
10069+ // is one file under two spellings, and matching by spelling alone
10070+ // said the film had no colour. Only asked when the spellings
10071+ // differ, so the common paint costs no syscall.
10072+ let path = std::fs::canonicalize(path).ok()?;
10073+ sources.iter().position(|s| s.path == path)
10074+ })
1001110075 .map(source_tint)
1001210076 }
1001310077
@@ -12025,7 +12089,7 @@ mod tests {
1202512089 use super::{
1202612090 SUB_BOTTOM, SUB_CUE_MIN_W, SUB_INK, SUB_LANE_H, SUB_LINE_H, SUB_ROWS_H, SUB_TEXT, cue_box,
1202712091 cues_at, file_tint, is_matroska, is_subtitle, lang_human, subtitle_detail, subtitle_notice,
12028- subtitle_rows, subtitle_strip_h,
12092+ sub_pick_name, subtitle_rows, subtitle_strip_h,
1202912093 };
1203012094
1203112095 /// What the file manager is handed: the parts a path keeps as they are, and
@@ -16091,6 +16155,18 @@ mod tests {
1609116155 );
1609216156 assert_eq!(file_tint(&sources, Path::new("/subs/a.eng.srt")), None);
1609316157 assert_eq!(file_tint(&[], Path::new("/films/a.mkv")), None);
16158+ // The same file under two spellings is one file and one colour: a
16159+ // source is stored symlink-resolved, everything else as it was typed.
16160+ let here = std::fs::canonicalize(".").expect("the crate directory");
16161+ let sources = [Source {
16162+ path: here.join("Cargo.toml"),
16163+ audio_stream: 0,
16164+ }];
16165+ assert_eq!(
16166+ file_tint(&sources, Path::new("Cargo.toml")),
16167+ Some(source_tint(0)),
16168+ "a relative spelling of the source file wears the source's colour"
16169+ );
1609416170 }
1609516171
1609616172 fn sub(path: &str, track: Option<u64>, label: &str) -> engine::subtitle::SubtitleTrack {
@@ -16154,6 +16230,39 @@ mod tests {
1615416230 assert_eq!(file_tint(&sources, &groups[2].path), None);
1615516231 }
1615616232
16233+ /// What the strip header, the section heading and the toggle's notice all
16234+ /// say. Two films each carrying an "eng" track are one word apart until the
16235+ /// film is in the name; a film carrying two is one word apart from itself.
16236+ #[test]
16237+ fn the_picked_subtitle_is_named_with_the_film_it_came_out_of() {
16238+ let tracks = [
16239+ sub("/films/a.mkv", Some(1), "eng"),
16240+ sub("/films/b.mkv", Some(1), "eng"),
16241+ sub("/films/a.mkv", Some(2), "eng"),
16242+ sub("/films/b.mkv", Some(2), "und"),
16243+ sub("/subs/late.srt", None, "late.srt"),
16244+ ];
16245+ let name = |track| sub_pick_name(&tracks, track).expect("a track that is there");
16246+ // The two "eng"s of two films: one file gave several so its tracks are
16247+ // numbered, the other gave one so it is not.
16248+ assert_eq!(name(0), "eng 1 — a");
16249+ assert_eq!(name(2), "eng 2 — a");
16250+ assert_eq!(name(1), "eng 1 — b");
16251+ assert_ne!(name(0), name(1), "two films' eng tracks read apart");
16252+ for picked in [name(0), name(1), name(2)] {
16253+ assert!(picked.contains(" — a") || picked.contains(" — b"));
16254+ }
16255+ // "und" is the tag for "nobody said", humanised once by
16256+ // `subtitle_rows` and not again here.
16257+ assert_eq!(name(3), "unknown language 2 — b");
16258+ // A standalone `.srt` is its own file and its label already says so:
16259+ // one track, so no number, and no stem after it saying it again.
16260+ assert_eq!(name(4), "late.srt");
16261+ // The silence `subtitle_track` gives at the same moment.
16262+ assert_eq!(sub_pick_name(&tracks, 5), None);
16263+ assert_eq!(sub_pick_name(&[], 0), None);
16264+ }
16265+
1615716266 /// The one thing regrouping must not break: `sub_track` is a flat index
1615816267 /// into the add-order list, a click sets it and a save writes it into the
1615916268 /// `.edith`. Every row must still name the track it was made from -- rows