tried to add accelerators/kb shortcuts

This commit is contained in:
Wyatt J. Miller 2022-05-24 10:44:19 -04:00
parent 20cc623431
commit 0088e52398

View File

@ -4,6 +4,8 @@ mod boxes;
mod menu; mod menu;
mod popover; mod popover;
use gio::SimpleAction;
use glib::clone;
use titlebar::CustomTitleBar; use titlebar::CustomTitleBar;
use boxes::*; use boxes::*;
use popover::CustomPopoverMenu; use popover::CustomPopoverMenu;
@ -26,6 +28,7 @@ use gtk4::{
fn main() { fn main() {
let app = Application::new(Some("com.wyattjmiller.snespatcher"), Default::default()); let app = Application::new(Some("com.wyattjmiller.snespatcher"), Default::default());
app.connect_activate(build_ui); app.connect_activate(build_ui);
app.set_accels_for_action("win.close", &["<Ctrl>W"]);
app.run(); app.run();
} }
@ -43,14 +46,10 @@ fn build_ui(app: &Application) {
gtk4::STYLE_PROVIDER_PRIORITY_APPLICATION, gtk4::STYLE_PROVIDER_PRIORITY_APPLICATION,
); );
let builder = Builder::new();
builder.add_from_resource("/com/wyattjmiller/snespatcher/appmenu.xml").expect("Error initializing app menu!");
//println!("{:?}", builder.list_properties());
let app_window: Rc<ApplicationWindow> = Rc::new(ApplicationWindow::new(app)); let app_window: Rc<ApplicationWindow> = Rc::new(ApplicationWindow::new(app));
let file_picker_window: Window = Window::new(); let file_picker_window: Window = Window::new();
let popover_menu: CustomPopoverMenu = CustomPopoverMenu::new(); let popover_menu: CustomPopoverMenu = CustomPopoverMenu::new();
let header_bar: CustomTitleBar = CustomTitleBar::new(&popover_menu); let header_bar: CustomTitleBar = CustomTitleBar::new();
let app_box: AppBox = AppBox::new(); let app_box: AppBox = AppBox::new();
let patch_box: PatchBox = PatchBox::new(&app_window); let patch_box: PatchBox = PatchBox::new(&app_window);
let rom_box: RomBox = RomBox::new(&app_window); let rom_box: RomBox = RomBox::new(&app_window);
@ -61,11 +60,11 @@ fn build_ui(app: &Application) {
// TODO: Set popover textviews and put them in a separate file // TODO: Set popover textviews and put them in a separate file
// set header bar methods // set header bar methods
header_bar.set_actions();
header_bar.set_buttons(); header_bar.set_buttons();
header_bar.set_titlebar(); header_bar.set_titlebar();
header_bar.set_window(&app_window); header_bar.set_window(&app_window);
header_bar.click_run_button(); header_bar.click_run_button();
header_bar.click_menu();
// set patch box methods // set patch box methods
patch_box.set_label(); patch_box.set_label();
@ -86,6 +85,15 @@ fn build_ui(app: &Application) {
app_window.set_title(Some("SNES Patcher")); app_window.set_title(Some("SNES Patcher"));
app_window.set_resizable(false); app_window.set_resizable(false);
app_window.set_child(Some(&app_box.app_box)); app_window.set_child(Some(&app_box.app_box));
// keyboard shortcuts
let action_close = SimpleAction::new("close", None);
action_close.connect_activate(clone!(@weak app_window => move |_, _| {
app_window.close();
}));
app_window.add_action(&action_close);
// show the app
app_window.show(); app_window.show();
} }