mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge #16079 into the merge queue batch
Assign Profile: ask before assigning on a document with layers
This commit is contained in:
commit
11f3caafc5
5 files changed
+178
-2
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))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user