Yoda/src/browser/mod.rs

123 lines
3.3 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-18 20:33:29 +03:00
2024-09-24 23:08:40 +03:00
use header::Header;
use main::Main;
use gtk::{
gio::ActionEntry,
prelude::{ActionMapExtManual, GtkWindowExt},
Application, ApplicationWindow,
};
2024-09-23 01:57:16 +03:00
use std::sync::Arc;
2024-09-22 02:00:54 +03:00
pub struct Browser {
// Extras
2024-09-23 18:51:48 +03:00
// db: db::Browser,
widget: ApplicationWindow,
// Components
2024-09-24 23:08:40 +03:00
header: Arc<Header>,
main: Arc<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 18:51:48 +03:00
// connection: Arc<sqlite::Connection>,
2024-09-22 17:36:31 +03:00
default_width: i32,
default_height: i32,
2024-09-23 18:51:48 +03:00
) -> Browser {
2024-09-23 01:57:16 +03:00
// Init components
2024-09-23 18:51:48 +03:00
// let db = db::Browser::new(connection);
2024-09-23 01:57:16 +03:00
let header = header::Header::new();
let main = main::Main::new();
2024-09-23 18:51:48 +03:00
let widget = ApplicationWindow::builder()
.application(app)
.default_width(default_width)
.default_height(default_height)
.titlebar(header.widget())
.child(main.widget())
.build();
// Init actions
widget.add_action_entries([
2024-09-24 23:08:40 +03:00
ActionEntry::builder("update")
.activate({
2024-09-25 22:19:48 +03:00
let header = header.clone();
2024-09-24 23:08:40 +03:00
let main = main.clone();
2024-09-25 22:19:48 +03:00
move |_, _, _| {
2024-09-24 23:08:40 +03:00
main.update();
2024-09-25 22:19:48 +03:00
header.update(main.tab_page_title(), main.tab_page_description());
2024-09-24 23:08:40 +03:00
}
})
.build(),
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({
2024-09-24 23:08:40 +03:00
let main = main.clone();
2024-09-23 01:57:16 +03:00
move |_, _, _| {
main.tab_append();
}
})
.build(),
2024-09-25 01:14:45 +03:00
ActionEntry::builder("tab_page_reload")
.activate({
let main = main.clone();
move |_, _, _| {
main.tab_page_reload();
}
})
.build(),
2024-09-23 16:03:39 +03:00
ActionEntry::builder("tab_close")
.activate({
2024-09-24 23:08:40 +03:00
let main = main.clone();
2024-09-23 16:03:39 +03:00
move |_, _, _| {
main.tab_close();
}
})
.build(),
ActionEntry::builder("tab_close_all")
.activate({
2024-09-24 23:08:40 +03:00
let main = main.clone();
2024-09-23 16:03:39 +03:00
move |_, _, _| {
main.tab_close_all();
}
})
.build(),
2024-09-23 15:44:33 +03:00
ActionEntry::builder("tab_pin")
.activate({
2024-09-24 23:08:40 +03:00
let main = main.clone();
2024-09-23 15:44:33 +03:00
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 18:51:48 +03:00
Self {
// db,
widget,
2024-09-24 23:08:40 +03:00
header,
main,
2024-09-23 18:51:48 +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
2024-09-23 18:51:48 +03:00
pub fn widget(&self) -> &ApplicationWindow {
2024-09-22 17:34:22 +03:00
&self.widget
2024-09-22 12:42:34 +03:00
}
2024-09-20 18:02:10 +03:00
}