forge
Explore
Log in

Don't you dare go Hollow

The export that locks the editor says so as a card, and takes two answers to stop

Browse files at this commit

ef7689fc425edd48d9e86ef60519bd0e7be052baAhmet Kaan GümüşParent: 563161a
  • feat
    • the export that locks the editor says so as a card, and takes two answers to stop
Show full message
✨ feat(app): the export that locks the editor says so as a card, and takes two answers to stop

An export takes the whole editor -- nothing may touch the edit list while the
worker reads it -- and until now it said that in a hint line under a panel it
had just switched off. The running export is drawn as what it is: the same
scrim, width and raised box the export card itself uses, so the answer arrives
where the question was put, with the bar, the percentage and both clocks, the
row and the seats the worker really opened, the source it reads and the file it
writes. The timeline is still read around it, and the ruler keeps the fill --
the one part of the progress the card does not cover.

Getting out of it now takes intent, twice over. The chord is ctrl+esc: bare
escape is the stroke a hand throws at anything on screen, and thrown at an
export it used to delete an hour of encoding. Bare escape now does nothing at
all here -- the card is not dismissable, so there is nothing left for it to
mean. And the pointer's way out is a pair, never a cycle: "Cancel export" swaps
the row for "Keep exporting" beside it, both on screen at once, each saying
which one it is.

