mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-30 21:58:36 +00:00
Shape Builder: saved Artwork from earlier versions switches to Color Swatches once
Leaving the Shape Builder saved every one of its options, so preferences from earlier versions hold pickColorFrom "artwork" whether or not it was picked, and kept the old default after Color Swatches became the default. The preferences now carry toolSettingsVersion, written as 1 once a tool setting is stored. Applying preferences without it changes a saved Shape Builder pickColorFrom "artwork" to "swatches" and writes the version, so Artwork picked after that is kept at the next launch. A saved "swatches" and preferences without a saved pickColorFrom are unchanged. Docs: docs/mcp.md and the tool options params text.
This commit is contained in:
@@ -725,6 +725,8 @@ impl Session {
|
||||
for e in self.prefs.keep_folders(&mut p) {
|
||||
log::warn!("{e}");
|
||||
}
|
||||
// Tool settings saved by an earlier version are updated once.
|
||||
p.migrate_tool_settings();
|
||||
// Saved gradient presets get names no built-in preset or other saved one has.
|
||||
for (old, new) in super::gradpresets::rename_clashing_presets(&mut p.gradient_presets) {
|
||||
log::warn!("saved gradient preset {old} is listed as {new}: another preset has its name");
|
||||
|
||||
@@ -438,6 +438,12 @@ pub struct Prefs {
|
||||
/// resetting the preferences keeps them; `tool.setOption` edits them.
|
||||
#[serde(skip_serializing_if = "std::collections::BTreeMap::is_empty")]
|
||||
pub tool_settings: std::collections::BTreeMap<String, serde_json::Map<String, Value>>,
|
||||
/// The version of [`Self::tool_settings`]: [`TOOL_SETTINGS_VERSION`] once this version stores
|
||||
/// or updates a tool setting, 0 while none is stored and in preferences saved without one.
|
||||
/// [`Prefs::migrate_tool_settings`] updates older tool settings once. Not a Preferences dialog
|
||||
/// field: resetting the preferences keeps it.
|
||||
#[serde(default, skip_serializing_if = "is_zero")]
|
||||
pub tool_settings_version: u32,
|
||||
/// View → Perspective Grid presets: the user's (the built-in ones aren't stored). A local
|
||||
/// library, not a Preferences dialog field: resetting the preferences keeps it;
|
||||
/// `perspective.presets.*` edit it.
|
||||
@@ -464,7 +470,36 @@ pub const KEY_HOLD_DELAY: f64 = 0.35;
|
||||
/// The range of the Hold Shortcut Delay, in seconds.
|
||||
pub const KEY_HOLD_DELAY_RANGE: (f64, f64) = (0.2, 1.0);
|
||||
|
||||
/// The version of the tool settings these preferences write ([`Prefs::tool_settings_version`]).
|
||||
/// Version 1 makes Color Swatches the Shape Builder's Pick Color From.
|
||||
pub const TOOL_SETTINGS_VERSION: u32 = 1;
|
||||
|
||||
fn is_zero(v: &u32) -> bool {
|
||||
*v == 0
|
||||
}
|
||||
|
||||
impl Prefs {
|
||||
/// Update tool settings saved by an earlier version to [`TOOL_SETTINGS_VERSION`], once. Before
|
||||
/// version 1, leaving the Shape Builder saved its `pickColorFrom` whether or not it was
|
||||
/// changed, so a saved `artwork` becomes `swatches`. Without tool settings, nothing changes; a
|
||||
/// version newer than this one is kept.
|
||||
pub fn migrate_tool_settings(&mut self) {
|
||||
if self.tool_settings_version < 1
|
||||
&& let Some(saved) = self.tool_settings.get_mut("shapeBuilder")
|
||||
&& saved.get("pickColorFrom").and_then(Value::as_str) == Some("artwork")
|
||||
{
|
||||
saved.insert("pickColorFrom".into(), Value::from("swatches"));
|
||||
}
|
||||
self.mark_tool_settings_current();
|
||||
}
|
||||
|
||||
/// Record that [`Self::tool_settings`], when any is stored, is in this version's form.
|
||||
pub(crate) fn mark_tool_settings_current(&mut self) {
|
||||
if !self.tool_settings.is_empty() {
|
||||
self.tool_settings_version = self.tool_settings_version.max(TOOL_SETTINGS_VERSION);
|
||||
}
|
||||
}
|
||||
|
||||
/// The `document.open` / place params `p` with `embeddedFonts: false` added when Preferences
|
||||
/// › File Handling › Use fonts embedded in imported PDFs is off and `p` gives no choice of its own.
|
||||
pub fn with_pdf_font_choice(&self, p: &serde_json::Value) -> serde_json::Value {
|
||||
@@ -672,6 +707,7 @@ impl Default for Prefs {
|
||||
use_registration_point_for_symbol: false,
|
||||
show_on_shape_creation: false,
|
||||
tool_settings: Default::default(),
|
||||
tool_settings_version: 0,
|
||||
perspective_presets: vec![],
|
||||
blend_options: None,
|
||||
perspective_widget: Default::default(),
|
||||
|
||||
@@ -700,26 +700,53 @@ fn a_parametric_shape_kind_and_its_values_set_together() {
|
||||
}
|
||||
|
||||
/// The Shape Builder picks colors from the color swatches by default: a fresh session, and saved
|
||||
/// preferences that hold other Shape Builder options but no `pickColorFrom`, give `swatches`. A
|
||||
/// saved `artwork` (or `swatches`) is kept.
|
||||
/// preferences that hold other Shape Builder options but no `pickColorFrom`, give `swatches`.
|
||||
/// Preferences saved without `toolSettingsVersion` read a saved `artwork` as `swatches` once and
|
||||
/// are then written with the version, so a later `artwork` is kept. A saved `swatches` is kept.
|
||||
#[test]
|
||||
fn shape_builder_pick_color_from_defaults_to_swatches_and_keeps_a_saved_choice() {
|
||||
fn shape_builder_pick_color_from_defaults_to_swatches_and_migrates_a_saved_artwork_once() {
|
||||
let mut s = session();
|
||||
select(&mut s, "shapeBuilder");
|
||||
assert_eq!(s.tool_options()["pickColorFrom"], json!("swatches"), "a fresh session");
|
||||
for (saved, want) in [
|
||||
(json!({"highlightFill": false}), "swatches"),
|
||||
(json!({"pickColorFrom": "artwork"}), "artwork"),
|
||||
(json!({"pickColorFrom": "swatches"}), "swatches"),
|
||||
] {
|
||||
let mut prefs = s.prefs.clone();
|
||||
prefs.tool_settings.insert("shapeBuilder".into(), saved.as_object().unwrap().clone());
|
||||
let saved_text = serde_json::to_string(&prefs).unwrap();
|
||||
select(&mut s, "selection");
|
||||
assert_eq!(s.prefs.to_json()["toolSettingsVersion"], json!(1), "stored settings are written with the version");
|
||||
let load = |version: Option<u32>, saved: &Value| {
|
||||
let mut prefs = Prefs::default().to_json();
|
||||
prefs["toolSettings"] = json!({ "shapeBuilder": saved });
|
||||
let fields = prefs.as_object_mut().unwrap();
|
||||
match version {
|
||||
Some(v) => fields.insert("toolSettingsVersion".into(), json!(v)),
|
||||
None => fields.remove("toolSettingsVersion"),
|
||||
};
|
||||
let mut next = session();
|
||||
next.apply_prefs(serde_json::from_str(&saved_text).unwrap());
|
||||
next.apply_prefs(serde_json::from_str(&prefs.to_string()).unwrap());
|
||||
next
|
||||
};
|
||||
for (version, saved, want) in [
|
||||
(None, json!({"highlightFill": false}), "swatches"),
|
||||
(None, json!({"pickColorFrom": "artwork"}), "swatches"),
|
||||
(None, json!({"pickColorFrom": "swatches"}), "swatches"),
|
||||
(Some(1), json!({"pickColorFrom": "artwork"}), "artwork"),
|
||||
(Some(1), json!({"pickColorFrom": "swatches"}), "swatches"),
|
||||
(Some(1), json!({"highlightFill": false}), "swatches"),
|
||||
] {
|
||||
let mut next = load(version, &saved);
|
||||
assert_eq!(next.prefs.tool_settings_version, 1, "the version is written: {version:?} {saved}");
|
||||
select(&mut next, "shapeBuilder");
|
||||
assert_eq!(next.tool_options()["pickColorFrom"], json!(want), "saved {saved}");
|
||||
assert_eq!(next.tool_options()["pickColorFrom"], json!(want), "saved {version:?} {saved}");
|
||||
select(&mut next, "selection");
|
||||
assert_eq!(next.prefs.tool_settings["shapeBuilder"]["pickColorFrom"], json!(want), "stored again: {saved}");
|
||||
assert_eq!(next.prefs.tool_settings["shapeBuilder"]["pickColorFrom"], json!(want), "stored again: {version:?} {saved}");
|
||||
}
|
||||
// Artwork picked after the update, or in a session that started without saved settings, is
|
||||
// kept at the next launch.
|
||||
for mut next in [load(None, &json!({"pickColorFrom": "artwork"})), session()] {
|
||||
select(&mut next, "shapeBuilder");
|
||||
next.set_tool_option("pickColorFrom", &json!("artwork"));
|
||||
select(&mut next, "selection");
|
||||
let saved_text = serde_json::to_string(&next.prefs).unwrap();
|
||||
let mut later = session();
|
||||
later.apply_prefs(serde_json::from_str(&saved_text).unwrap());
|
||||
select(&mut later, "shapeBuilder");
|
||||
assert_eq!(later.tool_options()["pickColorFrom"], json!("artwork"), "picked after the update: {saved_text}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -581,6 +581,7 @@ impl Session {
|
||||
}
|
||||
}
|
||||
}
|
||||
prefs.mark_tool_settings_current();
|
||||
}
|
||||
|
||||
/// Keep the active tool's persistent options for the next time it, or a tool sharing them, is
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -70,7 +70,8 @@ pub struct ShapeBuilderOptions {
|
||||
/// fills the new shape with the current fill, and the Left and Right arrow keys step the current
|
||||
/// fill through the document's color swatches. With Artwork, the shape takes the look of the
|
||||
/// object where the drag starts, else of the one where it ends, else of the front-most selected
|
||||
/// object. A saved `pickColorFrom` is kept; preferences without one take Color Swatches.
|
||||
/// object. A saved `pickColorFrom` is kept, except that preferences saved by an earlier version
|
||||
/// read a saved Artwork as Color Swatches once; preferences without one take Color Swatches.
|
||||
pub swatches: bool,
|
||||
/// Cursor Swatch Preview (`cursorSwatchPreview`, off): with Color Swatches, the current fill
|
||||
/// and the swatches before and after it show as chips above the pointer while no drag is on.
|
||||
|
||||
File diff suppressed because one or more lines are too long
+2
-1
@@ -15729,7 +15729,8 @@ as an unfilled path does), `pickColorFrom` (`swatches`, the default: a merged sh
|
||||
the Left and Right arrow keys without Shift, Alt or Cmd/Ctrl step the current fill through the document's color
|
||||
swatches; `artwork`: a merged shape takes the appearance, opacity and blending mode of the front-most selected object
|
||||
under the drag's first point, else of the one under its last point, else of the front-most selected object; a
|
||||
`pickColorFrom` saved with the preferences is kept, and preferences saved without one take `swatches`), `cursorSwatchPreview` (off; with `swatches`, chips above the
|
||||
`pickColorFrom` saved with the preferences is kept, except that preferences saved by an earlier version, without
|
||||
`toolSettingsVersion`, read a saved `artwork` as `swatches` once; preferences saved without one take `swatches`), `cursorSwatchPreview` (off; with `swatches`, chips above the
|
||||
pointer show the current fill and the swatches before and after it), `selection` (`freeform`, the default, or
|
||||
`straightLine`: a drag touches what the line from its first point to the pointer crosses), `highlightFill` (on by
|
||||
default; when it is off, merge mode shades no regions), `gapDetection` (off) with `gapLength` (pt, 0 to 72; 3), `clickStrokeSplitsPath` (In Merge Mode,
|
||||
|
||||
Reference in New Issue
Block a user