dialogs-w4: net change of 3 commits

- dialogs-w4: written by an agent
- dialogs-w4: review fixes (review-1)
- dialogs-w4: review fixes (review-2)
This commit is contained in:
Dylan M. Taylor committed 2026-11-27 14:51:30 +00:00
1 parent 2e6c33887b
commit 705d90e2ad
2 files changed
+276 -1755

No files matched your search

+276 -339
View File
@@ -1,441 +1,378 @@
//! Dialogs (Insert Table, Slide Size, Font, Paragraph, Tabs, Header & Footer, Hyperlink, Set Up Show, Zoom, …) and the
//! About window. The start screen is File › Home (`backstage.rs`).
//! Dialog requests, hosted forms and typed dialog lifecycles for the main window.
use deckcraft_color::SchemeSlot;
use egui::{Align2, Color32, CornerRadius, Rect, Sense, Stroke, Ui, pos2, vec2};
use craft::automation::{dialogs as automation, protocol::Params};
use craft::ui::dialog::{DialogHost, DialogId, DialogResult, StackDialog, UnsavedChangesDialog};
use craft::ui::patterns::form_dialogs::{HostedAbout, HostedListManager, HostedParamDialog, ParamResult};
use craft::ui::runtime::env::{Label, WindowKey};
use craft::ui::shell::WindowDialogs;
use egui::Context;
use serde_json::{Value, json};
use crate::SlideApp;
use crate::theme::{self, Tokens};
#[derive(Clone, Debug, serde::Serialize)]
pub struct Dialog {
pub id: String,
pub params: Value,
/// Field values while the dialog is open.
#[serde(skip)]
pub fields: std::collections::HashMap<String, String>,
}
impl Dialog {
pub fn new(id: &str) -> Self {
Dialog { id: id.into(), params: Value::Null, fields: Default::default() }
}
pub fn modal(&self) -> bool {
true
}
fn get(&mut self, k: &str, default: &str) -> String {
self.fields.entry(k.into()).or_insert_with(|| default.to_string()).clone()
}
}
fn title(id: &str) -> &'static str {
match id {
"table" => "Insert Table",
"slideSize" => "Slide Size",
"sizePosition" => "Size and Position",
"headerFooter" => "Header and Footer",
"hyperlink" => "Insert Hyperlink",
"setupShow" => "Set Up Slide Show",
"zoom" => "Zoom",
"comment" => "New Comment",
"altText" => "Alt Text",
"outline" => "Slides from Outline",
"renameSection" => "Rename Section",
"reuseSlides" => "Reuse Slides",
"renameShape" => "Rename",
"renameLayout" => "Rename Layout",
"paragraph" => "Paragraph",
"tabs" => "Tabs",
"font" => "Font",
"about" => "About DeckCraft",
"preferences" => "Preferences",
"autocorrect" => "AutoCorrect",
"gridOptions" => "Grid Options",
"columns" => "Columns",
"export" => "Export",
"symbol" => "Symbol",
"photoAlbum" => "Photo Album",
"replaceFonts" => "Replace Font",
"equation" => "Equation",
"dateTime" => "Date and Time",
"spelling" => "Spelling",
"pasteSpecial" => "Paste Special",
"find" => "Find and Replace",
"accessibility" => "Accessibility Checker",
"language" => "Language",
"customShow" => "Custom Shows",
"chartData" => "Chart Data",
"trim" => "Trim Media",
"smartart" => "Choose a Diagram Graphic",
"bullets" => "Bullets and Numbering",
"action" => "Action Settings",
"quit" => "DeckCraft",
"themeColors" => "Create New Theme Colors",
"themeFonts" => "Create New Theme Fonts",
_ => "DeckCraft",
}
}
/// Render the active dialog, clearing it when dismissed and preserving or restoring application
/// state as its close path requires.
pub fn show(app: &mut SlideApp, ctx: &egui::Context) {
let Some(mut d) = app.dialog.take() else { return };
let mut open = true;
let mut close = false;
let mut window = egui::Window::new(title(&d.id))
.id(egui::Id::unique(("dialog", d.id.clone())))
.collapsible(false)
.resizable(false)
.anchor(Align2::CENTER_CENTER, vec2(0.0, -40.0))
.open(&mut open);
// Two columns of colour rows plus Save must fit the first frame (Theme Colors), as must Save
// in Theme Fonts. A later resize clips the buttons (the window size sticks) and clicks miss them.
if d.id == "themeColors" {
window = window.default_size(vec2(760.0, 420.0)).min_width(720.0).min_height(420.0);
} else if d.id == "themeFonts" {
window = window.default_size(vec2(460.0, 320.0)).min_width(420.0).min_height(300.0);
}
window.show(ctx, |ui| {
ui.set_min_width(match d.id.as_str() {
"themeColors" => 700.0,
"themeFonts" => 400.0,
_ => 340.0,
});
if d.id == "themeColors" {
ui.set_min_height(360.0);
} else if d.id == "themeFonts" {
ui.set_min_height(280.0);
}
close = body(app, ui, &mut d);
});
let escape = ctx.input(|i| i.key_pressed(egui::Key::Escape));
if open && !close && !escape {
app.dialog = Some(d);
} else if !close && d.id == "preferences" {
// Esc or the window's close button: the same as Cancel.
restore_preferences(app, &d);
} else if app.dialog.is_none()
&& let Some(ret) = d.params.get("returnParams").filter(|v| v.is_object()).cloned()
{
// Tabs… opened from Paragraph: closing it (OK, Cancel, Esc or the window) returns there.
let id = d.params.get("returnId").and_then(Value::as_str).unwrap_or("paragraph");
let mut back = Dialog::new(id);
back.params = ret;
app.dialog = Some(back);
}
}
fn buttons(ui: &mut Ui, ok_label: &str) -> (bool, bool) {
let mut ok = false;
let mut cancel = false;
ui.add_space(8.0);
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
let t = Tokens::get(ui.ctx());
if ui.add(egui::Button::new(egui::RichText::new(ok_label).color(t.accent_text)).fill(t.accent).min_size(vec2(72.0, 24.0))).clicked()
|| ui.input(|i| i.key_pressed(egui::Key::Enter))
{
ok = true;
}
if ui.add(egui::Button::new("Cancel").min_size(vec2(72.0, 24.0))).clicked() {
cancel = true;
}
});
(ok, cancel)
}
/// Draw a labelled single-line field bound to `key`, falling back to `default`, and store the
/// edited value in the dialog.
fn field(ui: &mut Ui, d: &mut Dialog, label: &str, key: &str, default: &str) {
let mut v = d.get(key, default);
ui.horizontal(|ui| {
let l = ui.add_sized(vec2(120.0, 20.0), egui::Label::new(label));
ui.add(egui::TextEdit::singleline(&mut v).desired_width(180.0)).labelled_by(l.id);
});
d.fields.insert(key.into(), v);
}
fn check(ui: &mut Ui, d: &mut Dialog, label: &str, key: &str, default: bool) -> bool {
let mut v = d.get(key, if default { "1" } else { "0" }) == "1";
ui.checkbox(&mut v, label);
d.fields.insert(key.into(), if v { "1".into() } else { "0".into() });
v
}
fn num(d: &mut Dialog, key: &str, default: f64) -> f64 {
d.get(key, "").trim().trim_end_matches(['"', '%', ' ']).parse::<f64>().ok().filter(|v| v.is_finite()).unwrap_or(default)
}
fn num_text(v: f64) -> String {
crate::widgets::fmt_num(v, "")
}
fn field_of(d: &Dialog, key: &str) -> String {
d.fields.get(key).cloned().unwrap_or_default()
}
fn parse_shown(s: &str) -> Option<f64> {
let t = s.trim().trim_end_matches(['%', '"']).trim();
if t.is_empty() {
return None;
}
t.parse().ok().filter(|v: &f64| v.is_finite())
}
fn edited(d: &Dialog, key: &str) -> bool {
field_of(d, key) != field_of(d, &format!("seed{key}"))
}
fn exact_of(d: &Dialog, key: &str) -> Option<f64> {
parse_shown(&field_of(d, &format!("{key}Pt")))
}
/// Draw a labelled single-line text row bound to a dialog key and store the edited value.
fn text_row(ui: &mut Ui, d: &mut Dialog, label: &str, key: &str) {
let mut v = field_of(d, key);
ui.horizontal(|ui| {
let l = ui.add_sized(vec2(148.0, 20.0), egui::Label::new(label));
ui.add(egui::TextEdit::singleline(&mut v).desired_width(96.0)).labelled_by(l.id);
});
d.fields.insert(key.into(), v);
}
use deckcraft_text::datetime::DATE_KINDS;
mod about;
mod accessibility;
mod action;
mod alt_text;
mod body;
mod bullets;
mod chart_data;
mod choice_forms;
mod closing;
mod columns;
mod custom_shows;
mod date_time;
mod equation;
mod export;
mod find;
mod font;
mod grid_options;
mod header_footer;
mod hyperlink;
mod insert_forms;
mod language;
mod paragraph;
mod photo_album;
mod preferences;
/// Preferences drafts and their nested AutoCorrect transaction.
pub(crate) mod preferences;
mod replace_fonts;
mod reuse_slides;
mod size_position;
mod slide_size;
mod spelling;
mod symbol;
mod tabs;
mod theme_colors;
mod theme_fonts;
mod trim;
mod zoom;
pub use about::{about, paint_logo, version_line};
use body::body;
pub use about::version_line;
#[cfg(test)]
use hyperlink::{
CurrentLink, HyperlinkSeed, common_click, hyperlink_command, hyperlink_seed_of, hyperlink_should_apply, link_covering, seed_from, seed_of_link,
};
// PLAN: assumed hyperlink::current_link_of(Option<&deckcraft_engine::DocState>) -> craft::text::ui::hyperlink::CurrentLink (dialogs-w9)
use hyperlink::{common_click, current_link_of, link_covering};
pub use language::selected_language;
use preferences::restore_preferences;
pub use zoom::parse_zoom_percent;
fn seed_once(d: &mut Dialog, key: &str, val: String) {
d.fields.entry(key.to_string()).or_insert(val);
}
fn json_text(v: Option<&Value>, default: &str) -> String {
match v {
Some(Value::String(s)) => s.clone(),
Some(Value::Number(n)) => n.as_f64().map(|x| crate::widgets::fmt_num(x, "")).unwrap_or_else(|| default.to_string()),
Some(Value::Bool(true)) => "1".into(),
Some(Value::Bool(false)) => "0".into(),
_ => default.to_string(),
}
}
fn color_label(v: &Value) -> String {
match v {
Value::String(s) => s.clone(),
Value::Object(o) => o.get("scheme").or_else(|| o.get("rgb")).and_then(Value::as_str).unwrap_or("").to_string(),
_ => String::new(),
}
}
/// Draw a uniquely identified accessible choice combo box and store the selected key;
/// the caller supplies the visible label.
fn choice(ui: &mut Ui, d: &mut Dialog, salt: &str, name: &str, key: &str, choices: &[(&str, &str)]) {
let cur = d.get(key, "");
let label = choices.iter().find(|(v, _)| *v == cur).map(|(_, l)| *l).unwrap_or(cur.as_str());
// P3(dialogs-w4): earlier framework ComboBox removal (no contract id)
let combo = egui::ComboBox::from_id_salt(salt).selected_text(label).width(140.0).show_ui(ui, |ui| {
for (v, l) in choices {
if ui.selectable_label(cur == *v, *l).clicked() {
d.fields.insert((*key).into(), (*v).into());
}
}
});
combo.response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::ComboBox, true, name));
}
fn labeled_text(ui: &mut Ui, d: &mut Dialog, label: &str, key: &str, width: f32) -> String {
let mut v = d.get(key, "");
let l = ui.label(label);
ui.add(egui::TextEdit::singleline(&mut v).desired_width(width)).labelled_by(l.id);
d.fields.insert(key.into(), v.clone());
v
}
fn finite_pt(text: &str) -> Option<f64> {
text.trim().trim_end_matches("pt").trim().parse::<f64>().ok().filter(|v| v.is_finite())
}
fn pt_text(v: Option<&Value>, default: f64) -> String {
match v.and_then(Value::as_f64).filter(|n| n.is_finite()) {
Some(n) => crate::widgets::fmt_num(n, ""),
None => crate::widgets::fmt_num(default, ""),
}
}
fn inches_text(v: Option<&Value>) -> String {
crate::widgets::fmt_num(v.and_then(Value::as_f64).filter(|n| n.is_finite()).unwrap_or(0.0) / 72.0, "")
}
pub mod credits;
#[cfg(test)]
mod font_dialog_tests;
#[cfg(not(target_arch = "wasm32"))]
pub(super) mod updates_ui;
#[cfg(test)]
mod font_dialog_tests;
#[cfg(test)]
mod size_position_tests;
#[cfg(test)]
mod columns_dialog_tests;
#[cfg(test)]
mod photo_album_tests;
#[cfg(test)]
mod theme_colors_tests;
#[cfg(test)]
mod theme_fonts_tests;
#[cfg(test)]
mod tests;
#[cfg(test)]
mod spelling_tests;
#[cfg(test)]
mod paragraph_dialog_tests;
#[cfg(test)]
mod preferences_tests;
use craft::ui::dialog::{DialogHost, DialogId};
use craft::ui::patterns::form_dialogs::{HostedParamDialog, ParamResult};
use egui::Context;
/// All dialog state and pending requests.
#[allow(dead_code)] // P3(dialogs-w4): dl.A2
/// App-owned dialog state, independent of a UI context.
#[derive(Default)]
pub(crate) struct DialogState {
/// Opens waiting for the main window's host.
pub requests: Vec<DialogRequest>,
/// Unapplied Paragraph values held during a Tabs round trip.
pub paragraph_draft: Option<craft::text::ui::character::ParagraphFormat>,
/// Document locations corresponding to the spelling dialog's items.
pub spelling: Option<spelling::SpellingRun>,
/// Photo Album's outstanding file picker ticket.
pub album_pick: Option<craft::host::PickId>,
/// The current match and continuation position for Find.
pub find: find::FindProgress,
/// The document closing transaction.
pub closing: Option<closing::Closing>,
/// Settings restored when Preferences closes with Cancel.
pub preferences_opening: Option<preferences::PrefDraft>,
}
/// A queued dialog request and its parameters.
#[allow(dead_code)] // P3(dialogs-w4): dl.A2
/// An opener's dialog key and seed parameters.
pub(crate) struct DialogRequest {
/// The registry or typed dialog key.
pub id: String,
/// Values passed to the module's opener.
pub params: Value,
}
impl crate::SlideApp {
/// Queues a dialog request for the current pass.
#[allow(dead_code)] // P3(dialogs-w4): dl.A3
impl SlideApp {
/// Queues an open for the main window's dialog pump.
pub(crate) fn open_dialog(&mut self, id: &str, params: Value) {
let _ = (id, params);
todo!("dl.A3")
self.dialogs.requests.push(DialogRequest { id: id.into(), params });
}
}
/// The open, finish and per-pass steps for a hosted form.
#[allow(dead_code)] // P3(dialogs-w4): dl.A4
/// The callbacks and acceptance policy of one hosted form.
pub(crate) struct FormSpec {
/// Builds the form from application state and opener parameters.
pub open: fn(&SlideApp, &Context, &Value) -> HostedParamDialog,
/// Applies an accepted answer through the application's commands.
pub finish: fn(&mut SlideApp, &ParamResult, &mut DialogHost) -> Result<(), String>,
/// Whether acceptance waits for the command's success before closing.
pub held: bool,
/// Advances asynchronous work and consumes this form's actions, if present.
pub each_pass: Option<fn(&mut SlideApp, &Context, &mut HostedParamDialog)>,
/// Consumes actions for a form without a per-pass callback.
pub action: Option<fn(&mut SlideApp, &str) -> Result<(), String>>,
}
/// The hosted form registry.
#[allow(dead_code)] // P3(dialogs-w4): dl.A4
const FORMS: &[(&str, FormSpec)] = &[];
impl FormSpec {
const fn new(
open: fn(&SlideApp, &Context, &Value) -> HostedParamDialog,
finish: fn(&mut SlideApp, &ParamResult, &mut DialogHost) -> Result<(), String>,
held: bool,
) -> Self {
Self { open, finish, held, each_pass: None, action: None }
}
}
/// Opens a registered or typed dialog now.
#[allow(dead_code)] // P3(dialogs-w4): dl.A5
const FORMS: &[(&str, FormSpec)] = &[
("table", FormSpec::new(insert_forms::table::open, insert_forms::table::finish, false)),
("comment", FormSpec::new(insert_forms::comment::open, insert_forms::comment::finish, false)),
("outline", FormSpec::new(insert_forms::outline::open, insert_forms::outline::finish, false)),
("renameSection", FormSpec::new(insert_forms::rename_section::open, insert_forms::rename_section::finish, false)),
("renameShape", FormSpec::new(insert_forms::rename_shape::open, insert_forms::rename_shape::finish, false)),
("renameLayout", FormSpec::new(insert_forms::rename_layout::open, insert_forms::rename_layout::finish, false)),
("equation", FormSpec::new(insert_forms::equation::open, insert_forms::equation::finish, false)),
("smartart", FormSpec::new(insert_forms::smartart::open, insert_forms::smartart::finish, false)),
("slideSize", FormSpec::new(slide_size::open, slide_size::finish, false)),
("headerFooter", FormSpec::new(header_footer::open, header_footer::finish, false)),
("setupShow", FormSpec::new(choice_forms::setup_show::open, choice_forms::setup_show::finish, false)),
("pasteSpecial", FormSpec::new(choice_forms::paste_special::open, choice_forms::paste_special::finish, false)),
("zoom", FormSpec::new(zoom::open, zoom::finish, false)),
("trim", FormSpec::new(trim::open, trim::finish, false)),
("gridOptions", FormSpec::new(grid_options::open, grid_options::finish, true)),
("columns", FormSpec::new(columns::open, columns::finish, true)),
("font", FormSpec::new(font::open, font::finish, true)),
("sizePosition", FormSpec::new(size_position::open, size_position::finish, true)),
("bullets", FormSpec::new(bullets::open, bullets::finish, true)),
("language", FormSpec::new(language::open, language::finish, true)),
("dateTime", FormSpec::new(date_time::open, date_time::finish, true)),
("replaceFonts", FormSpec::new(replace_fonts::open, replace_fonts::finish, true)),
("symbol", FormSpec { action: Some(symbol::action), ..FormSpec::new(symbol::open, symbol::finish, false) }),
("action", FormSpec::new(action::open, action::finish, true)),
("altText", FormSpec::new(alt_text::open, alt_text::finish, true)),
("export", FormSpec::new(export::open, export::finish, true)),
("themeColors", FormSpec::new(theme_colors::open, theme_colors::finish, true)),
("themeFonts", FormSpec::new(theme_fonts::open, theme_fonts::finish, true)),
("photoAlbum", FormSpec { each_pass: Some(photo_album::each_pass), ..FormSpec::new(photo_album::open, photo_album::finish, true) }),
("chartData", FormSpec::new(chart_data::open, chart_data::finish, true)),
("reuseSlides", FormSpec::new(reuse_slides::open, reuse_slides::finish, true)),
];
fn form(key: &str) -> Option<&'static FormSpec> {
FORMS.iter().find(|(id, _)| *id == key).map(|(_, spec)| spec)
}
fn typed_id<D: StackDialog>(host: &DialogHost) -> Option<DialogId> {
host.get::<D>().map(StackDialog::id)
}
// PreferencesDialog and AccessibilityDialog publish their routing keys through StackDialog::key.
// AutoCorrect belongs to Preferences; opening it must preserve the parent's transaction.
fn matching_dialog(host: &DialogHost, key: &str) -> Option<DialogId> {
match key {
"paragraph" => typed_id::<craft::text::ui::character::ParagraphDialog>(host),
"tabs" => typed_id::<craft::text::ui::tabs_dialog::TabStopsDialog>(host),
"hyperlink" => typed_id::<craft::text::ui::hyperlink::HyperlinkDialog>(host),
"customShow" => typed_id::<HostedListManager>(host),
"spelling" => typed_id::<craft::text::ui::spelling::CheckSpellingDialog>(host),
"find" => typed_id::<craft::text::ui::find::FindReplaceDialog>(host),
"quit" => typed_id::<UnsavedChangesDialog>(host),
"about" => typed_id::<HostedAbout>(host),
_ => host.open_dialogs().into_iter().find(|dialog| dialog.key.as_deref() == Some(key)).map(|dialog| dialog.id),
}
}
/// Opens a form or typed dialog after settling the instance it replaces.
pub(crate) fn open_now(app: &mut SlideApp, ctx: &Context, host: &mut DialogHost, id: &str, params: &Value) -> Result<Option<DialogId>, String> {
let _ = (app, ctx, host, id, params);
todo!("dl.A5")
let mut spelled = false;
settle(app, ctx, host, &mut spelled);
if let Some(old) = matching_dialog(host, id) {
finish_held(app, ctx, host, Some(old));
host.cancel_by_id(ctx, old);
settle(app, ctx, host, &mut spelled);
}
if let Some(spec) = form(id) {
let mut params = params.clone();
if id == "bullets" && params.get("tab").is_none() {
let state = app.session.execute("format.state", &json!({})).map_err(|error| error.to_string())?;
if !params.is_object() {
params = json!({});
}
params["tab"] = json!(if state["numbering"].as_bool() == Some(true) { "numbered" } else { "bulleted" });
} else if id == "replaceFonts" {
let used = app.session.execute("font.used", &json!({})).map_err(|error| error.to_string())?;
if !params.is_object() {
params = json!({});
}
params["used"] = used;
}
let dialog = (spec.open)(app, ctx, &params);
return Ok(Some(host.open(if spec.held { dialog.held_ok() } else { dialog })));
}
match id {
"paragraph" => paragraph::open(app, ctx, host, params),
"tabs" => tabs::open(app, ctx, host, params),
"hyperlink" => hyperlink::open(app, ctx, host, params),
"customShow" => custom_shows::open(app, ctx, host, params),
"spelling" => spelling::open(app, ctx, host, params),
"accessibility" => accessibility::open(app, ctx, host, params),
"find" => find::open(app, ctx, host, params),
"quit" => closing::open(app, ctx, host, params),
"about" => about::open(app, ctx, host, params),
"preferences" => preferences::open(app, ctx, host, params),
"autocorrect" => preferences::open_autocorrect(app, ctx, host, params),
_ => Err(format!("no dialog {id}")),
}
}
/// Drains requests and advances hosted dialogs.
#[allow(dead_code)] // P3(dialogs-w4): dl.A6
fn finish_held(app: &mut SlideApp, ctx: &Context, host: &mut DialogHost, only: Option<DialogId>) {
for open in host.open_dialogs() {
if only.is_some_and(|id| id != open.id) {
continue;
}
let Some(spec) = open.key.as_deref().and_then(form).filter(|spec| spec.held) else { continue };
let result = host.get_mut_by_id::<HostedParamDialog>(open.id).and_then(HostedParamDialog::take_ok);
let Some(result) = result else { continue };
let answer = (spec.finish)(app, &result, host);
if answer.is_ok() {
result.remember(ctx);
}
if let Some(dialog) = host.get_mut_by_id::<HostedParamDialog>(result.id) {
dialog.answer_ok(answer.map_err(Label::from));
}
}
}
/// Takes finished results and runs the typed modules' pumps; `spelled` is set when the spelling pump consumed an action.
fn settle(app: &mut SlideApp, ctx: &Context, host: &mut DialogHost, spelled: &mut bool) {
// Preferences drains its action channel before restoring a cancelled opening snapshot.
preferences::pump(app, ctx, host);
while let Some((closed, key)) = host.take_keyed::<HostedParamDialog>() {
if let DialogResult::Ok(result) = closed
&& let Some(spec) = form(&result.key)
&& !spec.held
{
match (spec.finish)(app, &result, host) {
Ok(()) => result.remember(ctx),
Err(error) => app.set_status(error),
}
}
if key.as_deref() == Some("photoAlbum")
&& let Some(pick) = app.dialogs.album_pick.take()
{
app.host.files().forget(pick);
}
}
paragraph::pump(app, ctx, host);
tabs::pump(app, ctx, host);
hyperlink::pump(app, ctx, host);
custom_shows::pump(app, ctx, host);
// PLAN: assumed spelling::pump(&mut SlideApp, &Context, &mut DialogHost) -> bool, true when an action was consumed (dialogs-w15)
*spelled |= spelling::pump(app, ctx, host);
accessibility::pump(app, ctx, host);
find::pump(app, ctx, host);
closing::pump(app, ctx, host);
about::pump(app, ctx, host);
}
/// Advances dialogs inside the main window's single host lock for this pass.
pub(crate) fn pump(app: &mut SlideApp, ctx: &Context) {
let _ = (app, ctx);
todo!("dl.A6")
WindowDialogs::of(ctx, &WindowKey::main()).with(|host| {
let mut spelled = false;
settle(app, ctx, host, &mut spelled);
for request in std::mem::take(&mut app.dialogs.requests) {
if let Err(error) = open_now(app, ctx, host, &request.id, &request.params) {
app.set_status(error);
}
}
for open in host.open_dialogs() {
let Some(spec) = open.key.as_deref().and_then(form) else { continue };
let Some(dialog) = host.get_mut_by_id::<HostedParamDialog>(open.id) else { continue };
if let Some(each_pass) = spec.each_pass {
each_pass(app, ctx, dialog);
} else if let Some(action) = spec.action {
for id in dialog.take_actions() {
if let Err(error) = action(app, &id) {
app.set_status(error);
}
}
}
}
finish_held(app, ctx, host, None);
settle(app, ctx, host, &mut spelled);
// PLAN: assumed spelling::refresh(&mut SlideApp, &Context, &mut DialogHost, bool) (dialogs-w15)
spelling::refresh(app, ctx, host, spelled);
#[cfg(not(target_arch = "wasm32"))]
updates_ui::run(app, ctx, host);
});
}
/// Runs a dialog control request.
#[allow(dead_code)] // P3(dialogs-w4): dl.A7
/// Handles dialog automation on the same host as pointer and keyboard interaction.
pub(crate) fn control(app: &mut SlideApp, ctx: &Context, method: &str, params: &Value) -> Option<Result<Value, String>> {
let _ = (app, ctx, method, params);
todo!("dl.A7")
if !matches!(method, "ui.dialog.open" | "ui.dialog.close" | "ui.dialog.set" | "ui.dialog.confirm" | "ui.dialog.cancel") {
return None;
}
WindowDialogs::of(ctx, &WindowKey::main()).with(|host| match method {
"ui.dialog.open" => Some((|| {
let params = Params(params).only(None, &["id", "params", "fields"])?;
let id = Params(&params).str_field("id")?.ok_or("missing `id`")?;
let fields = match params.get("fields") {
Some(Value::Object(fields)) => fields.iter().map(|(key, value)| (key.clone(), value.clone())).collect::<Vec<_>>(),
Some(_) => return Err("fields must be an object".into()),
None => Vec::new(),
};
let opened = open_now(app, ctx, host, id, params.get("params").unwrap_or(&Value::Null))?;
if let Some(opened) = opened {
host.set_json_fields(ctx, opened, &fields)?;
} else if !fields.is_empty() {
return Err("the request completed without a dialog to set fields on".into());
}
Ok(Value::Null)
})()),
"ui.dialog.close" => Some((|| {
let mut params = Params(params).only(None, &["dialog"])?;
if params.get("dialog").is_none() {
if host.stack().top().is_none() {
return Ok(Value::Null);
}
params["dialog"] = json!("top");
}
let id = automation::dialog_id(host, &params)?;
host.close_by_id(id);
Ok(Value::Null)
})()),
_ => automation::dialog_method(host, ctx, method, params),
})
}
/// Inspects the hosted dialogs.
#[allow(dead_code)] // P3(dialogs-w4): dl.A7
/// Returns the host's automation inspection of every open dialog.
pub(crate) fn inspect(ctx: &Context) -> Value {
let _ = ctx;
todo!("dl.A7")
WindowDialogs::of(ctx, &WindowKey::main()).with(|host| automation::inspect(host))
}
/// Whether a hosted modal is open.
#[allow(dead_code)] // P3(dialogs-w4): dl.A7
/// Reports whether the main window has a hosted modal.
pub(crate) fn modal_open(ctx: &Context) -> bool {
let _ = ctx;
todo!("dl.A7")
WindowDialogs::of(ctx, &WindowKey::main()).with(|host| host.shows_modal())
}
/// The top hosted dialog.
#[allow(dead_code)] // P3(dialogs-w4): dl.A7
/// Returns the main window's top hosted dialog id.
pub(crate) fn top_dialog(ctx: &Context) -> Option<DialogId> {
let _ = ctx;
todo!("dl.A7")
WindowDialogs::of(ctx, &WindowKey::main()).with(|host| host.stack().top())
}
/// Lists the keys exposed by the open dialogs, in stack order.
#[cfg(test)]
/// The ids of the open dialogs.
#[allow(dead_code)] // P3(dialogs-w4): dl.A7
pub(crate) fn open_keys(ctx: &Context) -> Vec<String> {
let _ = ctx;
todo!("dl.A7")
WindowDialogs::of(ctx, &WindowKey::main()).with(|host| host.open_dialogs().into_iter().filter_map(|dialog| dialog.key).collect())
}
mod accessibility;
mod action;
mod bullets;
mod chart_data;
mod choice_forms;
mod closing;
mod custom_shows;
mod header_footer;
mod insert_forms;
mod replace_fonts;
mod reuse_slides;
mod spelling;
mod symbol;
File diff suppressed because it is too large. Load diff