naming: use Diagram and Decorative Text labels

This commit is contained in:
FredApps committed 2026-11-08 21:39:00 +01:00
1 parent 4b0d399599
commit b66122f718
12 files changed
+86 -30

No files matched your search

+9 -9
View File
@@ -28,7 +28,7 @@ const ITEMS: &str = r#"[string | {"text": string, "level"?: 0-7, "color"?: RRGGB
pub fn specs() -> Vec<CommandSpec> {
vec![
CommandSpec::new("insert.smartArt", "SmartArt", "Insert › Illustrations", insert).params(
CommandSpec::new("insert.smartArt", "Diagram", "Insert › Illustrations", insert).params(
r#"{"layout"?: "basicList|process|cycle|hierarchy|pyramid|radial|matrix|venn", "items"?: [string | {"text": string, "level"?: 0-7, "color"?: RRGGBB}], "colors"?: "accent1…accent6|colorful", "width"?: pt, "height"?: pt} (no items: sample items for the layout)"#,
),
CommandSpec::new("smartArt.items", "Edit Items", "SmartArt Design › Create Graphic", |s, v| {
@@ -53,7 +53,7 @@ pub fn specs() -> Vec<CommandSpec> {
let below = p::bool(v, "below").unwrap_or(false);
edit(s, move |g| {
if g.items.len() >= MAX_ITEMS {
return Err(CmdError::Failed(format!("a SmartArt graphic holds at most {MAX_ITEMS} items")));
return Err(CmdError::Failed(format!("a diagram holds at most {MAX_ITEMS} items")));
}
let Some(last) = g.items.len().checked_sub(1) else {
g.items.push(SmartArtItem::new(text.clone(), 0));
@@ -120,7 +120,7 @@ pub fn specs() -> Vec<CommandSpec> {
})
.params(r#"{"layout": "basicList|process|cycle|hierarchy|pyramid|radial|matrix|venn"}"#)
.when(has_smart_art),
CommandSpec::new("smartArt.colors", "Change Colors", "SmartArt Design › SmartArt Styles", |s, v| {
CommandSpec::new("smartArt.colors", "Change Colors", "SmartArt Design › Diagram Styles", |s, v| {
let colors = colors_of(v)?.ok_or_else(|| CmdError::Params(format!("`variant` is required: {COLORS}")))?;
edit(s, move |g| {
g.colors = colors;
@@ -130,7 +130,7 @@ pub fn specs() -> Vec<CommandSpec> {
})
.params(r#"{"variant": "accent1|accent2|accent3|accent4|accent5|accent6|colorful"} (the items' own colours are dropped)"#)
.when(has_smart_art),
CommandSpec::new("smartArt.itemColor", "Item Color", "SmartArt Design › SmartArt Styles", |s, v| {
CommandSpec::new("smartArt.itemColor", "Item Color", "SmartArt Design › Diagram Styles", |s, v| {
let i = index(v, "index")?;
let color = match v.get("color") {
None | Some(Value::Null) => None,
@@ -174,9 +174,9 @@ fn has_smart_art(s: &Session) -> Option<&'static str> {
match selected(s) {
Some((_, InlineObject::Graphic { graphic, .. })) if graphic.smart_art.is_some() => None,
Some((_, InlineObject::Graphic { graphic, .. })) if graphic.kind == GraphicKind::Diagram => {
Some("this SmartArt was made in another program: WordCraft shows it but can't edit it")
Some("this diagram was made in another program: WordCraft shows it but can't edit it")
}
_ => Some("select a SmartArt graphic first"),
_ => Some("select a diagram first"),
}
}
@@ -299,9 +299,9 @@ fn insert(s: &mut Session, v: &Value) -> CmdResult {
/// Change the selected graphic's model with `f`, then lay it out again at its size.
fn edit(s: &mut Session, f: impl Fn(&mut SmartArtSpec) -> Result<(), CmdError>) -> CmdResult {
let (pos, obj) = selected(s).ok_or_else(|| CmdError::Disabled("select a SmartArt graphic first".into()))?;
let InlineObject::Graphic { w, h, graphic, .. } = obj else { return Err(CmdError::Disabled("select a SmartArt graphic first".into())) };
let mut spec = graphic.smart_art.as_deref().cloned().ok_or_else(|| CmdError::Disabled("this SmartArt graphic can't be edited".into()))?;
let (pos, obj) = selected(s).ok_or_else(|| CmdError::Disabled("select a diagram first".into()))?;
let InlineObject::Graphic { w, h, graphic, .. } = obj else { return Err(CmdError::Disabled("select a diagram first".into())) };
let mut spec = graphic.smart_art.as_deref().cloned().ok_or_else(|| CmdError::Disabled("this diagram can't be edited".into()))?;
f(&mut spec)?;
let next = Arc::new(smart_art_graphic(spec, &s.doc.settings.theme_colors, w, h));
let out = json!({"smartArt": next.smart_art.as_deref()});
+10 -10
View File
@@ -19,24 +19,24 @@ const EFFECT_PARAMS: &str = r#"{"style"?: "solid"|"outlined"|"hollow"|"gradient"
pub fn specs() -> Vec<CommandSpec> {
vec![
CommandSpec::new("insert.wordArt", "WordArt", "Insert › Text", insert).params(
r#"{"text"?: string, "style"?: WordArt style id (see format.textEffects), "transform"?: "textArchUp"|"textArchDown"|"textCircle"|"textWave1"|… (a DrawingML preset text warp)}"#,
CommandSpec::new("insert.wordArt", "Decorative Text", "Insert › Text", insert).params(
r#"{"text"?: string, "style"?: Decorative Text style id (see format.textEffects), "transform"?: "textArchUp"|"textArchDown"|"textCircle"|"textWave1"|… (a DrawingML preset text warp)}"#,
),
CommandSpec::new("format.textEffects", "Text Effects", "Home › Font", text_effects).params(EFFECT_PARAMS),
CommandSpec::new("wordArt.style", "WordArt Styles", "Shape Format › WordArt Styles", |s, v| {
CommandSpec::new("wordArt.style", "Decorative Text Styles", "Shape Format › Decorative Text Styles", |s, v| {
let id = p::req_str(v, "style")?;
text_effects(s, &json!({"style": id}))
})
.params(r#"{"style": "solid"|"outlined"|"hollow"|"gradient"|"shadowed"|"glowing"|"reflected"|"sunset"}"#),
CommandSpec::new("wordArt.textFill", "Text Fill", "Shape Format › WordArt Styles", |s, v| {
CommandSpec::new("wordArt.textFill", "Text Fill", "Shape Format › Decorative Text Styles", |s, v| {
text_effects(s, &json!({"fill": v.get("fill").or_else(|| v.get("color")).cloned().unwrap_or(Value::Null)}))
})
.params(r#"{"fill": "RRGGBB"|"none"|{"gradient": ["RRGGBB", …], "angle"?: deg}|null}"#),
CommandSpec::new("wordArt.textOutline", "Text Outline", "Shape Format › WordArt Styles", |s, v| {
CommandSpec::new("wordArt.textOutline", "Text Outline", "Shape Format › Decorative Text Styles", |s, v| {
text_effects(s, &json!({"outline": v.get("outline").cloned().unwrap_or_else(|| v.clone())}))
})
.params(r#"{"color"?: "RRGGBB"|null, "width"?: pt} or {"outline": "none"|null}"#),
CommandSpec::new("wordArt.transform", "Transform", "Shape Format › WordArt Styles", transform)
CommandSpec::new("wordArt.transform", "Transform", "Shape Format › Decorative Text Styles", transform)
.params(r#"{"preset": "textArchUp"|"textArchDown"|"textCircle"|"textWave1"|"textSlantUp"|"textSlantDown"|"textInflate"|"textDeflate"|"textChevron"|"textChevronInverted"|"textTriangle"|"textTriangleInverted"|… (any DrawingML preset text warp)|"none", "adj"?: n (the preset's adjust value)}"#),
]
}
@@ -186,7 +186,7 @@ fn text_effects(s: &mut Session, v: &Value) -> CmdResult {
let theme = theme(s);
let accent = theme.get(4).copied().unwrap_or(Rgb(0x15, 0x60, 0x82));
let style = match p::str(v, "style") {
Some(id) => Some(art_style(id, &theme).ok_or_else(|| CmdError::Params(format!("unknown WordArt style `{id}`")))?),
Some(id) => Some(art_style(id, &theme).ok_or_else(|| CmdError::Params(format!("unknown decorative text style `{id}`")))?),
None => None,
};
let clear = p::bool(v, "clear").unwrap_or(false);
@@ -244,11 +244,11 @@ fn transform(s: &mut Session, v: &Value) -> CmdResult {
Some(w)
}
};
let pos = warp_target(s).ok_or_else(|| CmdError::Disabled("select a shape or WordArt first".into()))?;
let pos = warp_target(s).ok_or_else(|| CmdError::Disabled("select a shape or decorative text first".into()))?;
let para = s.doc.para_mut(pos.story, &pos.path)?;
match para.object_at_mut(pos.off) {
Some(InlineObject::Shape { extra, .. }) => extra.warp = warp.clone(),
_ => return Err(CmdError::Disabled("select a shape or WordArt first".into())),
_ => return Err(CmdError::Disabled("select a shape or decorative text first".into())),
}
para.touch();
Ok(json!({"transform": warp.map(|w| w.preset)}))
@@ -269,7 +269,7 @@ fn insert(s: &mut Session, v: &Value) -> CmdResult {
let text: String = p::str(v, "text").unwrap_or("Your text here").chars().filter(|c| !c.is_control()).take(1000).collect();
let text = if text.trim().is_empty() { "Your text here".to_string() } else { text };
let style = p::str(v, "style").unwrap_or("solid");
let fx = art_style(style, &theme(s)).ok_or_else(|| CmdError::Params(format!("unknown WordArt style `{style}`")))?;
let fx = art_style(style, &theme(s)).ok_or_else(|| CmdError::Params(format!("unknown decorative text style `{style}`")))?;
let warp = match p::str(v, "transform") {
None | Some("none") => None,
Some(id) => Some(TextWarp::new(id).ok_or_else(|| CmdError::Params(format!("unknown text warp `{id}`")))?),
+9
View File
@@ -200,3 +200,12 @@ fn wordart_reflection_and_outline_none_options() {
assert_eq!(outline.color, None);
assert_eq!(outline.width, 1.5);
}
#[test]
fn descriptive_feature_labels_keep_existing_command_ids() {
let s = Session::new(Document::new());
for (id, label) in [("insert.smartArt", "Diagram"), ("insert.wordArt", "Decorative Text"), ("wordArt.style", "Decorative Text Styles")] {
assert_eq!(s.registry.get(id).map(|spec| spec.label), Some(label));
}
assert!(s.registry.get("smartArt.colors").unwrap().location.starts_with("SmartArt Design › "));
}
+1 -1
View File
@@ -54,7 +54,7 @@ impl InsertDialog {
InsertDialog::Columns(_) => "Columns",
InsertDialog::Symbol(_) => "Symbol",
InsertDialog::Field(_) => "Field",
InsertDialog::SmartArt(_) => "Insert SmartArt",
InsertDialog::SmartArt(_) => "Insert Diagram",
InsertDialog::ChartType(f) if f.change => "Change Chart Type",
InsertDialog::ChartType(_) => "Insert Chart",
InsertDialog::ChartData(_) => "Edit Data",
+10
View File
@@ -349,8 +349,15 @@ pub fn current() -> Lang {
CURRENT.get()
}
/// The contextual tab has an existing saved/control-channel identity. Keep it separate from
/// the source text displayed to users, so saved layouts and ui.tab calls keep working.
fn display_source(source: &str) -> &str {
if source == "SmartArt Design" { "Diagram Design" } else { source }
}
/// Does `lang` have a translation for this string? (English never does: it is the source.)
pub fn has(lang: Lang, s: &str) -> bool {
let s = display_source(s);
lang.i18n().get(lang.lang, "", s).is_some()
}
@@ -379,6 +386,7 @@ pub fn tc<'a>(context: &str, s: &'a str) -> &'a str {
/// [`tc`] in a given language.
pub fn trc<'a>(lang: Lang, context: &str, s: &'a str) -> &'a str {
let s = display_source(s);
#[cfg(test)]
if pseudo::on() {
return I18N.tc(craft_i18n::Lang::PSEUDO, context, s);
@@ -390,6 +398,7 @@ pub fn trc<'a>(lang: Lang, context: &str, s: &'a str) -> &'a str {
/// or English: for a word whose plain translation means something else here (the "Open"
/// paragraph-spacing preset is not the file verb).
pub fn get<'a>(context: &str, s: &'a str) -> Option<&'a str> {
let s = display_source(s);
#[cfg(test)]
if pseudo::on() {
return I18N.get(craft_i18n::Lang::PSEUDO, context, s);
@@ -419,6 +428,7 @@ pub fn lowercase(s: &str) -> String {
/// `s` in `lang`; strings without a translation come back unchanged.
pub fn tr(lang: Lang, s: &str) -> &str {
let s = display_source(s);
#[cfg(test)]
if pseudo::on() {
return I18N.t(craft_i18n::Lang::PSEUDO, s);
+16
View File
@@ -1299,3 +1299,19 @@ fn a_path_in_a_message_is_isolated_in_a_right_to_left_interface() {
set_current(Lang::EN);
assert_eq!(msg, "تعذر فتح \u{2066}C:\\\u{200E}ملفات\\\u{200E}تقرير\u{200E}.docx\u{2069}: \u{2068}bad\u{2069}");
}
#[test]
fn diagram_tab_display_keeps_the_legacy_identity() {
assert!(wordcraft_engine::ribbon::CONTEXTUAL_TABS.contains(&"SmartArt Design"));
assert_eq!(tr(Lang::EN, "SmartArt Design"), "Diagram Design");
assert_eq!(trc(Lang::EN, "preview", "SmartArt Design"), "Diagram Design");
assert_eq!(tr(Lang::EN, "Home"), "Home");
let fx = fixture_lang("x-fixture", "\tDiagram Design\tDiagram-FX\npreview\tDiagram Design\tDiagram-Preview-FX\n\tDiagram Styles\tStyles-FX\n");
assert!(has(fx, "SmartArt Design"));
assert_eq!(tr(fx, "SmartArt Design"), "Diagram-FX");
assert_eq!(trc(fx, "preview", "SmartArt Design"), "Diagram-Preview-FX");
set_current(fx);
assert_eq!(get("preview", "SmartArt Design"), Some("Diagram-Preview-FX"));
assert_eq!(location("SmartArt Design › Diagram Styles"), "Diagram-FX › Styles-FX");
set_current(Lang::EN);
}
+2 -2
View File
@@ -240,7 +240,7 @@ fn controls(tab: &str) -> Vec<Control> {
c("Pictures", "insert.picture"),
m("Shapes", "insert.shape"),
c("Icons", "insert.icon"),
c("SmartArt", "insert.smartArt"),
c("Diagram", "insert.smartArt"),
c("Chart", "insert.chart"),
d("Link", "link"),
d("Bookmark", "bookmark"),
@@ -251,7 +251,7 @@ fn controls(tab: &str) -> Vec<Control> {
m("Page Number", "insert.pageNumber"),
c("Text Box", "insert.textBox"),
c("Quick Parts", "insert.quickParts"),
m("WordArt", "insert.wordArt"),
m("Decorative Text", "insert.wordArt"),
m("Drop Cap", "insert.dropCap"),
c("Signature Line", "insert.signatureLine"),
c("Date & Time", "insert.dateTime"),
+1 -1
View File
@@ -53,7 +53,7 @@ pub(super) fn smart_art_design(app: &mut WordApp, ui: &mut Ui) {
}
});
});
group(ui, "SmartArt Styles", None, app, |ui, app| {
group(ui, "Diagram Styles", None, app, |ui, app| {
menu_button(
ui,
app,
+7 -4
View File
@@ -97,7 +97,7 @@ pub(super) fn insert(app: &mut WordApp, ui: &mut Ui) {
});
stack(ui, |ui| {
small(ui, app, "icons", Some("Icons"), "Icons", crate::widgets::ButtonAction::new("insert.icon", json!({}), false));
small(ui, app, "smartArt", Some("SmartArt"), "SmartArt", crate::widgets::ButtonAction::new("insert.smartArt", json!({}), false));
small(ui, app, "smartArt", Some("Diagram"), "Diagram", crate::widgets::ButtonAction::new("insert.smartArt", json!({}), false));
small(ui, app, "chart", Some("Chart"), "Chart", crate::widgets::ButtonAction::new("insert.chart", json!({}), false));
});
});
@@ -177,9 +177,12 @@ pub(super) fn insert(app: &mut WordApp, ui: &mut Ui) {
mi(ui, app, "Field…", "ui.dialog", json!({"name": "field"}));
},
);
menu_button(ui, app, crate::widgets::MenuButtonOptions::new("wordArt", Some("WordArt"), "WordArt", false, ""), |ui, app| {
crate::wordart_menus::style_gallery(ui, app, "insert.wordArt")
});
menu_button(
ui,
app,
crate::widgets::MenuButtonOptions::new("wordArt", Some("Decorative Text"), "Decorative Text", false, ""),
|ui, app| crate::wordart_menus::style_gallery(ui, app, "insert.wordArt"),
);
menu_button(
ui,
app,
+2 -2
View File
@@ -102,8 +102,8 @@ pub(super) fn shape_format(app: &mut WordApp, ui: &mut Ui) {
});
});
}
group(ui, "WordArt Styles", None, app, |ui, app| {
menu_button(ui, app, crate::widgets::MenuButtonOptions::new("wordArt", Some("Styles"), "WordArt Styles", true, ""), |ui, app| {
group(ui, "Decorative Text Styles", None, app, |ui, app| {
menu_button(ui, app, crate::widgets::MenuButtonOptions::new("wordArt", Some("Styles"), "Decorative Text Styles", true, ""), |ui, app| {
crate::wordart_menus::style_gallery(ui, app, "wordArt.style")
});
stack(ui, |ui| {
+4 -1
View File
@@ -578,12 +578,15 @@ fn page_setup_launcher_opens_the_dialog() {
#[test]
fn smart_art_picker_inserts_and_design_tab_follows_the_selection() {
let mut app = crate::WordApp::new(Session::new(wordcraft_doc::Document::new()), Default::default());
// Insert › SmartArt without a layout opens the picker.
// Insert › Diagram without a layout opens the picker.
let _ = app.run("insert.smartArt", json!({}));
assert_eq!(app.dialog.as_ref().map(crate::dialogs::Dialog::name), Some("insertSmartArt"));
app.dialog = None;
app.run("insert.smartArt", json!({"layout": "cycle"})).unwrap();
assert!(contextual_tabs(&app.session).contains(&"SmartArt Design"));
app.run("ui.tab", json!({"tab": "SmartArt Design"})).unwrap();
assert_eq!(app.ui.tab, "SmartArt Design");
assert_eq!(crate::i18n::tr(crate::i18n::Lang::EN, &app.ui.tab), "Diagram Design");
app.run("smartArt.textPane", json!({})).unwrap();
assert!(app.session.view.smart_art_pane);
app.session.run("select.collapse", &json!({"end": true})).unwrap();
+15
View File
@@ -0,0 +1,15 @@
# Feature naming
WordCraft uses **Diagram**, **Diagram Design**, **Diagram Styles**, and **Decorative Text** for its own creation and editing features. Existing command IDs, public Rust type names and file-format mappings remain unchanged.
## Stable identities
The saved/control-channel contextual tab key `SmartArt Design` remains stable. Display-time localization maps that key to Diagram Design; dispatch and saved ribbon layouts do not depend on the new visible name. `insert.smartArt`, `smartArt.*`, `insert.wordArt`, `wordArt.*`, dialog IDs and icon IDs remain stable.
OOXML diagram/WordArt mappings, existing document-owned names and attribution are untouched. This is a naming change, not a legal determination.
## Translation dependency and readiness
WordCraft embeds shared catalogs from craft-i18n at `craft-i18n.rev`. The companion catalog PR must merge, then this pin must be advanced to its upstream commit before this app draft is marked ready. Until then, newly renamed labels can fall back to English. Do not merge the app change first.
The companion includes localized feature labels for every offered non-English language. Native-speaker review, the normal engine/UI/OOXML tests, visual ribbon/dialog checks and full CI remain required.