diff --git a/src/popover.rs b/src/popover.rs index 245b47f..91eef14 100644 --- a/src/popover.rs +++ b/src/popover.rs @@ -1,23 +1,10 @@ -use std::rc::Rc; -use futures::executor::block_on; use gtk4::prelude::*; -use gtk4::subclass::prelude::*; use gtk4::{ AboutDialog, - gdk::Paintable, glib::*, - ApplicationWindow, - HeaderBar, Button, - Window, Popover, - Builder, License, - IconTheme, - IconLookupFlags, - TextDirection, - MenuButton, - TextView, Box, Orientation, }; diff --git a/src/titlebar.rs b/src/titlebar.rs index d9e3ded..e7d4cd2 100644 --- a/src/titlebar.rs +++ b/src/titlebar.rs @@ -1,6 +1,8 @@ use std::rc::Rc; use futures::executor::block_on; -use gtk4::{prelude::*}; +use gio::{Menu, MenuItem, SimpleAction, SimpleActionGroup}; +use gtk4::builders::PopoverMenuBuilder; +use gtk4::{prelude::*, PopoverMenu, AboutDialog, License}; use gtk4::subclass::prelude::*; use gtk4::{ gdk::Paintable, @@ -19,24 +21,26 @@ use gtk4::{ use crate::popover::CustomPopoverMenu; -#[derive(Debug, Downgrade)] +#[derive(Debug)] pub struct CustomTitleBar { pub window: Window, pub titlebar: HeaderBar, pub run_button: Button, pub menu_button: MenuButton, - pub popover_menu: CustomPopoverMenu, + pub menu: Menu, + pub menu_actions: SimpleActionGroup, } impl CustomTitleBar { - pub fn new(pop: &CustomPopoverMenu) -> CustomTitleBar { + pub fn new() -> CustomTitleBar { // loading PopoverMenu logic goes here CustomTitleBar { window: Window::new(), titlebar: HeaderBar::new(), run_button: Button::new(), menu_button: MenuButton::new(), - popover_menu: pop.clone(), + menu: Menu::new(), + menu_actions: SimpleActionGroup::new(), } } @@ -55,8 +59,39 @@ impl CustomTitleBar { // symbolic // let menu_button = IconTheme::new(); // menu_button.lookup_icon("open-menu-symbolic", &[], 16, 1, TextDirection::Ltr, IconLookupFlags::empty()); - self.menu_button.set_popover(Some(&self.popover_menu.popover)); + //self.menu_button.set_popover(Some(&self.popover_menu.popover)); + self.menu.append(Some("About"), Some("about_action")); + self.menu.append(Some("Keyboard Shortcuts"), None); + self.menu.append(Some("Quit"), None); + let popover_menu = Some(PopoverMenu::builder().menu_model(&self.menu).build()); + self.menu_button.set_popover(Some(&popover_menu.unwrap())); + } + pub fn set_actions(&self) { + // about action + let about_action = SimpleAction::new("about_action", None); + about_action.set_enabled(true); + about_action.connect_activate(clone!(@strong self as this => + move |_, _| { + let about_dialog = AboutDialog::builder() + .program_name("SNESPatcher") + .version("0.1.0") + .comments("GTK4 app to patch your SNES ROMs!") + .authors(["Wyatt J. Miller".to_string()].to_vec()) + .documenters(["Wyatt J. Miller".to_string()].to_vec()) + .license_type(License::Mpl20) + .website("https://scm.wyattjmiller.com/wymiller/snespatcher") + .website_label("Website?") + .modal(false) + .can_focus(true) + //.child(&window) + .build(); + about_dialog.show(); + })); + + // add actions to the menu + self.menu_actions.add_action(&about_action); + //println!("{:?}", self.menu_actions.is_action_enabled("About")); } pub fn click_run_button(&self) { @@ -65,13 +100,6 @@ impl CustomTitleBar { }); } - pub fn click_menu(&self) { - // self.menu_button.connect_clicked(clone!(@weak self as this => - // move |_| { - // this.popover.show(); - // })); - } - pub fn set_window(&self, window: &ApplicationWindow) { window.set_titlebar(Some(&self.titlebar)); }