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.
This commit is contained in:
2026-03-06 14:53:04 +02:00
parent 23c1f33d32
commit d1b811aa6a

View File

@@ -423,14 +423,25 @@ fn build_menu() -> gtk::gio::Menu {
fn setup_window_actions(window: &adw::ApplicationWindow, ui: &WizardUi) { fn setup_window_actions(window: &adw::ApplicationWindow, ui: &WizardUi) {
let action_group = gtk::gio::SimpleActionGroup::new(); let action_group = gtk::gio::SimpleActionGroup::new();
// Next step action // Next step action (skips disabled steps)
{ {
let ui = ui.clone(); let ui = ui.clone();
let action = gtk::gio::SimpleAction::new("next-step", None); let action = gtk::gio::SimpleAction::new("next-step", None);
action.connect_activate(move |_, _| { action.connect_activate(move |_, _| {
let mut s = ui.state.wizard.borrow_mut(); let mut s = ui.state.wizard.borrow_mut();
if s.can_go_next() { if !s.can_go_next() {
s.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; let idx = s.current_step;
drop(s); drop(s);
navigate_to_step(&ui, idx); navigate_to_step(&ui, idx);
@@ -439,18 +450,26 @@ fn setup_window_actions(window: &adw::ApplicationWindow, ui: &WizardUi) {
action_group.add_action(&action); action_group.add_action(&action);
} }
// Previous step action // Previous step action (skips disabled steps)
{ {
let ui = ui.clone(); let ui = ui.clone();
let action = gtk::gio::SimpleAction::new("prev-step", None); let action = gtk::gio::SimpleAction::new("prev-step", None);
action.connect_activate(move |_, _| { action.connect_activate(move |_, _| {
let mut s = ui.state.wizard.borrow_mut(); let mut s = ui.state.wizard.borrow_mut();
if s.can_go_back() { if !s.can_go_back() {
s.go_back(); return;
let idx = s.current_step;
drop(s);
navigate_to_step(&ui, idx);
} }
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); 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::<i32>()) { if let Some(step) = param.and_then(|p| p.get::<i32>()) {
let target = (step - 1) as usize; let target = (step - 1) as usize;
let s = ui.state.wizard.borrow(); 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); drop(s);
ui.state.wizard.borrow_mut().current_step = target; ui.state.wizard.borrow_mut().current_step = target;
navigate_to_step(&ui, 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)); 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) { fn navigate_to_step(ui: &WizardUi, target: usize) {
let s = ui.state.wizard.borrow(); let s = ui.state.wizard.borrow();