window: Add permanently delete shortcut

Permanently delete images with Shift + Delete like in Files. Adding this
since EOG supported it as well.

Closes #323

Part-of: <https://gitlab.gnome.org/GNOME/loupe/-/merge_requests/369>
This commit is contained in:
Sophie Herold 2024-02-09 21:19:35 +01:00
parent b44412fac6
commit 0dc71357f1
3 changed files with 26 additions and 4 deletions

View file

@ -27,6 +27,12 @@
<property name="accelerator">Delete</property> <property name="accelerator">Delete</property>
</object> </object>
</child> </child>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut window">Permanently Delete Image</property>
<property name="accelerator">&lt;Shift&gt;Delete</property>
</object>
</child>
<child> <child>
<object class="GtkShortcutsShortcut"> <object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut window">Toggle Image Properties</property> <property name="title" translatable="yes" context="shortcut window">Toggle Image Properties</property>

View file

@ -158,6 +158,7 @@ impl LpApplication {
self.set_accels_for_action("win.print", &["<Ctrl>P"]); self.set_accels_for_action("win.print", &["<Ctrl>P"]);
self.set_accels_for_action("win.copy", &["<Ctrl>C"]); self.set_accels_for_action("win.copy", &["<Ctrl>C"]);
self.set_accels_for_action("win.trash", &["Delete", "KP_Delete"]); self.set_accels_for_action("win.trash", &["Delete", "KP_Delete"]);
self.set_accels_for_action("win.delete", &["<Shift>Delete", "<Shift>KP_Delete"]);
self.set_accels_for_action("win.show-help-overlay", &["<Ctrl>question"]); self.set_accels_for_action("win.show-help-overlay", &["<Ctrl>question"]);
self.set_accels_for_action("win.leave-fullscreen", &["Escape"]); self.set_accels_for_action("win.leave-fullscreen", &["Escape"]);
self.set_accels_for_action("win.toggle-properties", &["F9", "<Alt>Return"]); self.set_accels_for_action("win.toggle-properties", &["F9", "<Alt>Return"]);

View file

@ -276,6 +276,10 @@ mod imp {
win.trash().await; win.trash().await;
}); });
klass.install_action_async("win.delete", None, |win, _, _| async move {
win.delete().await;
});
klass.install_action( klass.install_action(
"win.show-toast", "win.show-toast",
Some(VariantTy::TUPLE), Some(VariantTy::TUPLE),
@ -704,7 +708,7 @@ impl LpWindow {
} }
Err(err) => { Err(err) => {
if Some(gio::IOErrorEnum::NotSupported) == err.kind::<gio::IOErrorEnum>() { if Some(gio::IOErrorEnum::NotSupported) == err.kind::<gio::IOErrorEnum>() {
self.delete(&path).await; self.delete_future(&path).await;
} else { } else {
log::error!("Failed to delete file {path:?}: {err}"); log::error!("Failed to delete file {path:?}: {err}");
self.show_toast( self.show_toast(
@ -716,16 +720,27 @@ impl LpWindow {
} }
} }
/// Delete action called
async fn delete(&self) {
let image_view = self.image_view();
let Some(path) = image_view.current_file().and_then(|x| x.path()) else {
log::error!("No file to delete");
return;
};
self.delete_future(&path).await;
}
/// Permanently delete image /// Permanently delete image
/// ///
/// Fallback for when trash not available /// Fallback for when trash not available or explicit call with shortcut
async fn delete(&self, path: &Path) { async fn delete_future(&self, path: &Path) {
let dialog = adw::MessageDialog::builder() let dialog = adw::MessageDialog::builder()
.modal(true) .modal(true)
.transient_for(self) .transient_for(self)
.heading(gettext("Permanently Delete Image?")) .heading(gettext("Permanently Delete Image?"))
.body(gettext_f( .body(gettext_f(
"The image “{}” can only be deleted permanently.", "After deleting the image “{}” it will be permanently lost.",
[PathBuf::from(&path.file_name().unwrap_or_default()) [PathBuf::from(&path.file_name().unwrap_or_default())
.display() .display()
.to_string()], .to_string()],