Skip to content

Commit

Permalink
make trash-rs an optional dep resolves #18
Browse files Browse the repository at this point in the history
  • Loading branch information
Kl4rry committed Sep 16, 2022
1 parent a8eb6c3 commit ae385db
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ rexif = "0.7.3"
rfd = "0.10.0"
serde = { version = "1", features = ["derive"] }
tiny-skia = "0.6.0"
trash = "2.0"
trash = { version = "2.0", optional = true }
usvg = "0.23.0"
webbrowser = "0.7.1"
webp-animation = "0.6.0"
Expand All @@ -61,5 +61,5 @@ strip = true
opt-level = 3

[features]
default = []
default = ["trash"]
avif = ["image/avif-decoder"]
5 changes: 3 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::{
path::PathBuf,
process::Command,
sync::{
atomic::{AtomicBool, Ordering},
Expand Down Expand Up @@ -318,6 +317,7 @@ impl App {
if let Some(key) = input.virtual_keycode {
match input.state {
ElementState::Pressed => match key {
#[cfg(feature = "trash")]
VirtualKeyCode::Delete => {
if let Some(ref view) = self.image_view {
if let Some(ref path) = view.path {
Expand Down Expand Up @@ -977,7 +977,8 @@ impl App {
}
}

pub fn delete(path: PathBuf, proxy: EventLoopProxy<UserEvent>, display: &Display) {
#[cfg(feature = "trash")]
pub fn delete(path: std::path::PathBuf, proxy: EventLoopProxy<UserEvent>, display: &Display) {
let dialog = rfd::MessageDialog::new()
.set_parent(display.gl_window().window())
.set_level(rfd::MessageLevel::Warning)
Expand Down
1 change: 1 addition & 0 deletions src/app/image_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ impl ImageList {

/// Removes path from list and returns the path to the new current image in the dir.
/// Will return None if there are no more images in the current dir.
#[cfg(feature = "trash")]
pub fn trash(&mut self, path: &PathBuf) -> Option<PathBuf> {
self.cache.pop(path);
let mut lock = self.list.lock().unwrap();
Expand Down
28 changes: 15 additions & 13 deletions src/app/menu_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::thread;
use egui::{menu, TopBottomPanel};
use glium::Display;

use super::{delete, load_image, new_window, op_queue::Op, save_image, App};
use super::{load_image, new_window, op_queue::Op, save_image, App};
use crate::util::UserEvent;

mod menu_button;
Expand Down Expand Up @@ -266,21 +266,23 @@ impl App {
ui.close_menu();
}

ui.separator();

if ui
.add_enabled(
self.image_view.is_some(),
MenuButton::new("Delete").tip("Delete"),
)
.clicked()
#[cfg(feature = "trash")]
{
if let Some(ref view) = self.image_view {
if let Some(ref path) = view.path {
delete(path.clone(), self.proxy.clone(), display);
ui.separator();
if ui
.add_enabled(
self.image_view.is_some(),
MenuButton::new("Delete").tip("Delete"),
)
.clicked()
{
if let Some(ref view) = self.image_view {
if let Some(ref path) = view.path {
super::delete(path.clone(), self.proxy.clone(), display);
}
}
ui.close_menu();
}
ui.close_menu();
}
});

Expand Down
5 changes: 5 additions & 0 deletions src/app/op_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ impl OpQueue {
Op::Paste => {
clipboard::paste(self.proxy.clone());
}
#[cfg(feature = "trash")]
Op::Delete(path) => match trash::delete(&path) {
Ok(_) => match self.image_list.trash(&path) {
Some(path) => {
Expand All @@ -248,6 +249,10 @@ impl OpQueue {
.send_event(UserEvent::ErrorMessage(error.to_string()));
}
},
#[cfg(not(feature = "trash"))]
_ => {
let _ = self.proxy.send_output(Output::Done);
}
}
}
}
Expand Down

0 comments on commit ae385db

Please sign in to comment.