mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-03-13 06:01:21 +00:00
separate features to submodules
This commit is contained in:
parent
80fecec656
commit
c38363b8cc
31
src/browser/action.rs
Normal file
31
src/browser/action.rs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
use gtk::gio::ActionEntry;
|
||||||
|
use gtk::prelude::GtkWindowExt;
|
||||||
|
use gtk::ApplicationWindow;
|
||||||
|
|
||||||
|
pub fn debug() -> ActionEntry<ApplicationWindow> {
|
||||||
|
ActionEntry::builder("debug")
|
||||||
|
.activate(|this: &ApplicationWindow, _, _| {
|
||||||
|
this.emit_enable_debugging(true);
|
||||||
|
})
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn quit() -> ActionEntry<ApplicationWindow> {
|
||||||
|
ActionEntry::builder("quit")
|
||||||
|
.activate(|this: &ApplicationWindow, _, _| {
|
||||||
|
this.close();
|
||||||
|
})
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
/* @TODO
|
||||||
|
pub fn tab_append(main) -> ActionEntry<ApplicationWindow> {
|
||||||
|
let action_tab_append = ActionEntry::builder("tab_append")
|
||||||
|
.activate({
|
||||||
|
let main = main.clone();
|
||||||
|
move |_, _, _| {
|
||||||
|
main.tab_append();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.build();
|
||||||
|
}*/
|
@ -5,13 +5,19 @@ pub struct Browser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Browser {
|
impl Browser {
|
||||||
|
// Construct new browser DB (connection)
|
||||||
|
pub fn new(connection: Arc<sqlite::Connection>) -> Browser {
|
||||||
|
let this = Self { connection };
|
||||||
|
this.init();
|
||||||
|
this
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create browser table in DB if not exist yet
|
||||||
fn init(&self) {}
|
fn init(&self) {}
|
||||||
|
|
||||||
|
// Save active browser session to DB
|
||||||
fn save(&self) {}
|
fn save(&self) {}
|
||||||
|
|
||||||
|
// Restore previous browser session from DB
|
||||||
fn restore(&self) {}
|
fn restore(&self) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(connection: Arc<sqlite::Connection>) -> Browser {
|
|
||||||
let this = Browser { connection };
|
|
||||||
this.init();
|
|
||||||
this
|
|
||||||
}
|
|
||||||
|
@ -1,72 +1,47 @@
|
|||||||
|
mod action;
|
||||||
mod db;
|
mod db;
|
||||||
mod header;
|
mod header;
|
||||||
mod main;
|
mod main;
|
||||||
|
mod widget;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use gtk::prelude::ActionMapExtManual;
|
||||||
|
|
||||||
use gtk::{
|
|
||||||
gio::ActionEntry,
|
|
||||||
prelude::{ActionMapExtManual, GtkWindowExt},
|
|
||||||
Application, ApplicationWindow,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub struct Browser {
|
pub struct Browser {
|
||||||
db: db::Browser,
|
db: db::Browser,
|
||||||
pub widget: Arc<gtk::ApplicationWindow>,
|
widget: widget::Browser,
|
||||||
pub header: Arc<header::Header>,
|
|
||||||
pub main: Arc<main::Main>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(
|
impl Browser {
|
||||||
app: &Application,
|
// Construct new browser
|
||||||
connection: Arc<sqlite::Connection>,
|
pub fn new(
|
||||||
width: i32,
|
app: >k::Application,
|
||||||
height: i32,
|
connection: std::sync::Arc<sqlite::Connection>,
|
||||||
) -> Browser {
|
width: i32,
|
||||||
// Init components
|
height: i32,
|
||||||
let header = Arc::new(header::new());
|
) -> Browser {
|
||||||
let main = Arc::new(main::new());
|
// Init widget
|
||||||
|
let widget = widget::Browser::new(
|
||||||
|
app,
|
||||||
|
header::new().widget.as_ref(), // @TODO
|
||||||
|
main::new().widget.as_ref(), // @TODO
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
);
|
||||||
|
|
||||||
// Init widget
|
// Connect actions
|
||||||
let widget = Arc::new(
|
widget
|
||||||
ApplicationWindow::builder()
|
.gtk()
|
||||||
.default_width(width)
|
.add_action_entries([action::debug(), action::quit()]);
|
||||||
.default_height(height)
|
|
||||||
.application(app)
|
|
||||||
.titlebar(header.widget.as_ref())
|
|
||||||
.child(main.widget.as_ref())
|
|
||||||
.build(),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Init actions
|
// Return
|
||||||
let action_tab_append = ActionEntry::builder("tab_append")
|
Self {
|
||||||
.activate({
|
db: db::Browser::new(connection),
|
||||||
let main = main.clone();
|
widget,
|
||||||
move |_, _, _| {
|
}
|
||||||
main.tab_append();
|
}
|
||||||
}
|
|
||||||
})
|
|
||||||
.build();
|
|
||||||
|
|
||||||
let action_debug = ActionEntry::builder("debug")
|
// Getters
|
||||||
.activate(|this: &ApplicationWindow, _, _| {
|
pub fn widget(&self) -> &widget::Browser {
|
||||||
this.emit_enable_debugging(true);
|
&self.widget
|
||||||
})
|
|
||||||
.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,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
27
src/browser/widget.rs
Normal file
27
src/browser/widget.rs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
pub struct Browser {
|
||||||
|
gtk: gtk::ApplicationWindow,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Browser {
|
||||||
|
pub fn new(
|
||||||
|
application: >k::Application,
|
||||||
|
titlebar: >k::HeaderBar,
|
||||||
|
child: >k::Box,
|
||||||
|
default_width: i32,
|
||||||
|
default_height: i32,
|
||||||
|
) -> Browser {
|
||||||
|
Self {
|
||||||
|
gtk: gtk::ApplicationWindow::builder()
|
||||||
|
.application(application)
|
||||||
|
.default_width(default_width)
|
||||||
|
.default_height(default_height)
|
||||||
|
.titlebar(titlebar)
|
||||||
|
.child(child)
|
||||||
|
.build(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn gtk(&self) -> >k::ApplicationWindow {
|
||||||
|
&self.gtk
|
||||||
|
}
|
||||||
|
}
|
@ -41,7 +41,10 @@ fn main() -> glib::ExitCode {
|
|||||||
};
|
};
|
||||||
|
|
||||||
move |this| {
|
move |this| {
|
||||||
browser::new(&this, db.clone(), 640, 480).widget.present();
|
browser::Browser::new(&this, db.clone(), 640, 480)
|
||||||
|
.widget()
|
||||||
|
.gtk()
|
||||||
|
.present();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user