PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Options bar: Reset Tool and Reset All Tools (#2825) (#2830)
Valentin Klein830541ded278
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rsindex 4dde4f185..c14b9fc48 100644--- a/crates/ui-egui/src/dialogs.rs+++ b/crates/ui-egui/src/dialogs.rs@@ -215,6 +215,7 @@ pub fn show(app: &mut PhotocraftApp, ctx: &egui::Context) {DialogKind::Command if crate::shape_dialog::owns(&fields) => crate::shape_dialog::body(app, ui, &mut fields),DialogKind::Command if crate::delete_layer_prompt::owns(&fields) => crate::delete_layer_prompt::body(ui, &mut fields),DialogKind::Command if crate::rasterize_prompt::owns(&fields) => crate::rasterize_prompt::body(ui, &fields),+ DialogKind::Command if crate::tool_reset::owns(&fields) => crate::tool_reset::body(ui),DialogKind::Command if crate::crop_presets::owns(&fields) => crate::crop_presets::body(app, ui, &mut fields),DialogKind::Command if crate::variables_ui::owns(&fields) => crate::variables_ui::body(app, ui, &mut fields),DialogKind::Command if crate::file_ui::owns(&fields) => crate::file_ui::body(app, ui, &mut fields),@@ -433,6 +434,7 @@ pub fn confirm(app: &mut PhotocraftApp, id: u64) -> Result<Value, String> {DialogKind::Command if crate::shape_dialog::owns(&d.fields) => crate::shape_dialog::confirm(app, &d.fields),DialogKind::Command if crate::delete_layer_prompt::owns(&d.fields) => crate::delete_layer_prompt::confirm(app, &d.fields),DialogKind::Command if crate::rasterize_prompt::owns(&d.fields) => crate::rasterize_prompt::confirm(app, &d.fields),+ DialogKind::Command if crate::tool_reset::owns(&d.fields) => crate::tool_reset::confirm(app),DialogKind::Command if crate::crop_presets::owns(&d.fields) => crate::crop_presets::confirm(app, &d.fields),DialogKind::Command if crate::variables_ui::owns(&d.fields) => crate::variables_ui::confirm(app, &d.fields),DialogKind::Command if crate::file_ui::owns(&d.fields) => crate::file_ui::confirm(app, &d.fields),diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsvindex 85dbca93d..bdb46574f 100644--- a/crates/ui-egui/src/i18n/cs.tsv+++ b/crates/ui-egui/src/i18n/cs.tsv@@ -687,6 +687,9 @@New Workspace… Nový pracovní prostor…Delete Workspace… Odstranit pracovní prostor…Reset Workspace Obnovit pracovní prostor+ Reset Tool Obnovit nástroj+ Reset All Tools Obnovit všechny nástroje+ Reset all tools to their default settings? Obnovit výchozí nastavení všech nástrojů?Lock Workspace Zamknout pracovní prostorTheme MotivPro Theme Motiv Prodiff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsvindex 31c821f4b..2f38e62dc 100644--- a/crates/ui-egui/src/i18n/de.tsv+++ b/crates/ui-egui/src/i18n/de.tsv@@ -673,6 +673,9 @@New Workspace… Neuer Arbeitsbereich…Delete Workspace… Arbeitsbereich löschen…Reset Workspace Arbeitsbereich zurücksetzen+ Reset Tool Werkzeug zurücksetzen+ Reset All Tools Alle Werkzeuge zurücksetzen+ Reset all tools to their default settings? Alle Werkzeuge auf ihre Standardeinstellungen zurücksetzen?Lock Workspace Arbeitsbereich sperrenTheme DesignPro Theme Pro-Designdiff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsvindex ffd2a314e..4ed84eb65 100644--- a/crates/ui-egui/src/i18n/el.tsv+++ b/crates/ui-egui/src/i18n/el.tsv@@ -2849,6 +2849,9 @@Reset Transform Επαναφορά μετασχηματισμούReset View Επαναφορά προβολήςReset Workspace Επαναφορά χώρου εργασίας+ Reset Tool Επαναφορά εργαλείου+ Reset All Tools Επαναφορά όλων των εργαλείων+ Reset all tools to their default settings? Επαναφορά όλων των εργαλείων στις προεπιλεγμένες ρυθμίσεις τους;Reset to defaults Επαναφορά προεπιλογώνResize image during place Αλλαγή μεγέθους εικόνας κατά την τοποθέτησηResolution: Ανάλυση:diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsvindex 8faf05f16..6898881e8 100644--- a/crates/ui-egui/src/i18n/es.tsv+++ b/crates/ui-egui/src/i18n/es.tsv@@ -679,6 +679,9 @@New Workspace… Nuevo espacio de trabajo…Delete Workspace… Eliminar espacio de trabajo…Reset Workspace Restablecer espacio de trabajo+ Reset Tool Restablecer herramienta+ Reset All Tools Restablecer todas las herramientas+ Reset all tools to their default settings? ¿Restablecer todas las herramientas a sus valores predeterminados?Lock Workspace Bloquear espacio de trabajoTheme TemaPro Theme Tema Prodiff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsvindex 95de8d6e3..81ab41c79 100644--- a/crates/ui-egui/src/i18n/fr.tsv+++ b/crates/ui-egui/src/i18n/fr.tsv@@ -670,6 +670,9 @@New Workspace… Nouvel espace de travail…Delete Workspace… Supprimer l'espace de travail…Reset Workspace Réinitialiser l'espace de travail+ Reset Tool Réinitialiser l'outil+ Reset All Tools Réinitialiser tous les outils+ Reset all tools to their default settings? Réinitialiser tous les outils à leurs paramètres par défaut ?Lock Workspace Verrouiller l'espace de travailTheme ThèmePro Theme Thème Prodiff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsvindex 1f6b5e6ff..be11cbff9 100644--- a/crates/ui-egui/src/i18n/id.tsv+++ b/crates/ui-egui/src/i18n/id.tsv@@ -663,6 +663,9 @@New Workspace… Ruang Kerja Baru…Delete Workspace… Hapus Ruang Kerja…Reset Workspace Reset Ruang Kerja+ Reset Tool Reset Alat+ Reset All Tools Reset Semua Alat+ Reset all tools to their default settings? Reset semua alat ke pengaturan bawaannya?Lock Workspace Kunci Ruang KerjaTheme TemaPro Theme Tema Prodiff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsvindex fa5526859..a564eb43f 100644--- a/crates/ui-egui/src/i18n/it.tsv+++ b/crates/ui-egui/src/i18n/it.tsv@@ -677,6 +677,9 @@New Workspace… Nuova area di lavoro…Delete Workspace… Elimina area di lavoro…Reset Workspace Ripristina area di lavoro+ Reset Tool Ripristina strumento+ Reset All Tools Ripristina tutti gli strumenti+ Reset all tools to their default settings? Ripristinare tutti gli strumenti alle impostazioni predefinite?Lock Workspace Blocca area di lavoroTheme TemaPro Theme Tema Prodiff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsvindex 0c8663a9a..9c1fd51cd 100644--- a/crates/ui-egui/src/i18n/ja.tsv+++ b/crates/ui-egui/src/i18n/ja.tsv@@ -682,6 +682,9 @@New Workspace… 新規ワークスペース…Delete Workspace… ワークスペースを削除…Reset Workspace ワークスペースをリセット+ Reset Tool ツールをリセット+ Reset All Tools すべてのツールをリセット+ Reset all tools to their default settings? すべてのツールを初期設定に戻しますか?Lock Workspace ワークスペースをロックTheme テーマPro Theme プロテーマdiff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsvindex b70784e9e..bc350c88a 100644--- a/crates/ui-egui/src/i18n/ko.tsv+++ b/crates/ui-egui/src/i18n/ko.tsv@@ -655,6 +655,9 @@New Workspace… 새 작업 영역…Delete Workspace… 작업 영역 삭제…Reset Workspace 작업 영역 초기화+ Reset Tool 도구 초기화+ Reset All Tools 모든 도구 초기화+ Reset all tools to their default settings? 모든 도구를 기본 설정으로 초기화하시겠습니까?Lock Workspace 작업 영역 잠금Theme 테마Pro Theme 프로 테마diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsvindex b76fda03e..f427ee9f7 100644--- a/crates/ui-egui/src/i18n/nl.tsv+++ b/crates/ui-egui/src/i18n/nl.tsv@@ -664,6 +664,9 @@New Workspace… Nieuwe werkruimte…Delete Workspace… Werkruimte verwijderen…Reset Workspace Werkruimte herstellen+ Reset Tool Gereedschap herstellen+ Reset All Tools Alle gereedschappen herstellen+ Reset all tools to their default settings? Alle gereedschappen herstellen naar hun standaardinstellingen?Lock Workspace Werkruimte vergrendelenTheme ThemaPro Theme Pro-themadiff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsvindex 3c77f855b..6841bf685 100644--- a/crates/ui-egui/src/i18n/pl.tsv+++ b/crates/ui-egui/src/i18n/pl.tsv@@ -680,6 +680,9 @@New Workspace… Nowy obszar roboczy…Delete Workspace… Usuń obszar roboczy…Reset Workspace Resetuj obszar roboczy+ Reset Tool Resetuj narzędzie+ Reset All Tools Resetuj wszystkie narzędzia+ Reset all tools to their default settings? Przywrócić domyślne ustawienia wszystkich narzędzi?Lock Workspace Zablokuj obszar roboczyTheme MotywPro Theme Motyw Prodiff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsvindex dbd4362d4..815f08505 100644--- a/crates/ui-egui/src/i18n/pt-br.tsv+++ b/crates/ui-egui/src/i18n/pt-br.tsv@@ -667,6 +667,9 @@New Workspace… Novo espaço de trabalho…Delete Workspace… Excluir espaço de trabalho…Reset Workspace Redefinir espaço de trabalho+ Reset Tool Redefinir ferramenta+ Reset All Tools Redefinir todas as ferramentas+ Reset all tools to their default settings? Redefinir todas as ferramentas para as configurações padrão?Lock Workspace Bloquear espaço de trabalhoTheme TemaPro Theme Tema Prodiff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsvindex 51aeb8b99..7044d7a89 100644--- a/crates/ui-egui/src/i18n/ru.tsv+++ b/crates/ui-egui/src/i18n/ru.tsv@@ -1413,6 +1413,9 @@New Workspace… Новая рабочая среда…Delete Workspace… Удалить рабочую среду…Reset Workspace Сбросить рабочую среду+ Reset Tool Сбросить инструмент+ Reset All Tools Сбросить все инструменты+ Reset all tools to their default settings? Сбросить все инструменты к настройкам по умолчанию?Lock Workspace Заблокировать рабочую средуPhotography ФотографияGraphic and web Графика и webdiff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsvindex 41a88cd09..2b5eeef07 100644--- a/crates/ui-egui/src/i18n/uk.tsv+++ b/crates/ui-egui/src/i18n/uk.tsv@@ -1395,6 +1395,9 @@New Workspace… Новий робочий простір…Delete Workspace… Видалити робочий простір…Reset Workspace Скинути робочий простір+ Reset Tool Скинути інструмент+ Reset All Tools Скинути всі інструменти+ Reset all tools to their default settings? Скинути всі інструменти до налаштувань за замовчуванням?Lock Workspace Заблокувати робочий простірPhotography ФотографіяGraphic and web Графіка та вебdiff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsvindex 6ad5ed919..2aaff8cfe 100644--- a/crates/ui-egui/src/i18n/zh-hans.tsv+++ b/crates/ui-egui/src/i18n/zh-hans.tsv@@ -682,6 +682,9 @@New Workspace… 新建工作区…Delete Workspace… 删除工作区…Reset Workspace 重置工作区+ Reset Tool 重置工具+ Reset All Tools 重置所有工具+ Reset all tools to their default settings? 要将所有工具重置为默认设置吗?Lock Workspace 锁定工作区Theme 主题Pro Theme 专业主题diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsvindex 29d1b1a01..b6dbb048a 100644--- a/crates/ui-egui/src/i18n/zh-hant.tsv+++ b/crates/ui-egui/src/i18n/zh-hant.tsv@@ -687,6 +687,9 @@New Workspace… 新增工作區…Delete Workspace… 刪除工作區…Reset Workspace 重設工作區+ Reset Tool 重設工具+ Reset All Tools 重設所有工具+ Reset all tools to their default settings? 要將所有工具重設為預設設定嗎?Lock Workspace 鎖定工作區Theme 主題Pro Theme 專業主題diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex 1f0fefc34..546d339dc 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -167,6 +167,7 @@ pub mod tone;mod tool_cursor;pub mod tool_feedback;pub(crate) mod tool_memory;+mod tool_reset;pub mod transform_tex;pub mod transform_tool;mod type_font_preview;diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rsindex 990af5e2e..401bf3b3d 100644--- a/crates/ui-egui/src/menus.rs+++ b/crates/ui-egui/src/menus.rs@@ -22,6 +22,9 @@ pub const TOP_MENUS: [&str; 10] = ["File", "Edit", "Image", "Layer", "Type", "Se/// UI-level commands (handled by the shell rather than the engine): id, label, menu, shortcut.pub const UI_COMMANDS: &[(&str, &str, &[&str], Option<&str>)] = &[("ui.symmetryTransform", "Transform Symmetry", &[], None),+ // Right-click the options bar's tool icon (#2825); `tool.resetAll` asks first.+ ("tool.reset", "Reset Tool", &[], None),+ ("tool.resetAll", "Reset All Tools", &[], None),("window.panel.group", "Change Panel Group", &[], None),("window.panel.layout", "Change Panel Layout", &[], None),("window.panel.move", "Move Panel", &[], None),@@ -155,6 +158,9 @@ pub(crate) fn invoke_unguarded(app: &mut PhotocraftApp, ctx: &egui::Context, id:if id == "ui.symmetryTransform" {return crate::symmetry_ui::begin(app).map(|_| Value::Null);}+ if let Some(r) = crate::tool_reset::invoke(app, id, ¶ms) {+ return r;+ }// A pending Pen anchor is gesture state; Edit › Undo must match the keyboard.if id == "edit.undo" && crate::vector_ui::pen_undo_last_point(app) {return Ok(Value::Null);diff --git a/crates/ui-egui/src/paint_mouse.rs b/crates/ui-egui/src/paint_mouse.rsindex 382a28458..d754b20b4 100644--- a/crates/ui-egui/src/paint_mouse.rs+++ b/crates/ui-egui/src/paint_mouse.rs@@ -58,6 +58,12 @@ fn session_fields(current: &BrushSettings, brush: &BrushSettings) -> BrushSettinBrushSettings { color: current.color, background: current.background, erase: current.erase, seed: current.seed, ..brush.clone() }}+/// A tool's brush as it starts out (Reset Tool, #2825): the default brush at Photoshop's+/// smoothing, with the session's own fields of `current`.+pub(crate) fn fresh_brush(current: &BrushSettings) -> BrushSettings {+ session_fields(current, &BrushSettings { smoothing: first_smoothing(), ..BrushSettings::default() })+}+/// Photoshop's 10 % stroke smoothing, what a tool's brush starts at.fn first_smoothing() -> photocraft_engine::paint::brush::Smoothing {photocraft_engine::paint::brush::Smoothing { amount: 0.1, ..Default::default() }diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rsindex 4748d2bc0..e5bef7643 100644--- a/crates/ui-egui/src/panels.rs+++ b/crates/ui-egui/src/panels.rs@@ -834,7 +834,24 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {crate::chrome_ui::home_button(app, ui);widgets::vline(ui, 22.0);}- let _ = icons::button(ui, icons::tool_icon(app.ui.tool), if t.pro { 26.0 } else { 28.0 }, !t.pro, tl!(app.ui.tool.label()));+ let tool_icon = icons::button(ui, icons::tool_icon(app.ui.tool), if t.pro { 26.0 } else { 28.0 }, !t.pro, tl!(app.ui.tool.label()));+ // Photoshop: right-click the tool icon for Reset Tool / Reset All Tools (#2825).+ let mut reset = None;+ tool_icon.context_menu(|ui| {+ if ui.button(tl!("Reset Tool")).clicked() {+ reset = Some("tool.reset");+ ui.close();+ }+ if ui.button(tl!("Reset All Tools")).clicked() {+ reset = Some("tool.resetAll");+ ui.close();+ }+ });+ if let Some(id) = reset+ && let Err(e) = crate::menus::invoke(app, ui.ctx(), id, json!({}))+ {+ app.ui.status = e;+ }if t.pro {let (r, _) = ui.allocate_exact_size(vec2(10.0, 20.0), Sense::hover());icons::paint(ui, r, "chevron-down", 10.0, t.text_faint);diff --git a/crates/ui-egui/src/tool_reset.rs b/crates/ui-egui/src/tool_reset.rsnew file mode 100644index 000000000..eb8cd5816--- /dev/null+++ b/crates/ui-egui/src/tool_reset.rs@@ -0,0 +1,219 @@+//! Reset Tool and Reset All Tools (#2825), as in Photoshop: right-click the tool icon at the far+//! left of the options bar. Reset Tool puts the current tool's options back to their defaults;+//! Reset All Tools asks first ("Reset all tools to their default settings?"), then resets every+//! tool's options.+//!+//! Both are shell commands (`tool.reset`, `tool.resetAll`) that the control channel can run.+//! `tool.resetAll` opens the confirmation as an ordinary dialog (`ui.dialog.confirm` /+//! `ui.dialog.cancel` answer it); `{"confirmed": true}` skips it, for agents that already asked.+//!+//! What a tool's options are: [`ToolOptions`] is one struct, not one per tool, and a few fields+//! are shared by the tools that show them (Tolerance, Anti-alias, Contiguous and Sample All Layers+//! by the Magic Wand, Paint Bucket and Magic Eraser; Feather by the marquees and lassos; Strength+//! by Blur, Sharpen and Smudge). Resetting one of those tools resets the shared field too.+//! [`reset_options`] lists the fields of each tool. The selection tools also go back to New+//! Selection, and the painting tools (the ones with a brush in the options bar) get the default+//! brush, keeping the colours. Tools without options (Hand, Rotate View, Ruler, Note, …) have+//! nothing to reset.++use serde_json::{Map, Value, json};++use crate::PhotocraftApp;+use crate::state::{DialogKind, Tool, ToolOptions};++pub const RESET: &str = "tool.reset";+pub const RESET_ALL: &str = "tool.resetAll";+const MARK: &str = "__resetAllTools";+const MESSAGE: &str = "Reset all tools to their default settings?";++/// Is this the Reset All Tools confirmation?+pub fn owns(fields: &Map<String, Value>) -> bool {+ fields.contains_key(MARK)+}++/// Run `tool.reset` / `tool.resetAll`; `None` for any other command.+pub fn invoke(app: &mut PhotocraftApp, id: &str, params: &Value) -> Option<Result<Value, String>> {+ match id {+ RESET => {+ let tool = app.ui.tool;+ reset_tool(app, tool);+ Some(Ok(json!({"reset": tool.label()})))+ }+ RESET_ALL if params.get("confirmed").and_then(Value::as_bool) == Some(true) => {+ reset_all(app);+ Some(Ok(json!({"reset": "all"})))+ }+ RESET_ALL => {+ if let Some(d) = app.ui.dialogs.iter().find(|d| owns(&d.fields)) {+ return Some(Ok(json!({"dialog": d.id, "confirmationPending": true})));+ }+ let fields = json!({MARK: true, "__label": "Reset All Tools", "message": MESSAGE});+ let id = app.ui.open_dialog(DialogKind::Command, fields.as_object().cloned().unwrap_or_default());+ Some(Ok(json!({"dialog": id, "confirmationPending": true})))+ }+ _ => None,+ }+}++/// The confirmation's text.+pub fn body(ui: &mut egui::Ui) {+ ui.label(tl!("Reset all tools to their default settings?"));+}++/// OK in the confirmation.+pub fn confirm(app: &mut PhotocraftApp) -> Result<Value, String> {+ reset_all(app);+ Ok(json!({"reset": "all"}))+}++/// Reset Tool: `tool`'s options, its selection mode and its brush.+fn reset_tool(app: &mut PhotocraftApp, tool: Tool) {+ reset_options(&mut app.ui.tool_options, tool);+ if is_selection_tool(tool) {+ app.ui.selection_mode = 0;+ }+ if crate::paint_mouse::has_brush_picker(tool) {+ // The session brush is the options bar's tool's: make sure it is `tool`'s before resetting.+ crate::paint_mouse::sync_tool_brush(app);+ app.ui.tool_brushes.retain(|(t, _)| *t != tool);+ reset_session_brush(app);+ }+}++/// Reset All Tools: every option, the selection mode and every tool's brush.+fn reset_all(app: &mut PhotocraftApp) {+ app.ui.tool_options = ToolOptions::default();+ app.ui.selection_mode = 0;+ app.ui.tool_brushes.clear();+ reset_session_brush(app);+}++fn reset_session_brush(app: &mut PhotocraftApp) {+ app.session.tools.brush = crate::paint_mouse::fresh_brush(&app.session.tools.brush);+ app.session.tools.brush_gesture = None;+ app.session.tools.current_preset = None;+}++fn is_selection_tool(tool: Tool) -> bool {+ matches!(+ tool,+ Tool::RectMarquee+ | Tool::EllipseMarquee+ | Tool::SingleRowMarquee+ | Tool::SingleColumnMarquee+ | Tool::Lasso+ | Tool::PolygonLasso+ | Tool::MagneticLasso+ | Tool::MagicWand+ | Tool::QuickSelection+ | Tool::ObjectSelection+ )+}++/// Put `tool`'s fields of `o` back to their defaults.+pub fn reset_options(o: &mut ToolOptions, tool: Tool) {+ let d = ToolOptions::default();+ macro_rules! reset {+ ($($f:ident),* $(,)?) => {{ $( o.$f = d.$f.clone(); )* }};+ }+ match tool {+ Tool::Move => reset!(move_auto_select, move_target, move_show_transform),+ Tool::RectMarquee | Tool::EllipseMarquee => reset!(feather, anti_alias, marquee_style, marquee_width, marquee_height),+ // The single-pixel marquees are never anti-aliased: Feather is their only option.+ Tool::SingleRowMarquee | Tool::SingleColumnMarquee => reset!(feather),+ Tool::Lasso | Tool::PolygonLasso => reset!(feather, anti_alias),+ Tool::MagneticLasso => reset!(feather, anti_alias, magnetic_width, magnetic_contrast, magnetic_frequency, magnetic_pressure),+ Tool::MagicWand => reset!(tolerance, anti_alias, contiguous, sample_all_layers),+ Tool::QuickSelection | Tool::ObjectSelection => reset!(sample_all_layers, enhance_edge),+ Tool::Crop => reset!(+ crop_ratio,+ crop_delete,+ crop_width,+ crop_height,+ crop_resolution,+ crop_resolution_unit,+ crop_overlay,+ crop_overlay_show,+ crop_overlay_orientation,+ crop_shield,+ crop_custom_ratio_width,+ crop_custom_ratio_height,+ ),+ Tool::Eyedropper => reset!(eyedropper_size, eyedropper_sample, eyedropper_ring),+ Tool::Pencil => reset!(pencil_auto_erase),+ Tool::BackgroundEraser => reset!(bg_sampling, bg_limits, bg_tolerance, bg_protect_fg),+ Tool::ColorReplacement => reset!(cr_mode, cr_sampling, cr_limits, cr_tolerance, cr_anti_alias),+ Tool::MagicEraser => reset!(tolerance, anti_alias, contiguous, sample_all_layers, magic_eraser_opacity),+ Tool::Gradient => reset!(gradient_style, gradient_reverse, gradient_dither, gradient_classic, gradient_blend_mode, fill_opacity),+ Tool::PaintBucket => reset!(bucket_fill_pattern, fill_opacity, tolerance, anti_alias, contiguous, sample_all_layers),+ Tool::Type | Tool::VerticalType => reset!(type_font, type_style, type_size, type_aa, type_align),+ Tool::Zoom => reset!(zoom_scrubby),+ Tool::SpotHealing => reset!(spot_type, sample_all_layers),+ Tool::Healing => reset!(clone_aligned, clone_sample),+ Tool::Patch => reset!(patch_mode, patch_content_aware, patch_structure, patch_color, sample_all_layers),+ Tool::ContentAwareMove => reset!(cam_mode, cam_structure, cam_color, sample_all_layers),+ Tool::RedEye => reset!(red_eye_pupil_size, red_eye_darken),+ Tool::CloneStamp => reset!(clone_aligned, clone_sample),+ Tool::PatternStamp => reset!(pattern_stamp_aligned, pattern_stamp_impressionist, pattern_stamp_scale, pattern_stamp_angle),+ Tool::Blur | Tool::Sharpen => reset!(strength, sample_all_layers, protect_detail),+ Tool::Smudge => reset!(strength, sample_all_layers, finger_painting),+ Tool::Dodge | Tool::Burn => reset!(tone_range, exposure, protect_tones),+ Tool::Sponge => reset!(sponge_mode, vibrance),+ Tool::Pen => reset!(vector_mode),+ Tool::Rectangle | Tool::EllipseShape | Tool::Triangle | Tool::Polygon | Tool::Line | Tool::CustomShape => {+ reset!(vector_mode, shape_fill, stroke_width, shape_stroke, corner_radius, polygon_sides, line_weight)+ }+ Tool::Ruler+ | Tool::Note+ | Tool::Count+ | Tool::Brush+ | Tool::MixerBrush+ | Tool::Eraser+ | Tool::Hand+ | Tool::RotateView+ | Tool::Remove+ | Tool::HistoryBrush+ | Tool::PathSelection+ | Tool::DirectSelection+ | Tool::Slice+ | Tool::SliceSelect+ | Tool::AddAnchorPoint+ | Tool::DeleteAnchorPoint => {}+ }+}++#[cfg(test)]+mod tests {+ use super::*;++ fn app() -> PhotocraftApp {+ let mut s = photocraft_engine::Session::new();+ s.execute("file.new", json!({"width": 8, "height": 8})).unwrap();+ PhotocraftApp::new(s, crate::Services::default())+ }++ /// Reset Tool resets only the current tool's options; Reset All Tools asks, then resets all.+ #[test]+ fn reset_tool_and_reset_all_tools() {+ let mut app = app();+ let ctx = egui::Context::default();+ app.ui.tool_options.move_auto_select = false;+ app.ui.tool_options.feather = 12.0;+ app.ui.tool = Tool::Move;+ crate::menus::invoke(&mut app, &ctx, RESET, json!({})).unwrap();+ assert!(app.ui.tool_options.move_auto_select, "Move › Auto-Select is back to its default");+ assert_eq!(app.ui.tool_options.feather, 12.0, "the marquee's Feather is not the Move tool's");++ app.ui.tool_options.move_auto_select = false;+ let r = crate::menus::invoke(&mut app, &ctx, RESET_ALL, json!({})).unwrap();+ let dialog = r["dialog"].as_u64().unwrap();+ assert_eq!(app.ui.tool_options.feather, 12.0, "nothing changes before OK");+ crate::dialogs::cancel(&mut app, dialog).unwrap();+ assert_eq!(app.ui.tool_options.feather, 12.0, "Cancel keeps the options");++ let dialog = crate::menus::invoke(&mut app, &ctx, RESET_ALL, json!({})).unwrap()["dialog"].as_u64().unwrap();+ crate::dialogs::confirm(&mut app, dialog).unwrap();+ assert_eq!(app.ui.tool_options, ToolOptions::default());+ assert!(app.ui.dialogs.is_empty());+ }+}