Color: assigned profiles follow the document in front

The profiles Edit > Assign Profile gives a document stayed the active
color settings after another document came to the front, so a new,
opened or switched-to document drew and converted its colors through the
previous document's profile, and closing the last document left it in
use.

The session now puts the front document's profiles in use (the working
spaces where it has none, or no document is open) after a new or opened
document, a tab switch, a close, File > Revert, every command including
each batch step and Undo or Redo of Assign Profile, a failed batch or
plug-in call, a script's rollback and slice boundaries, a canceled
preview, undo group or undo scope, and for each document Export All Open
and the update of placed documents work in. The active settings are
rebuilt, and the documents redrawn, only when they change.
This commit is contained in:
dotCooCoo
2026-11-13 07:44:19 -08:00
parent 77970c6924
commit 5741c7bba0
13 changed files with 156 additions and 10 deletions
+4 -1
View File
@@ -132,8 +132,10 @@ fn export_all_open(s: &mut Session, p: &Value) -> Result<Value> {
let active = s.active;
for i in 0..s.docs.len() {
// Each document in turn is the one Save a Copy writes; switching tabs this way leaves every
// document's tool and interaction alone, and the active one comes back below.
// document's tool and interaction alone, and the active one comes back below. Its colors
// are written through its own profiles.
s.active = Some(i);
s.sync_front_profiles();
let Ok(st) = s.doc() else { continue };
let title = st.doc.title.clone();
let stem = fileio::file_stem(st.path.as_deref().unwrap_or(&title));
@@ -160,6 +162,7 @@ fn export_all_open(s: &mut Session, p: &Value) -> Result<Value> {
}
}
s.active = active;
s.sync_front_profiles();
Ok(json!({ "files": files, "failed": failed, "format": format.id }))
}
+6 -4
View File
@@ -5,9 +5,11 @@
//! Colour settings and the proof view are process-wide (`vectorcraft_color::cms::active`,
//! `vectorcraft_render::proof::view`). A document's assigned profiles are stored in
//! `Document::color_profiles` (files before format v3: `Document.unknown["colorProfiles"]`) and
//! take the place of the working spaces in the active settings when assigned, and when the working
//! settings change while the document is in front ([`use_front_profiles`]); the working spaces stay
//! as Edit → Color Settings set them.
//! take the place of the working spaces in the active settings while the document is in front
//! ([`use_front_profiles`]): when they are assigned, when the working settings change, and when the
//! document comes to the front or its assignment comes back (an open, a switch, a close, a revert,
//! an undo or a rollback, [`Session::sync_front_profiles`]); the working spaces stay as Edit → Color
//! Settings set them.
use std::collections::BTreeMap;
use std::sync::Arc;
@@ -181,7 +183,7 @@ fn touch_all(s: &mut Session) {
/// Make the active settings the working settings with the profiles the front document is assigned
/// in place of the working spaces (none, or no document open: the working spaces). The open
/// documents redraw when the active settings change.
fn use_front_profiles(s: &mut Session) {
pub(crate) fn use_front_profiles(s: &mut Session) {
let (rgb, cmyk) = s.active().map(|d| doc_profiles(&d.doc)).unwrap_or_default();
if cms::use_document_profiles(rgb.as_deref(), cmyk.as_deref()) {
touch_all(s);
+1
View File
@@ -41,6 +41,7 @@ pub(super) fn batch(s: &mut Session, p: &Value) -> Result<Value> {
roll_back(s, start, &stash);
s.notify_text_tool("batch.rollBack");
s.active = active;
s.sync_front_profiles();
(s.paint, s.fill_active, s.draw_mode, s.draw_inside, s.clipboard, s.untitled_counter, s.explicit_undo_group) = saved;
s.pending_paint = None;
return Err(e);
+4 -1
View File
@@ -1331,14 +1331,17 @@ pub(crate) fn refresh_placed(s: &mut Session, saved: u64, path: &str) {
if targets.is_empty() {
return;
}
// Each document is updated as the active one, without switching tools.
// Each document is updated as the active one, through its own profiles, without switching
// tools.
let back = s.active;
for i in targets {
s.active = Some(i);
s.sync_front_profiles();
// A file that can't be read leaves what its objects show: links.check reports it.
let _ = update_where(s, None, Some(&path));
}
s.active = back;
s.sync_front_profiles();
}
// ---------- relative paths ----------
+1
View File
@@ -413,6 +413,7 @@ pub(crate) fn transaction(s: &mut Session, label: &str, f: impl FnOnce(&mut Sess
st.interaction = None;
}
saved.restore(s);
s.sync_front_profiles();
Err(e)
}
}
+5
View File
@@ -672,6 +672,7 @@ impl Savepoint {
s.pending_paint = self.pending_paint;
self.choices.put(s);
s.journal.truncate(self.journal);
s.sync_front_profiles();
exact
}
}
@@ -2199,6 +2200,9 @@ fn failure_text(report: &Value) -> String {
fn run_slice(s: &mut Session, job: &mut Job) -> std::result::Result<std::result::Result<Progress, RunError>, String> {
let depth = std::mem::replace(&mut s.depth, 0);
job.world.swap(s);
// The run's front document draws and converts through its own profiles, and the interface's
// again after the slice.
s.sync_front_profiles();
s.script_in_run = true;
let cell = job.host.session.clone();
std::mem::swap(s, &mut *cell.borrow_mut());
@@ -2221,6 +2225,7 @@ fn run_slice(s: &mut Session, job: &mut Job) -> std::result::Result<std::result:
s.script_in_run = false;
job.world.swap(s);
s.depth = depth;
s.sync_front_profiles();
r
}
+16 -1
View File
@@ -220,6 +220,7 @@ impl Session {
self.active = Some(index);
if switched {
self.sync_front_composite_fonts();
self.sync_front_profiles();
}
true
} else {
@@ -227,6 +228,15 @@ impl Session {
}
}
/// Make the profiles the document in front is assigned the ones colors are drawn and converted
/// through, in place of the working spaces (with no document open, or none assigned: the working
/// spaces), after a switch, an open, a close, a revert or a restored document brought another
/// document or another assignment to the front. The open documents redraw when the active color
/// settings change.
pub(crate) fn sync_front_profiles(&mut self) {
cmd::colormgmt::use_front_profiles(self);
}
/// Register the composite fonts of the document now in front ([`cmd::compositefonts::sync`]),
/// after a switch or a close brought it there. Its type set in a composite font that differs
/// from the one of that name before (added, changed or removed) is measured again, and type not
@@ -316,6 +326,7 @@ impl Session {
let i = self.docs.len() - 1;
self.active = Some(i);
self.sync_opened_composite_fonts(i);
self.sync_front_profiles();
if self.depth == 0
&& let Some(label) = self.explicit_undo_group.clone()
{
@@ -384,7 +395,10 @@ impl Session {
}
match back_names {
Some(names) => self.refresh_document_text_bounds(index, |t| t.cached_bounds.is_none() && !sets_in_any(t, &names)),
None => self.sync_opened_composite_fonts(index),
None => {
self.sync_opened_composite_fonts(index);
self.sync_front_profiles();
}
}
true
}
@@ -403,6 +417,7 @@ impl Session {
}
self.active = if self.docs.is_empty() { None } else { Some(index.min(self.docs.len() - 1)) };
self.sync_front_composite_fonts();
self.sync_front_profiles();
true
}
+4
View File
@@ -311,6 +311,8 @@ impl Session {
self.paint = paint.clone();
}
self.pending_paint = None;
// The previous preview's Assign Profile is undone with it.
self.sync_front_profiles();
let rw = cmd::distortcmds::perspective_rewrite(self, cmd, params).or_else(|| cmd::bounds_rewrite(self, cmd, params));
let (cmd, params) = rw.as_ref().map_or((cmd, params), |(c, p)| (c.as_str(), p));
// A selected object's converted appearance must not replace the current paints while
@@ -436,6 +438,8 @@ impl Session {
st.undo_interaction();
// Guides locked and slices locked or hidden during the interaction stay deselected.
deselect_hidden(&menu, &st.doc, &mut st.selection);
// A canceled preview's Assign Profile is undone with it.
self.sync_front_profiles();
// With New Art Has Basic Appearance off, new art takes the appearance of the selection as
// the document has it again, not as a preview left it.
self.inherit_new_art();
+4
View File
@@ -168,6 +168,10 @@ impl Session {
let (doc, journal, grouped) = (self.active().map(|d| d.uid), self.journal.len(), self.undo_group_docs());
let open = (self.depth == 0).then(|| self.docs.iter().map(|d| d.uid).collect::<Vec<_>>());
let r = if self.depth == 0 { self.run_guarded(id, run) } else { self.run_nested(run) };
// Colors are drawn and converted through the profiles of the document in front now, also
// after an undone or redone Assign Profile, a failed or panicked command's documents put
// back, and a batch step, before the next step converts through them.
self.sync_front_profiles();
if r.is_err() && self.depth == 0 {
self.batch_paint_docs.clear();
// A failed or panicked command's documents are put back: type is drawn in their
+6
View File
@@ -164,6 +164,10 @@ impl Session {
if self.depth == 0 {
self.trim_histories();
}
// A canceled group's Assign Profile is undone with it.
if cancel {
self.sync_front_profiles();
}
}
/// When journal entry `n` is a `command.batch` with `steps` noted in canceled undo groups and
@@ -280,5 +284,7 @@ impl Session {
g.journal.retain(|&(n, _)| n < scope.journal);
g.steps.retain(|&(n, _)| n < scope.journal);
}
// A canceled scope's Assign Profile is undone with it.
self.sync_front_profiles();
}
}