mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 00:55:28 +00:00
separate features to submodules
This commit is contained in:
parent
80fecec656
commit
c38363b8cc
5 changed files with 107 additions and 65 deletions
|
|
@ -1,72 +1,47 @@
|
|||
mod action;
|
||||
mod db;
|
||||
mod header;
|
||||
mod main;
|
||||
mod widget;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use gtk::{
|
||||
gio::ActionEntry,
|
||||
prelude::{ActionMapExtManual, GtkWindowExt},
|
||||
Application, ApplicationWindow,
|
||||
};
|
||||
use gtk::prelude::ActionMapExtManual;
|
||||
|
||||
pub struct Browser {
|
||||
db: db::Browser,
|
||||
pub widget: Arc<gtk::ApplicationWindow>,
|
||||
pub header: Arc<header::Header>,
|
||||
pub main: Arc<main::Main>,
|
||||
widget: widget::Browser,
|
||||
}
|
||||
|
||||
pub fn new(
|
||||
app: &Application,
|
||||
connection: Arc<sqlite::Connection>,
|
||||
width: i32,
|
||||
height: i32,
|
||||
) -> Browser {
|
||||
// Init components
|
||||
let header = Arc::new(header::new());
|
||||
let main = Arc::new(main::new());
|
||||
impl Browser {
|
||||
// Construct new browser
|
||||
pub fn new(
|
||||
app: >k::Application,
|
||||
connection: std::sync::Arc<sqlite::Connection>,
|
||||
width: i32,
|
||||
height: i32,
|
||||
) -> Browser {
|
||||
// Init widget
|
||||
let widget = widget::Browser::new(
|
||||
app,
|
||||
header::new().widget.as_ref(), // @TODO
|
||||
main::new().widget.as_ref(), // @TODO
|
||||
width,
|
||||
height,
|
||||
);
|
||||
|
||||
// Init widget
|
||||
let widget = Arc::new(
|
||||
ApplicationWindow::builder()
|
||||
.default_width(width)
|
||||
.default_height(height)
|
||||
.application(app)
|
||||
.titlebar(header.widget.as_ref())
|
||||
.child(main.widget.as_ref())
|
||||
.build(),
|
||||
);
|
||||
// Connect actions
|
||||
widget
|
||||
.gtk()
|
||||
.add_action_entries([action::debug(), action::quit()]);
|
||||
|
||||
// Init actions
|
||||
let action_tab_append = ActionEntry::builder("tab_append")
|
||||
.activate({
|
||||
let main = main.clone();
|
||||
move |_, _, _| {
|
||||
main.tab_append();
|
||||
}
|
||||
})
|
||||
.build();
|
||||
// Return
|
||||
Self {
|
||||
db: db::Browser::new(connection),
|
||||
widget,
|
||||
}
|
||||
}
|
||||
|
||||
let action_debug = ActionEntry::builder("debug")
|
||||
.activate(|this: &ApplicationWindow, _, _| {
|
||||
this.emit_enable_debugging(true);
|
||||
})
|
||||
.build();
|
||||
|
||||
let action_quit = ActionEntry::builder("quit")
|
||||
.activate(|this: &ApplicationWindow, _, _| {
|
||||
this.close();
|
||||
})
|
||||
.build();
|
||||
|
||||
widget.add_action_entries([action_tab_append, action_debug, action_quit]);
|
||||
|
||||
// Done
|
||||
Browser {
|
||||
db: db::new(connection),
|
||||
widget,
|
||||
header,
|
||||
main,
|
||||
// Getters
|
||||
pub fn widget(&self) -> &widget::Browser {
|
||||
&self.widget
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue