mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 20:16:29 -05:00
Merge pull request #19033
Co-authored-by: autocraft-bot[bot] <354215646+autocraft-bot[bot]@users.noreply.github.com>
This commit is contained in:
commit
c091426fdd
4 files changed
+134
-2
No files matched your search
@@ -0,0 +1,116 @@
|
||||
use craft::ui::dialog::{DialogId, StackDialog as _};
|
||||
use craft::ui::patterns::form_dialogs::HostedParamDialog;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::PhotocraftApp;
|
||||
|
||||
use super::tab_title_at;
|
||||
|
||||
const CONVERT: &str = "edit.convertToProfile";
|
||||
|
||||
fn app() -> Box<PhotocraftApp> {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.run("file.new", json!({"width": 40, "height": 30, "name": "oracle", "background": "white"})).unwrap();
|
||||
app.sync_views();
|
||||
app
|
||||
}
|
||||
|
||||
fn open(app: &mut PhotocraftApp, command: &str) -> DialogId {
|
||||
let ctx = app.ctx().clone();
|
||||
crate::menus::invoke(app, &ctx, command, json!({})).unwrap();
|
||||
app.framework.dialogs.get::<HostedParamDialog>().unwrap().id()
|
||||
}
|
||||
|
||||
fn set(app: &mut PhotocraftApp, dialog: DialogId, key: &str, value: Value) {
|
||||
let ctx = app.ctx().clone();
|
||||
app.framework.dialogs.set_json_field(&ctx, dialog, key, value).unwrap();
|
||||
}
|
||||
|
||||
fn title(app: &PhotocraftApp) -> String {
|
||||
tab_title_at(app, app.session.active_index().unwrap(), 100.0)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn convert_profile_preview_suffix_follows_the_checkbox_immediately() {
|
||||
let mut app = app();
|
||||
let normal = title(&app);
|
||||
assert_eq!(normal, "oracle @ 100% (RGB/8)");
|
||||
let dialog = open(&mut app, CONVERT);
|
||||
set(&mut app, dialog, "preview", json!(true));
|
||||
assert_eq!(title(&app), "oracle @ 100% (RGB/8/Preview)");
|
||||
assert!(app.filter_preview.is_none(), "the title does not wait for the pixel preview worker");
|
||||
set(&mut app, dialog, "preview", json!(false));
|
||||
assert_eq!(title(&app), normal);
|
||||
set(&mut app, dialog, "preview", json!(true));
|
||||
assert!(title(&app).ends_with("/Preview)"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ok_and_cancel_each_restore_the_normal_title() {
|
||||
for confirm in [false, true] {
|
||||
let mut app = app();
|
||||
let normal = title(&app);
|
||||
let dialog = open(&mut app, CONVERT);
|
||||
set(&mut app, dialog, "profile", json!("srgb"));
|
||||
set(&mut app, dialog, "preview", json!(true));
|
||||
assert!(title(&app).ends_with("/Preview)"));
|
||||
let ctx = app.ctx().clone();
|
||||
if confirm {
|
||||
crate::dialogs::confirm(&mut app, &ctx, dialog).unwrap();
|
||||
} else {
|
||||
crate::dialogs::cancel(&mut app, &ctx, dialog).unwrap();
|
||||
}
|
||||
assert!(app.framework.dialogs.get_by_id::<HostedParamDialog>(dialog).is_none());
|
||||
assert_eq!(title(&app), normal);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_the_active_document_gets_the_suffix() {
|
||||
let mut app = app();
|
||||
app.run("file.new", json!({"width": 40, "height": 30, "name": "other", "background": "white"})).unwrap();
|
||||
app.sync_views();
|
||||
let dialog = open(&mut app, CONVERT);
|
||||
set(&mut app, dialog, "preview", json!(true));
|
||||
assert_eq!(tab_title_at(&app, 0, 50.0), "oracle @ 50% (RGB/8)");
|
||||
assert_eq!(tab_title_at(&app, 1, 100.0), "other @ 100% (RGB/8/Preview)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn other_preview_dialogs_keep_their_normal_tab_title() {
|
||||
for command in ["edit.assignProfile", "filter.blur.gaussianBlur"] {
|
||||
let mut app = app();
|
||||
let normal = title(&app);
|
||||
let dialog = open(&mut app, command);
|
||||
set(&mut app, dialog, "preview", json!(true));
|
||||
assert!(app.framework.dialogs.get_by_id::<HostedParamDialog>(dialog).unwrap().is_previewing());
|
||||
assert_eq!(title(&app), normal, "{command}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn existing_mode_depth_and_layer_labels_stay_in_front_of_the_suffix() {
|
||||
for (mode, depth) in [("rgb", 16), ("rgb", 32), ("cmyk", 8), ("grayscale", 16), ("lab", 8)] {
|
||||
let mut app = app();
|
||||
app.run("file.new", json!({"width": 40, "height": 30, "mode": mode, "depth": depth, "name": "modes", "background": "white"})).unwrap();
|
||||
app.sync_views();
|
||||
app.run("layer.new.layer", json!({"name": "Paint"})).unwrap();
|
||||
let normal = title(&app);
|
||||
let dialog = open(&mut app, CONVERT);
|
||||
set(&mut app, dialog, "preview", json!(true));
|
||||
let expected = format!("{}/Preview)", normal.strip_suffix(')').unwrap());
|
||||
assert_eq!(title(&app), expected, "{mode}/{depth}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn preview_checkbox_changes_the_cached_document_area_version() {
|
||||
let mut app = app();
|
||||
let dialog = open(&mut app, CONVERT);
|
||||
set(&mut app, dialog, "preview", json!(false));
|
||||
let before = crate::panels::region_versions::canvas(&app);
|
||||
set(&mut app, dialog, "preview", json!(true));
|
||||
assert_ne!(crate::panels::region_versions::canvas(&app), before);
|
||||
set(&mut app, dialog, "preview", json!(false));
|
||||
assert_eq!(crate::panels::region_versions::canvas(&app), before);
|
||||
}
|
||||
@@ -275,7 +275,12 @@ pub(crate) fn tab_title_at(app: &PhotocraftApp, i: usize, zoom: f32) -> String {
|
||||
};
|
||||
// A save in progress: "name @ 100% (Layer 1, RGB/16) - Saving 45%", as Photoshop does (#3389).
|
||||
let saving = crate::jobs_ui::save_progress(app, st.doc.id).map(|s| format!(" - {s}")).unwrap_or_default();
|
||||
format!("{} @ {}% ({layer}{mode}){saving}", titled_name(app, st), fmt_zoom(zoom))
|
||||
let preview = if app.session.active_index() == Some(i) && crate::filter_dialog::convert_profile_previewing(app) {
|
||||
format!("/{}", tl!("Preview"))
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
format!("{} @ {}% ({layer}{mode}{preview}){saving}", titled_name(app, st), fmt_zoom(zoom))
|
||||
}
|
||||
|
||||
/// The document's name as its tab and window title show it: "© name" when File Info marks it
|
||||
@@ -330,3 +335,7 @@ mod tabs_perspective_crop_close_tests;
|
||||
#[cfg(test)]
|
||||
#[path = "../tab_title_channel_target_tests.rs"]
|
||||
mod tab_title_channel_target_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "convert_profile_preview_title_tests.rs"]
|
||||
mod convert_profile_preview_title_tests;
|
||||
@@ -14,7 +14,7 @@ use std::sync::Arc;
|
||||
use craft::behavior::NumberCodec;
|
||||
use craft::host::{PickRequest, Picked};
|
||||
use craft::ui::contract::{Bind, Show as _};
|
||||
use craft::ui::dialog::{DialogId, dialog_id};
|
||||
use craft::ui::dialog::{DialogId, StackDialog as _, dialog_id};
|
||||
use craft::ui::patterns::form_dialogs::{DialogFields, FieldValue, HostedParamDialog, Param, ParamDialog, ParamKind, ParamLayout, ParamResult};
|
||||
use craft::ui::runtime::env::{Env, Label, UnitKind};
|
||||
use craft::ui::runtime::requests::PathKind;
|
||||
@@ -207,6 +207,12 @@ pub(crate) fn previews(command: &str) -> bool {
|
||||
command.starts_with("filter.") || PREVIEWED.contains(&command)
|
||||
}
|
||||
|
||||
/// Whether the open Convert to Profile dialog currently asks to preview the active document.
|
||||
/// Read the live checkbox, since a worker result may arrive late or remain while OK commits.
|
||||
pub(crate) fn convert_profile_previewing(app: &PhotocraftApp) -> bool {
|
||||
app.framework.dialogs.get::<HostedParamDialog>().is_some_and(|dialog| dialog.key() == Some("edit.convertToProfile") && dialog.is_previewing())
|
||||
}
|
||||
|
||||
/// Whether `command` opens a schema dialog.
|
||||
pub fn has_dialog(command: &str) -> bool {
|
||||
// The Filter Gallery has its own full-window dialog (gallery_ui).
|
||||
|
||||
@@ -314,6 +314,7 @@ pub(crate) fn canvas(app: &PhotocraftApp) -> u64 {
|
||||
crate::canvas::filter_preview::canvas_key(app),
|
||||
crate::levels_clipping::canvas_key(app),
|
||||
crate::color_range_ui::canvas_key(app),
|
||||
crate::filter_dialog::convert_profile_previewing(app),
|
||||
);
|
||||
let opening: Vec<_> = crate::jobs_ui::open_tabs(app).into_iter().map(|(job, _, fraction)| (job, fraction.map(f32::to_bits))).collect();
|
||||
let display = crate::monitor_status::view_display(app, app.ctx());
|
||||
|
||||
Reference in new issue
Block a user