mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 16:59:43 +01:00
Merge pull request #9636 from dotCooCoo/fix/canvas-linked-swatch-source-drawing
Keep linked Canvas swatch drops in their source drawing
This commit is contained in:
2 files changed
+66
-2
No files matched your search
@@ -353,7 +353,7 @@ pub(crate) fn apply_drop(app: &mut VectorcraftApp, drop: &Dropped) -> Result<(),
|
||||
run(app, "graphicStyle.apply", json!({"name": style.name, "ids": [top], "add": drop.op == DropOperation::Copy}))
|
||||
}
|
||||
Payload::Style(_) => Ok(()),
|
||||
Payload::Panel(drag @ PanelDrag::Paint { params, paint, .. }) if !params.is_null() => {
|
||||
Payload::Panel(drag @ PanelDrag::Paint { params, paint, rows, .. }) if !params.is_null() => {
|
||||
if let Some(color) = paint.color()
|
||||
&& crate::panels::proxy_cmd(app, false) == "paint.setFill"
|
||||
&& let Some((id, points)) = selected_mesh_drop(app, at, zoom)
|
||||
@@ -362,7 +362,14 @@ pub(crate) fn apply_drop(app: &mut VectorcraftApp, drop: &Dropped) -> Result<(),
|
||||
return run(app, "object.mesh.setPointColor", params);
|
||||
}
|
||||
let Some(hit) = hit() else { return Ok(()) };
|
||||
let Some(mut params) = drag.paint_drop_params(app.session.active().map(|st| st.uid)) else { return Ok(()) };
|
||||
let destination = app.session.active().map(|st| st.uid);
|
||||
if rows.as_ref().is_some_and(|rows| !rows.unlinked_process_color && destination.is_some_and(|uid| uid != rows.document))
|
||||
&& paint.color().is_some()
|
||||
&& !paint.is_registration()
|
||||
{
|
||||
return Err(tl!("A linked color swatch can only be applied in its own document.").into());
|
||||
}
|
||||
let Some(mut params) = drag.paint_drop_params(destination) else { return Ok(()) };
|
||||
params["ids"] = json!([owner(app, &hit)?]);
|
||||
params["focus"] = json!(false);
|
||||
let cmd = crate::panels::proxy_cmd(app, false);
|
||||
|
||||
@@ -331,6 +331,63 @@ fn a_swatch_drag_keeps_its_color_after_next_document() {
|
||||
assert_eq!(app.session.active().unwrap().doc.node(target).unwrap().appearance.fill_paint(), source);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn linked_swatch_drops_stay_in_their_source_document() {
|
||||
use crate::tests::panel_harness::Panel;
|
||||
use craft::ui::contract::Role;
|
||||
use craft::ui::runtime::drag;
|
||||
use egui::{Key, Modifiers};
|
||||
|
||||
for spot in [false, true] {
|
||||
for (different_drawing, same_name) in [(false, false), (true, false), (true, true)] {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
let name = "Shared Swatch";
|
||||
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
|
||||
app.run("swatch.new", json!({"name": name, "color": "#ff0000", "global": true, "spot": spot})).unwrap();
|
||||
if different_drawing {
|
||||
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
|
||||
}
|
||||
if same_name {
|
||||
app.run("swatch.new", json!({"name": name, "color": "#0000ff", "global": true})).unwrap();
|
||||
}
|
||||
let target = NodeId(app.run("shape.rectangle", json!({"x": 50, "y": 50, "width": 100, "height": 100})).unwrap()["id"].as_u64().unwrap());
|
||||
app.run("paint.setFill", json!({"color": "#00ff00"})).unwrap();
|
||||
let destination = app.session.active().unwrap().uid;
|
||||
if different_drawing {
|
||||
app.run("window.previousDocument", json!({})).unwrap();
|
||||
}
|
||||
let mut panel = Panel::new(app, |app, ui| {
|
||||
app.sync_views();
|
||||
ui.allocate_ui_with_layout(egui::vec2(280.0, 480.0), egui::Layout::top_down(egui::Align::Min), |ui| {
|
||||
crate::panels::swatches::show(app, ui);
|
||||
});
|
||||
canvas::show(app, ui);
|
||||
});
|
||||
let label = "Shared Swatch, #ff0000";
|
||||
let from = panel.rect(label).center();
|
||||
let to = panel.app().canvas_view().unwrap().to_screen(Point::new(100.0, 100.0));
|
||||
panel.drag_hold_role(label, Role::LIST_ITEM, to - from);
|
||||
assert!(drag::active::<PanelDrag>(panel.ctx()).is_some(), "the Swatches row starts a paint drag");
|
||||
if different_drawing {
|
||||
panel.key(Key::F6, Modifiers::COMMAND);
|
||||
}
|
||||
assert_eq!(panel.app().session.active().unwrap().uid, destination);
|
||||
assert!(drag::active::<PanelDrag>(panel.ctx()).is_some(), "the drag stays active");
|
||||
panel.release();
|
||||
let app = panel.app();
|
||||
let doc = &app.session.active().unwrap().doc;
|
||||
let fill = doc.node(target).unwrap().appearance.fill_paint();
|
||||
if different_drawing {
|
||||
assert_eq!(fill, Paint::solid(Color::rgb8(0, 255, 0)), "the destination fill stays unchanged");
|
||||
assert_eq!(app.ui.status, "A linked color swatch can only be applied in its own document.");
|
||||
assert_eq!(doc.swatch(name).and_then(|s| s.paint.color()), same_name.then_some(Color::rgb8(0, 0, 255)));
|
||||
} else {
|
||||
assert_eq!(fill, doc.tint_paint(name, 1.0).unwrap(), "the fill remains linked to its swatch");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_color_dropped_on_a_selected_mesh_recolors_the_point_or_patch_under_it() {
|
||||
use vectorcraft_doc::GradientMesh;
|
||||
|
||||
Reference in new issue
Block a user