mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 09:05:27 +00:00
define browser entities as structs
This commit is contained in:
parent
3fbfe6a7e0
commit
c0ebe95eb8
4 changed files with 84 additions and 40 deletions
|
|
@ -1,6 +1,8 @@
|
|||
mod header;
|
||||
mod main;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use gtk::{
|
||||
gio::ActionEntry,
|
||||
prelude::{ActionMapExtManual, GtkWindowExt},
|
||||
|
|
@ -8,32 +10,50 @@ use gtk::{
|
|||
};
|
||||
|
||||
use sqlite::Connection;
|
||||
pub struct Browser {
|
||||
pub widget: Arc<ApplicationWindow>,
|
||||
pub main: Arc<main::Main>,
|
||||
}
|
||||
|
||||
pub fn new(app: &Application, db: &Connection, width: i32, height: i32) -> ApplicationWindow {
|
||||
// Init browser window
|
||||
let browser = ApplicationWindow::builder()
|
||||
.default_width(width)
|
||||
.default_height(height)
|
||||
.application(app)
|
||||
.titlebar(&header::new())
|
||||
.child(&main::new())
|
||||
.build();
|
||||
pub fn new(app: &Application, db: &Connection, width: i32, height: i32) -> Browser {
|
||||
// Init components
|
||||
let main = Arc::new(main::new());
|
||||
|
||||
// Init widget
|
||||
let widget = Arc::new(
|
||||
ApplicationWindow::builder()
|
||||
.default_width(width)
|
||||
.default_height(height)
|
||||
.application(app)
|
||||
.titlebar(&header::new())
|
||||
.child(main.widget.as_ref())
|
||||
.build(),
|
||||
);
|
||||
|
||||
// Init actions
|
||||
let action_tab_append = ActionEntry::builder("tab_append")
|
||||
.activate({
|
||||
let main = main.clone();
|
||||
move |_, _, _| {
|
||||
main.tab_append();
|
||||
}
|
||||
})
|
||||
.build();
|
||||
|
||||
let action_debug = ActionEntry::builder("debug")
|
||||
.activate(|browser: &ApplicationWindow, _, _| {
|
||||
browser.emit_enable_debugging(true);
|
||||
.activate(|this: &ApplicationWindow, _, _| {
|
||||
this.emit_enable_debugging(true);
|
||||
})
|
||||
.build();
|
||||
|
||||
let action_quit = ActionEntry::builder("quit")
|
||||
.activate(|browser: &ApplicationWindow, _, _| {
|
||||
browser.close();
|
||||
.activate(|this: &ApplicationWindow, _, _| {
|
||||
this.close();
|
||||
})
|
||||
.build();
|
||||
|
||||
browser.add_action_entries([action_debug, action_quit]);
|
||||
widget.add_action_entries([action_tab_append, action_debug, action_quit]);
|
||||
|
||||
// Done
|
||||
browser
|
||||
Browser { widget, main }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue