From 745c560409d08f6e88a9b6233eb7d18ba38e59fb Mon Sep 17 00:00:00 2001 From: Arthur Roberts Date: Mon, 10 Jul 2023 20:54:29 +0100 Subject: [PATCH] Added Drag and Drop files And fixed the add stuff window not being able to be closed --- src/main.rs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 055bf68..49474cf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -104,6 +104,7 @@ impl RustDoomLauncher { } Ok((launcher, command)) => { // Note to self, don't hit launch button when running from emacs + // if you do, close it and hold down C+g let result = Command::new(launcher).args(command).spawn(); match result { Err(e) => panic!("{}", e), @@ -399,8 +400,9 @@ impl eframe::App for RustDoomLauncher { }); } - if self.add_stuff_window_displayed { - egui::Window::new("Add WAD or Launcher").show(ctx, |ui| { + egui::Window::new("Add WAD or Launcher") + .open(&mut self.add_stuff_window_displayed) + .show(ctx, |ui| { ui.horizontal(|ui| { let name_label = ui.label("Name"); ui.text_edit_singleline(&mut self.add_name) @@ -477,6 +479,25 @@ impl eframe::App for RustDoomLauncher { } } }); - } + + ctx.input(|i| { + if !i.raw.dropped_files.is_empty() { + let dropped_files = i.raw.dropped_files.clone(); + match dropped_files.len() { + 1 => { + self.selected_file_path = dropped_files[0].path.clone().unwrap(); + self.add_stuff_window_displayed = true; + } + _ => { + MessageDialog::new() + .set_type(MessageType::Error) + .set_title("I can't let you do that") + .set_text(&format!("Multiple files not supported")) + .show_alert() + .unwrap(); + } + } + } + }); } }