Skip to content

Commit

Permalink
delete_current_image function
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrabovets committed Sep 21, 2023
1 parent 03e5c16 commit f15509d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
17 changes: 12 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}
}
7 changes: 3 additions & 4 deletions src/ui.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -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",
Expand All @@ -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);
}
}

Expand Down

0 comments on commit f15509d

Please sign in to comment.