2021-06-24 17:05:41 -05:00
|
|
|
mod patch;
|
2021-06-27 15:41:23 -05:00
|
|
|
mod titlebar;
|
|
|
|
mod boxes;
|
2021-08-25 18:37:59 -05:00
|
|
|
mod menu;
|
|
|
|
mod popover;
|
2021-06-27 15:41:23 -05:00
|
|
|
|
|
|
|
use titlebar::CustomTitleBar;
|
|
|
|
use boxes::*;
|
2021-08-25 18:37:59 -05:00
|
|
|
use popover::CustomPopoverMenu;
|
2021-06-27 15:41:23 -05:00
|
|
|
|
|
|
|
use std::path::PathBuf;
|
|
|
|
use std::rc::Rc;
|
2021-06-24 17:05:41 -05:00
|
|
|
|
|
|
|
use gtk4::prelude::*;
|
|
|
|
use gtk4::{
|
2021-06-27 15:41:23 -05:00
|
|
|
gdk::{
|
|
|
|
Display
|
|
|
|
},
|
2021-08-25 18:37:59 -05:00
|
|
|
gio::MenuModel,
|
2021-06-24 17:05:41 -05:00
|
|
|
Application,
|
|
|
|
ApplicationWindow,
|
2021-08-25 18:37:59 -05:00
|
|
|
Builder,
|
2021-06-27 15:41:23 -05:00
|
|
|
StyleContext,
|
2021-06-24 17:05:41 -05:00
|
|
|
};
|
|
|
|
|
2021-06-23 21:28:05 -05:00
|
|
|
fn main() {
|
2021-06-24 17:05:41 -05:00
|
|
|
let app = Application::new(Some("com.wyattjmiller.snespatcher"), Default::default());
|
|
|
|
app.connect_activate(build_ui);
|
|
|
|
app.run();
|
2021-06-23 21:28:05 -05:00
|
|
|
}
|
2021-06-24 17:05:41 -05:00
|
|
|
|
|
|
|
fn build_ui(app: &Application) {
|
2021-06-27 15:41:23 -05:00
|
|
|
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,
|
2021-08-25 18:37:59 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
let builder = Builder::new();
|
|
|
|
builder.add_from_resource("/com/wyattjmiller/snespatcher/appmenu.xml").expect("Error initializing app menu!");
|
|
|
|
//println!("{:?}", builder.list_properties());
|
2021-06-27 15:41:23 -05:00
|
|
|
|
|
|
|
let app_window: Rc<ApplicationWindow> = Rc::new(ApplicationWindow::new(app));
|
2021-08-25 18:37:59 -05:00
|
|
|
let popover_menu: CustomPopoverMenu = CustomPopoverMenu::new();
|
|
|
|
let header_bar: CustomTitleBar = CustomTitleBar::new(&popover_menu);
|
2021-06-27 15:41:23 -05:00
|
|
|
let app_box: AppBox = AppBox::new();
|
|
|
|
let patch_box: PatchBox = PatchBox::new(&app_window);
|
|
|
|
let rom_box: RomBox = RomBox::new(&app_window);
|
|
|
|
|
2021-08-25 18:37:59 -05:00
|
|
|
// set popover_menu methods
|
|
|
|
popover_menu.set_texts();
|
|
|
|
|
|
|
|
// TODO: Set popover textviews and put them in a separate file
|
2021-06-27 15:41:23 -05:00
|
|
|
// set header bar methods
|
|
|
|
header_bar.set_buttons();
|
|
|
|
header_bar.set_titlebar();
|
|
|
|
header_bar.set_window(&app_window);
|
|
|
|
header_bar.click_run_button();
|
2021-08-25 18:37:59 -05:00
|
|
|
header_bar.click_menu();
|
2021-06-27 15:41:23 -05:00
|
|
|
|
|
|
|
// set patch box methods
|
|
|
|
patch_box.set_label();
|
|
|
|
patch_box.set_button();
|
|
|
|
patch_box.set_box();
|
2021-07-03 18:56:30 -05:00
|
|
|
patch_box.click_button(app_window.clone());
|
2021-06-24 17:05:41 -05:00
|
|
|
|
2021-06-27 15:41:23 -05:00
|
|
|
// set rom box methods
|
|
|
|
rom_box.set_label();
|
|
|
|
rom_box.set_button();
|
|
|
|
rom_box.set_box();
|
2021-07-03 18:56:30 -05:00
|
|
|
rom_box.click_button(app_window.clone());
|
2021-06-27 15:41:23 -05:00
|
|
|
|
|
|
|
// set app box methods
|
|
|
|
app_box.set_box(&rom_box, &patch_box);
|
|
|
|
|
|
|
|
// set apps default methods
|
|
|
|
app_window.set_title(Some("SNES Patcher"));
|
|
|
|
app_window.set_resizable(false);
|
|
|
|
app_window.set_child(Some(&app_box.app_box));
|
|
|
|
app_window.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn dialog<W: IsA<gtk4::Window>>(window: Rc<W>) {
|
|
|
|
let question_dialog = gtk4::MessageDialog::builder()
|
|
|
|
.transient_for(&*window)
|
|
|
|
.modal(true)
|
|
|
|
.buttons(gtk4::ButtonsType::OkCancel)
|
|
|
|
.text("What is your answer?")
|
2021-06-24 17:05:41 -05:00
|
|
|
.build();
|
|
|
|
|
2021-06-27 15:41:23 -05:00
|
|
|
let answer = question_dialog.run_future().await;
|
|
|
|
question_dialog.close();
|
2021-06-24 17:05:41 -05:00
|
|
|
|
2021-06-27 15:41:23 -05:00
|
|
|
let info_dialog = gtk4::MessageDialog::builder()
|
|
|
|
.transient_for(&*window)
|
|
|
|
.modal(true)
|
|
|
|
.buttons(gtk4::ButtonsType::Close)
|
|
|
|
.text("You answered")
|
|
|
|
.secondary_text(&format!("Your answer: {:?}", answer))
|
|
|
|
.build();
|
|
|
|
|
|
|
|
info_dialog.run_future().await;
|
|
|
|
info_dialog.close();
|
|
|
|
}
|