Rebinding still works and still adds a way out rather than replacing this one,
and the card shows whatever the keymap has.
crates/app/src/export_ui.rsmodified+9 -8
@@ -821,14 +821,15 @@ pub(crate) fn commit_mbps(text: &str) -> Result<u32, String> {
821 }821 }
822 }822 }
823 823
824-/// Whether a stroke gets out of a running export. Escape does, whatever824+/// Whether a stroke gets out of a running export. `ctrl+escape` does -- a chord
825-/// modifiers are held with it, for the same reason it gets out of a capture and825+/// and not the bare key, which used to end an hour of encoding on the stroke a
826-/// out of the overlay: it is this window's way out, and a way out that only826+/// hand reaches for to shut a menu it has already shut. Bare escape does nothing
827-/// works with the right modifiers is not one. Whatever the keymap has on cancel827+/// at all here: the progress card is not dismissable, so there is nothing left
828-/// works too, so rebinding it adds a way rather than replacing the one that828+/// for it to mean. Whatever the keymap has on cancel works too, so rebinding it
829-/// always worked -- and that binding is still what the progress line shows.829+/// adds a way rather than replacing this one -- and that binding is what the
830-pub(crate) fn cancels_export(key: &str, action: Option<ActionId>) -> bool {830+/// card shows.
831- key == ESCAPE || action == Some(ActionId::CancelExport)831+pub(crate) fn cancels_export(key: &str, ctrl: bool, action: Option<ActionId>) -> bool {
832+ (ctrl && key == ESCAPE) || action == Some(ActionId::CancelExport)
832 }833 }
833 834
834 /// A clip's share of the lane. A timeline with no length reads as one full-width835 /// A clip's share of the lane. A timeline with no length reads as one full-width
crates/app/src/keymap.rsmodified+11 -4
@@ -869,7 +869,12 @@ impl Keymap {
869 // it is a preference set once, not a stroke wanted under a hand869 // it is a preference set once, not a stroke wanted under a hand
870 // that is editing.870 // that is editing.
871 b(ActionId::Theme, "h", true),871 b(ActionId::Theme, "h", true),
872- b(ActionId::CancelExport, "escape", false),872+ // A chord, and the only escape in this table: bare `esc` is the
873+ // stroke a hand throws at anything on screen, and throwing it
874+ // at a running export used to delete an hour of encoding. The
875+ // key stays the one people look for -- the modifier is what
876+ // makes it an intention ([`crate::cancels_export`]).
877+ b(ActionId::CancelExport, "escape", true),
873 // The help key, where every program's list of what it can do878 // The help key, where every program's list of what it can do
874 // has always been. Free -- gpui names it "f1"879 // has always been. Free -- gpui names it "f1"
875 // (platform.rs:880, the keysym's own name lowercased) -- and880 // (platform.rs:880, the keysym's own name lowercased) -- and
@@ -1200,7 +1205,9 @@ mod tests {
1200 assert_eq!(k.lookup("=", false), Some(ActionId::VolumeUp));1205 assert_eq!(k.lookup("=", false), Some(ActionId::VolumeUp));
1201 assert_eq!(k.lookup("-", false), Some(ActionId::VolumeDown));1206 assert_eq!(k.lookup("-", false), Some(ActionId::VolumeDown));
1202 assert_eq!(k.lookup("+", false), None);1207 assert_eq!(k.lookup("+", false), None);
1203- assert_eq!(k.lookup("escape", false), Some(ActionId::CancelExport));1208+ // The chord, and *only* the chord: bare escape reaches no action at all.
1209+ assert_eq!(k.lookup("escape", true), Some(ActionId::CancelExport));
1210+ assert_eq!(k.lookup("escape", false), None);
1204 // The modifier is half the chord: ctrl+e is not e.1211 // The modifier is half the chord: ctrl+e is not e.
1205 assert_eq!(k.lookup("e", true), None);1212 assert_eq!(k.lookup("e", true), None);
1206 assert_eq!(k.lookup("space", true), None);1213 assert_eq!(k.lookup("space", true), None);
@@ -1222,7 +1229,7 @@ mod tests {
1222 let text = emit(&Keymap::defaults());1229 let text = emit(&Keymap::defaults());
1223 assert!(text.starts_with("edith-keys 1\nplay space\n"));1230 assert!(text.starts_with("edith-keys 1\nplay space\n"));
1224 assert!(text.contains("save ctrl+s\n"));1231 assert!(text.contains("save ctrl+s\n"));
1225- assert!(text.contains("cancel-export escape\n"));1232+ assert!(text.contains("cancel-export ctrl+escape\n"));
1226 // Both directions: the file this writes is the file it reads back, and1233 // Both directions: the file this writes is the file it reads back, and
1227 // a file read in comes out byte for byte as it went.1234 // a file read in comes out byte for byte as it went.
1228 assert_eq!(whole(&text), Keymap::defaults());1235 assert_eq!(whole(&text), Keymap::defaults());
@@ -1389,7 +1396,7 @@ mod tests {
1389 assert_eq!(k.display(ActionId::Delete), "x or delete");1396 assert_eq!(k.display(ActionId::Delete), "x or delete");
1390 assert_eq!(k.display(ActionId::Undo), "z or ctrl+z");1397 assert_eq!(k.display(ActionId::Undo), "z or ctrl+z");
1391 // The one key whose common name is not gpui's.1398 // The one key whose common name is not gpui's.
1392- assert_eq!(k.display(ActionId::CancelExport), "esc");1399+ assert_eq!(k.display(ActionId::CancelExport), "ctrl+esc");
1393 assert_eq!(whole("edith-keys 1\n").display(ActionId::Cut), "unbound");1400 assert_eq!(whole("edith-keys 1\n").display(ActionId::Cut), "unbound");
1394 // The label is the editor's column, and never the file's word for it.1401 // The label is the editor's column, and never the file's word for it.
1395 assert_eq!(ActionId::CancelExport.label(), "Cancel export");1402 assert_eq!(ActionId::CancelExport.label(), "Cancel export");
crates/app/src/main.rsmodified+6 -0
@@ -286,6 +286,11 @@ struct Player {
286 /// handle is held until the worker settles, because its last act is to286 /// handle is held until the worker settles, because its last act is to
287 /// delete the output file and a second export must not be what it deletes.287 /// delete the output file and a second export must not be what it deletes.
288 cancelling: bool,288 cancelling: bool,
289+ /// The pointer asked to cancel and the progress card is showing the pair
290+ /// that answers it ("Keep exporting" / "Cancel export"). One press is never
291+ /// the cancel itself: an hour of encoding must not end on a stray click,
292+ /// which is the reason the stroke is a chord too ([`cancels_export`]).
293+ cancel_armed: bool,
289 /// When the running export started, and how far it had come at each sample294 /// When the running export started, and how far it had come at each sample
290 /// since, as `(elapsed, progress)` marks. The elapsed clock and the295 /// since, as `(elapsed, progress)` marks. The elapsed clock and the
291 /// rolling-window estimate the progress line reads; see [`note_progress`].296 /// rolling-window estimate the progress line reads; see [`note_progress`].
@@ -658,6 +663,7 @@ fn main() {
658 last_target: 0,663 last_target: 0,
659 export: None,664 export: None,
660 cancelling: false,665 cancelling: false,
666+ cancel_armed: false,
661 export_started: None,667 export_started: None,
662 export_marks: Vec::new(),668 export_marks: Vec::new(),
663 // Both derived from the file when it lands, by the same669 // Both derived from the file when it lands, by the same
crates/app/src/player/export.rsmodified+7 -2
@@ -603,8 +603,12 @@ impl Player {
603 // happens to notice it.603 // happens to notice it.
604 self.export_started = Some(Instant::now());604 self.export_started = Some(Instant::now());
605 self.export_marks.clear();605 self.export_marks.clear();
606- // The card has been answered; the progress line takes the panel from606+ // A confirm left armed by the *previous* export would open this one on
607- // here, and it is the running export's escape that matters now.607+ // the pair, offering to cancel a job nobody has asked about yet.
608+ self.cancel_armed = false;
609+ // The card has been answered; the progress card takes the window from
610+ // here ([`Player::export_progress_card`]), and it is the running
611+ // export's chord that matters now.
608 self.export_open = false;612 self.export_open = false;
609 cx.notify();613 cx.notify();
610 }614 }
@@ -615,6 +619,7 @@ impl Player {
615 if let Some(export) = &self.export {619 if let Some(export) = &self.export {
616 export.cancel();620 export.cancel();
617 self.cancelling = true;621 self.cancelling = true;
622+ self.cancel_armed = false;
618 }623 }
619 }624 }
620 625
crates/app/src/render.rsmodified+5 -1
@@ -141,7 +141,7 @@ impl Render for Player {
141 // would change, so cancelling is the only one that means141 // would change, so cancelling is the only one that means
142 // anything until it is over.142 // anything until it is over.
143 if this.exporting().is_some() {143 if this.exporting().is_some() {
144- if cancels_export(key, action) {144+ if cancels_export(key, ctrl, action) {
145 this.cancel_export();145 this.cancel_export();
146 }146 }
147 cx.notify();147 cx.notify();
@@ -661,6 +661,10 @@ impl Render for Player {
661 // window.661 // window.
662 .children(self.keys_overlay(cx))662 .children(self.keys_overlay(cx))
663 .children(self.export_card(window.viewport_size(), cx))663 .children(self.export_card(window.viewport_size(), cx))
664+ // The same sheet once the card has been answered: the running
665+ // export is the one state in this window where nothing may be
666+ // edited, so it is drawn as what it is rather than as a strip.
667+ .children(self.export_progress_card(cx))
664 // Last, so it floats over whatever opened it -- an inspector row or668 // Last, so it floats over whatever opened it -- an inspector row or
665 // a clip menu -- rather than under it.669 // a clip menu -- rather than under it.
666 .children(self.picker_card(window.viewport_size(), cx))670 .children(self.picker_card(window.viewport_size(), cx))
crates/app/src/tests/cards.rsmodified+19 -12
@@ -4,20 +4,27 @@
4 use super::*;4 use super::*;
5 5
6 #[test]6 #[test]
7-fn escape_gets_out_of_an_export_whatever_is_held_with_it() {7+fn only_a_chord_gets_out_of_an_export() {
8 use keymap::ActionId;8 use keymap::ActionId;
9- // The regression this guards: looking the stroke up in the keymap made9+ // What this guards: bare escape is the stroke a hand throws at anything on
10- // ctrl+escape mean nothing, and an export that a modifier could trap10+ // screen, and while an export ran it deleted the encode. The way out is the
11- // the user inside of is worse than an unbound chord.11+ // same key with control on it, and the card says so.
12- assert!(cancels_export("escape", None));12+ assert!(cancels_export("escape", true, Some(ActionId::CancelExport)));
13- assert!(cancels_export("escape", Some(ActionId::CancelExport)));13+ assert!(!cancels_export("escape", false, None));
14- // A rebound cancel works as well -- it adds a way out, never replaces14+ // Even if something else were ever bound to bare escape, it is not this.
15- // the one that always worked.15+ assert!(!cancels_export("escape", false, Some(ActionId::Play)));
16- assert!(cancels_export("q", Some(ActionId::CancelExport)));16+ // A rebound cancel works as well -- it adds a way out, never replaces the
17+ // chord, and the keymap is what decides whether that one carries control.
18+ assert!(cancels_export("q", false, Some(ActionId::CancelExport)));
17 // Nothing else does, whatever it means outside an export.19 // Nothing else does, whatever it means outside an export.
18- assert!(!cancels_export("e", Some(ActionId::Export)));20+ assert!(!cancels_export("e", false, Some(ActionId::Export)));
19- assert!(!cancels_export("space", Some(ActionId::Play)));21+ assert!(!cancels_export("space", false, Some(ActionId::Play)));
20- assert!(!cancels_export("q", None));22+ assert!(!cancels_export("q", false, None));
23+ // The default keymap is what the handler feeds this: the chord reaches the
24+ // action, the bare key reaches nothing.
25+ let k = keymap::Keymap::defaults();
26+ assert!(cancels_export("escape", true, k.lookup("escape", true)));
27+ assert!(!cancels_export("escape", false, k.lookup("escape", false)));
21 }28 }
22 29
23 #[test]30 #[test]
crates/app/src/ui/cards.rsmodified+164 -0
@@ -601,6 +601,170 @@ impl Player {
601 )601 )
602 }602 }
603 603
604+ /// The export while it runs, on the same sheet it was asked for on: an
605+ /// editor that takes no edit until the worker is done says so as a card and
606+ /// not as a strip under a panel nobody may touch. Same scrim, same width,
607+ /// same raised box as [`Player::export_card`] -- the answer arrives where
608+ /// the question was put -- and the timeline is still read around it.
609+ ///
610+ /// Two things it does *not* do. It never closes: not on a press away, not
611+ /// on `esc`. There is nothing here to dismiss while the export is still
612+ /// running, and a modal that vanishes leaves a locked editor with no reason
613+ /// on screen. And its cancel is two presses, never one -- an hour of
614+ /// encoding must not end on a stray click, which is why the stroke is a
615+ /// chord as well ([`cancels_export`]).
616+ pub(crate) fn export_progress_card(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> {
617+ let export = self.exporting()?;
618+ let progress = export.progress().clamp(0., 1.);
619+ let elapsed = self
620+ .export_started
621+ .map_or(0., |t| t.elapsed().as_secs_f32());
622+ // Two numbers that must both be honest: the one that counts up is
623+ // measured, the one that counts down is a guess and says so.
624+ let left = eta_secs(&self.export_marks, elapsed, progress).map_or_else(
625+ || "estimating…".to_owned(),
626+ |s| format!("~{} left", clock(s)),
627+ );
628+ // What is being read, the same files the engine names on stderr
629+ // ("export source:"): the project's own sources, never a stand-in.
630+ let source = match self.sources() {
631+ [] => "the timeline".to_owned(),
632+ [one] => file_name(&one.path),
633+ [first, rest @ ..] => format!("{} +{} more", file_name(&first.path), rest.len()),
634+ };
635+ let note = |text: SharedString| {
636+ div()
637+ .flex_none()
638+ .px(px(6.))
639+ .text_size(px(11.))
640+ .text_color(rgb(FG_SECONDARY()))
641+ .child(text)
642+ };
643+ let armed = self.cancel_armed;
644+ Some(
645+ scrim()
646+ .flex()
647+ .justify_center()
648+ .items_center()
649+ .bg(rgba(SCRIM()))
650+ // No `close_card` here, unlike every other sheet: a press away
651+ // is not a way out of a running export, and the only thing that
652+ // ends this card is the export ending.
653+ .on_mouse_down(MouseButton::Left, swallow)
654+ .child(
655+ div()
656+ .w(px(EXPORT_W))
657+ .on_mouse_down(MouseButton::Left, swallow)
658+ .flex()
659+ .flex_col()
660+ .gap(px(6.))
661+ .p(px(12.))
662+ .rounded(px(6.))
663+ .bg(rgb(BG_RAISED()))
664+ .child(div().flex_none().px(px(6.)).child("Exporting"))
665+ // The bar itself: the same number as the percentage
666+ // below it, and it only ever moves forward -- the
667+ // worker's progress is a monotone `fetch_max`.
668+ .child(
669+ div()
670+ .flex_none()
671+ .mx(px(6.))
672+ .h(px(6.))
673+ .rounded(px(3.))
674+ .bg(rgb(BG_PANEL()))
675+ .child(
676+ div()
677+ .h_full()
678+ .w(relative(progress))
679+ .rounded(px(3.))
680+ .bg(rgb(STATUS_PROGRESS())),
681+ ),
682+ )
683+ .child(div().flex_none().px(px(6.)).text_size(px(11.)).child(
684+ SharedString::from(format!(
685+ "{}% · {} elapsed · {left}",
686+ (progress * 100.) as u32,
687+ clock(elapsed),
688+ )),
689+ ))
690+ // The row that was picked, then the seats the worker
691+ // actually opened -- so a fallback to the software
692+ // encoder shows here rather than being invisible.
693+ .child(note(
694+ format!(
695+ "{} · {}",
696+ format_label(self.format),
697+ export
698+ .encoders()
699+ .unwrap_or_else(|| "opening the encoder".to_string()),
700+ )
701+ .into(),
702+ ))
703+ .child(note(
704+ format!("{source} → {}", file_name(&self.export_path)).into(),
705+ ))
706+ .child(note(
707+ match armed {
708+ true => "cancelling deletes what has been written so far"
709+ .to_string(),
710+ false => format!(
711+ "{} cancels · esc alone does nothing while this runs · the \
712+ timeline is read-only until it finishes",
713+ self.keymap.display(ActionId::CancelExport)
714+ ),
715+ }
716+ .into(),
717+ ))
718+ // One button, or the pair that answers it: never a
719+ // control that cycles -- both choices are on screen at
720+ // once, each saying which one it is.
721+ .child(
722+ div()
723+ .mt(px(2.))
724+ .flex()
725+ .gap(px(6.))
726+ .justify_end()
727+ .when(armed, |d| {
728+ d.child(control(
729+ "export-keep",
730+ 140.,
731+ ACCENT_PRIMARY(),
732+ None,
733+ "Keep exporting",
734+ "leaves the export running".to_string(),
735+ true,
736+ cx.listener(|this, _: &ClickEvent, _, cx| {
737+ this.cancel_armed = false;
738+ cx.notify();
739+ }),
740+ ))
741+ })
742+ .child(control(
743+ "export-cancel",
744+ 140.,
745+ BG_RAISED(),
746+ None,
747+ "Cancel export",
748+ match armed {
749+ true => "stops the worker and deletes the part file"
750+ .to_string(),
751+ false => "asks first -- one press only offers the choice"
752+ .to_string(),
753+ },
754+ true,
755+ cx.listener(move |this, _: &ClickEvent, _, cx| {
756+ match this.cancel_armed {
757+ true => this.cancel_export(),
758+ false => this.cancel_armed = true,
759+ }
760+ cx.notify();
761+ }),
762+ )),
763+ ),
764+ ),
765+ )
766+ }
767+
604 /// The custom bitrate's two pointer buttons. The typed digits were the last768 /// The custom bitrate's two pointer buttons. The typed digits were the last
605 /// control in this card a mouse could not reach at all -- and a number that769 /// control in this card a mouse could not reach at all -- and a number that
606 /// can only be typed is a number a hand on the pointer has to leave the770 /// can only be typed is a number a hand on the pointer has to leave the
crates/app/src/ui/timeline.rsmodified+6 -31
@@ -41,37 +41,12 @@ impl Player {
41 rows.push(self.lane_row(lane, filled, cx));41 rows.push(self.lane_row(lane, filled, cx));
42 }42 }
43 let (hint, filled) = if let Some(export) = self.exporting() {43 let (hint, filled) = if let Some(export) = self.exporting() {
44- let progress = export.progress();44+ // The words are the card's now ([`Player::export_progress_card`]):
45- let elapsed = self45+ // the export is modal, so this line is under its scrim and a second
46- .export_started46+ // copy of the clocks there is one that can only be read dimmed. The
47- .map_or(0., |t| t.elapsed().as_secs_f32());47+ // ruler keeps the number -- it is the one part of the progress the
48- // Two numbers that must both be honest: the one that counts up is48+ // card does not cover, and it costs nothing.
49- // measured, the one that counts down is a guess and says so.49+ (String::new(), export.progress())
50- let left = eta_secs(&self.export_marks, elapsed, progress).map_or_else(
51- || "estimating…".to_owned(),
52- |s| format!("~{} left", clock(s)),
53- );
54- (
55- format!(
56- // Clocks, then the way out, then what is encoding: at the
57- // 640 px floor the tail is what truncation eats, and the
58- // codec pair is the one part of this line the card already
59- // said. The escape must not be what goes missing.
60- "EXPORTING {}% · {} elapsed · {left} — {} cancels · {} · {}",
61- (progress * 100.) as u32,
62- clock(elapsed),
63- key(ActionId::CancelExport),
64- // The row that was picked; the engine's line below names the
65- // seats alone, since the library is what identifies a codec.
66- format_label(self.format),
67- // What the worker actually opened, so a fallback to the
68- // software encoder shows here rather than being invisible.
69- export
70- .encoders()
71- .unwrap_or_else(|| "opening the encoder".to_string()),
72- ),
73- progress,
74- )
75 } else {50 } else {
76 // The strokes no button carries; the rest ride on the buttons'51 // The strokes no button carries; the rest ride on the buttons'
77 // tooltips. Keys first: at a 640 px window the tail is what a52 // tooltips. Keys first: at a 640 px window the tail is what a