mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
10 files changed
+234
-26
No files matched your search
@@ -252,6 +252,7 @@ pub(crate) const FIELD_KEYS: &[FieldKey] = &[
|
||||
prompt!(crate::dialogs::rasterize_prompt::Rasterize, &[("rasterize", "proceed"), ("smartObject", "alternate"), CANCEL]),
|
||||
prompt!(crate::dialogs::preset_group_prompt::PresetClash, &[("new", "proceed"), ("replace", "alternate"), CANCEL]),
|
||||
prompt!(crate::dialogs::live_shape_prompt::LiveShapeAsk, &[("yes", "proceed"), ("no", "cancel"), CANCEL]),
|
||||
prompt!(crate::dialogs::assign_profile_layers_alert::AssignProfileAsk, &[("ok", "proceed"), CANCEL]),
|
||||
prompt!(crate::dialogs::delete_layer_prompt::PendingDelete, &[("delete", "proceed"), CANCEL]),
|
||||
prompt!(crate::dialogs::open_prompt::DamageTag, &[("continue", "proceed"), ("open", "proceed"), CANCEL]),
|
||||
prompt!(crate::dialogs::open_prompt::MemoryTag, &[("continue", "proceed"), ("open", "proceed"), CANCEL]),
|
||||
|
||||
@@ -415,6 +415,7 @@ pub(crate) const PROMPTS: &[PromptRow] = &[
|
||||
disk_change_prompt::answer,
|
||||
rasterize_prompt::answer,
|
||||
live_shape_prompt::answer,
|
||||
assign_profile_layers_alert::answer,
|
||||
preset_group_prompt::answer,
|
||||
open_prompt::answer_prompt,
|
||||
alerts::answer,
|
||||
@@ -633,8 +634,14 @@ const ENGINE_READ: &[&str] = &["ui.layersPanelOptions", "file.print", "file.expo
|
||||
|
||||
/// The "Don't show again" entries (`{"skip": true}`), by key, as their prompt modules read them. Told apart by key, not
|
||||
/// by the shape of the value.
|
||||
fn dont_show_again_keys() -> [&'static str; 4] {
|
||||
[delete_layer_prompt::PREF, live_shape_prompt::PREF, crate::analysis::note_alerts::DELETE_NOTE_PREF, crate::retouch_ui::CAM_NO_PIXELS_PREF]
|
||||
fn dont_show_again_keys() -> [&'static str; 5] {
|
||||
[
|
||||
delete_layer_prompt::PREF,
|
||||
live_shape_prompt::PREF,
|
||||
assign_profile_layers_alert::PREF,
|
||||
crate::analysis::note_alerts::DELETE_NOTE_PREF,
|
||||
crate::retouch_ui::CAM_NO_PIXELS_PREF,
|
||||
]
|
||||
}
|
||||
|
||||
/// Where the remembered value of the preference entry `key` goes: `None` keeps it in `Preferences.dialogs`, else the
|
||||
@@ -698,6 +705,9 @@ pub mod adjust_preview;
|
||||
pub mod alerts;
|
||||
#[cfg(test)]
|
||||
mod arbitrary_ruler_prefill_tests;
|
||||
pub mod assign_profile_layers_alert;
|
||||
#[cfg(test)]
|
||||
mod assign_profile_layers_alert_tests;
|
||||
pub(crate) mod bitmap_dialog;
|
||||
pub mod blend_options;
|
||||
pub mod blur_pins;
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
//! Edit › Assign Profile on a document with layers first asks whether to go on (#14235): giving the document another
|
||||
//! profile can change how its layers look. OK (the default) and Cancel, and a "Don't show again" box kept with the
|
||||
//! other dialog preferences. OK opens the Assign Profile dialog; Cancel or Escape ends the command with nothing changed.
|
||||
//! A document with only a Background layer never asks, nor does `edit.assignProfile` run with params (scripts,
|
||||
//! actions, agents, the control channel), which the menu arm leaves to the command.
|
||||
|
||||
use craft::ui::dialog::{DialogId, PromptAnswer, PromptChoice, StandardPrompt};
|
||||
|
||||
use super::alerts;
|
||||
use crate::PhotocraftApp;
|
||||
|
||||
/// Its "Don't show again", under `Preferences::dialogs`.
|
||||
pub const PREF: &str = "edit.assignProfile.layers";
|
||||
|
||||
/// PhotoCraft's own wording of the reference application's warning.
|
||||
const QUESTION: &str = "Giving the document another profile can change how its layers look. Assign a profile anyway?";
|
||||
|
||||
/// The tag of the open question.
|
||||
pub(crate) struct AssignProfileAsk;
|
||||
|
||||
/// Whether the menu's Assign Profile asks first: the active document has anything but a lone Background layer, and
|
||||
/// "Don't show again" was not ticked.
|
||||
pub fn asks(app: &PhotocraftApp) -> bool {
|
||||
let Some(st) = app.session.active() else { return false };
|
||||
let flat = st.doc.layers.len() == 1 && st.doc.background().is_some();
|
||||
!flat && !alerts::dismissed(app, PREF)
|
||||
}
|
||||
|
||||
/// Opens the question; the id of the question already open when there is one.
|
||||
pub fn open(app: &mut PhotocraftApp) -> DialogId {
|
||||
let prompt = StandardPrompt::custom(tl!(QUESTION).to_owned())
|
||||
.title(tl!("Assign Profile").to_owned())
|
||||
.button(PromptChoice::Proceed, tl!("OK").to_owned())
|
||||
.button(PromptChoice::Cancel, tl!("Cancel").to_owned())
|
||||
.dont_show_again()
|
||||
.tag(AssignProfileAsk);
|
||||
alerts::open_prompt(app, prompt).unwrap_or_else(|open| open)
|
||||
}
|
||||
|
||||
/// The `PROMPTS` entry: OK keeps a ticked "Don't show again" and opens the Assign Profile dialog; Cancel changes
|
||||
/// nothing. `false` for another family's answer.
|
||||
pub(crate) fn answer(app: &mut PhotocraftApp, _ctx: &egui::Context, answer: &mut PromptAnswer) -> bool {
|
||||
if answer.take_tag::<AssignProfileAsk>().is_none() {
|
||||
return false;
|
||||
}
|
||||
if answer.choice != PromptChoice::Proceed {
|
||||
return true;
|
||||
}
|
||||
if answer.skip {
|
||||
alerts::remember_skip(app, PREF);
|
||||
}
|
||||
if let Err(error) = crate::filter_dialog::open(app, "edit.assignProfile") {
|
||||
alerts::report_error(app, error);
|
||||
}
|
||||
true
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
//! #14235: Edit › Assign Profile on a document with layers asks first, with OK, Cancel and an unticked "Don't show
|
||||
//! again". OK opens the Assign Profile dialog, Cancel changes nothing; a flat document and a run with params never ask;
|
||||
//! a ticked box with OK keeps the question away.
|
||||
|
||||
use craft::ui::dialog::{DialogId, StackDialog as _, StandardPrompt};
|
||||
use craft::ui::patterns::form_dialogs::HostedParamDialog;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use super::alerts;
|
||||
use super::assign_profile_layers_alert::{AssignProfileAsk, PREF};
|
||||
use crate::PhotocraftApp;
|
||||
|
||||
/// An RGB document; with `layers`, a pixel layer above the Background.
|
||||
fn app(layers: bool) -> Box<PhotocraftApp> {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.run("file.new", json!({"width": 40, "height": 30})).unwrap();
|
||||
if layers {
|
||||
app.run("layer.new.layer", json!({})).unwrap();
|
||||
}
|
||||
app
|
||||
}
|
||||
|
||||
fn menu(app: &mut PhotocraftApp) -> Value {
|
||||
let ctx = app.ctx().clone();
|
||||
crate::menus::invoke(app, &ctx, "edit.assignProfile", json!({})).unwrap()
|
||||
}
|
||||
|
||||
fn question(app: &PhotocraftApp) -> Option<DialogId> {
|
||||
alerts::prompt_tagged::<AssignProfileAsk>(app)
|
||||
}
|
||||
|
||||
fn assign_dialog_open(app: &PhotocraftApp) -> bool {
|
||||
app.framework.dialogs.get::<HostedParamDialog>().is_some()
|
||||
}
|
||||
|
||||
fn answer(app: &mut PhotocraftApp, id: DialogId, choice: &str, skip: bool) {
|
||||
let ctx = app.ctx().clone();
|
||||
app.framework.dialogs.set_json_field(&ctx, id, "choice", json!(choice)).unwrap();
|
||||
app.framework.dialogs.set_json_field(&ctx, id, "skip", json!(skip)).unwrap();
|
||||
crate::dialogs::confirm(app, &ctx, id).unwrap();
|
||||
}
|
||||
|
||||
fn steps(app: &PhotocraftApp) -> usize {
|
||||
app.session.active().unwrap().history.past_len()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_document_with_layers_asks_before_the_dialog() {
|
||||
let mut app = app(true);
|
||||
let before = steps(&app);
|
||||
menu(&mut app);
|
||||
assert!(question(&app).is_some(), "the question");
|
||||
assert!(!assign_dialog_open(&app), "the dialog waits for the answer");
|
||||
let fields = app.framework.dialogs.get::<StandardPrompt>().and_then(|p| p.json_fields()).unwrap();
|
||||
assert_eq!(fields["skip"], json!(false), "Don't show again starts unticked");
|
||||
assert_eq!(steps(&app), before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ok_opens_the_assign_profile_dialog() {
|
||||
let mut app = app(true);
|
||||
menu(&mut app);
|
||||
let id = question(&app).unwrap();
|
||||
answer(&mut app, id, "proceed", false);
|
||||
assert!(question(&app).is_none() && assign_dialog_open(&app));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cancel_ends_the_command_with_nothing_changed() {
|
||||
let mut app = app(true);
|
||||
let before = steps(&app);
|
||||
menu(&mut app);
|
||||
let id = question(&app).unwrap();
|
||||
answer(&mut app, id, "cancel", false);
|
||||
assert!(question(&app).is_none() && !assign_dialog_open(&app), "no dialog");
|
||||
assert_eq!(steps(&app), before, "no history state");
|
||||
menu(&mut app);
|
||||
assert!(question(&app).is_some(), "a Cancel keeps nothing: it asks again");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_flat_document_and_a_run_with_params_never_ask() {
|
||||
let mut app = app(false);
|
||||
menu(&mut app);
|
||||
assert!(question(&app).is_none() && assign_dialog_open(&app), "only a Background: the dialog opens at once");
|
||||
let mut app = self::app(true);
|
||||
app.run("edit.assignProfile", json!({"profile": "none"})).unwrap();
|
||||
assert!(question(&app).is_none(), "a scripted run doesn't ask");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dont_show_again_with_ok_keeps_the_question_away() {
|
||||
let mut app = app(true);
|
||||
menu(&mut app);
|
||||
let id = question(&app).unwrap();
|
||||
answer(&mut app, id, "proceed", true);
|
||||
assert!(alerts::dismissed(&app, PREF));
|
||||
let ctx = app.ctx().clone();
|
||||
for d in app.framework.dialogs.open_dialogs() {
|
||||
let _ = crate::dialogs::cancel(&mut app, &ctx, d.id);
|
||||
}
|
||||
assert!(!assign_dialog_open(&app));
|
||||
menu(&mut app);
|
||||
assert!(question(&app).is_none() && assign_dialog_open(&app), "the dialog opens without asking");
|
||||
}
|
||||
@@ -779,6 +779,10 @@ fn invoke_view_command(app: &mut PhotocraftApp, ctx: &egui::Context, id: &str, p
|
||||
crate::equalize_ui::COMMAND if params.as_object().is_none_or(|object| object.is_empty()) && crate::equalize_ui::asks(app) => {
|
||||
Some(Ok(dialog_reply(crate::equalize_ui::open(app))))
|
||||
}
|
||||
// Edit › Assign Profile on a document with layers asks first (#14235).
|
||||
"edit.assignProfile" if params.as_object().is_none_or(|object| object.is_empty()) && crate::dialogs::assign_profile_layers_alert::asks(app) => {
|
||||
Some(Ok(dialog_reply(crate::dialogs::assign_profile_layers_alert::open(app))))
|
||||
}
|
||||
fl if crate::filter_dialog::has_dialog(fl) && params.as_object().is_none_or(|object| object.is_empty()) => {
|
||||
Some(crate::filter_dialog::open(app, fl).map(dialog_reply))
|
||||
}
|
||||
|
||||
@@ -66,6 +66,8 @@ mod count_show_extras_tests;
|
||||
#[cfg(test)]
|
||||
mod crop_mode_tests;
|
||||
#[cfg(test)]
|
||||
mod freeform_shift_tests;
|
||||
#[cfg(test)]
|
||||
mod gradient_options_bar_mode_tests;
|
||||
#[cfg(test)]
|
||||
mod line_tool_defaults_tests;
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
//! #12832: Shift held while drawing with the Freeform Pen leaves the freehand stroke as drawn: a vee gives the same
|
||||
//! path with Shift as without, its corner kept. Shift keeps constraining the painting tools (their own tests).
|
||||
|
||||
use egui::Modifiers;
|
||||
use serde_json::json;
|
||||
|
||||
use crate::PhotocraftApp;
|
||||
use crate::canvas::testing;
|
||||
use crate::state::Tool;
|
||||
use craft::draw::ui::VectorMode;
|
||||
|
||||
fn app() -> Box<PhotocraftApp> {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 800, "height": 600})).unwrap();
|
||||
app.sync_views();
|
||||
app.ui.tool = Tool::FreeformPen;
|
||||
app.ui.extras.snap = false;
|
||||
app.ui.tool_options.vector_mode = VectorMode::Path;
|
||||
app
|
||||
}
|
||||
|
||||
/// The anchors of the Work Path a vee from (100,450) down to (250,550) and up to (400,450) leaves, drawn with `mods`.
|
||||
fn vee(mods: Modifiers) -> Vec<[f64; 2]> {
|
||||
let mut app = app();
|
||||
testing::press(&mut app, [100.0, 450.0], mods);
|
||||
for i in 1..=10 {
|
||||
let t = f64::from(i) / 10.0;
|
||||
testing::move_to(&mut app, [100.0 + 150.0 * t, 450.0 + 100.0 * t], mods);
|
||||
}
|
||||
for i in 1..=10 {
|
||||
let t = f64::from(i) / 10.0;
|
||||
testing::move_to(&mut app, [250.0 + 150.0 * t, 550.0 - 100.0 * t], mods);
|
||||
}
|
||||
testing::release(&mut app, [400.0, 450.0], mods);
|
||||
let work = app.session.active().unwrap().doc.work_path.clone().expect("the stroke committed a work path");
|
||||
work.subpaths[0].knots.iter().map(|k| [k.anchor.x, k.anchor.y]).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shift_leaves_the_freehand_vee_as_drawn() {
|
||||
let plain = vee(Modifiers::NONE);
|
||||
let shifted = vee(Modifiers::SHIFT);
|
||||
assert_eq!(shifted, plain, "the same path with and without Shift");
|
||||
assert!(shifted.iter().any(|a| a[1] > 520.0), "the corner is kept: {shifted:?}");
|
||||
}
|
||||
@@ -37,10 +37,10 @@ pub struct Axis {
|
||||
pub dir: Option<[f64; 2]>,
|
||||
}
|
||||
|
||||
/// Tools whose drag ⇧ constrains: every painting tool, the Gradient tool, and the Freeform Pen
|
||||
/// (Photoshop's freehand path segment with ⇧, #7171).
|
||||
/// Tools whose drag ⇧ constrains: every painting tool and the Gradient tool. The Freeform Pen draws freehand with ⇧
|
||||
/// too (#12832).
|
||||
pub fn applies(tool: Tool) -> bool {
|
||||
tool.is_brushlike() || tool == Tool::Gradient || tool == Tool::FreeformPen
|
||||
tool.is_brushlike() || tool == Tool::Gradient
|
||||
}
|
||||
|
||||
/// Tools that ⇧-click connects to the previous stroke with a straight line.
|
||||
@@ -208,8 +208,8 @@ mod tests {
|
||||
// The Brush never locks to a diagonal: this slightly-more-vertical movement goes vertical.
|
||||
let mut axis = None;
|
||||
assert!(close(p([40.0, 43.0], &mut axis), [10.0, 43.0]), "the Brush's near-diagonal goes vertical");
|
||||
// Every other ⇧-constrained drag keeps the 45° lock (#178, and #7304 for the Freeform Pen).
|
||||
for tool in [Tool::Pencil, Tool::Eraser, Tool::FreeformPen] {
|
||||
// Every other ⇧-constrained drag keeps the 45° lock (#178).
|
||||
for tool in [Tool::Pencil, Tool::Eraser] {
|
||||
let mut axis = None;
|
||||
let q = constrain(tool, &mut axis, o, o, [40.0, 43.0], true, 1.0);
|
||||
assert!((q[0] - 10.0 - (q[1] - 10.0)).abs() < 1e-9, "{tool:?} should lock to 45°: {q:?}");
|
||||
@@ -219,8 +219,9 @@ mod tests {
|
||||
let mut axis = None;
|
||||
assert!(close(p([100.0, 100.0], &mut axis), o), "exact tie stays on the start point");
|
||||
assert!(close(p([160.0, 140.0], &mut axis), [160.0, 10.0]), "a later point breaks the tie");
|
||||
// Other tools pass through.
|
||||
// Other tools pass through, the Freeform Pen too (#12832).
|
||||
assert!(close(constrain(Tool::Move, &mut None, o, o, [30.0, 12.0], true, 1.0), [30.0, 12.0]));
|
||||
assert!(close(constrain(Tool::FreeformPen, &mut None, o, o, [40.0, 43.0], true, 1.0), [40.0, 43.0]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -67,7 +67,8 @@ impl Default for FreeformPenTool {
|
||||
Self {
|
||||
admit: Admit::Open,
|
||||
refused: false,
|
||||
draft: OutlineDraft::new(DraftKind::Mixed, DraftReach::new(0.0, 0.0)).locking_shift_drags(),
|
||||
// ⇧ leaves the freehand trace as drawn, as the reference's Freeform Pen does (#12832).
|
||||
draft: OutlineDraft::new(DraftKind::Mixed, DraftReach::new(0.0, 0.0)),
|
||||
owner: None,
|
||||
target: None,
|
||||
closed: None,
|
||||
|
||||
@@ -133,20 +133,3 @@ fn another_freeform_trace_cannot_replace_a_failed_owned_draft_or_retry_it_automa
|
||||
assert_eq!(app.session.journal.len(), journal, "drawing must not retry the failed engine command");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shift_drag_constrains_freeform_pen_to_a_straight_line() {
|
||||
let mut app = app();
|
||||
app.ui.tool_options.vector_mode = VectorMode::Path;
|
||||
let shift = Modifiers::SHIFT;
|
||||
testing::press(&mut app, [10.0, 60.0], shift);
|
||||
for (x, y) in [(30.0, 63.0), (50.0, 55.0), (80.0, 68.0), (100.0, 52.0)] {
|
||||
testing::move_to(&mut app, [x, y], shift);
|
||||
}
|
||||
testing::release(&mut app, [100.0, 52.0], shift);
|
||||
let work = app.session.active().unwrap().doc.work_path.clone().expect("the stroke committed a work path");
|
||||
let knots = &work.subpaths[0].knots;
|
||||
assert!(knots.len() >= 2, "{knots:?}");
|
||||
let y0 = knots[0].anchor.y;
|
||||
assert!(knots.iter().all(|k| (k.anchor.y - y0).abs() < 1e-6), "⇧ keeps the freehand segment horizontal: {knots:?}");
|
||||
}
|
||||
Reference in new issue
Block a user