got filechoosedialogs accepting commands!

This commit is contained in:
Wyatt J. Miller 2021-07-03 19:56:30 -04:00
parent 765f1e28be
commit a76b097c35
3 changed files with 58 additions and 133 deletions

View File

@ -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<ApplicationWindow>) {
self.rom_button.connect_clicked(clone!(@strong self as this =>
move |_| {
let dialog = FileChooserDialog::new::<ApplicationWindow>(
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<ApplicationWindow>) {
self.patch_button.connect_clicked(clone!(@weak self as this =>
move |_| {
let dialog = FileChooserDialog::new::<ApplicationWindow>(
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);

View File

@ -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::<Label>(&patch_lbl)
// .child::<Button>(&patch_btn)
// .build();
// let app_box: Box = Box::builder()
// .visible(false)
// .can_focus(false)
// .orientation(Orientation::Vertical)
// .build();
// let app_window: ApplicationWindow = ApplicationWindow::builder()
// .can_focus(false)
// .title("SNES Patcher")
// .show_menubar(true)
// .child::<Box>(&app_box)
// .child::<HeaderBar>(&headerbar_ctr)
// .build();
// app_window.show();
// }
fn build_ui(app: &Application) {
let resources_bytes = include_bytes!("../resources/resources.gresource");
let resource_data = glib::Bytes::from(&resources_bytes[..]);
@ -146,13 +54,13 @@ fn build_ui(app: &Application) {
patch_box.set_label();
patch_box.set_button();
patch_box.set_box();
patch_box.click_button();
patch_box.click_button(app_window.clone());
// set rom box methods
rom_box.set_label();
rom_box.set_button();
rom_box.set_box();
rom_box.click_button();
rom_box.click_button(app_window.clone());
// set app box methods
app_box.set_box(&rom_box, &patch_box);

View File

@ -56,5 +56,6 @@ impl CustomTitleBar {
pub fn set_titlebar(&self) {
self.titlebar.pack_start(&self.run_button);
self.titlebar.pack_start(&self.type_button);
self.titlebar.set_css_classes(&["headerbar"])
}
}