implement about dialog

This commit is contained in:
yggverse 2024-11-03 19:57:44 +02:00
parent 39ee50c4ba
commit eca93df1eb
7 changed files with 74 additions and 11 deletions

View File

@ -41,6 +41,7 @@ impl App {
profile_path: PathBuf, profile_path: PathBuf,
) -> Self { ) -> Self {
// Init actions // Init actions
let action_about = Action::new("win", true, None);
let action_debug = Action::new("win", true, None); let action_debug = Action::new("win", true, None);
let action_profile = Action::new("win", true, None); let action_profile = Action::new("win", true, None);
let action_quit = Action::new("win", true, None); let action_quit = Action::new("win", true, None);
@ -80,6 +81,7 @@ impl App {
// Init components // Init components
let browser = Arc::new(Browser::new( let browser = Arc::new(Browser::new(
profile_path, profile_path,
action_about.simple(),
action_debug.simple(), action_debug.simple(),
action_profile.simple(), action_profile.simple(),
action_quit.simple(), action_quit.simple(),

View File

@ -1,7 +1,9 @@
mod about;
mod database; mod database;
mod widget; mod widget;
mod window; mod window;
use about::About;
use database::Database; use database::Database;
use widget::Widget; use widget::Widget;
use window::Window; use window::Window;
@ -28,6 +30,7 @@ impl Browser {
// Extras // Extras
profile_path: PathBuf, profile_path: PathBuf,
// Actions // Actions
action_about: SimpleAction,
action_debug: SimpleAction, action_debug: SimpleAction,
action_profile: SimpleAction, action_profile: SimpleAction,
action_quit: SimpleAction, action_quit: SimpleAction,
@ -43,6 +46,7 @@ impl Browser {
) -> Browser { ) -> Browser {
// Init components // Init components
let window = Arc::new(Window::new( let window = Arc::new(Window::new(
action_about.clone(),
action_debug.clone(), action_debug.clone(),
action_profile.clone(), action_profile.clone(),
action_quit.clone(), action_quit.clone(),
@ -61,6 +65,7 @@ impl Browser {
let widget = Arc::new(Widget::new( let widget = Arc::new(Widget::new(
window.gobject(), window.gobject(),
&[ &[
action_about.clone(),
action_debug.clone(), action_debug.clone(),
action_profile.clone(), action_profile.clone(),
action_quit.clone(), action_quit.clone(),
@ -77,6 +82,13 @@ impl Browser {
)); ));
// Init events // Init events
action_about.connect_activate({
let window = window.clone();
move |_, _| {
About::new().present(Some(window.gobject()));
}
});
action_debug.connect_activate({ action_debug.connect_activate({
let widget = widget.clone(); let widget = widget.clone();
move |_, _| { move |_, _| {

41
src/app/browser/about.rs Normal file
View File

@ -0,0 +1,41 @@
use adw::{prelude::AdwDialogExt, AboutDialog};
use gtk::{prelude::IsA, License};
pub struct About {
gobject: AboutDialog,
}
impl About {
// Construct
pub fn new() -> Self {
// Collect debug info
let debug = &[
format!(
"GTK {}.{}.{}",
gtk::major_version(),
gtk::minor_version(),
gtk::micro_version()
),
format!("SQLite {}", sqlite::version()),
// @TODO
];
// Init gobject
let gobject = AboutDialog::builder()
.application_name(env!("CARGO_PKG_NAME"))
.debug_info(debug.join("\n"))
.developer_name(env!("CARGO_PKG_DESCRIPTION"))
.issue_url(env!("CARGO_PKG_REPOSITORY"))
.license_type(License::MitX11)
.version(env!("CARGO_PKG_VERSION"))
.build();
// Return new struct
Self { gobject }
}
// Actions
pub fn present(&self, parent: Option<&impl IsA<gtk::Widget>>) {
self.gobject.present(parent);
}
}

View File

@ -23,6 +23,7 @@ impl Window {
// Construct // Construct
pub fn new( pub fn new(
// Actions // Actions
action_about: SimpleAction,
action_debug: SimpleAction, action_debug: SimpleAction,
action_profile: SimpleAction, action_profile: SimpleAction,
action_quit: SimpleAction, action_quit: SimpleAction,
@ -47,17 +48,18 @@ impl Window {
let header = Header::new_arc( let header = Header::new_arc(
// Actions // Actions
action_debug.clone(), action_about,
action_profile.clone(), action_debug,
action_quit.clone(), action_profile,
action_page_new.clone(), action_quit,
action_page_close.clone(), action_page_new,
action_page_close_all.clone(), action_page_close,
action_page_home.clone(), action_page_close_all,
action_page_history_back.clone(), action_page_home,
action_page_history_forward.clone(), action_page_history_back,
action_page_reload.clone(), action_page_history_forward,
action_page_pin.clone(), action_page_reload,
action_page_pin,
// Widgets // Widgets
tab.gobject(), tab.gobject(),
); );

View File

@ -16,6 +16,7 @@ impl Header {
// Construct // Construct
pub fn new_arc( pub fn new_arc(
// Actions // Actions
action_about: SimpleAction,
action_debug: SimpleAction, action_debug: SimpleAction,
action_profile: SimpleAction, action_profile: SimpleAction,
action_quit: SimpleAction, action_quit: SimpleAction,
@ -32,6 +33,7 @@ impl Header {
) -> Arc<Self> { ) -> Arc<Self> {
// Init components // Init components
let bar = Bar::new_arc( let bar = Bar::new_arc(
action_about,
action_debug, action_debug,
action_profile, action_profile,
action_quit, action_quit,

View File

@ -19,6 +19,7 @@ pub struct Bar {
impl Bar { impl Bar {
// Construct // Construct
pub fn new_arc( pub fn new_arc(
action_about: SimpleAction,
action_debug: SimpleAction, action_debug: SimpleAction,
action_profile: SimpleAction, action_profile: SimpleAction,
action_quit: SimpleAction, action_quit: SimpleAction,
@ -36,6 +37,7 @@ impl Bar {
let control = Control::new_arc(); let control = Control::new_arc();
let tab = Tab::new_arc(action_page_new.clone(), view); let tab = Tab::new_arc(action_page_new.clone(), view);
let menu = Menu::new_arc( let menu = Menu::new_arc(
action_about,
action_debug, action_debug,
action_profile, action_profile,
action_quit, action_quit,

View File

@ -17,6 +17,7 @@ pub struct Menu {
#[rustfmt::skip] // @TODO template builder? #[rustfmt::skip] // @TODO template builder?
impl Menu { impl Menu {
pub fn new_arc( pub fn new_arc(
action_about: SimpleAction,
action_debug: SimpleAction, action_debug: SimpleAction,
action_profile: SimpleAction, action_profile: SimpleAction,
action_quit: SimpleAction, action_quit: SimpleAction,
@ -64,6 +65,7 @@ impl Menu {
let main_tool = gio::Menu::new(); let main_tool = gio::Menu::new();
main_tool.append(Some("Debug"), Some(&detailed_action_name(action_debug))); main_tool.append(Some("Debug"), Some(&detailed_action_name(action_debug)));
main_tool.append(Some("Profile"), Some(&detailed_action_name(action_profile))); main_tool.append(Some("Profile"), Some(&detailed_action_name(action_profile)));
main_tool.append(Some("About"), Some(&detailed_action_name(action_about)));
main.append_submenu(Some("Tool"), &main_tool); main.append_submenu(Some("Tool"), &main_tool);