Add Ctrl+Z undo last batch and register select/deselect shortcuts
- Ctrl+Z moves output files from last batch to system trash via GIO - Select all / deselect all actions now registered as window actions - Shortcuts registered: Ctrl+A, Ctrl+Shift+A, Ctrl+Z
This commit is contained in:
@@ -130,6 +130,7 @@ fn setup_shortcuts(app: &adw::Application) {
|
|||||||
app.set_accels_for_action("win.add-files", &["<Control>o"]);
|
app.set_accels_for_action("win.add-files", &["<Control>o"]);
|
||||||
app.set_accels_for_action("win.select-all-images", &["<Control>a"]);
|
app.set_accels_for_action("win.select-all-images", &["<Control>a"]);
|
||||||
app.set_accels_for_action("win.deselect-all-images", &["<Control><Shift>a"]);
|
app.set_accels_for_action("win.deselect-all-images", &["<Control><Shift>a"]);
|
||||||
|
app.set_accels_for_action("win.undo-last-batch", &["<Control>z"]);
|
||||||
app.set_accels_for_action("app.quit", &["<Control>q"]);
|
app.set_accels_for_action("app.quit", &["<Control>q"]);
|
||||||
app.set_accels_for_action("win.show-settings", &["<Control>comma"]);
|
app.set_accels_for_action("win.show-settings", &["<Control>comma"]);
|
||||||
app.set_accels_for_action("win.show-shortcuts", &["<Control>question", "F1"]);
|
app.set_accels_for_action("win.show-shortcuts", &["<Control>question", "F1"]);
|
||||||
@@ -545,6 +546,16 @@ fn setup_window_actions(window: &adw::ApplicationWindow, ui: &WizardUi) {
|
|||||||
action_group.add_action(&action);
|
action_group.add_action(&action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Undo last batch action
|
||||||
|
{
|
||||||
|
let ui = ui.clone();
|
||||||
|
let action = gtk::gio::SimpleAction::new("undo-last-batch", None);
|
||||||
|
action.connect_activate(move |_, _| {
|
||||||
|
undo_last_batch(&ui);
|
||||||
|
});
|
||||||
|
action_group.add_action(&action);
|
||||||
|
}
|
||||||
|
|
||||||
// Keyboard shortcuts window
|
// Keyboard shortcuts window
|
||||||
{
|
{
|
||||||
let window = window.clone();
|
let window = window.clone();
|
||||||
@@ -1459,6 +1470,43 @@ fn wire_results_actions(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn undo_last_batch(ui: &WizardUi) {
|
||||||
|
let history = pixstrip_core::storage::HistoryStore::new();
|
||||||
|
let entries = match history.list() {
|
||||||
|
Ok(e) => e,
|
||||||
|
Err(_) => {
|
||||||
|
ui.toast_overlay.add_toast(adw::Toast::new("No processing history available"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let Some(last) = entries.last() else {
|
||||||
|
ui.toast_overlay.add_toast(adw::Toast::new("No batches to undo"));
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
if last.output_files.is_empty() {
|
||||||
|
ui.toast_overlay.add_toast(adw::Toast::new("No output files recorded for last batch"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move output files to trash using GIO
|
||||||
|
let mut trashed = 0usize;
|
||||||
|
for path_str in &last.output_files {
|
||||||
|
let file = gtk::gio::File::for_path(path_str);
|
||||||
|
if file.trash(gtk::gio::Cancellable::NONE).is_ok() {
|
||||||
|
trashed += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let toast = adw::Toast::new(&format!(
|
||||||
|
"Undo: moved {} files to trash",
|
||||||
|
trashed
|
||||||
|
));
|
||||||
|
toast.set_timeout(5);
|
||||||
|
ui.toast_overlay.add_toast(toast);
|
||||||
|
}
|
||||||
|
|
||||||
fn reset_wizard(ui: &WizardUi) {
|
fn reset_wizard(ui: &WizardUi) {
|
||||||
// Reset state
|
// Reset state
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user