Parameters: move user parameters up and down (#1323)
Fixes #1187. New parameters.move {name, before|after} reorders user parameters (the design's own params order, so it is saved with no format change, and undoable); the Parameters dialog's user rows get up/down buttons. Label in every catalog. I merged main in. Checked on main + this branch: cargo check --workspace, the engine parameters tests, the UI parameter_order test, and docs/features.md regenerates unchanged.
This commit is contained in:
1 parent
d7a4a29ce3
commit
4dc638109b
14 files changed
+152
-11
No files matched your search
@@ -24,6 +24,8 @@ pub static COMMANDS: &[CommandSpec] = &[
|
||||
.params("name, new_name (expressions, feature inputs and dimensions that use it follow)"),
|
||||
CommandSpec::new("parameters.delete", "Delete Parameter", delete).params("name (refused while something uses it; the error lists the users)"),
|
||||
CommandSpec::new("parameters.favorite", "Favourite Parameter", favorite).params("name, favorite?: bool (default true)"),
|
||||
CommandSpec::new("parameters.move", "Move Parameter", move_param)
|
||||
.params("name, before | after: another user parameter; the user parameter is listed just before or after it"),
|
||||
CommandSpec::new("parameters.comment", "Comment Parameter", comment).params("name, comment"),
|
||||
CommandSpec::new("parameters.users", "Parameter Users", users)
|
||||
.noundo()
|
||||
@@ -179,6 +181,19 @@ fn favorite(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
Ok(json!({"name": name, "favorite": on}))
|
||||
}
|
||||
|
||||
fn move_param(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let cmd = "parameters.move";
|
||||
let name = param_name(cmd, p)?.to_string();
|
||||
let (target, after) = match (str_(p, "before"), str_(p, "after")) {
|
||||
(Some(t), None) => (t.to_string(), false),
|
||||
(None, Some(t)) => (t.to_string(), true),
|
||||
_ => return Err(bad(cmd, "give one of `before` or `after`: another user parameter")),
|
||||
};
|
||||
s.doc_mut().move_user_param(&name, &target, after)?;
|
||||
let order: Vec<&str> = s.doc.params.iter().filter(|q| !q.model).map(|q| q.name.as_str()).collect();
|
||||
Ok(json!({"name": name, "order": order}))
|
||||
}
|
||||
|
||||
fn comment(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let cmd = "parameters.comment";
|
||||
let name = param_name(cmd, p)?.to_string();
|
||||
|
||||
Reference in new issue
Block a user