forge
Explore
Log in

Don't you dare go Hollow

+ S makes a subtitle track, and the file door keeps its own name

Browse files at this commit

6830c39b3fc6a9f72d661c34aa594e6466d4148dAhmet Kaan GümüşParent: 57fb0f3
  • feat
    • + S makes a subtitle track, and the file door keeps its own name
Show full message
✨ feat(app): + S makes a subtitle track, and the file door keeps its own name

"if I press button +S it should create subtitle track section": it opened a
file chooser instead, which is the one thing a track button never does. The
button and its "s" now add a `LaneKind::Subtitle` lane exactly as + V and + A
add theirs, ctrl+t takes the last one back, and the chooser survives as
`ImportSubtitles` (ctrl+i) behind the Text tab's own "Add subtitles from a
file…" -- the panel where the tracks it reads are listed.

Every notice follows the split: an import lands rows "in the palette", a lane
says "drag a subtitle from the panel onto it", and a remove with no subtitle
lane says so instead of "open a file first" over an open file.

The export card's Subtitles row was framed around palette picks: with an empty
pick list it dropped the engine's sentence whole, so a lane the export carries
nothing of said nothing at all. The sentence is kept whatever the picks are,
and a row the sentence already speaks for gets no clause of its own.
crates/app/src/keymap.rsmodified+30 -13
@@ -99,8 +99,13 @@ actions! {
9999 AddAudioLane,
100100 RemoveVideoLane,
101101 RemoveAudioLane,
102- AddSubtitleTrack,
103- RemoveSubtitleTrack,
102+ AddSubtitleLane,
103+ RemoveSubtitleLane,
104+ /// The palette's own door: a file's subtitle tracks read into the list the
105+ /// panel shows, which is where a lane's words are dragged *from*. Adding a
106+ /// track to that list places nothing -- the pair above it is what makes the
107+ /// timeline row a caption can land on.
108+ ImportSubtitles,
104109 ToggleMute,
105110 VolumeUp,
106111 VolumeDown,
@@ -172,8 +177,9 @@ impl ActionId {
172177 ActionId::AddAudioLane => "Add an audio track",
173178 ActionId::RemoveVideoLane => "Remove the last video track (it must be empty)",
174179 ActionId::RemoveAudioLane => "Remove the last audio track (it must be empty)",
175- ActionId::AddSubtitleTrack => "Add subtitles from a file…",
176- ActionId::RemoveSubtitleTrack => "Remove the picked subtitle track",
180+ ActionId::AddSubtitleLane => "Add a subtitle track",
181+ ActionId::RemoveSubtitleLane => "Remove the last subtitle track (it must be empty)",
182+ ActionId::ImportSubtitles => "Add subtitles from a file…",
177183 ActionId::ToggleMute => "Mute / Unmute",
178184 ActionId::VolumeUp => "Volume up",
179185 ActionId::VolumeDown => "Volume down",
@@ -228,8 +234,9 @@ impl ActionId {
228234 ActionId::AddAudioLane => "add-audio-lane",
229235 ActionId::RemoveVideoLane => "remove-video-lane",
230236 ActionId::RemoveAudioLane => "remove-audio-lane",
231- ActionId::AddSubtitleTrack => "add-subtitle-track",
232- ActionId::RemoveSubtitleTrack => "remove-subtitle-track",
237+ ActionId::AddSubtitleLane => "add-subtitle-lane",
238+ ActionId::RemoveSubtitleLane => "remove-subtitle-lane",
239+ ActionId::ImportSubtitles => "import-subtitles",
233240 ActionId::ToggleMute => "toggle-mute",
234241 ActionId::VolumeUp => "volume-up",
235242 ActionId::VolumeDown => "volume-down",
@@ -319,8 +326,12 @@ impl ActionId {
319326 // they add is on the timeline and goes into the file an export
320327 // writes, where the toggle two headings down only decides whether
321328 // this window draws it.
322- | ActionId::AddSubtitleTrack
323- | ActionId::RemoveSubtitleTrack
329+ | ActionId::AddSubtitleLane
330+ | ActionId::RemoveSubtitleLane
331+ // ...and the door that fills the palette those lanes are dragged
332+ // from: it edits no lane, but what it brings in is the project's
333+ // and is saved with it, which is not a view setting.
334+ | ActionId::ImportSubtitles
324335 | ActionId::RemoveAudioLane => Category::Editing,
325336 ActionId::ToggleMute
326337 | ActionId::VolumeUp
@@ -806,8 +817,12 @@ impl Keymap {
806817 // ctrl chord takes it back. Ctrl+s is that save, so the removal
807818 // takes the other letter subtitles already answer to here: "t"
808819 // shows and hides them, and ctrl+t takes one off the timeline.
809- b(ActionId::AddSubtitleTrack, "s", false),
810- b(ActionId::RemoveSubtitleTrack, "t", true),
820+ b(ActionId::AddSubtitleLane, "s", false),
821+ b(ActionId::RemoveSubtitleLane, "t", true),
822+ // Reading a file's tracks into the palette is not adding a
823+ // track to the timeline, so it is not the bare "s": ctrl+i, the
824+ // i of import, free and next to nothing that deletes.
825+ b(ActionId::ImportSubtitles, "i", true),
811826 b(ActionId::ToggleMute, "m", false),
812827 // The unshifted pair, which is what gpui reports for those two
813828 // keys ("=" and "-", platform.rs:862): the volume keys every
@@ -1123,7 +1138,7 @@ mod tests {
11231138 #[test]
11241139 fn every_default_stroke_reaches_its_action() {
11251140 let k = Keymap::defaults();
1126- assert_eq!(k.entries().len(), 51);
1141+ assert_eq!(k.entries().len(), 52);
11271142 assert_eq!(k.lookup("p", true), Some(ActionId::ToggleProxies));
11281143 assert_eq!(k.lookup("o", true), Some(ActionId::ToggleAutoProxies));
11291144 assert_eq!(k.lookup("f1", false), Some(ActionId::ShowActions));
@@ -1174,8 +1189,10 @@ mod tests {
11741189 assert_eq!(k.lookup("a", true), Some(ActionId::RemoveAudioLane));
11751190 // The subtitle pair, the third kind of track: the initial adds and the
11761191 // subtitle letter's chord takes it back.
1177- assert_eq!(k.lookup("s", false), Some(ActionId::AddSubtitleTrack));
1178- assert_eq!(k.lookup("t", true), Some(ActionId::RemoveSubtitleTrack));
1192+ assert_eq!(k.lookup("s", false), Some(ActionId::AddSubtitleLane));
1193+ assert_eq!(k.lookup("t", true), Some(ActionId::RemoveSubtitleLane));
1194+ // ...and the palette's own door, which adds no track to the timeline.
1195+ assert_eq!(k.lookup("i", true), Some(ActionId::ImportSubtitles));
11791196 assert_eq!(k.lookup("m", false), Some(ActionId::ToggleMute));
11801197 assert_eq!(k.lookup("q", false), Some(ActionId::Equalizer));
11811198 // The volume pair is the unshifted one, so neither needs a modifier
crates/app/src/oracle.rsmodified+5 -5
@@ -186,11 +186,11 @@ pub(crate) fn enable(action: ActionId, ctx: Ctx) -> Enable {
186186 // Nothing to draw over the picture, so nothing to switch off: the
187187 // library says how subtitles arrive, and this row would flip a state
188188 // with no visible half either way.
189- // ...and nothing to take off the timeline either, for the same reason:
190- // the row would name a track that is not there.
191- ActionId::ToggleSubtitles | ActionId::RemoveSubtitleTrack if !ctx.subtitles => {
192- Enable::No("no subtitles yet")
193- }
189+ //
190+ // The × on a palette row is refused by this very fact and asks this very
191+ // arm ([`Player::remove_subtitle_track`]): an empty list is a list with
192+ // no row to take off, said in the same words the toggle says it in.
193+ ActionId::ToggleSubtitles if !ctx.subtitles => Enable::No("no subtitles yet"),
194194 // Not `No`: with nothing running there is no export for this to be
195195 // about at all, which is what keeps `esc` -- the same key -- a quiet
196196 // way out of a card rather than a line about exports.
crates/app/src/player/actions.rsmodified+8 -5
@@ -73,11 +73,14 @@ impl Player {
7373 // through the × in its own header.
7474 ActionId::RemoveVideoLane => self.remove_last_lane(LaneKind::Video, cx),
7575 ActionId::RemoveAudioLane => self.remove_last_lane(LaneKind::Audio, cx),
76- // The same chooser the + S button opens, and the picked row -- the
77- // one the panel draws highlighted -- for the removal: the × on any
78- // other row is that row's own door, and both doors are one call.
79- ActionId::AddSubtitleTrack => self.pick_and_add_subtitles(cx),
80- ActionId::RemoveSubtitleTrack => self.remove_subtitle_track(self.sub_track, cx),
76+ // The third kind of track, added and taken back exactly as the two
77+ // above it: what a caption is dragged onto. The words themselves
78+ // arrive by the door below, which places nothing.
79+ ActionId::AddSubtitleLane => self.add_lane(LaneKind::Subtitle, cx),
80+ ActionId::RemoveSubtitleLane => self.remove_last_lane(LaneKind::Subtitle, cx),
81+ // The chooser the palette's own button opens: a file's tracks into
82+ // the list, the file itself joining nothing.
83+ ActionId::ImportSubtitles => self.pick_and_add_subtitles(cx),
8184 ActionId::ToggleMute => self.set_volume(|volume| volume.muted = !volume.muted, cx),
8285 ActionId::VolumeUp => self.set_volume(|volume| volume.step(true), cx),
8386 ActionId::VolumeDown => self.set_volume(|volume| volume.step(false), cx),
crates/app/src/player/library.rsmodified+42 -8
@@ -693,7 +693,7 @@ impl Player {
693693 // same question -- and *before* the chooser rather than after it: a door
694694 // that opens a dialog, waits for a file and only then says the timeline
695695 // was never there is the second door disagreeing with the first.
696- if let Some(why) = self.enable(ActionId::AddSubtitleTrack, None).why() {
696+ if let Some(why) = self.enable(ActionId::ImportSubtitles, None).why() {
697697 let text = format!("NO SUBTITLES ADDED — {why}");
698698 eprintln!("{text}");
699699 self.notify_user(text.into());
@@ -784,12 +784,17 @@ impl Player {
784784 ) {
785785 let text = match added {
786786 Some(Ok(0)) => format!(
787- "{}'s subtitles are on the timeline already",
787+ "{}'s subtitles are in the palette already",
788788 file_name(path)
789789 ),
790+ // Where they are and what to do with them: the tracks are in the
791+ // palette and nothing is placed until one is dragged onto an S
792+ // track, which is the whole of what this door does.
790793 Some(Ok(n)) => format!(
791- "SUBTITLES {} — {n} track(s), showing over the picture, {} hides them",
794+ "SUBTITLES {} — {n} track(s) in the palette — drag one onto an S track ({} adds \
795+ one), showing over the picture meanwhile, {} hides them",
792796 file_name(path),
797+ self.keymap.display(ActionId::AddSubtitleLane),
793798 self.keymap.display(ActionId::ToggleSubtitles)
794799 ),
795800 Some(Err(e)) => format!("SUBTITLE IMPORT FAILED: {e}"),
@@ -818,7 +823,10 @@ impl Player {
818823 // action with nothing to act on, and the engine's "there is no subtitle
819824 // track 0" is an index nobody typed. A real removal that fails still
820825 // says what the engine said, below.
821- if let Some(why) = self.enable(ActionId::RemoveSubtitleTrack, None).why() {
826+ // The palette's list is what this takes a row off, and an empty list is
827+ // the very fact the toggle is refused by -- so the same arm answers
828+ // both (oracle.rs) rather than a second reading of the same state.
829+ if let Some(why) = self.enable(ActionId::ToggleSubtitles, None).why() {
822830 let text = format!("NO SUBTITLES REMOVED — {why}");
823831 eprintln!("{text}");
824832 self.notify_user(text.into());
@@ -849,8 +857,9 @@ impl Player {
849857 // note, for its reason and with its upgrade path.
850858 self.sub_image = None;
851859 format!(
852- "{name} REMOVED — {} puts a file's subtitles back on, the file itself stays off",
853- self.keymap.display(ActionId::AddSubtitleTrack)
860+ "{name} REMOVED — {} puts a file's subtitles back in the palette, the file \
861+ itself stays off",
862+ self.keymap.display(ActionId::ImportSubtitles)
854863 )
855864 }
856865 Some(Err(e)) => format!("NO SUBTITLES REMOVED — {e}"),
@@ -956,8 +965,16 @@ impl Player {
956965 let lane = session.add_lane(kind);
957966 self.notify_user(
958967 format!(
959- "{} ADDED — drag a clip onto it, {} takes it back",
968+ "{} ADDED — drag {} onto it, {} takes it back",
960969 lane.label(),
970+ // A subtitle lane takes no clip at all: what lands on it
971+ // is a palette row, so the notice names the panel the
972+ // hand has to go to rather than "a clip", which is the
973+ // one thing that will never work here.
974+ match kind {
975+ LaneKind::Subtitle => "a subtitle from the panel",
976+ _ => "a clip",
977+ },
961978 self.keymap.display(ActionId::Undo)
962979 )
963980 .into(),
@@ -1079,8 +1096,25 @@ impl Player {
10791096 });
10801097 match last {
10811098 Some(lane) => self.remove_lane(lane, cx),
1099+ // Two different nothings: no timeline at all, and a timeline whose
1100+ // lanes of this kind have all gone -- which is the ordinary state of
1101+ // the subtitle ones, since a project starts with none. "Open a file
1102+ // first" over an open file is a notice that reads as a bug.
10821103 None => {
1083- self.notify_user("NO TRACK REMOVED — open a file first".into());
1104+ self.notify_user(
1105+ match self.session.is_some() {
1106+ true => format!(
1107+ "NO TRACK REMOVED — there is no {} track to remove",
1108+ match kind {
1109+ LaneKind::Video => "video",
1110+ LaneKind::Audio => "audio",
1111+ LaneKind::Subtitle => "subtitle",
1112+ }
1113+ ),
1114+ false => "NO TRACK REMOVED — open a file first".to_string(),
1115+ }
1116+ .into(),
1117+ );
10841118 cx.notify();
10851119 }
10861120 }
crates/app/src/subs.rsmodified+30 -8
@@ -323,17 +323,24 @@ pub(crate) fn subtitle_plan(
323323 picks: &[usize],
324324 ) -> String {
325325 let mut parts: Vec<String> = Vec::new();
326- // "none" is the engine's word for an empty pick list and would read as a
327- // verdict on the tracks named after it.
328- if !picks.is_empty() {
329- parts.push(plan);
326+ // "none" is the engine's word for having nothing to say and would read as a
327+ // verdict on the tracks named after it. Anything else is the sentence the
328+ // export is actually planned from -- the lanes' own, wherever the timeline
329+ // places words ([`engine::export::planned_subtitles`]) -- and it is kept
330+ // whatever the palette picks are: dropping it on an empty pick list is how a
331+ // card showing "S1 eng — past the last picture" said nothing at all.
332+ if plan != "none" {
333+ parts.push(plan.clone());
330334 }
331335 parts.extend(
332336 tracks
333337 .iter()
334338 .enumerate()
335- .filter(|(i, _)| !picks.contains(i))
336- .map(|(_, track)| format!("{} — no cues here", track.label)),
339+ .filter(|(i, track)| !picks.contains(i) && !spoken_for(&plan, track))
340+ // Not "no cues here": a row the export leaves out is a row nothing
341+ // on the timeline placed, and what puts that right is the drag --
342+ // the same sentence the import notice ends with.
343+ .map(|(_, track)| format!("{} — in the palette, on no track", track.label)),
337344 );
338345 let named = parts.join("; ");
339346 if named.chars().count() <= SUB_PLAN_CHARS {
@@ -347,7 +354,7 @@ pub(crate) fn subtitle_plan(
347354 match (
348355 track.refused.is_some(),
349356 track.is_bitmap(),
350- picks.contains(&i),
357+ picks.contains(&i) || spoken_for(&plan, track),
351358 ) {
352359 (true, _, _) => unread += 1,
353360 (_, true, _) => pictures += 1,
@@ -360,7 +367,7 @@ pub(crate) fn subtitle_plan(
360367 [
361368 (pictures, "pictures"),
362369 (unread, "unread"),
363- (off, "no cues here"),
370+ (off, "in the palette, on no track"),
364371 ]
365372 .into_iter()
366373 .filter(|(n, _)| *n > 0)
@@ -369,6 +376,21 @@ pub(crate) fn subtitle_plan(
369376 counted.join("; ")
370377 }
371378
379+/// Whether the engine's sentence already speaks for this row: with words placed
380+/// on lanes, every clause of it names the palette row its lane shows
381+/// ([`engine::export::planned_subtitles`]) -- and a line that embeds a track and
382+/// then says the same track is on no track is a line contradicting itself.
383+///
384+/// corner-cut: the match is the label found in the sentence, because the engine
385+/// hands back one string and not the rows it spoke for. Ceiling: two rows whose
386+/// labels are one a prefix of the other ("eng", "eng 2") -- with the longer one
387+/// placed, the shorter loses its clause; it never gains a wrong one. Upgrade
388+/// path: `planned_subtitles` handing its clauses back as data, the same upgrade
389+/// [`subtitle_plan`]'s own note names.
390+fn spoken_for(plan: &str, track: &engine::subtitle::SubtitleTrack) -> bool {
391+ !track.label.is_empty() && plan.contains(track.label.as_str())
392+}
393+
372394 /// Every subtitle track one file gave, kept together. Plain data, planned
373395 /// before anything is drawn -- the grouping is the branchy part and it is the
374396 /// same answer whatever a styling puts around it.
crates/app/src/tests/layout.rsmodified+21 -4
@@ -759,7 +759,7 @@ fn the_card_names_the_subtitle_it_leaves_off_and_counts_them_when_it_cannot() {
759759 // What the engine answers about the one pick that reached it, and what
760760 // this side knows about the row that did not.
761761 let named = subtitle_plan("[ASS] → embedded".to_string(), &two, &[0]);
762- assert_eq!(named, "[ASS] → embedded; [ASS] [FOR DUB] — no cues here");
762+ assert_eq!(named, "[ASS] → embedded; [ASS] [FOR DUB] — in the palette, on no track");
763763 assert!(
764764 named.chars().count() <= SUB_PLAN_CHARS,
765765 "two tracks fit the value box: {named}"
@@ -778,13 +778,30 @@ fn the_card_names_the_subtitle_it_leaves_off_and_counts_them_when_it_cannot() {
778778 // and the nine picture ones, which the engine drops itself.
779779 let picks: Vec<usize> = (0..31usize).collect();
780780 let counted = subtitle_plan("22 tracks → embedded (…)".to_string(), &many, &picks);
781- assert_eq!(counted, "22 of 35 → embedded; 9 pictures; 1 unread; 3 no cues here");
781+ assert_eq!(
782+ counted,
783+ "22 of 35 → embedded; 9 pictures; 1 unread; 3 in the palette, on no track"
784+ );
782785 assert!(
783786 counted.chars().count() <= SUB_PLAN_CHARS,
784787 "thirty-five tracks still fit the value box: {counted}"
785788 );
786789 // Nothing on the timeline at all is still the engine's word for it.
787790 assert_eq!(subtitle_plan("none".to_string(), &[], &[]), "none");
791+ // The lanes are what an export writes once anything is placed on one, and
792+ // the engine words that whole ([`engine::export::planned_subtitles`]) --
793+ // including the lanes it carries *nothing* of, which is a sentence with no
794+ // pick behind it at all. That used to be dropped on the floor: the card said
795+ // "[ASS] — no cues here" twice and never said what became of the lane.
796+ let placed = "S1 [ASS] — past the last picture".to_string();
797+ assert_eq!(
798+ subtitle_plan(placed.clone(), &two, &[]),
799+ "S1 [ASS] — past the last picture; [ASS] [FOR DUB] — in the palette, on no track"
800+ );
801+ // ...and the row that sentence speaks for gets no clause of its own: a line
802+ // that names a lane's track and then calls the same track unplaced is the
803+ // card contradicting itself in one breath.
804+ assert!(!subtitle_plan(placed, &two[..1], &[]).contains("in the palette"));
788805 }
789806
790807 /// The list is in the order tracks were added, which is not the order a
@@ -884,9 +901,9 @@ fn the_text_tab_carries_the_add_subtitles_door() {
884901 let at = library
885902 .find("\"add-subtitles\"")
886903 .expect("no add-subtitles control in the library column");
887- let block = &library[at..(at + 1400).min(library.len())];
904+ let block = &library[at..(at + 1600).min(library.len())];
888905 assert!(
889- block.contains("ActionId::AddSubtitleTrack"),
906+ block.contains("ActionId::ImportSubtitles"),
890907 "the button is a door of its own rather than the action: {block}"
891908 );
892909 assert!(
crates/app/src/ui/library.rsmodified+3 -3
@@ -319,9 +319,9 @@ impl Player {
319319 true => "Add subtitles from a file…",
320320 false => "Add subtitles",
321321 },
322- "reads a file's subtitle tracks onto this timeline — the file itself \
323- joins nothing",
324- ActionId::AddSubtitleTrack,
322+ "reads a file's subtitle tracks into the palette below — drag one onto an S \
323+ track to place it; the file itself joins nothing",
324+ ActionId::ImportSubtitles,
325325 cx.listener(|this, _: &ClickEvent, _, cx| this.pick_and_add_subtitles(cx)),
326326 )))
327327 })
crates/app/src/ui/timeline.rsmodified+3 -2
@@ -322,7 +322,7 @@ impl Player {
322322 let groups = subtitle_rows(tracks);
323323 // What the row's × says the way back is, in the stroke this keymap
324324 // actually binds: a file's subtitles go on without the file.
325- let add_key = self.keymap.display(ActionId::AddSubtitleTrack);
325+ let add_key = self.keymap.display(ActionId::ImportSubtitles);
326326 // One file's tracks need no prefix saying which file: it is the only
327327 // one, and every row would carry the same word.
328328 let several_files = groups.len() > 1;
@@ -376,7 +376,8 @@ impl Player {
376376 // the tooltip is what says which track it takes off.
377377 let remove_tip: SharedString =
378378 format!(
379- "Remove {title} — {} puts a file's subtitles back on",
379+ "Remove {title} from the palette — {} puts a file's subtitles \
380+ back in it",
380381 add_key
381382 )
382383 .into();
crates/app/src/ui/toolbar.rsmodified+4 -4
@@ -307,15 +307,15 @@ impl Player {
307307 }),
308308 ))
309309 .child(self.action_control(
310- "add-subtitle-track",
310+ "add-subtitle-lane",
311311 0.,
312312 BG_RAISED(),
313313 None,
314314 "+ S",
315- "adds every subtitle track in a file you pick",
316- ActionId::AddSubtitleTrack,
315+ "adds a subtitle track under the ones there",
316+ ActionId::AddSubtitleLane,
317317 cx.listener(|this, _: &ClickEvent, _, cx| {
318- this.pick_and_add_subtitles(cx)
318+ this.add_lane(LaneKind::Subtitle, cx)
319319 }),
320320 ))
321321 .child(separator())