mirror of
https://github.com/storytold/deckcraft.git
synced 2026-12-02 22:30:34 +00:00
Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f10e820dd6 | ||
|
|
dd11c26ce0 | ||
|
|
deed5990f8 | ||
|
|
d5c1d46c29 | ||
|
|
0cae0572e5 | ||
|
|
a22a9b75bc |
@@ -234,7 +234,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Change Layout",
|
||||
["Diagram Design", "Layouts"],
|
||||
None,
|
||||
"{id?, kind: list|blockList|hBulletList|process|chevron|verticalProcess|stepUp|cycle|blockCycle|radial|hierarchy|pyramid|invertedPyramid|matrix|titledMatrix|pictureList|pictureCaption|pictureProcess|pictureHList|timeline|venn|target|textCycle|continuousCycle|horizontalHierarchy|gridMatrix|gear|funnel|segmentedCycle|multidirectionalCycle|orgChart|halfCircleOrgChart|cycleMatrix|segmentedPyramid|pie|nameTitleOrgChart|verticalBoxList|trapezoidList|tableList|accentProcess|continuousBlockProcess|bendingProcess|linearVenn|stackedVenn|nestedTarget}",
|
||||
"{id?, kind: list|blockList|hBulletList|process|chevron|verticalProcess|stepUp|cycle|blockCycle|radial|hierarchy|pyramid|invertedPyramid|matrix|titledMatrix|pictureList|pictureCaption|pictureProcess|pictureHList|timeline|venn|target|textCycle|continuousCycle|horizontalHierarchy|gridMatrix|gear|funnel|segmentedCycle|multidirectionalCycle|orgChart|halfCircleOrgChart|cycleMatrix|segmentedPyramid|pie|nameTitleOrgChart|verticalBoxList|trapezoidList|tableList|accentProcess|continuousBlockProcess|bendingProcess|linearVenn|stackedVenn|nestedTarget} → {id, ids: the regenerated shapes}",
|
||||
has_diagram,
|
||||
change_layout
|
||||
),
|
||||
@@ -279,7 +279,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Diagram Styles",
|
||||
["Diagram Design", "Diagram Styles"],
|
||||
None,
|
||||
"{id?, style: flat|subtle|intense|outline|polished|inset|cartoon|powder|brick}",
|
||||
"{id?, style: flat|subtle|intense|outline|polished|inset|cartoon|powder|brick} → {id, ids: the regenerated shapes}",
|
||||
has_diagram,
|
||||
change_style
|
||||
),
|
||||
@@ -288,7 +288,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Change Colors",
|
||||
["Diagram Design", "Diagram Styles"],
|
||||
None,
|
||||
"{id?, colors: colorful|range23|range34|range45|range56|accent1|…|accent6|accent1Grad|…|accent6Grad}",
|
||||
"{id?, colors: colorful|range23|range34|range45|range56|accent1|…|accent6|accent1Grad|…|accent6Grad} → {id, ids: the regenerated shapes}",
|
||||
has_diagram,
|
||||
change_colors
|
||||
),
|
||||
|
||||
@@ -339,33 +339,47 @@ pub(super) fn set_picture(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
})
|
||||
}
|
||||
|
||||
/// The answer of a command that regenerated a graphic's shapes: the group's id and its new children's ids.
|
||||
fn regenerated(s: &Session, gid: ShapeId) -> Value {
|
||||
let kids: Vec<u32> = match s.doc().ok().and_then(|st| st.shape(gid).map(|g| g.kind.clone())) {
|
||||
Some(ShapeKind::Group { children, .. }) => children.iter().map(|c| c.id.0).collect(),
|
||||
_ => vec![],
|
||||
};
|
||||
json!({"id": gid.0, "ids": kids})
|
||||
}
|
||||
|
||||
pub(super) fn change_style(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
const CMD: &str = "smartArt.style";
|
||||
let v = str_param(p, "style").filter(|k| STYLES.iter().any(|(id, _)| id == k)).ok_or_else(|| bad(CMD, "unknown style"))?.to_string();
|
||||
let gid = target_group(s, p, CMD)?;
|
||||
edit_diagram(s, p, CMD, |d| {
|
||||
if d.style != v {
|
||||
d.style_xml = None;
|
||||
}
|
||||
d.style = v;
|
||||
Ok(Value::Null)
|
||||
})
|
||||
})?;
|
||||
Ok(regenerated(s, gid))
|
||||
}
|
||||
|
||||
pub(super) fn change_colors(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
const CMD: &str = "smartArt.colors";
|
||||
let v = str_param(p, "colors").filter(|k| COLORS.iter().any(|(id, _)| id == k)).ok_or_else(|| bad(CMD, "unknown colours"))?.to_string();
|
||||
let gid = target_group(s, p, CMD)?;
|
||||
edit_diagram(s, p, CMD, |d| {
|
||||
if d.colors != v {
|
||||
d.colors_xml = None;
|
||||
}
|
||||
d.colors = v;
|
||||
Ok(Value::Null)
|
||||
})
|
||||
})?;
|
||||
Ok(regenerated(s, gid))
|
||||
}
|
||||
|
||||
pub(super) fn change_layout(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
const CMD: &str = "smartArt.layout";
|
||||
let kind = str_param(p, "kind").filter(|k| is_kind(k)).ok_or_else(|| bad(CMD, "unknown layout"))?.to_string();
|
||||
let gid = target_group(s, p, CMD)?;
|
||||
edit_diagram(s, p, CMD, |d| {
|
||||
if d.kind != kind {
|
||||
// PowerPoint's own layout no longer applies.
|
||||
@@ -374,5 +388,6 @@ pub(super) fn change_layout(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
d.kind = kind;
|
||||
Ok(Value::Null)
|
||||
})
|
||||
})?;
|
||||
Ok(regenerated(s, gid))
|
||||
}
|
||||
|
||||
@@ -7803,6 +7803,31 @@ fn save_to_image_path_is_an_error_not_zip_bytes() {
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn smartart_colors_layout_and_style_answer_the_regenerated_ids() {
|
||||
let mut s = session();
|
||||
let r = s.execute("insert.smartArt", &json!({"kind": "process"})).unwrap();
|
||||
let gid = r["id"].clone();
|
||||
for (cmd, params) in [
|
||||
("smartArt.colors", json!({"id": gid, "colors": "colorful"})),
|
||||
("smartArt.layout", json!({"id": gid, "kind": "cycle"})),
|
||||
("smartArt.style", json!({"id": gid, "style": "intense"})),
|
||||
] {
|
||||
let a = s.execute(cmd, ¶ms).unwrap();
|
||||
assert_eq!(a["id"], gid, "{cmd}: {a}");
|
||||
let st = s.doc().unwrap();
|
||||
let g = st
|
||||
.doc
|
||||
.slides
|
||||
.iter()
|
||||
.find_map(|sl| deckcraft_model::find_shape(&sl.shapes, deckcraft_model::ShapeId(gid.as_u64().unwrap() as u32)))
|
||||
.unwrap();
|
||||
let deckcraft_model::ShapeKind::Group { children, .. } = &g.kind else { panic!("group") };
|
||||
let kids: Vec<u32> = children.iter().map(|c| c.id.0).collect();
|
||||
assert_eq!(a["ids"], json!(kids), "{cmd}: {a}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unsupported_save_paths_are_refused_and_write_nothing() {
|
||||
let dir = std::env::temp_dir().join(format!("deckcraft-save-ext-{}", std::process::id()));
|
||||
|
||||
Reference in New Issue
Block a user