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-22 02:00:54 +03:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
2024-09-19 18:08:09 +03:00
|
|
|
use gtk::{
|
|
|
|
gio::ActionEntry,
|
2024-09-20 18:02:10 +03:00
|
|
|
prelude::{ActionMapExtManual, GtkWindowExt},
|
|
|
|
Application, ApplicationWindow,
|
2024-09-19 18:08:09 +03:00
|
|
|
};
|
2024-09-18 20:33:29 +03:00
|
|
|
|
2024-09-22 02:00:54 +03:00
|
|
|
pub struct Browser {
|
2024-09-22 13:17:18 +03:00
|
|
|
db: db::Browser,
|
2024-09-22 02:57:09 +03:00
|
|
|
pub widget: Arc<gtk::ApplicationWindow>,
|
2024-09-22 12:42:34 +03:00
|
|
|
pub header: Arc<header::Header>,
|
2024-09-22 02:00:54 +03:00
|
|
|
pub main: Arc<main::Main>,
|
|
|
|
}
|
2024-09-21 20:48:12 +03:00
|
|
|
|
2024-09-22 13:04:27 +03:00
|
|
|
pub fn new(
|
|
|
|
app: &Application,
|
|
|
|
connection: Arc<sqlite::Connection>,
|
|
|
|
width: i32,
|
|
|
|
height: i32,
|
|
|
|
) -> Browser {
|
2024-09-22 02:00:54 +03:00
|
|
|
// Init components
|
2024-09-22 12:41:20 +03:00
|
|
|
let header = Arc::new(header::new());
|
2024-09-22 02:00:54 +03:00
|
|
|
let main = Arc::new(main::new());
|
|
|
|
|
|
|
|
// Init widget
|
|
|
|
let widget = Arc::new(
|
|
|
|
ApplicationWindow::builder()
|
|
|
|
.default_width(width)
|
|
|
|
.default_height(height)
|
|
|
|
.application(app)
|
2024-09-22 12:41:20 +03:00
|
|
|
.titlebar(header.widget.as_ref())
|
2024-09-22 02:00:54 +03:00
|
|
|
.child(main.widget.as_ref())
|
|
|
|
.build(),
|
|
|
|
);
|
2024-09-19 18:08:09 +03:00
|
|
|
|
2024-09-20 18:02:10 +03:00
|
|
|
// Init actions
|
2024-09-22 02:00:54 +03:00
|
|
|
let action_tab_append = ActionEntry::builder("tab_append")
|
|
|
|
.activate({
|
|
|
|
let main = main.clone();
|
|
|
|
move |_, _, _| {
|
|
|
|
main.tab_append();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.build();
|
|
|
|
|
2024-09-20 18:02:10 +03:00
|
|
|
let action_debug = ActionEntry::builder("debug")
|
2024-09-22 02:00:54 +03:00
|
|
|
.activate(|this: &ApplicationWindow, _, _| {
|
|
|
|
this.emit_enable_debugging(true);
|
2024-09-20 18:02:10 +03:00
|
|
|
})
|
|
|
|
.build();
|
2024-09-19 18:08:09 +03:00
|
|
|
|
2024-09-20 18:02:10 +03:00
|
|
|
let action_quit = ActionEntry::builder("quit")
|
2024-09-22 02:00:54 +03:00
|
|
|
.activate(|this: &ApplicationWindow, _, _| {
|
|
|
|
this.close();
|
2024-09-20 18:02:10 +03:00
|
|
|
})
|
|
|
|
.build();
|
2024-09-19 18:08:09 +03:00
|
|
|
|
2024-09-22 02:00:54 +03:00
|
|
|
widget.add_action_entries([action_tab_append, action_debug, action_quit]);
|
2024-09-19 18:08:09 +03:00
|
|
|
|
|
|
|
// Done
|
2024-09-22 12:42:34 +03:00
|
|
|
Browser {
|
2024-09-22 13:23:46 +03:00
|
|
|
db: db::new(connection),
|
2024-09-22 12:42:34 +03:00
|
|
|
widget,
|
|
|
|
header,
|
|
|
|
main,
|
|
|
|
}
|
2024-09-20 18:02:10 +03:00
|
|
|
}
|