editing: Correctly detect if trash is supported

Don't activate "Replace Original" action, if trashing of the original
file is not supported.

Closes #509
This commit is contained in:
Sophie Herold 2025-10-21 22:47:39 +02:00
parent 2c121bf19e
commit 246c4a6bcc
2 changed files with 7 additions and 2 deletions

View file

@ -0,0 +1 @@
editing: Don't enable option to trash and replace with trash is not supported.

View file

@ -15,7 +15,7 @@
// //
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
use std::cell::{OnceCell, RefCell}; use std::cell::{Cell, OnceCell, RefCell};
use std::sync::Arc; use std::sync::Arc;
use adw::prelude::*; use adw::prelude::*;
@ -56,6 +56,9 @@ mod imp {
#[property(get, construct_only)] #[property(get, construct_only)]
pub edit_crop: OnceCell<LpEditCrop>, pub edit_crop: OnceCell<LpEditCrop>,
/// Whether the original file can be trashed
pub(super) can_trash: Cell<bool>,
pub(super) operations: RefCell<Option<Arc<Operations>>>, pub(super) operations: RefCell<Option<Arc<Operations>>>,
save_cancellable: RefCell<Option<gio::Cancellable>>, save_cancellable: RefCell<Option<gio::Cancellable>>,
} }
@ -107,6 +110,7 @@ mod imp {
obj, obj,
async move { async move {
let can_trash = obj.original_image().can_trash().await; let can_trash = obj.original_image().can_trash().await;
obj.imp().can_trash.replace(can_trash);
obj.action_set_enabled("edit.save-overwrite", can_trash); obj.action_set_enabled("edit.save-overwrite", can_trash);
} }
)); ));
@ -451,7 +455,7 @@ mod imp {
let enabled = self.is_save_sensitive() && !force_disabled; let enabled = self.is_save_sensitive() && !force_disabled;
self.save.set_sensitive(enabled); self.save.set_sensitive(enabled);
obj.action_set_enabled("edit.save-overwrite", enabled); obj.action_set_enabled("edit.save-overwrite", enabled & self.can_trash.get());
obj.action_set_enabled("edit.save-copy", enabled); obj.action_set_enabled("edit.save-copy", enabled);
} }
} }