Variables: Save Variable Library… writes the variables and data sets as an XML library

Squashed from #5147 onto main.
This commit is contained in:
dotCooCoo
2026-11-02 14:32:52 +07:00
committed by bflatastic
parent 9031906abd
commit e8cd6c173a
33 changed files with 628 additions and 11 deletions
+12 -2
View File
@@ -10,7 +10,8 @@
//! `name` column, and header cells that define new variables (`#` for visibility, `@` for
//! image, no prefix for text). `variable.loadLibrary` replaces the variables and data sets with the
//! text variables and data sets of a variable library, the XML file of the reference app's Save
//! Variable Library. Agents reach every command through `run_command`, like all engine commands.
//! Variable Library, and `variable.saveLibrary` writes the text variables and data sets as one.
//! Agents reach every command through `run_command`, like all engine commands.
use std::collections::{BTreeMap, BTreeSet};
@@ -26,7 +27,7 @@ mod csv;
mod library;
use csv::{MAX_GRAPH_CSV, dataset_export, dataset_import};
use library::load_library;
use library::{load_library, save_library};
/// The longest variable or dataset name, in characters (names arrive from MCP and files).
const MAX_NAME: usize = 255;
@@ -837,5 +838,14 @@ pub fn specs() -> Vec<CommandSpec> {
has_doc,
load_library
),
cmd!(
query "variable.saveLibrary",
"Save Variable Library…",
["Window", "Variables"],
None,
"{path?} write the document's text variables and every data set as a variable library, the XML that variable.loadLibrary reads: a `variable` element with `varName` and `trait=\"textcontent\"` per text variable, and a `sampleDataSet` element with `dataSetName` per data set, holding an element named after each text variable it has a value for, with one `p` element per line of the value. Variables of other kinds are left out with their values and named in `skipped` and `warning`. Refused without a text variable, for a text variable whose name isn't an XML name (letters, digits, `-`, `_` and `.`, starting with a letter or `_`), for a data set name or value that holds a control character, for a data set name with white space at either end, for a name longer than 255 characters or used twice, and past variable.loadLibrary's caps (256 variables, 1,000 data sets, 8 MiB). Without path → {xml, variables, datasets, skipped, warning?}; with it → {path, variables, datasets, skipped, warning?}",
has_doc,
save_library
),
]
}