mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 02:09:00 +00:00
ui-patterns: the hosted Save PDF's automation OK in the preset editor files nothing for an empty name or one the app's check refuses, as the footer's OK is off then
This commit is contained in:
@@ -303,12 +303,16 @@ impl HostedPdfExport {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a failing check or a bad artboard range keeps OK off, as the dialog's own footer has it.
|
||||
/// Whether a failing check, a bad artboard range or, in the preset editor, an empty or refused name keeps OK off,
|
||||
/// as the dialog's own footer has it.
|
||||
fn blocked(&self) -> bool {
|
||||
let catalog = Self::catalog_of(&self.catalog);
|
||||
let range = self.choice.range.trim();
|
||||
let range_bad = self.choice.range_only && !range.is_empty() && self.artboard_count.is_some_and(|count| check_range(range, count).is_err());
|
||||
range_bad || self.settings.check(catalog).and_then(|()| self.settings.check_destination(catalog, self.color_mode)).is_err()
|
||||
let name = self.draft.name.trim();
|
||||
let name_refused =
|
||||
self.mode == PdfExportMode::PresetEditor && (name.is_empty() || self.check_name.as_ref().is_some_and(|check| check(name).is_some()));
|
||||
range_bad || name_refused || self.settings.check(catalog).and_then(|()| self.settings.check_destination(catalog, self.color_mode)).is_err()
|
||||
}
|
||||
|
||||
/// Whether the four bleed sides are equal, which is what the link between them means.
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
use craft_pdf::settings::{Compatibility, PdfPreset, PdfSettings, Standard};
|
||||
use craft_ui::dialog::{DialogHost, DialogId};
|
||||
use craft_ui::patterns::form_dialogs::{HostedPdfExport, PdfExportWords, summary_text};
|
||||
use craft_ui::patterns::form_dialogs::{HostedPdfExport, PdfExportMode, PdfExportWords, summary_text};
|
||||
use craft_ui::patterns::presets::PresetError;
|
||||
use craft_ui::runtime::env::Env;
|
||||
use craft_ui::testing::{Fixture, trial};
|
||||
use egui::{Context, Modifiers, Vec2};
|
||||
@@ -125,6 +126,22 @@ fn ok_files_the_settings_once_for_the_app() {
|
||||
assert!(pdf.take_ok().is_none(), "handed out once");
|
||||
}
|
||||
|
||||
/// In the preset editor, OK by automation files nothing for an empty name or one the app's check refuses, as the
|
||||
/// footer's OK is off then.
|
||||
#[trial]
|
||||
fn ok_in_the_preset_editor_files_nothing_for_a_refused_name() {
|
||||
let ctx = Context::default();
|
||||
let mut host = DialogHost::new();
|
||||
let editor = dialog().mode(PdfExportMode::PresetEditor).check_name(|name| (name == "Mine").then_some(PresetError::NameTaken));
|
||||
let id = host.open(editor);
|
||||
for (name, files) in [("", false), ("Mine", false), ("Fresh", true)] {
|
||||
assert_eq!(write_field(&mut host, &ctx, id, "name", json!(name)), Ok(()), "{name}");
|
||||
host.confirm_by_id(&ctx, id);
|
||||
let filed = host.get_mut_by_id::<HostedPdfExport>(id).expect("open").take_ok();
|
||||
assert_eq!(filed.is_some(), files, "{name:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn reset_restores_the_chosen_preset_and_keeps_the_artboards() {
|
||||
let host = Rc::new(RefCell::new(DialogHost::new()));
|
||||
|
||||
Reference in New Issue
Block a user