From d1b811aa6a20b414ab0f53b072c50627e5ae93cc Mon Sep 17 00:00:00 2001 From: lashman Date: Fri, 6 Mar 2026 14:53:04 +0200 Subject: [PATCH] Add wizard step-skipping for disabled operations Steps for disabled operations (resize, adjustments, convert, compress, metadata, watermark, rename) are automatically skipped when navigating forward or backward. Jump-to-step also respects skip logic. --- pixstrip-gtk/src/app.rs | 55 +++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/pixstrip-gtk/src/app.rs b/pixstrip-gtk/src/app.rs index 5cc34b9..b1cdd60 100644 --- a/pixstrip-gtk/src/app.rs +++ b/pixstrip-gtk/src/app.rs @@ -423,14 +423,25 @@ fn build_menu() -> gtk::gio::Menu { fn setup_window_actions(window: &adw::ApplicationWindow, ui: &WizardUi) { let action_group = gtk::gio::SimpleActionGroup::new(); - // Next step action + // Next step action (skips disabled steps) { let ui = ui.clone(); let action = gtk::gio::SimpleAction::new("next-step", None); action.connect_activate(move |_, _| { let mut s = ui.state.wizard.borrow_mut(); - if s.can_go_next() { - s.go_next(); + if !s.can_go_next() { + return; + } + let total = s.total_steps; + let cfg = ui.state.job_config.borrow(); + let mut next = s.current_step + 1; + while next < total && should_skip_step(next, &cfg) { + next += 1; + } + drop(cfg); + if next < total { + s.current_step = next; + s.visited[next] = true; let idx = s.current_step; drop(s); navigate_to_step(&ui, idx); @@ -439,18 +450,26 @@ fn setup_window_actions(window: &adw::ApplicationWindow, ui: &WizardUi) { action_group.add_action(&action); } - // Previous step action + // Previous step action (skips disabled steps) { let ui = ui.clone(); let action = gtk::gio::SimpleAction::new("prev-step", None); action.connect_activate(move |_, _| { let mut s = ui.state.wizard.borrow_mut(); - if s.can_go_back() { - s.go_back(); - let idx = s.current_step; - drop(s); - navigate_to_step(&ui, idx); + if !s.can_go_back() { + return; } + let cfg = ui.state.job_config.borrow(); + let mut prev = s.current_step.saturating_sub(1); + while prev > 0 && should_skip_step(prev, &cfg) { + prev = prev.saturating_sub(1); + } + drop(cfg); + s.current_step = prev; + s.visited[prev] = true; + let idx = s.current_step; + drop(s); + navigate_to_step(&ui, idx); }); action_group.add_action(&action); } @@ -466,7 +485,9 @@ fn setup_window_actions(window: &adw::ApplicationWindow, ui: &WizardUi) { if let Some(step) = param.and_then(|p| p.get::()) { let target = (step - 1) as usize; let s = ui.state.wizard.borrow(); - if target < s.total_steps && s.visited[target] { + let cfg = ui.state.job_config.borrow(); + if target < s.total_steps && s.visited[target] && !should_skip_step(target, &cfg) { + drop(cfg); drop(s); ui.state.wizard.borrow_mut().current_step = target; navigate_to_step(&ui, target); @@ -680,6 +701,20 @@ fn setup_window_actions(window: &adw::ApplicationWindow, ui: &WizardUi) { window.insert_action_group("win", Some(&action_group)); } +fn should_skip_step(step: usize, cfg: &JobConfig) -> bool { + match step { + 0 | 1 | 9 => false, // Workflow, Images, Output - always shown + 2 => !cfg.resize_enabled, + 3 => !cfg.adjustments_enabled, + 4 => !cfg.convert_enabled, + 5 => !cfg.compress_enabled, + 6 => !cfg.metadata_enabled, + 7 => !cfg.watermark_enabled, + 8 => !cfg.rename_enabled, + _ => false, + } +} + fn navigate_to_step(ui: &WizardUi, target: usize) { let s = ui.state.wizard.borrow();