Color Settings: the paste question has a choice for each model when both differ

profileMismatch also takes {rgb?, cmyk?}, a choice for each model, a
model left out following its policy, on the paste commands,
edit.dropSelection and clipboard.conflicts. With colors of both models
from other profiles, the paste question shows a choice under each
model's line, each starting on its model's policy, so OK no longer
gives the CMYK colors the RGB policy's choice.
This commit is contained in:
dotCooCoo committed 2026-11-15 09:25:18 -08:00
1 parent 5d75eb4475
commit 1f411c8fa1
7 files changed
+201 -40

No files matched your search

+45 -13
View File
@@ -982,16 +982,47 @@ impl PasteProfile {
if policy == Policy::Convert { PasteProfile::Convert } else { PasteProfile::PreserveNumbers }
}
/// The `profileMismatch` param of paste command `cmd` (`None` when left out).
pub(crate) fn param(p: &Value, cmd: &str) -> Result<Option<Self>> {
match text_param(p, "profileMismatch", cmd)? {
None => Ok(None),
Some("preserveNumbers") => Ok(Some(PasteProfile::PreserveNumbers)),
Some("convert") => Ok(Some(PasteProfile::Convert)),
Some(_) => {
let key = "profileMismatch";
Err(bad(cmd, format!("`{key}` must be one of {}", "preserveNumbers, convert")))
/// The `profileMismatch` param of paste command `cmd` (`None` when left out): one choice for
/// both models, or `{rgb?, cmyk?}` with a choice for each (a model left out follows its policy).
pub(crate) fn param(p: &Value, cmd: &str) -> Result<Option<PasteChoice>> {
let key = "profileMismatch";
let refuse = || bad(cmd, format!("`{key}` must be one of {}", "preserveNumbers, convert, {rgb?, cmyk?} of those"));
let one = |v: &Value| match v.as_str() {
Some("preserveNumbers") => Ok(PasteProfile::PreserveNumbers),
Some("convert") => Ok(PasteProfile::Convert),
_ => Err(refuse()),
};
match p.get(key) {
None | Some(Value::Null) => Ok(None),
Some(Value::Object(o)) => {
if o.keys().any(|k| k != "rgb" && k != "cmyk") {
return Err(refuse());
}
let model = |m: &str| o.get(m).map(&one).transpose();
Ok(Some(PasteChoice { rgb: model("rgb")?, cmyk: model("cmyk")? }))
}
Some(v) => {
let c = one(v)?;
Ok(Some(PasteChoice { rgb: Some(c), cmyk: Some(c) }))
}
}
}
}
/// What Paste does with the mismatched colors of each model (`profileMismatch`); a model without a
/// choice follows its policy ([`PasteProfile::of`]).
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct PasteChoice {
pub rgb: Option<PasteProfile>,
pub cmyk: Option<PasteProfile>,
}
impl PasteChoice {
/// The choice for the colors of `model`, if any.
pub fn of(&self, model: ColorMode) -> Option<PasteProfile> {
match model {
ColorMode::Rgb => self.rgb,
ColorMode::Cmyk => self.cmyk,
}
}
}
@@ -1044,14 +1075,15 @@ pub(crate) fn paste_mismatches(clip: &super::clipboard::Clipboard, d: &vectorcra
/// The clipboard `clip` as pasting it into `d` brings it: for each mismatched model
/// ([`paste_mismatches`]), its colors keep their numbers or convert from the source profile into
/// the destination's with the working intent, as `choice` says (default: each model's policy,
/// [`PasteProfile::of`]). A source or destination profile that is not available keeps the numbers.
/// the destination's with the working intent, as `choice` says for that model (default: the
/// model's policy, [`PasteProfile::of`]). A source or destination profile that is not available
/// keeps the numbers.
/// → the converted clipboard (`None` when nothing converts; its resources paste as another
/// document's) and a line for each mismatched model (`{model, clipboard, document, choice}`).
pub(crate) fn paste_profiles(
clip: &super::clipboard::Clipboard,
d: &vectorcraft_doc::Document,
choice: Option<PasteProfile>,
choice: Option<PasteChoice>,
) -> (Option<super::clipboard::Clipboard>, Vec<Value>) {
let mismatches = paste_mismatches(clip, d);
let mut report = Vec::new();
@@ -1061,7 +1093,7 @@ pub(crate) fn paste_profiles(
// Both profiles must be here to convert between them.
let here = |name: &str| cms::profile(name).is_some_and(|p| p.kind == kind);
let available = here(&m.from) && here(&m.to);
let picked = if available { choice.unwrap_or(m.default) } else { PasteProfile::PreserveNumbers };
let picked = if available { choice.and_then(|c| c.of(m.model)).unwrap_or(m.default) } else { PasteProfile::PreserveNumbers };
if picked == PasteProfile::Convert {
match m.model {
ColorMode::Rgb => rgb_on = true,
+2 -2
View File
@@ -114,7 +114,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Drop Artwork",
[],
None,
"{sourceDocument: uid, ids: [id…], grab: [x,y], at: [x,y], profileMismatch?: \"preserveNumbers\"|\"convert\"} copy 1–10000 editable source objects from an open document to the active document, preserving the grab point and clipboard, as one undo step; colors from a document with another RGB or CMYK profile keep their numbers or convert as profileMismatch says, else as edit.colorSettings' policy of their model says (as edit.paste; clipboard.profileMismatch {sourceDocument, ids} lists them, and with askMismatchPaste on the desktop app asks first) → {ids, added, merged, renamed, profileMismatch?}",
"{sourceDocument: uid, ids: [id…], grab: [x,y], at: [x,y], profileMismatch?: as edit.paste} copy 1–10000 editable source objects from an open document to the active document, preserving the grab point and clipboard, as one undo step; colors from a document with another RGB or CMYK profile keep their numbers or convert as profileMismatch says, else as edit.colorSettings' policy of their model says (as edit.paste; clipboard.profileMismatch {sourceDocument, ids} lists them, and with askMismatchPaste on the desktop app asks first) → {ids, added, merged, renamed, profileMismatch?}",
has_doc,
drop_selection
),
@@ -179,7 +179,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Paste",
["Edit"],
Some("Cmd+V"),
"{center?: [x, y], artboardsAt?: [x, y], dx?, dy?, swatchConflict?, profileMismatch?: \"preserveNumbers\"|\"convert\"} paste centred on `center` (the app passes the view centre), else offset by dx/dy (default: the Paste Offset preference). Pasting brings the image blobs, symbols, patterns, global and spot swatches (with the tint swatches of the tints used), gradient swatches, graphic styles, character and paragraph styles and brushes the objects use; one of the same name that differs comes in renamed. swatchConflict, for a swatch whose name the document gives another colour (clipboard.conflicts): \"merge\" (default: the objects take the document's swatch) | \"add\" (the pasted swatch comes in renamed) | {name: \"merge\"|\"add\"}. profileMismatch, for colors copied from a document whose RGB or CMYK profile is not this document's (clipboard.profileMismatch): \"preserveNumbers\" keeps their numbers, \"convert\" converts them into this document's profile with the working intent (default: as the model's policy of edit.colorSettings says; every paste command takes it, and the reply's profileMismatch lists [{model, clipboard, document, choice}]). With Paste Remembers Layers on (layer.pasteRemembersLayers), objects go back into the layers and sublayers they came from (by the names of the layer and the layers around it in another document; a missing sublayer is made inside its layer; a hidden or locked one is an error and nothing is pasted). Artboards copied with artboard.copy come with their art, together right of the last artboard as they lay, or centered on `artboardsAt` (the Artboard tool's canvas menu passes the right-click point; a value that is not [x, y] is an error) (the other paste commands but Paste on All Artboards: where they were), their art back in the layers it came from, and the Artboard tool, when chosen, selects them. In Draw Inside (view.drawMode) the objects go inside the object drawn into, as new art does, and Paste Remembers Layers doesn't apply; edit.pasteInPlace and edit.pasteOnAllArtboards do the same, and in Draw Behind they go behind the selection as edit.pasteInBack puts them; edit.pasteInFront and edit.pasteInBack ignore the drawing mode → {ids, artboard: the first new artboard's index or null, artboards: the new artboards' indices, added: resources added, merged: conflicts merged, renamed: [{kind, from, to}]}",
"{center?: [x, y], artboardsAt?: [x, y], dx?, dy?, swatchConflict?, profileMismatch?: \"preserveNumbers\"|\"convert\"|{rgb?, cmyk?}} paste centred on `center` (the app passes the view centre), else offset by dx/dy (default: the Paste Offset preference). Pasting brings the image blobs, symbols, patterns, global and spot swatches (with the tint swatches of the tints used), gradient swatches, graphic styles, character and paragraph styles and brushes the objects use; one of the same name that differs comes in renamed. swatchConflict, for a swatch whose name the document gives another colour (clipboard.conflicts): \"merge\" (default: the objects take the document's swatch) | \"add\" (the pasted swatch comes in renamed) | {name: \"merge\"|\"add\"}. profileMismatch, for colors copied from a document whose RGB or CMYK profile is not this document's (clipboard.profileMismatch): \"preserveNumbers\" keeps their numbers, \"convert\" converts them into this document's profile with the working intent, and {rgb?, cmyk?} gives one of those for each model (default, also for a model left out: as the model's policy of edit.colorSettings says; any other value is an error; every paste command takes it, and the reply's profileMismatch lists [{model, clipboard, document, choice}]). With Paste Remembers Layers on (layer.pasteRemembersLayers), objects go back into the layers and sublayers they came from (by the names of the layer and the layers around it in another document; a missing sublayer is made inside its layer; a hidden or locked one is an error and nothing is pasted). Artboards copied with artboard.copy come with their art, together right of the last artboard as they lay, or centered on `artboardsAt` (the Artboard tool's canvas menu passes the right-click point; a value that is not [x, y] is an error) (the other paste commands but Paste on All Artboards: where they were), their art back in the layers it came from, and the Artboard tool, when chosen, selects them. In Draw Inside (view.drawMode) the objects go inside the object drawn into, as new art does, and Paste Remembers Layers doesn't apply; edit.pasteInPlace and edit.pasteOnAllArtboards do the same, and in Draw Behind they go behind the selection as edit.pasteInBack puts them; edit.pasteInFront and edit.pasteInBack ignore the drawing mode → {ids, artboard: the first new artboard's index or null, artboards: the new artboards' indices, added: resources added, merged: conflicts merged, renamed: [{kind, from, to}]}",
has_clipboard,
|s, p| paste(s, p, PasteMode::Offset)
),