ElyShow: an open dialog is never pushed aside; a stuck show start is gone (S-04)

This commit is contained in:
ZacharyZhang-NY committed 2026-10-09 20:17:16 -04:00
1 parent fd6e651478
commit 41a99962aa
13 files changed
+59 -26

No files matched your search

+2 -2
View File
@@ -186,8 +186,8 @@ impl Deck {
return log::info!("show: a chart dialog for tab {tab} came late");
}
let editing = Editing::new(tab, chart, window, cx);
deck.dialog = Some(Dialog::Chart(Box::new(editing)));
cx.notify();
// Refused while another dialog is open; it says so.
let _ = deck.open_dialog(Dialog::Chart(Box::new(editing)), cx);
})
})
.detach_and_log_err(cx);
+2 -2
View File
@@ -128,8 +128,8 @@ impl Deck {
Ok((check, slides)) if deck.dialog_due(asked, id) => {
let found = findings(&check, &slides, &missing);
log::info!("show: the check found {} things", found.len());
deck.dialog = Some(Dialog::Check(found));
cx.notify();
// Refused while another dialog is open; it says so.
let _ = deck.open_dialog(Dialog::Check(found), cx);
}
Ok(_) => log::info!("show: the check is no longer due"),
Err(error) => deck.engine_failed(&format!("the check: {error}"), cx),
+16 -3
View File
@@ -1,6 +1,7 @@
//! ElyShow's one open dialog.
use ely_gpui_component::forms::TextInput;
use ely_gpui_component::{forms::TextInput, primitives::Severity};
use ely_office::prelude::*;
use gpui::{App, Context, Entity, IntoElement as _};
use crate::deck::Deck;
@@ -41,6 +42,18 @@ pub(crate) fn edit(
}
impl Deck {
/// Opens `dialog`, or hands it back while another is open.
pub(crate) fn open_dialog(&mut self, dialog: Dialog, cx: &mut Context<Self>) -> Result<(), Dialog> {
if self.dialog.is_some() {
let text = Deck::text(cx, "show.dialog.busy", &[]);
self.toast(text, Severity::Warning, cx);
return Err(dialog);
}
self.dialog = Some(dialog);
cx.notify();
Ok(())
}
/// A read that will open a dialog; earlier ones lapse.
pub fn ask_dialog(&mut self) -> u64 {
self.dialog_asked += 1;
@@ -56,9 +69,9 @@ impl Deck {
}
}
/// Whether read `asked` may open its dialog now.
/// Whether read `asked` still stands; `open_dialog` checks the rest.
pub fn dialog_due(&self, asked: u64, id: u64) -> bool {
self.dialog_asked == asked && self.dialog.is_none() && self.core.active == Some(id)
self.dialog_asked == asked && self.core.active == Some(id)
}
/// The open dialog, drawn.
+2 -2
View File
@@ -34,8 +34,8 @@ impl Deck {
match ely_lok::templates("presnt") {
Ok(templates) => {
log::info!("show: {} bundled templates", templates.len());
self.dialog = Some(Dialog::New(Choosing { templates }));
cx.notify();
// Refused while another dialog is open; it says so.
let _ = self.open_dialog(Dialog::New(Choosing { templates }), cx);
}
Err(error) => self.engine_failed(&error.to_string(), cx),
}
+4 -3
View File
@@ -148,7 +148,8 @@ impl Deck {
|worker, doc| ely_lok::show::slide_show(&worker.values(doc, ely_lok::show::SLIDE_SHOW)?),
move |deck, read, _, cx| match read {
Ok(slides) if deck.dialog_due(asked, id) => {
deck.dialog = Some(Dialog::Output(Output {
// Refused while another dialog is open; it says so.
let output = Output {
tab: id,
print,
kind: Kind::Slides,
@@ -156,8 +157,8 @@ impl Deck {
per: 3,
current,
hidden: slides.iter().map(|slide| slide.hidden).collect(),
}));
cx.notify();
};
let _ = deck.open_dialog(Dialog::Output(output), cx);
}
Ok(_) => log::info!("show: the output dialog is no longer due"),
Err(error) => deck.engine_failed(&format!("the slides: {error}"), cx),
+2 -2
View File
@@ -77,8 +77,8 @@ impl Deck {
input.set_text(text, cx);
input
});
self.dialog = Some(Dialog::Remark { tab, edit, field });
cx.notify();
// Refused while another dialog is open; it says so.
let _ = self.open_dialog(Dialog::Remark { tab, edit, field }, cx);
}
/// Sends the dialog's text: a new comment or an edit.
+5 -5
View File
@@ -196,11 +196,11 @@ impl Deck {
};
match cx.displays().len() {
1 => deck.open_show(starting, cx),
_ => {
deck.show_starting = true;
deck.dialog = Some(Dialog::Show(starting));
cx.notify();
}
_ => match deck.open_dialog(Dialog::Show(starting), cx) {
Ok(()) => deck.show_starting = true,
Err(Dialog::Show(refused)) => discard(worker, refused.doc, refused.copy, cx),
Err(_) => unreachable!("the show dialog comes back"),
},
}
},
cx,
+2 -6
View File
@@ -21,12 +21,8 @@ use crate::dialog::{Dialog, edit};
impl Deck {
pub fn ask_table(&mut self, cx: &mut Context<Self>) {
if let Some(tab) = self.core.active {
self.dialog = Some(Dialog::Table {
tab,
columns: 3,
rows: 3,
});
cx.notify();
// Refused while another dialog is open; it says so.
let _ = self.open_dialog(Dialog::Table { tab, columns: 3, rows: 3 }, cx);
}
}
+17
View File
@@ -104,6 +104,23 @@ fn the_table_dialog_inserts_a_table() {
});
}
#[test]
fn an_open_dialog_is_not_pushed_aside() {
let dir = tempfile::tempdir().expect("a temp dir");
let mut cx = TestAppContext::single();
let Some(deck) = blank(&mut cx, dir.path()) else {
eprintln!("SKIP: no LOK build");
return;
};
update(&mut cx, &deck, |deck, cx| deck.ask_table(cx));
update(&mut cx, &deck, |deck, cx| deck.ask_new(cx));
// The chart dialog opens after a background read.
update(&mut cx, &deck, |deck, cx| deck.ask_chart(cx));
cx.run_until_parked();
let kept = cx.update(|app| matches!(deck.read(app).dialog, Some(crate::dialog::Dialog::Table { .. })));
assert!(kept, "the table dialog stays");
}
#[test]
fn typed_notes_reach_the_slide() {
let dir = tempfile::tempdir().expect("a temp dir");