mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-21 01:44:57 +01:00
Merge pull request #8754 from storytold/train/carry8729
HP-GL Options: OK writes nothing after another document became active (#8729)
This commit is contained in:
6 files changed
+36
-6
No files matched your search
@@ -1907,7 +1907,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"ui.hpglOptionsDialog",
|
||||
"HP-GL Options Dialog",
|
||||
"",
|
||||
"{path?, useArtboards?, range?, hpglVersion?, curveTolerance?, origin?, pens?, sortPaths?, insideFirst?} open HP-GL Options (dialog `hpglOptions`: fields = these document.export options over the ones used last; pens null is One Pen per Color); OK checks them, remembers them and writes path (else asks). Export As… → HP-GL opens it too",
|
||||
"{path?, useArtboards?, range?, hpglVersion?, curveTolerance?, origin?, pens?, sortPaths?, insideFirst?} open HP-GL Options (dialog `hpglOptions`: fields = these document.export options over the ones used last; pens null is One Pen per Color); OK checks them, remembers them and writes path (else asks); OK after another document has become active closes the dialog and writes nothing. Export As… → HP-GL opens it too",
|
||||
),
|
||||
(
|
||||
"file.saveForWeb",
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
//! an option or artboard choice the export refuses, or a save panel shown in line that is canceled,
|
||||
//! keeps the dialog open. A canceled save panel keeps the options remembered before. Opened by Export
|
||||
//! Selection, it checks and writes the selection alone. A typed Curve Tolerance is kept within 0.01
|
||||
//! to 10 points.
|
||||
//! to 10 points. OK after another document has become the active one closes the dialog and writes
|
||||
//! nothing.
|
||||
|
||||
use serde_json::{Map, Value, json};
|
||||
use vectorcraft_cad::hpgl::write::{DEFAULT_TOLERANCE, MAX_PENS, TOLERANCE_RANGE};
|
||||
@@ -42,6 +43,9 @@ const SET_ASIDE: &str = "__pens";
|
||||
/// Why Pen Table could not start from the art's pens, shown under the Pens row.
|
||||
const PEN_ERROR: &str = "__penError";
|
||||
|
||||
/// The field that holds the uid of the document the dialog was opened for.
|
||||
const DOC: &str = "__doc";
|
||||
|
||||
/// The Origin menu's names, in [`Origin::ALL`] order.
|
||||
pub(crate) const ORIGIN_NAMES: [&str; 2] = ["Bottom Left", "Center"];
|
||||
|
||||
@@ -71,6 +75,7 @@ pub fn open(app: &mut VectorcraftApp, params: &Value) {
|
||||
}
|
||||
}
|
||||
fields.insert("format".into(), json!("hpgl"));
|
||||
fields.insert(DOC.into(), json!(app.session.active().map(|st| st.uid)));
|
||||
app.ui.dialog = Some(Dialog::new(KIND, Value::Object(fields)));
|
||||
}
|
||||
|
||||
@@ -236,8 +241,13 @@ fn rgb(hex: &str) -> Option<[u8; 3]> {
|
||||
Some([byte(0)?, byte(2)?, byte(4)?])
|
||||
}
|
||||
|
||||
/// Check the options, remember them, and write the file(s).
|
||||
/// Check the options, remember them, and write the file(s). When another document has become the
|
||||
/// active one since the dialog opened, it closes as Cancel does and writes nothing.
|
||||
fn confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result<Value, String> {
|
||||
if d.fields.get(DOC).and_then(Value::as_u64) != app.session.active().map(|st| st.uid) {
|
||||
app.ui.dialog = None;
|
||||
return Ok(json!({}));
|
||||
}
|
||||
let params = super::form::params(d);
|
||||
let st = app.session.active().ok_or("no document")?;
|
||||
// A bad option or artboard choice, nothing selected, or no art to export keeps the dialog open.
|
||||
|
||||
@@ -258,6 +258,24 @@ fn pen_table_starts_from_the_pens_of_what_the_export_plots() {
|
||||
assert_eq!(seed(&app), on_board);
|
||||
}
|
||||
|
||||
/// OK after another document has become the active one closes HP-GL Options and writes nothing, so
|
||||
/// the other document is not written to the path chosen for the first.
|
||||
#[test]
|
||||
fn hpgl_options_write_nothing_after_another_document_became_active() {
|
||||
let (mut app, written) = app(1);
|
||||
app.run("ui.hpglOptionsDialog", json!({"path": "/out/first.plt"})).unwrap();
|
||||
app.run("file.new", json!({"width": 60, "height": 40})).unwrap();
|
||||
assert_eq!(kind(&app), Some("hpglOptions"));
|
||||
assert_eq!(confirm(&mut app).unwrap(), json!({}));
|
||||
assert!(app.ui.dialog.is_none());
|
||||
assert!(written.borrow().is_empty(), "nothing is written over the first document's path");
|
||||
// Opened for the document that is active, OK writes it.
|
||||
app.run("window.nextDocument", json!({})).unwrap();
|
||||
app.run("ui.hpglOptionsDialog", json!({"path": "/out/first.plt"})).unwrap();
|
||||
confirm(&mut app).unwrap();
|
||||
assert_eq!(names(&written), ["/out/first.plt"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_hpgl_options_dialog_needs_a_document() {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
|
||||
@@ -1908,7 +1908,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"ui.hpglOptionsDialog",
|
||||
"HP-GL Options Dialog",
|
||||
"",
|
||||
"{path?, useArtboards?, range?, hpglVersion?, curveTolerance?, origin?, pens?, sortPaths?, insideFirst?} open HP-GL Options (dialog `hpglOptions`: fields = these document.export options over the ones used last; pens null is One Pen per Color); OK checks them, remembers them and writes path (else asks). Export As… → HP-GL opens it too",
|
||||
"{path?, useArtboards?, range?, hpglVersion?, curveTolerance?, origin?, pens?, sortPaths?, insideFirst?} open HP-GL Options (dialog `hpglOptions`: fields = these document.export options over the ones used last; pens null is One Pen per Color); OK checks them, remembers them and writes path (else asks); OK after another document has become active closes the dialog and writes nothing. Export As… → HP-GL opens it too",
|
||||
),
|
||||
(
|
||||
"file.saveForWeb",
|
||||
|
||||
@@ -928,7 +928,8 @@ when the export refuses the options or the artboard choice, `pens` stays null an
|
||||
remembers the options for the next HP-GL Options (not `exportSelection`) and writes the `.plt` file(s), asking for a
|
||||
path when there is none (one per artboard with Use Artboards). A canceled save dialog writes nothing and keeps the
|
||||
options remembered before; a save dialog shown in line (not as a sheet or off the UI thread) also keeps HP-GL
|
||||
Options open.
|
||||
Options open. When another document has become the active one since the dialog opened, `ui.dialog.confirm` closes
|
||||
it and writes nothing.
|
||||
|
||||
TIFF, BMP and Targa Options: Export As… with the TIFF, BMP or Targa format (`file.exportAs {format: "tiff"}`, then
|
||||
the save dialog) opens `tiffOptions`, `bmpOptions` or `tgaOptions`: the raster rows of PNG Options (`ppi`,
|
||||
|
||||
+2
-1
@@ -10406,7 +10406,8 @@ its color, remove it or add one), Draw the Nearest Path Next (`sortPaths`) and D
|
||||
artboards, the bounds of the art, or the selection with Export Selection or Export Selected Art Only), or one black
|
||||
pen when that art draws nothing. When the export refuses the options or the artboard choice, One Pen per Color stays
|
||||
chosen and the dialog shows why. OK checks the options and the artboard choice, and remembers the options for the
|
||||
next export; a canceled save panel writes nothing and keeps the options remembered before.
|
||||
next export; a canceled save panel writes nothing and keeps the options remembered before. When another document has
|
||||
become the active one since the dialog opened, OK closes it and writes nothing.
|
||||
|
||||
## TIFF, BMP and Targa export
|
||||
|
||||
|
||||
Reference in new issue
Block a user