diff --git a/src/main.rs b/src/main.rs index bb33ff37..a0fe9546 100644 --- a/src/main.rs +++ b/src/main.rs @@ -411,11 +411,8 @@ fn event(app: &mut App, state: &mut OculanteState, evt: Event) { state.toggle_slideshow = !state.toggle_slideshow; } if key_pressed(app, state, DeleteFile) { - if let Some(img_path) = &state.current_path { - trash::delete(img_path).expect("Cannot delete file"); - state.send_message(format!("file {:?} removed", img_path).as_str()); - state.scrubber.delete(img_path); - state.reload_image(); + if state.current_path.is_some() { + delete_current_image(state); } } if key_pressed(app, state, Quit) { @@ -1350,3 +1347,13 @@ fn add_to_favourites(state: &mut OculanteState) { } } } + +fn delete_current_image(state: &mut OculanteState) { + if state.current_path.is_some() { + let img_path = state.current_path.as_ref().unwrap(); + trash::delete(&img_path).expect("Cannot delete file"); + state.send_message(format!("file {:?} removed", img_path).as_str()); + state.scrubber.delete(&img_path); + state.reload_image(); + } +} diff --git a/src/ui.rs b/src/ui.rs index 4043177f..0178ecd3 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -1,5 +1,5 @@ #[cfg(feature = "file_open")] -use crate::{browse_for_folder_path, browse_for_image_path}; +use crate::{browse_for_folder_path, browse_for_image_path, delete_current_image}; use crate::{ appstate::{ImageGeometry, Message, OculanteState}, image_editing::{process_pixels, Channel, GradientStop, ImageOperation, ScaleFilter}, @@ -1888,7 +1888,7 @@ pub fn main_menu(ui: &mut Ui, state: &mut OculanteState, app: &mut App, gfx: &mu } #[cfg(not(target_os = "netbsd"))] - if let Some(p) = &state.current_path { + if state.current_path.is_some() { if tooltip( unframed_button_colored("🗑", state.always_on_top, ui), "Move file to trash", @@ -1897,8 +1897,7 @@ pub fn main_menu(ui: &mut Ui, state: &mut OculanteState, app: &mut App, gfx: &mu ) .clicked() { - _ = trash::delete(p); - state.send_message("Deleted image"); + delete_current_image(state); } }