diff --git a/src/app.rs b/src/app.rs index 9be8ac7..3c657a7 100644 --- a/src/app.rs +++ b/src/app.rs @@ -236,7 +236,7 @@ impl App { let close = self .dialog_manager .get_proxy() - .spawn_dialog("Unsaved changes", move |ui| { + .spawn_dialog("Unsaved changes", move |ui, enter| { ui.label( "You have unsaved changes are you sure you want to close this image?", ); @@ -249,6 +249,11 @@ impl App { return Some(false); } + if *enter { + *enter = false; + return Some(true); + } + None }) .inner @@ -287,11 +292,14 @@ impl App { let error = error.clone(); self.dialog_manager .get_proxy() - .spawn_dialog("Error", move |ui| { + .spawn_dialog("Error", move |ui, enter| { ui.label(&error); ui.with_layout(egui::Layout::left_to_right(egui::Align::LEFT), |ui| { if ui.button("Ok").clicked() { Some(()) + } else if *enter { + *enter = false; + Some(()) } else { None } @@ -305,7 +313,7 @@ impl App { if self.op_queue.undo_stack().is_edited() { thread::spawn(move || { let close = dialog_proxy - .spawn_dialog("Unsaved changes", move |ui| { + .spawn_dialog("Unsaved changes", move |ui, enter| { ui.label( "You have unsaved changes are you sure you want to close this image?", ); @@ -320,6 +328,11 @@ impl App { return Some(false); } + if *enter { + *enter = false; + return Some(true); + } + None }, ) @@ -381,7 +394,7 @@ impl App { self.metadata_ui(ctx); self.crop_ui(ctx); - self.dialog_manager.update(ctx, self.size); + self.dialog_manager.update(ctx, self.size, &mut self.enter); } pub fn main_area(&mut self, wgpu: &WgpuState, ctx: &egui::Context) { @@ -1146,7 +1159,7 @@ pub fn delete( dialog_proxy: DialogProxy, proxy: EventLoopProxy, ) { - dialog_proxy.spawn_dialog("Move to trash", move |ui| { + dialog_proxy.spawn_dialog("Move to trash", move |ui, enter| { ui.label("Are you sure you want to move this to trash?"); ui.with_layout(egui::Layout::left_to_right(egui::Align::LEFT), |ui| { @@ -1159,6 +1172,12 @@ pub fn delete( return Some(()); } + if *enter { + *enter = false; + let _ = proxy.send_event(UserEvent::QueueDelete(path.clone())); + return Some(()); + } + None }) .inner diff --git a/src/app/dialog_manager.rs b/src/app/dialog_manager.rs index 4fc20fa..6a516e4 100644 --- a/src/app/dialog_manager.rs +++ b/src/app/dialog_manager.rs @@ -9,8 +9,8 @@ use winit::event_loop::EventLoopProxy; use crate::util::{p2, UserEvent}; -trait UiClosure: Fn(&mut egui::Ui) -> bool + Send {} -impl bool + Send> UiClosure for T {} +trait UiClosure: Fn(&mut egui::Ui, &mut bool) -> bool + Send {} +impl bool + Send> UiClosure for T {} struct Dialog { name: &'static str, @@ -39,7 +39,7 @@ impl DialogManager { self.proxy.clone() } - pub fn update(&mut self, ctx: &egui::Context, size: Vector2) { + pub fn update(&mut self, ctx: &egui::Context, size: Vector2, enter: &mut bool) { let mut rng = thread_rng(); while let Ok(dialog) = self.receiver.try_recv() { self.dialogs.insert(rng.gen(), dialog); @@ -56,7 +56,7 @@ impl DialogManager { .pivot(egui::Align2::CENTER_CENTER) .default_pos(p2(Point2::from_vec(size / 2.0))) .open(&mut open) - .show(ctx, |ui| done = (dialog.closure)(ui)); + .show(ctx, |ui| done = (dialog.closure)(ui, enter)); if !open || done { self.dialogs.remove(&key); } @@ -73,12 +73,12 @@ pub struct DialogProxy { impl DialogProxy { pub fn spawn_dialog(&self, name: &'static str, closure: F) -> DialogHandle where - F: Fn(&mut egui::Ui) -> Option + Send + 'static, + F: Fn(&mut egui::Ui, &mut bool) -> Option + Send + 'static, T: 'static + Send, { let (tx, rx) = mpsc::channel(); - let outer = move |ui: &mut egui::Ui| { - let value = (closure)(ui); + let outer = move |ui: &mut egui::Ui, enter: &mut bool| { + let value = (closure)(ui, enter); match value { Some(value) => { let _ = tx.send(value); diff --git a/src/app/menu_bar.rs b/src/app/menu_bar.rs index 5bbb65f..abef6a7 100644 --- a/src/app/menu_bar.rs +++ b/src/app/menu_bar.rs @@ -51,7 +51,12 @@ impl App { ) .clicked() { - save_image::open(self.current_filename.clone(), self.proxy.clone(), wgpu); + if let Some(image) = self.image_view.as_ref() { + if let Some(path) = &image.path { + let buf = path.to_path_buf(); + self.queue(Op::LoadPath(buf, false)); + } + } ui.close_menu(); } @@ -333,9 +338,14 @@ impl App { self.dialog_manager.get_proxy().spawn_dialog( "About", - move |ui| -> Option<()> { + move |ui, enter| -> Option<()> { ui.label(&about); + if *enter { + *enter = false; + return Some(()); + } + ui.button("Ok").clicked().then_some(()) }, ); diff --git a/src/app/op_queue.rs b/src/app/op_queue.rs index 56862e8..956ef4b 100644 --- a/src/app/op_queue.rs +++ b/src/app/op_queue.rs @@ -320,7 +320,7 @@ impl OpQueue { if edited_prompt { let close = dialog_proxy - .spawn_dialog("Unsaved changes", move |ui| { + .spawn_dialog("Unsaved changes", move |ui, enter| { ui.label( "You have unsaved changes are you sure you want to close this image?", ); @@ -334,6 +334,11 @@ impl OpQueue { return Some(false); } + if *enter { + *enter = false; + return Some(true); + } + None }) .inner diff --git a/src/app/save_image.rs b/src/app/save_image.rs index f687ad5..f5df2f7 100644 --- a/src/app/save_image.rs +++ b/src/app/save_image.rs @@ -133,7 +133,7 @@ pub fn save( pub fn get_jpeg_quality(dialog_proxy: DialogProxy) -> Option { dialog_proxy - .spawn_dialog("Export settings", |ui| { + .spawn_dialog("Export settings", |ui, enter| { let mut preferences = PREFERENCES.lock().unwrap(); let mut output = None; egui::Grid::new("jpeg export settings grid").show(ui, |ui| { @@ -160,6 +160,11 @@ pub fn get_jpeg_quality(dialog_proxy: DialogProxy) -> Option { } }, ); + + if *enter { + *enter = false; + output = Some(Some(preferences.jpeg_quality)) + } }); output }) @@ -169,7 +174,7 @@ pub fn get_jpeg_quality(dialog_proxy: DialogProxy) -> Option { pub fn get_webp_quality(dialog_proxy: DialogProxy) -> Option<(f32, bool)> { dialog_proxy - .spawn_dialog("Export settings", |ui| { + .spawn_dialog("Export settings", |ui, enter| { let mut preferences = PREFERENCES.lock().unwrap(); let mut output = None; egui::Grid::new("webp export settings grid").show(ui, |ui| { @@ -205,6 +210,11 @@ pub fn get_webp_quality(dialog_proxy: DialogProxy) -> Option<(f32, bool)> { } }, ); + + if *enter { + *enter = false; + output = Some(Some((preferences.webp_quality, preferences.webp_lossy))) + } }); output })