Yoda/src/browser/mod.rs

102 lines
2.6 KiB
Rust
Raw Normal View History

2024-09-22 13:17:18 +03:00
mod db;
2024-09-20 18:02:10 +03:00
mod header;
mod main;
2024-09-22 17:34:22 +03:00
mod widget;
2024-09-18 20:33:29 +03:00
2024-09-23 02:17:53 +03:00
use gtk::gio::ActionEntry;
use gtk::{Application, ApplicationWindow};
2024-09-23 01:57:16 +03:00
use std::sync::Arc;
use gtk::prelude::{ActionMapExtManual, GtkWindowExt};
2024-09-18 20:33:29 +03:00
2024-09-22 02:00:54 +03:00
pub struct Browser {
// Extras
2024-09-22 13:17:18 +03:00
db: db::Browser,
2024-09-22 17:34:22 +03:00
widget: widget::Browser,
// Components
header: Arc<header::Header>,
main: Arc<main::Main>,
2024-09-22 02:00:54 +03:00
}
2024-09-21 20:48:12 +03:00
2024-09-22 17:34:22 +03:00
impl Browser {
2024-09-23 13:58:56 +03:00
// Construct
2024-09-22 17:34:22 +03:00
pub fn new(
2024-09-23 02:17:53 +03:00
app: &Application,
2024-09-23 13:58:56 +03:00
connection: Arc<sqlite::Connection>,
2024-09-22 17:36:31 +03:00
default_width: i32,
default_height: i32,
2024-09-23 13:58:56 +03:00
) -> Arc<Browser> {
2024-09-23 01:57:16 +03:00
// Init components
let db = db::Browser::new(connection);
let header = header::Header::new();
let main = main::Main::new();
2024-09-22 17:34:22 +03:00
let widget = widget::Browser::new(
app,
2024-09-23 01:57:16 +03:00
header.widget().gtk(),
main.widget().gtk(),
2024-09-22 17:36:31 +03:00
default_width,
default_height,
2024-09-22 17:34:22 +03:00
);
2024-09-23 01:57:16 +03:00
// Init actions @TODO separated module
2024-09-23 14:02:42 +03:00
widget.window().add_action_entries([
2024-09-23 02:17:53 +03:00
ActionEntry::builder("debug")
.activate(|this: &ApplicationWindow, _, _| {
2024-09-23 01:57:16 +03:00
this.emit_enable_debugging(true);
})
.build(),
2024-09-23 02:17:53 +03:00
ActionEntry::builder("quit")
.activate(|this: &ApplicationWindow, _, _| {
2024-09-23 01:57:16 +03:00
this.close();
})
.build(),
2024-09-23 02:17:53 +03:00
ActionEntry::builder("tab_append")
2024-09-23 01:57:16 +03:00
.activate({
let main = main.clone();
move |_, _, _| {
main.tab_append();
}
})
.build(),
2024-09-23 16:03:39 +03:00
ActionEntry::builder("tab_close")
.activate({
let main = main.clone();
move |_, _, _| {
main.tab_close();
}
})
.build(),
ActionEntry::builder("tab_close_all")
.activate({
let main = main.clone();
move |_, _, _| {
main.tab_close_all();
}
})
.build(),
2024-09-23 15:44:33 +03:00
ActionEntry::builder("tab_pin")
.activate({
let main = main.clone();
move |_, _, _| {
main.tab_pin();
}
})
.build(),
2024-09-23 01:57:16 +03:00
]);
2024-09-22 17:34:22 +03:00
// Return
2024-09-23 13:58:56 +03:00
Arc::new(Self {
2024-09-23 01:57:16 +03:00
db,
widget,
2024-09-23 01:57:16 +03:00
header,
main,
2024-09-23 13:58:56 +03:00
})
2024-09-22 17:34:22 +03:00
}
2024-09-19 18:08:09 +03:00
2024-09-22 17:34:22 +03:00
// Getters
pub fn widget(&self) -> &widget::Browser {
&self.widget
2024-09-22 12:42:34 +03:00
}
2024-09-20 18:02:10 +03:00
}