diff --git a/src/boxes.rs b/src/boxes.rs index 64834ef..ba89499 100644 --- a/src/boxes.rs +++ b/src/boxes.rs @@ -1,3 +1,5 @@ +use std::rc::Rc; + use gtk4::prelude::*; use gtk4::{ glib::*, @@ -27,7 +29,6 @@ pub struct RomBox { pub rom_box: Box, pub rom_button: Button, pub rom_label: Label, - pub rom_filechooser: FileChooserDialog, } #[derive(Debug, Downgrade)] @@ -35,7 +36,6 @@ pub struct PatchBox { pub patch_box: Box, pub patch_button: Button, pub patch_label: Label, - pub patch_filechooser: FileChooserDialog, } impl AppBox { @@ -58,24 +58,42 @@ impl RomBox { rom_box: Box::new(Orientation::Horizontal, 0), rom_button: Button::new(), rom_label: Label::new(Some("Choose ROM")), - rom_filechooser: FileChooserDialog::new( - Some("Select a ROM"), - Some(app), - FileChooserAction::Open, - &[("OK", ResponseType::Ok), ("Cancel", ResponseType::Cancel)] - ), } } + + pub fn click_button(&self, window: Rc) { + self.rom_button.connect_clicked(clone!(@strong self as this => + move |_| { + let dialog = FileChooserDialog::new::( + Some("Choose a ROM"), + Some(&window), + FileChooserAction::Open, + &[("_Cancel", ResponseType::Cancel), ("_Open", ResponseType::Accept)] + ); + + dialog.run_async(|d, r| { + match r { + ResponseType::Accept => d.close(), + ResponseType::Cancel => d.close(), + _ => d.close(), + } + }) + + + + // if this.buttons[1] == this.response(ResponseType::Ok) { + + // } + })); + + // self.rom_filechooser.connect_response(clone!(@strong self.rom_filechooser as this => + // move |_, ResponseType| { + + // })); + } } impl CustomBox for RomBox { - fn click_button(&self) { - self.rom_button.connect_clicked(clone!(@weak self as this => - move |_| { - this.rom_filechooser.show(); - })); - } - fn set_button(&self) { self.rom_button.set_margin_top(20); self.rom_button.set_margin_bottom(0); @@ -107,33 +125,31 @@ impl PatchBox { patch_box: Box::new(Orientation::Horizontal, 0), patch_button: Button::new(), patch_label: Label::new(Some("Choose Patch")), - patch_filechooser: FileChooserDialog::new( - Some("Select a Patch"), - Some(app), - FileChooserAction::Open, - &[("OK", ResponseType::Ok), ("Cancel", ResponseType::Cancel)] - ), } } + + pub fn click_button(&self, app: Rc) { + self.patch_button.connect_clicked(clone!(@weak self as this => + move |_| { + let dialog = FileChooserDialog::new::( + Some("Choose a ROM"), + Some(&app), + FileChooserAction::Open, + &[("_Cancel", ResponseType::Cancel), ("_Open", ResponseType::Accept)] + ); + + dialog.run_async(|d, r| { + match r { + ResponseType::Accept => d.close(), + ResponseType::Cancel => d.close(), + _ => d.close(), + } + }) + })); + } } impl CustomBox for PatchBox{ - fn click_button(&self) { - self.patch_button.connect_clicked(clone!(@weak self as this => - move |_| { - this.patch_filechooser.show(); - - - - //this.patch_filechooser.close(); - })); - - // self.patch_filechooser.connect_response(clone!(@weak self as this => - // move |_, ResponseType::Ok| { - // this.patch_filechooser.close(); - // })); - } - fn set_button(&self) { self.patch_button.set_margin_top(20); self.patch_button.set_margin_bottom(20); diff --git a/src/main.rs b/src/main.rs index 8d1ec03..0fb4c10 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,98 +24,6 @@ fn main() { app.run(); } -// fn build_ui(app: &Application) { -// let resources_bytes = include_bytes!("../resources/resources.gresource"); -// let resource_data = glib::Bytes::from(&resources_bytes[..]); -// let res = gio::Resource::from_data(&resource_data).unwrap(); -// gio::resources_register(&res); - -// let provider = gtk4::CssProvider::new(); -// provider.load_from_resource("/com/wyattjmiller/snespatcher/style.css"); -// StyleContext::add_provider_for_display( -// &Display::default().expect("Error initializing CSS provider!"), -// &provider, -// gtk4::STYLE_PROVIDER_PRIORITY_APPLICATION, -// ); - -// let builder = Builder::from_resource("/com/wyattjmiller/snespatcher/snespatcher.ui"); - -// let window: ApplicationWindow = builder.object("app_window").expect("Failure to load window!"); -// let run_btn: Button = builder.object("run_btn").unwrap(); -// window.set_application(Some(app)); -// window.set_show_menubar(false); -// println!("{:?}", window.shows_menubar()); - -// run_btn.connect_clicked( move |_| { -// patch::apply_ips(PathBuf::from("/home/wyatt/Downloads/smw-widescreen.bps"), PathBuf::from("/home/wyatt/Downloads/smw-widescreen.bps")); -// }); - -// window.show(); -// } - -// fn build_ui(app: &Application) { -// let resources_bytes = include_bytes!("../resources/resources.gresource"); -// let resource_data = glib::Bytes::from(&resources_bytes[..]); -// let res = gio::Resource::from_data(&resource_data).unwrap(); -// gio::resources_register(&res); - -// let provider = gtk4::CssProvider::new(); -// provider.load_from_resource("/com/wyattjmiller/snespatcher/style.css"); -// StyleContext::add_provider_for_display( -// &Display::default().expect("Error initializing CSS provider!"), -// &provider, -// gtk4::STYLE_PROVIDER_PRIORITY_APPLICATION, -// ); - -// let run_btn = Button::builder() -// .label("Apply Patch") -// .css_name("run_btn") -// .build(); - -// let headerbar_ctr: HeaderBar = HeaderBar::builder() -// .visible(true) -// .can_focus(false) -// .title_widget(&run_btn) -// .build(); - -// let patch_btn: Button = Button::builder() -// .label("Open Patch") -// .build(); - -// let patch_lbl: Label = Label::builder() -// .label("Patch") -// .visible(true) -// .can_focus(false) -// .build(); - -// let patch_box: Box = Box::builder() -// .visible(true) -// .can_focus(false) -// .margin_start(20) -// .margin_end(20) -// .margin_top(20) -// .homogeneous(true) -// .child::