mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 21:29:35 +00:00
Scripts: guide, layer, move and addDocument fixes for the object model
- Document.selection and PageItem.selected refuse a path made into a guide while Lock Guides is on, instead of passing the check and then selecting nothing. The locked artboards are measured once per assignment. - An edit whose command selects the objects it changes puts the current layer and the highlighted Layers panel rows back as they were. layer.setCurrent takes keepRows, which leaves the highlighted rows as they are. - move on an object on a locked artboard throws Cannot move, as editable reads false for it. duplicate, with or without a relative object, on a hidden or locked object or an object on a locked artboard throws Cannot duplicate and makes no copy. - When move takes the last path out of a compound path, the empty compound path is deleted in the same undo step. - addDocument writes each warning from reading the profile's file to the Script Console as addDocument: <warning>, and a previewMode of PixelPreview throws an error that says it is not available yet.
This commit is contained in:
@@ -66,7 +66,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Set Current Layer",
|
||||
[],
|
||||
None,
|
||||
"{id} click a row: it alone is highlighted, and the layer it is (or the layer it is in) becomes the current layer, where new art goes. Not an undo step → {id, layer}",
|
||||
"{id, keepRows?: bool} click a row: it alone is highlighted, and the layer it is (or the layer it is in) becomes the current layer, where new art goes. `keepRows` true leaves the highlighted rows as they are. Not an undo step → {id, layer}",
|
||||
has_doc,
|
||||
set_current
|
||||
),
|
||||
@@ -633,10 +633,13 @@ fn duplicate_rows(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
fn set_current(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
const C: &str = "layer.setCurrent";
|
||||
let id = object_param(p, "id", C)?.ok_or_else(|| bad(C, "missing id"))?;
|
||||
let keep_rows = switch_or(p, "keepRows", false, C)?;
|
||||
let st = s.doc_mut()?;
|
||||
let layer = st.doc.layer_containing(id).ok_or(EngineError::NoNode(id))?;
|
||||
st.active_layer = Some(layer);
|
||||
st.layer_rows = vec![id];
|
||||
if !keep_rows {
|
||||
st.layer_rows = vec![id];
|
||||
}
|
||||
st.revision += 1;
|
||||
Ok(json!({ "id": id.0, "layer": layer.0 }))
|
||||
}
|
||||
|
||||
@@ -583,6 +583,31 @@ fn done_unless_refused(r: std::result::Result<Data, HostError>) -> std::result::
|
||||
}
|
||||
}
|
||||
|
||||
/// Makes `layer` the current layer of the active document `uid` again, with `rows` the highlighted
|
||||
/// Layers panel rows, after selecting objects made the layer of the last of them current and
|
||||
/// cleared the rows. Nothing runs when `layer` is gone. `layer.highlight` puts the rows back when
|
||||
/// they changed, and then `layer.setCurrent` with `keepRows` makes `layer` current when it is not.
|
||||
fn restore_layer(h: &Host, uid: u64, layer: Option<NodeId>, rows: &[NodeId]) -> std::result::Result<(), HostError> {
|
||||
let Some(layer) = layer else { return Ok(()) };
|
||||
let rows = {
|
||||
let s = h.session.borrow();
|
||||
let Some(st) = s.active().filter(|st| st.uid == uid) else { return Ok(()) };
|
||||
if st.doc.node(layer).is_none() {
|
||||
return Ok(());
|
||||
}
|
||||
let rows: Vec<NodeId> = rows.iter().copied().filter(|r| st.doc.node(*r).is_some()).collect();
|
||||
(st.highlighted_rows() != rows).then(|| rows.iter().map(|r| r.0).collect::<Vec<_>>())
|
||||
};
|
||||
if let Some(rows) = rows {
|
||||
command(h, "layer.highlight", &json!({"ids": rows, "mode": "set"}))?;
|
||||
}
|
||||
let current = h.session.borrow().active().is_some_and(|st| st.active_layer == Some(layer));
|
||||
if !current {
|
||||
command(h, "layer.setCurrent", &json!({"id": layer.0, "keepRows": true}))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Runs `f` with the document `uid` active, and makes the document that was active before active
|
||||
/// again after. With `keep_selection`, the document's selection is put back as it was when `f`'s
|
||||
/// commands changed it (commands given ids select them first), direct-selected anchors, segments,
|
||||
@@ -595,10 +620,11 @@ fn on_doc<T>(
|
||||
keep_selection: bool,
|
||||
f: impl FnOnce(&Host) -> std::result::Result<T, HostError>,
|
||||
) -> std::result::Result<T, HostError> {
|
||||
let (index, active, before) = {
|
||||
let (index, active, before, layer) = {
|
||||
let s = h.session.borrow();
|
||||
let index = s.documents().iter().position(|d| d.uid == uid).ok_or_else(|| HostError::Error(STALE_DOCUMENT.into()))?;
|
||||
(index, s.active_index(), s.documents()[index].selection.clone())
|
||||
let st = &s.documents()[index];
|
||||
(index, s.active_index(), st.selection.clone(), (st.active_layer, st.highlighted_rows()))
|
||||
};
|
||||
let switch = active != Some(index);
|
||||
if switch {
|
||||
@@ -614,6 +640,9 @@ fn on_doc<T>(
|
||||
if let Some(doc) = doc {
|
||||
restored = restore_selection(h, &doc, &before);
|
||||
}
|
||||
if restored.is_ok() {
|
||||
restored = restore_layer(h, uid, layer.0, &layer.1);
|
||||
}
|
||||
}
|
||||
// The document that was active is active again before any error is given: `f`'s error first,
|
||||
// then the selection's, then the switch back's.
|
||||
@@ -854,7 +883,10 @@ impl NewDoc<'_> {
|
||||
if let Some(d) = self.preview {
|
||||
let mode = match d {
|
||||
Data::String(s) if s == "DocumentPreviewMode.DefaultPreview" => "default",
|
||||
Data::String(s) if s == "DocumentPreviewMode.PixelPreview" => "pixel",
|
||||
// Pixel Preview is a setting of the app's view, which a script cannot turn on.
|
||||
Data::String(s) if s == "DocumentPreviewMode.PixelPreview" => {
|
||||
return Err(HostError::Error("DocumentPreviewMode.PixelPreview is not available yet".into()));
|
||||
}
|
||||
Data::String(s) if s == "DocumentPreviewMode.OverprintPreview" => "overprint",
|
||||
_ => return Err(HostError::Type("previewMode must be a DocumentPreviewMode value".into())),
|
||||
};
|
||||
@@ -981,6 +1013,10 @@ fn docs_add_document(h: &Host, a: &[Data]) -> Answer {
|
||||
let reason = e["reason"].as_str().unwrap_or_default();
|
||||
return Err(HostError::Error(format!("the New Document profile {profile} could not be read: {reason}")));
|
||||
}
|
||||
// Each warning from reading the profile's file goes to the console.
|
||||
for w in value.get("warnings").and_then(Value::as_array).into_iter().flatten().filter_map(Value::as_str) {
|
||||
super::each_line(&format!("addDocument: {w}"), |line, cut| h.line(super::console::Entry::Log(line), cut));
|
||||
}
|
||||
let s = h.session.borrow();
|
||||
let st = s.active().ok_or_else(|| HostError::Error(NO_ACTIVE_DOCUMENT.into()))?;
|
||||
Ok(doc_ref(h, st.uid))
|
||||
@@ -1203,10 +1239,16 @@ fn selection_ids(h: &Host, doc: Doc, v: &Data) -> std::result::Result<Vec<NodeId
|
||||
d => vec![d],
|
||||
};
|
||||
let mut ids: Vec<NodeId> = Vec::with_capacity(list.len());
|
||||
for d in list {
|
||||
let item = item_of(h, d)?;
|
||||
// The document is read once for every object: nothing changes it while the list is checked.
|
||||
let (d, isolation, guides_locked) = with_doc(h, doc, |s, st| (st.doc.clone(), st.isolation, s.guides_locked()));
|
||||
let locks = d.locked_artboards();
|
||||
for v in list {
|
||||
let item = item_of(h, v)?;
|
||||
// A path made into a guide is not selected while Lock Guides is on, as the selection
|
||||
// commands leave it out.
|
||||
let ok = item.doc.uid == doc.uid
|
||||
&& with_doc(h, doc, |_, st| crate::cmd::select::is_selectable(&st.doc, st.isolation, &st.doc.locked_artboards(), item.id));
|
||||
&& crate::cmd::select::is_selectable(&d, isolation, &locks, item.id)
|
||||
&& !(guides_locked && crate::is_guide_path(&d, item.id));
|
||||
if !ok {
|
||||
let name = with_doc(h, item.doc, |_, st| st.doc.node(item.id).and_then(typename).unwrap_or("page item"));
|
||||
return Err(HostError::Error(format!("Cannot select {name} {}", item.id.0)));
|
||||
@@ -1689,7 +1731,8 @@ fn destination(h: &Host, item: Item, target: &Data, how: &Data, copy: bool) -> s
|
||||
if !editable(d, parent) {
|
||||
return Err(HostError::Error("the layer or group is hidden or locked".into()));
|
||||
}
|
||||
if !editable(d, item.id) {
|
||||
// An object on a locked artboard is not moved, as `editable` reads false for it.
|
||||
if !editable(d, item.id) || on_locked_artboard(h, st, item.id) {
|
||||
let name = d.node(item.id).and_then(typename).unwrap_or("page item");
|
||||
return Err(HostError::Error(format!("Cannot move {name} {}", item.id.0)));
|
||||
}
|
||||
@@ -1730,14 +1773,30 @@ fn place(h: &Host, doc: Doc, id: NodeId, to: &Destination) -> std::result::Resul
|
||||
}
|
||||
|
||||
/// `move(relativeObject, insertionLocation?)`: moves the item into or beside `relativeObject`, a
|
||||
/// page item or a layer of its document (`insertionLocation` defaults to `PLACEATBEGINNING`).
|
||||
/// page item or a layer of its document (`insertionLocation` defaults to `PLACEATBEGINNING`). An
|
||||
/// object that is hidden or locked, in a hidden or locked layer or group, or on a locked artboard
|
||||
/// is refused.
|
||||
fn item_move(h: &Host, a: &[Data]) -> Answer {
|
||||
let item = this_item(h, a)?;
|
||||
if matches!(arg(a, 1), Data::Undefined) {
|
||||
return Err(HostError::Type("move needs a relative object".into()));
|
||||
}
|
||||
let to = destination(h, item, arg(a, 1), arg(a, 2), false)?;
|
||||
place(h, item.doc, item.id, &to)?;
|
||||
// When the last path leaves a compound path, the compound path is deleted in the same step
|
||||
// rather than left empty.
|
||||
let emptied = with_doc(h, item.doc, |_, st| {
|
||||
let parent = st.doc.parent_of(item.id).and_then(|p| st.doc.node(p))?;
|
||||
(matches!(parent.kind, NodeKind::Compound { .. }) && parent.children().is_some_and(|c| c.len() == 1) && parent.id != to.parent)
|
||||
.then_some(parent.id)
|
||||
});
|
||||
match emptied {
|
||||
None => place(h, item.doc, item.id, &to)?,
|
||||
Some(compound) => atomically(h, |h| {
|
||||
place(h, item.doc, item.id, &to)?;
|
||||
on_doc(h, item.doc.uid, true, |h| command(h, "edit.clear", &json!({"ids": [compound.0]})))?;
|
||||
Ok(())
|
||||
})?,
|
||||
}
|
||||
Ok(arg(a, 0).clone())
|
||||
}
|
||||
|
||||
@@ -1761,6 +1820,13 @@ fn item_duplicate(h: &Host, a: &[Data]) -> Answer {
|
||||
if in_compound(h, item) {
|
||||
return Err(HostError::Error(COMPOUND_MEMBER.into()));
|
||||
}
|
||||
// `edit.duplicate` copies only what it can select.
|
||||
let refused = with_doc(h, item.doc, |_, st| {
|
||||
(!editable(&st.doc, item.id) || on_locked_artboard(h, st, item.id)).then(|| st.doc.node(item.id).and_then(typename).unwrap_or("page item"))
|
||||
});
|
||||
if let Some(name) = refused {
|
||||
return Err(HostError::Error(format!("Cannot duplicate {name} {}", item.id.0)));
|
||||
}
|
||||
let to = match arg(a, 1) {
|
||||
Data::Undefined => {
|
||||
if !matches!(arg(a, 2), Data::Undefined) {
|
||||
|
||||
@@ -157,6 +157,13 @@ fn clicking_rows_at_any_depth_highlights_them_and_sets_the_current_layer() {
|
||||
let n = rect(&mut s, 50.0);
|
||||
assert_eq!(parent(&s, n), Some(sub));
|
||||
assert!(s.execute("layer.setCurrent", &json!({"id": 9999})).is_err());
|
||||
// `keepRows` makes the layer current and leaves the highlighted rows.
|
||||
run(&mut s, "layer.setCurrent", json!({"id": b.0}));
|
||||
run(&mut s, "layer.setCurrent", json!({"id": c.0, "keepRows": true}));
|
||||
let st = s.doc().unwrap();
|
||||
assert_eq!((st.highlighted_rows(), st.current_layer()), (vec![b], Some(layer)));
|
||||
assert!(s.execute("layer.setCurrent", &json!({"id": a.0, "keepRows": 1})).is_err());
|
||||
assert_eq!(s.doc().unwrap().current_layer(), Some(layer), "a bad keepRows changes nothing");
|
||||
// Shift/Ctrl: several rows.
|
||||
run(&mut s, "layer.highlight", json!({"ids": [a.0, g.0], "mode": "set"}));
|
||||
run(&mut s, "layer.highlight", json!({"ids": [c.0], "mode": "add"}));
|
||||
|
||||
@@ -265,6 +265,25 @@ fn selection_assignment_is_atomic_across_invalid_items() {
|
||||
assert!(e.contains("Cannot select"), "{e}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_guide_path_is_not_selected_while_guides_are_locked() {
|
||||
let (mut s, a, b) = doc();
|
||||
s.execute("select.set", &json!({"ids": [a.0]})).unwrap();
|
||||
s.execute("view.guides.make", &json!({})).unwrap();
|
||||
s.execute("select.set", &json!({"ids": [b.0]})).unwrap();
|
||||
s.execute("view.guides.lock", &json!({"locked": true})).unwrap();
|
||||
// The assignment and `selected` refuse the guide path, and the selection stays as it was.
|
||||
for source in ["app.activeDocument.selection = app.activeDocument.pageItems[0];", "app.activeDocument.pageItems[0].selected = true;"] {
|
||||
let e = failure(&mut s, source);
|
||||
assert!(e.contains(&format!("Cannot select PathItem {}", a.0)), "{source}: {e}");
|
||||
assert_eq!(s.active().unwrap().selection.objects, vec![b], "{source}");
|
||||
}
|
||||
// With the guides unlocked, the guide path is selected.
|
||||
s.execute("view.guides.lock", &json!({"locked": false})).unwrap();
|
||||
log(&mut s, "app.activeDocument.selection = app.activeDocument.pageItems[0];");
|
||||
assert_eq!(s.active().unwrap().selection.objects, vec![a]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_inactive_document_changes_without_switching_tabs() {
|
||||
let (mut s, a, _) = doc();
|
||||
@@ -454,6 +473,30 @@ fn a_path_inside_a_compound_path_is_not_reordered() {
|
||||
assert_eq!(out, vec![json!([1, 2])]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn moving_the_last_path_out_of_a_compound_path_deletes_the_compound_path() {
|
||||
let (mut s, a, b) = doc();
|
||||
s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap();
|
||||
s.execute("object.compoundPath.make", &json!({})).unwrap();
|
||||
let compound = layer_order(&s)[0];
|
||||
let layer = s.active().unwrap().doc.layers[0].id;
|
||||
let steps = undo_steps(&s);
|
||||
let out = log(
|
||||
&mut s,
|
||||
"var d = app.activeDocument, c = d.pageItems[0], m = [d.pageItems[1], d.pageItems[2]];\
|
||||
m[0].move(c, ElementPlacement.PLACEBEFORE); vc.log(d.pageItems.length);\
|
||||
m[1].move(c, ElementPlacement.PLACEBEFORE); vc.log(d.pageItems.length);\
|
||||
try { c.name; } catch (e) { vc.log(e.message); }",
|
||||
);
|
||||
assert_eq!(out, vec![json!(3), json!(2), json!("Stale page item")]);
|
||||
let doc = &s.active().unwrap().doc;
|
||||
assert!(doc.node(compound).is_none(), "the empty compound path is deleted");
|
||||
// Each path went directly above the compound path, the second above the first.
|
||||
assert_eq!(layer_order(&s), [b, a]);
|
||||
assert!([a, b].iter().all(|id| doc.parent_of(*id) == Some(layer)));
|
||||
assert_eq!(undo_steps(&s), steps + 1, "the run is one undo step");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_copy_of_an_object_with_a_large_id_is_the_copy() {
|
||||
let mut s = Session::new();
|
||||
@@ -610,6 +653,37 @@ fn an_edit_keeps_a_layers_panel_target() {
|
||||
assert_eq!((sel.target, sel.objects.len(), sel.objects.contains(&b)), (Some(layer), 4, true));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_edit_keeps_the_current_layer() {
|
||||
let (mut s, a, b) = doc();
|
||||
let first = s.active().unwrap().doc.layers[0].id;
|
||||
let back = NodeId(s.execute("layer.new", &json!({})).unwrap()["id"].as_u64().unwrap());
|
||||
let layer = |s: &Session| (s.active().unwrap().active_layer, s.active().unwrap().highlighted_rows());
|
||||
assert_eq!(layer(&s), (Some(back), vec![back]));
|
||||
// Moving an object of the first layer selects it for the command; the new layer stays current.
|
||||
log(&mut s, "app.activeDocument.pageItems[0].left = 50;");
|
||||
assert_eq!(layer(&s), (Some(back), vec![back]));
|
||||
assert_eq!(s.active().unwrap().selection.objects, vec![b]);
|
||||
// With nothing selected and no row highlighted, the layer stays current and no row is highlighted.
|
||||
s.execute("select.none", &json!({})).unwrap();
|
||||
s.execute("layer.setCurrent", &json!({"id": back.0})).unwrap();
|
||||
s.execute("layer.highlight", &json!({"ids": [], "mode": "set"})).unwrap();
|
||||
assert_eq!(layer(&s), (Some(back), vec![]));
|
||||
log(&mut s, "app.activeDocument.pageItems[1].left = 120;");
|
||||
assert_eq!(layer(&s), (Some(back), vec![]));
|
||||
assert!(s.active().unwrap().selection.objects.is_empty());
|
||||
// Targeting a layer makes it current and leaves another layer's row highlighted; both stay.
|
||||
s.execute("layer.highlight", &json!({"ids": [first.0], "mode": "set"})).unwrap();
|
||||
s.execute("layer.target", &json!({"id": back.0})).unwrap();
|
||||
assert_eq!(layer(&s), (Some(back), vec![first]));
|
||||
log(&mut s, "app.activeDocument.pageItems[0].left = 70;");
|
||||
assert_eq!(layer(&s), (Some(back), vec![first]));
|
||||
// Assigning the selection makes the layer of the selected object current, as a click does.
|
||||
log(&mut s, "app.activeDocument.selection = app.activeDocument.pageItems[0];");
|
||||
assert_eq!(s.active().unwrap().active_layer, Some(first));
|
||||
assert_eq!(s.active().unwrap().selection.objects, vec![a]);
|
||||
}
|
||||
|
||||
/// A document with a rectangle at the bottom of the stack, then a dynamic symbol instance of two
|
||||
/// rectangles and an Objects on Path group of one rectangle: (session, instance, group, the
|
||||
/// group's rectangle).
|
||||
@@ -949,6 +1023,43 @@ fn add_document_applies_the_profile_file_and_throws_when_it_cannot_be_read() {
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_document_names_a_color_profile_of_the_profile_file_that_cannot_be_used() {
|
||||
let dir = std::env::temp_dir().join(format!("vc-script-add-document-warning-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
let mut s = Session::new();
|
||||
s.attach_new_doc_profiles(dir.clone());
|
||||
s.execute("file.newProfiles.edit", &json!({"name": "Print"})).unwrap();
|
||||
while !s.documents().is_empty() {
|
||||
s.execute("file.close", &json!({})).unwrap();
|
||||
}
|
||||
let file = dir.join("Print.vectorcraft");
|
||||
let mut v: Value = serde_json::from_slice(&std::fs::read(&file).unwrap()).unwrap();
|
||||
let broken = format!("Script profile broken {}", std::process::id());
|
||||
v["profiles"] = json!({ &broken: {"mime": "application/vnd.iccprofile", "data": "AAAA"} });
|
||||
std::fs::write(&file, serde_json::to_vec(&v).unwrap()).unwrap();
|
||||
let r = run(&mut s, "vc.log(app.documents.addDocument('Print').typename);").unwrap();
|
||||
assert_eq!(r["log"], json!(["Document"]));
|
||||
let lines = r["console"]["lines"].as_array().cloned().unwrap_or_default();
|
||||
let named = lines.iter().filter_map(Value::as_str).any(|l| l.starts_with("addDocument: ") && l.contains(&broken));
|
||||
assert!(named, "{lines:?}");
|
||||
assert_eq!(s.documents().len(), 1);
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_document_refuses_pixel_preview() {
|
||||
let mut s = Session::new();
|
||||
let e = failure(&mut s, "var p = new DocumentPreset(); p.previewMode = DocumentPreviewMode.PixelPreview; app.documents.addDocument('Web', p);");
|
||||
assert!(e.contains("DocumentPreviewMode.PixelPreview is not available yet"), "{e}");
|
||||
assert!(s.documents().is_empty());
|
||||
let out = log(
|
||||
&mut s,
|
||||
"var p = new DocumentPreset(); p.previewMode = DocumentPreviewMode.DefaultPreview; vc.log(app.documents.addDocument('Web', p).typename);",
|
||||
);
|
||||
assert_eq!(out, vec![json!("Document")]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn document_preset_values_count_toward_the_data_a_run_passes() {
|
||||
// A 64 KiB title, set once, then read or handed to addDocument 32 times: 2 MiB, over a 1 MiB limit.
|
||||
@@ -1061,6 +1172,55 @@ fn remove_and_remove_all_refuse_art_on_a_locked_artboard() {
|
||||
assert_eq!(out, vec![json!(0)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn move_and_duplicate_refuse_art_on_a_locked_artboard() {
|
||||
let (mut s, a, b) = doc();
|
||||
let lock = |s: &mut Session, locked: bool| {
|
||||
s.edit("Lock Artboard", |d, _| {
|
||||
d.artboards[0].locked = locked;
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
};
|
||||
lock(&mut s, true);
|
||||
let (order, steps) = (layer_order(&s), undo_steps(&s));
|
||||
let e = failure(&mut s, "var p = app.activeDocument.pageItems; p[0].move(p[1], ElementPlacement.PLACEBEFORE);");
|
||||
assert!(e.contains(&format!("Cannot move PathItem {}", a.0)), "{e}");
|
||||
assert_eq!((layer_order(&s), undo_steps(&s)), (order.clone(), steps));
|
||||
// `duplicate` refuses it too, with or without a relative object.
|
||||
for source in ["app.activeDocument.pageItems[0].duplicate();", "var p = app.activeDocument.pageItems; p[0].duplicate(p[1]);"] {
|
||||
let e = failure(&mut s, source);
|
||||
assert!(e.contains(&format!("Cannot duplicate PathItem {}", a.0)), "{source}: {e}");
|
||||
}
|
||||
assert_eq!((layer_order(&s), undo_steps(&s)), (order, steps));
|
||||
lock(&mut s, false);
|
||||
log(&mut s, "var p = app.activeDocument.pageItems; p[0].move(p[1], ElementPlacement.PLACEBEFORE);");
|
||||
assert_eq!(layer_order(&s), [b, a]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn duplicate_refuses_hidden_or_locked_art() {
|
||||
let (mut s, a, b) = doc();
|
||||
for (on, off) in [
|
||||
(json!({"ids": [b.0], "locked": true}), json!({"ids": [b.0], "locked": false})),
|
||||
(json!({"ids": [b.0], "visible": false}), json!({"ids": [b.0], "visible": true})),
|
||||
] {
|
||||
s.execute("object.setProps", &on).unwrap();
|
||||
let (order, steps) = (layer_order(&s), undo_steps(&s));
|
||||
// With no argument and with a relative object.
|
||||
for source in ["app.activeDocument.pageItems[1].duplicate();", "var p = app.activeDocument.pageItems; p[1].duplicate(p[0]);"] {
|
||||
let e = failure(&mut s, source);
|
||||
assert!(e.contains(&format!("Cannot duplicate PathItem {}", b.0)), "{on} {source}: {e}");
|
||||
}
|
||||
assert_eq!((layer_order(&s), undo_steps(&s)), (order, steps), "{on}");
|
||||
s.execute("object.setProps", &off).unwrap();
|
||||
}
|
||||
log(&mut s, "app.activeDocument.pageItems[1].duplicate();");
|
||||
let order = layer_order(&s);
|
||||
assert_eq!(order.len(), 3);
|
||||
assert!(order.contains(&a) && order.contains(&b));
|
||||
}
|
||||
|
||||
/// Reading `editable` on every member of a group on a locked artboard measures the group once.
|
||||
#[test]
|
||||
fn editable_measures_a_group_on_a_locked_artboard_once() {
|
||||
|
||||
+14
-6
@@ -2637,7 +2637,9 @@ app through the global object `vc`, and writes to the Script Console and runs ot
|
||||
`presetSettings` that is not a `DocumentPreset` (a plain object such as `{width: 500}` included) throws a
|
||||
`TypeError`. A script's `file.new` reads the profile's file in the profiles folder as the person's does, under the
|
||||
automation roots in force; when `file.new` reports a `profileError`, `addDocument` throws an error that names the
|
||||
profile and the reason, and makes no document.
|
||||
profile and the reason, and makes no document. Each warning from reading the profile's file (a color profile in it
|
||||
that cannot be used, for example) goes to the Script Console as a line `addDocument: <warning>`. A `previewMode` of
|
||||
`DocumentPreviewMode.PixelPreview` throws an error that says it is not available yet, and no document is made.
|
||||
`showOptionsDialog` true throws `Dialog unavailable` with no document made. A `Document` (https://ai-scripting.docsforadobe.dev/jsobjref/Document/) has `name`,
|
||||
`width`, `height`, `rulerUnits`, `documentColorSpace`, `rulerOrigin`, `convertCoordinate(point, source,
|
||||
destination)`, `pageItems` and `selection`. `pageItems` (https://ai-scripting.docsforadobe.dev/jsobjref/PageItems/)
|
||||
@@ -2657,7 +2659,10 @@ app through the global object `vc`, and writes to the Script Console and runs ot
|
||||
group's contents, `PLACEATEND` under them, `PLACEBEFORE` directly above the relative object and `PLACEAFTER`
|
||||
directly below it. An object of another document throws `Cross-document placement is not available`, and when
|
||||
`node.move` refuses the place of a copy, `duplicate` throws that error and leaves the documents, the selection and
|
||||
the undo history as they were before the call. `duplicate` on a path inside a compound path throws
|
||||
the undo history as they were before the call. `move` on an object that is hidden or locked, inside a hidden or
|
||||
locked layer or group, or on a locked artboard throws `Cannot move` and moves nothing. `duplicate` on such an
|
||||
object, with or without a relative object, throws `Cannot duplicate` and makes no copy. When `move` takes the last
|
||||
path out of a compound path, the empty compound path is deleted in the same undo step. `duplicate` on a path inside a compound path throws
|
||||
`Duplicating a path inside a compound path is not available yet`, and `zOrder` on one throws
|
||||
`Reordering a path inside a compound path is not available yet` and leaves the document unchanged. A script that holds a placed image keeps the
|
||||
same object when the image is embedded: the next read gives that object, now a `RasterItem`. The
|
||||
@@ -2671,7 +2676,8 @@ app through the global object `vc`, and writes to the Script Console and runs ot
|
||||
is `TextFrame` for type, and `BlendItem`, `EnvelopeItem`, `RepeatItem`, `PlacedDocumentItem` and `IntertwineItem`
|
||||
for kinds the help pages give no class. Each change runs a command and joins the run's one undo step for each
|
||||
changed document. A value that changes nothing runs no command, and a change to another document leaves the active
|
||||
tab as it was. A bad value throws an error and changes nothing. An object that was deleted, or that a named engine
|
||||
tab as it was. A command that selects the objects it changes leaves the current layer and the highlighted Layers
|
||||
panel rows as they were before the change. A bad value throws an error and changes nothing. An object that was deleted, or that a named engine
|
||||
kept from an earlier run, throws `Stale page item`. `remove()` on an object that is hidden or locked, is inside a
|
||||
hidden or locked layer or group, or is a group that holds one, and `removeAll()` when any object is, throw
|
||||
`cannot delete hidden or locked objects` and delete nothing. `remove()` on an object on a locked artboard, and `removeAll()`
|
||||
@@ -2680,7 +2686,8 @@ app through the global object `vc`, and writes to the Script Console and runs ot
|
||||
`Not found`; and
|
||||
`app.activeDocument` with no document open throws `No active document`. `Document.selection` takes one page item,
|
||||
a list of at most 10,000, `null` or `[]`, and an object that cannot be selected throws `Cannot select` with
|
||||
nothing changed. `getIsFileOpen` compares the path with the open documents' files as text (in a Windows path,
|
||||
nothing changed. While View › Guides › Lock Guides is on, a path made into a guide cannot be selected this way or
|
||||
with `selected`. `getIsFileOpen` compares the path with the open documents' files as text (in a Windows path,
|
||||
letter case is ignored and `\` matches `/`) and does not resolve the path it is given. A document counts only when
|
||||
the automation read roots allow its file, and that check can look the document's file up on disk. A path with
|
||||
`..`, a network path, a NUL character or more than 4,096 bytes throws an error. Some members the Application,
|
||||
@@ -6363,8 +6370,9 @@ itself, and each sublayer has its own colour for the selection highlight. `docum
|
||||
report `color`, `template`, `printable`, `preview`, `dimImages` and `clip`), the `currentLayer` (where new art goes)
|
||||
and `layerRows`, the rows highlighted in the panel.
|
||||
|
||||
- **Clicking rows** (not undo steps): `layer.setCurrent {id}` is a plain click on any row: it alone is highlighted
|
||||
and its layer (the row itself when it is a layer or sublayer) becomes current. `layer.highlight {ids, mode?:
|
||||
- **Clicking rows** (not undo steps): `layer.setCurrent {id, keepRows?}` is a plain click on any row: it alone is
|
||||
highlighted and its layer (the row itself when it is a layer or sublayer) becomes current; with `keepRows` true the
|
||||
highlighted rows stay as they are. `layer.highlight {ids, mode?:
|
||||
set|add|toggle}` is Shift-click (a range) and Ctrl/Cmd-click (toggle). Selecting art makes its layer current.
|
||||
Without `ids`, the panel commands below act on the highlighted rows, else on the current layer.
|
||||
- **Selection column**: `layer.selectAll {id, add?}` selects a row's visible, unlocked art (a layer's sublayers'
|
||||
|
||||
Reference in New Issue
Block a user