mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-03-10 12:41:34 +00:00
activate gtk before build children widgets, add browser pointer to the app struct
This commit is contained in:
parent
2d59115c7e
commit
b6fa1016f6
92
src/app.rs
92
src/app.rs
@ -19,23 +19,14 @@ use std::sync::Arc;
|
|||||||
const APPLICATION_ID: &str = "io.github.yggverse.Yoda";
|
const APPLICATION_ID: &str = "io.github.yggverse.Yoda";
|
||||||
|
|
||||||
pub struct App {
|
pub struct App {
|
||||||
|
// Actions
|
||||||
|
action_update: Arc<SimpleAction>,
|
||||||
|
// Components
|
||||||
|
browser: Arc<Browser>,
|
||||||
|
// Extras
|
||||||
|
database: Arc<Database>,
|
||||||
// GTK
|
// GTK
|
||||||
app: Application,
|
app: Application,
|
||||||
// Components
|
|
||||||
//browser: Arc<Browser>,
|
|
||||||
database: Arc<Database>,
|
|
||||||
// Actions
|
|
||||||
action_debug: Arc<SimpleAction>,
|
|
||||||
action_quit: Arc<SimpleAction>,
|
|
||||||
action_update: Arc<SimpleAction>,
|
|
||||||
action_tab_append: Arc<SimpleAction>,
|
|
||||||
action_tab_close: Arc<SimpleAction>,
|
|
||||||
action_tab_close_all: Arc<SimpleAction>,
|
|
||||||
action_tab_page_navigation_base: Arc<SimpleAction>,
|
|
||||||
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
|
||||||
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
|
||||||
action_tab_page_navigation_reload: Arc<SimpleAction>,
|
|
||||||
action_tab_pin: Arc<SimpleAction>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
@ -86,22 +77,28 @@ impl App {
|
|||||||
&["<Primary>r"],
|
&["<Primary>r"],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Init components
|
||||||
|
let browser = Arc::new(Browser::new(
|
||||||
|
/*db.clone(),*/
|
||||||
|
action_debug.simple(),
|
||||||
|
action_quit.simple(),
|
||||||
|
action_update.simple(),
|
||||||
|
action_tab_append.simple(),
|
||||||
|
action_tab_close.simple(),
|
||||||
|
action_tab_close_all.simple(),
|
||||||
|
action_tab_page_navigation_base.simple(),
|
||||||
|
action_tab_page_navigation_history_back.simple(),
|
||||||
|
action_tab_page_navigation_history_forward.simple(),
|
||||||
|
action_tab_page_navigation_reload.simple(),
|
||||||
|
action_tab_pin.simple(),
|
||||||
|
));
|
||||||
|
|
||||||
// Return app struct
|
// Return app struct
|
||||||
Self {
|
Self {
|
||||||
// Actions (SimpleAction)
|
// Actions (SimpleAction)
|
||||||
action_debug: action_debug.simple(),
|
|
||||||
action_quit: action_quit.simple(),
|
|
||||||
action_update: action_update.simple(),
|
action_update: action_update.simple(),
|
||||||
action_tab_append: action_tab_append.simple(),
|
// Components
|
||||||
action_tab_close: action_tab_close.simple(),
|
browser,
|
||||||
action_tab_close_all: action_tab_close_all.simple(),
|
|
||||||
action_tab_page_navigation_base: action_tab_page_navigation_base.simple(),
|
|
||||||
action_tab_page_navigation_history_back: action_tab_page_navigation_history_back
|
|
||||||
.simple(),
|
|
||||||
action_tab_page_navigation_history_forward: action_tab_page_navigation_history_forward
|
|
||||||
.simple(),
|
|
||||||
action_tab_page_navigation_reload: action_tab_page_navigation_reload.simple(),
|
|
||||||
action_tab_pin: action_tab_pin.simple(),
|
|
||||||
// Extras
|
// Extras
|
||||||
database,
|
database,
|
||||||
// GTK
|
// GTK
|
||||||
@ -111,45 +108,15 @@ impl App {
|
|||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
pub fn activate(&self) -> &Self {
|
pub fn activate(&self) -> &Self {
|
||||||
// Init events
|
|
||||||
self.app.connect_activate({
|
self.app.connect_activate({
|
||||||
// let database = database.clone();
|
// let database = database.clone();
|
||||||
let action_debug = self.action_debug.clone();
|
|
||||||
let action_quit = self.action_quit.clone();
|
|
||||||
let action_update = self.action_update.clone();
|
let action_update = self.action_update.clone();
|
||||||
let action_tab_append = self.action_tab_append.clone();
|
let browser = self.browser.clone();
|
||||||
let action_tab_close = self.action_tab_close.clone();
|
move |this| {
|
||||||
let action_tab_close_all = self.action_tab_close_all.clone();
|
// @TODO restore previous session from DB
|
||||||
let action_tab_page_navigation_base = self.action_tab_page_navigation_base.clone();
|
|
||||||
let action_tab_page_navigation_history_back =
|
|
||||||
self.action_tab_page_navigation_history_back.clone();
|
|
||||||
let action_tab_page_navigation_history_forward =
|
|
||||||
self.action_tab_page_navigation_history_forward.clone();
|
|
||||||
let action_tab_page_navigation_reload = self.action_tab_page_navigation_reload.clone();
|
|
||||||
let action_tab_pin = self.action_tab_pin.clone();
|
|
||||||
move |application| {
|
|
||||||
// Restore previous session
|
|
||||||
// @TODO
|
|
||||||
|
|
||||||
// Init components
|
|
||||||
let browser = Arc::new(Browser::new(
|
|
||||||
&application,
|
|
||||||
/*db.clone(),*/
|
|
||||||
action_debug.clone(),
|
|
||||||
action_quit.clone(),
|
|
||||||
action_update.clone(),
|
|
||||||
action_tab_append.clone(),
|
|
||||||
action_tab_close.clone(),
|
|
||||||
action_tab_close_all.clone(),
|
|
||||||
action_tab_page_navigation_base.clone(),
|
|
||||||
action_tab_page_navigation_history_back.clone(),
|
|
||||||
action_tab_page_navigation_history_forward.clone(),
|
|
||||||
action_tab_page_navigation_reload.clone(),
|
|
||||||
action_tab_pin.clone(),
|
|
||||||
));
|
|
||||||
|
|
||||||
// Activate events
|
// Activate events
|
||||||
browser.activate();
|
browser.activate().widget().set_application(Some(this));
|
||||||
|
|
||||||
// Show main widget
|
// Show main widget
|
||||||
browser.widget().present();
|
browser.widget().present();
|
||||||
@ -159,6 +126,9 @@ impl App {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// @TODO save session to DB
|
||||||
|
// self.app.connect_window_removed(|_, _| todo!());
|
||||||
|
|
||||||
&self
|
&self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ use main::Main;
|
|||||||
use gtk::{
|
use gtk::{
|
||||||
gio::SimpleAction,
|
gio::SimpleAction,
|
||||||
prelude::{ActionMapExt, GtkWindowExt},
|
prelude::{ActionMapExt, GtkWindowExt},
|
||||||
Application, ApplicationWindow,
|
ApplicationWindow,
|
||||||
};
|
};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@ -38,8 +38,6 @@ pub struct Browser {
|
|||||||
impl Browser {
|
impl Browser {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new(
|
pub fn new(
|
||||||
// Dependencies
|
|
||||||
application: &Application,
|
|
||||||
// Extras
|
// Extras
|
||||||
// connection: Arc<sqlite::Connection>,
|
// connection: Arc<sqlite::Connection>,
|
||||||
// Actions
|
// Actions
|
||||||
@ -82,7 +80,6 @@ impl Browser {
|
|||||||
|
|
||||||
// Init widget
|
// Init widget
|
||||||
let widget = ApplicationWindow::builder()
|
let widget = ApplicationWindow::builder()
|
||||||
.application(application)
|
|
||||||
.titlebar(header.widget())
|
.titlebar(header.widget())
|
||||||
.child(main.widget())
|
.child(main.widget())
|
||||||
.default_height(DEFAULT_HEIGHT)
|
.default_height(DEFAULT_HEIGHT)
|
||||||
@ -112,7 +109,7 @@ impl Browser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
pub fn activate(&self) {
|
pub fn activate(&self) -> &Self {
|
||||||
// Assign actions
|
// Assign actions
|
||||||
self.widget.add_action(self.action_debug.as_ref());
|
self.widget.add_action(self.action_debug.as_ref());
|
||||||
self.widget.add_action(self.action_quit.as_ref());
|
self.widget.add_action(self.action_quit.as_ref());
|
||||||
@ -211,6 +208,8 @@ impl Browser {
|
|||||||
main.tab_pin();
|
main.tab_pin();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
&self
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
|
@ -26,6 +26,9 @@ fn main() -> ExitCode {
|
|||||||
Err(error) => panic!("Failed to connect profile database: {error}"),
|
Err(error) => panic!("Failed to connect profile database: {error}"),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Start application
|
// Init GTK, start application
|
||||||
App::new(profile_database_connection).activate().run()
|
match gtk::init() {
|
||||||
|
Ok(_) => App::new(profile_database_connection).activate().run(),
|
||||||
|
Err(_) => ExitCode::FAILURE,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user