Keep Export As visible before a drawing opens

This commit is contained in:
dotCooCoo committed 2026-11-26 16:16:28 -08:00
1 parent fc8575ecfb
commit b372e2840d
3 files changed
+24 -7

No files matched your search

+6 -5
View File
@@ -111,9 +111,9 @@ pub fn open(app: &mut VectorcraftApp, format: Option<&str>, p: &Value) {
fn open_dialog(app: &mut VectorcraftApp, format: Option<&str>, p: &Value) -> Result<(), String> {
let ctx = app.ui_ctx.clone().ok_or("no window")?;
let source = app.session.active().ok_or("no document")?;
let document = source.uid;
let n = source.doc.artboards.len();
let source = app.session.active();
let document = source.map(|source| source.uid);
let n = source.map_or(0, |source| source.doc.artboards.len());
let missing = format.and_then(|f| UNAVAILABLE.iter().find(|u| u.0.eq_ignore_ascii_case(f.trim_start_matches('.'))));
let format = match missing {
Some((id, _)) => id,
@@ -138,7 +138,8 @@ fn open_dialog(app: &mut VectorcraftApp, format: Option<&str>, p: &Value) -> Res
export_host::open(app, Export::As { document }, false, dialog).map(|_| ()).ok_or_else(|| "no window".into())
}
fn require_source(app: &VectorcraftApp, document: u64) -> Result<(), String> {
fn require_source(app: &VectorcraftApp, document: Option<u64>) -> Result<(), String> {
let document = document.ok_or_else(|| tl!("Open Export As from the drawing you want to export").to_owned())?;
if app.session.active().is_none_or(|source| source.uid != document) {
return Err(tl!("Return to the original drawing to export it").into());
}
@@ -147,7 +148,7 @@ fn require_source(app: &VectorcraftApp, document: u64) -> Result<(), String> {
/// Check the artboard range and that there is something to export; the save panel and the format's options or
/// the file follow once the dialog has closed.
pub(super) fn confirm(app: &mut VectorcraftApp, document: u64, fields: &DialogFields) -> Result<After, String> {
pub(super) fn confirm(app: &mut VectorcraftApp, document: Option<u64>, fields: &DialogFields) -> Result<After, String> {
require_source(app, document)?;
if let Some((_, hint)) = unavailable(fields) {
return Err(hint.into());
+2 -2
View File
@@ -22,8 +22,8 @@ pub(crate) type After = Option<Box<dyn FnOnce(&mut VectorcraftApp) -> Result<Val
pub(crate) enum Export {
/// Export As.
As {
/// The drawing whose export the dialog configures.
document: u64,
/// The drawing whose export the dialog configures, when one was open.
document: Option<u64>,
},
/// The options of the raster format `format`.
Raster {
@@ -344,6 +344,22 @@ fn a_bad_range_keeps_export_as_open() {
assert!(written.borrow().is_empty());
}
#[test]
fn export_as_opened_without_a_drawing_does_not_take_a_later_drawing() {
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Services::default()));
save_panel(&mut app, |_| Some("/out/untitled.png".into()));
app.run("file.exportAs", json!({"format": "png"})).unwrap();
assert_eq!(kind(&app).as_deref(), Some("exportAs"));
assert_eq!(fields(&app)["format"], "png");
app.run("file.new", json!({"width": 200, "height": 100})).unwrap();
app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 50, "height": 40})).unwrap();
let error = try_confirm(&mut app).expect_err("the old Export As draft has no source drawing");
assert!(error.contains("Open Export As from the drawing"), "{error}");
assert_eq!(kind(&app).as_deref(), Some("exportAs"));
PANEL.with_borrow(|panel| assert!(panel.as_ref().unwrap().picker.requests().is_empty()));
}
#[test]
fn export_as_waits_for_the_drawing_that_opened_it() {
let (mut app, written) = app(2);