mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-03-13 06:01:21 +00:00
create separated struct activation api
This commit is contained in:
parent
17dedbd36e
commit
2d59115c7e
@ -47,9 +47,10 @@ Guide and protocol draft
|
|||||||
* implement only one public `struct` per file (same as one file for one class)
|
* implement only one public `struct` per file (same as one file for one class)
|
||||||
* implementable `struct` is public, where it members - private
|
* implementable `struct` is public, where it members - private
|
||||||
* contain main `struct` implementation:
|
* contain main `struct` implementation:
|
||||||
* at least one constructor that must return:
|
* at least one constructor that must:
|
||||||
* unwrapped main `Self` structure
|
* return unwrapped, non activated (_todo_) new `Self` object
|
||||||
* granted ownership for new object created
|
* grant ownership for new `Self` object created
|
||||||
|
* public `activate` action (_todo_)
|
||||||
* public link getter for privately constructed widget
|
* public link getter for privately constructed widget
|
||||||
* Public API oriented to simple (`integer`, `boolean`), standard (`std::*`) or system-wide (`gio`, `glib`, etc) data types usage to reduce internal dependencies from app implementation
|
* Public API oriented to simple (`integer`, `boolean`), standard (`std::*`) or system-wide (`gio`, `glib`, etc) data types usage to reduce internal dependencies from app implementation
|
||||||
|
|
||||||
|
84
src/app.rs
84
src/app.rs
@ -7,6 +7,7 @@ use browser::Browser;
|
|||||||
use database::Database;
|
use database::Database;
|
||||||
|
|
||||||
use gtk::{
|
use gtk::{
|
||||||
|
gio::SimpleAction,
|
||||||
glib::ExitCode,
|
glib::ExitCode,
|
||||||
prelude::{ActionExt, ApplicationExt, ApplicationExtManual, GtkApplicationExt, GtkWindowExt},
|
prelude::{ActionExt, ApplicationExt, ApplicationExtManual, GtkApplicationExt, GtkWindowExt},
|
||||||
Application,
|
Application,
|
||||||
@ -23,6 +24,18 @@ pub struct App {
|
|||||||
// Components
|
// Components
|
||||||
//browser: Arc<Browser>,
|
//browser: Arc<Browser>,
|
||||||
database: Arc<Database>,
|
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 {
|
||||||
@ -73,9 +86,47 @@ impl App {
|
|||||||
&["<Primary>r"],
|
&["<Primary>r"],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Return app struct
|
||||||
|
Self {
|
||||||
|
// Actions (SimpleAction)
|
||||||
|
action_debug: action_debug.simple(),
|
||||||
|
action_quit: action_quit.simple(),
|
||||||
|
action_update: action_update.simple(),
|
||||||
|
action_tab_append: action_tab_append.simple(),
|
||||||
|
action_tab_close: action_tab_close.simple(),
|
||||||
|
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
|
||||||
|
database,
|
||||||
|
// GTK
|
||||||
|
app,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
pub fn activate(&self) -> &Self {
|
||||||
// Init events
|
// Init events
|
||||||
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_tab_append = self.action_tab_append.clone();
|
||||||
|
let action_tab_close = self.action_tab_close.clone();
|
||||||
|
let action_tab_close_all = self.action_tab_close_all.clone();
|
||||||
|
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| {
|
move |application| {
|
||||||
// Restore previous session
|
// Restore previous session
|
||||||
// @TODO
|
// @TODO
|
||||||
@ -84,32 +135,33 @@ impl App {
|
|||||||
let browser = Arc::new(Browser::new(
|
let browser = Arc::new(Browser::new(
|
||||||
&application,
|
&application,
|
||||||
/*db.clone(),*/
|
/*db.clone(),*/
|
||||||
action_debug.simple(),
|
action_debug.clone(),
|
||||||
action_quit.simple(),
|
action_quit.clone(),
|
||||||
action_update.simple(),
|
action_update.clone(),
|
||||||
action_tab_append.simple(),
|
action_tab_append.clone(),
|
||||||
action_tab_close.simple(),
|
action_tab_close.clone(),
|
||||||
action_tab_close_all.simple(),
|
action_tab_close_all.clone(),
|
||||||
action_tab_page_navigation_base.simple(),
|
action_tab_page_navigation_base.clone(),
|
||||||
action_tab_page_navigation_history_back.simple(),
|
action_tab_page_navigation_history_back.clone(),
|
||||||
action_tab_page_navigation_history_forward.simple(),
|
action_tab_page_navigation_history_forward.clone(),
|
||||||
action_tab_page_navigation_reload.simple(),
|
action_tab_page_navigation_reload.clone(),
|
||||||
action_tab_pin.simple(),
|
action_tab_pin.clone(),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
// Activate events
|
||||||
|
browser.activate();
|
||||||
|
|
||||||
// Show main widget
|
// Show main widget
|
||||||
browser.widget().present();
|
browser.widget().present();
|
||||||
|
|
||||||
// Make initial update
|
// Make initial update
|
||||||
action_update.simple().activate(None);
|
action_update.activate(None);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Return activated struct
|
&self
|
||||||
Self { app, database }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
|
||||||
pub fn run(&self) -> ExitCode {
|
pub fn run(&self) -> ExitCode {
|
||||||
self.app.run()
|
self.app.run()
|
||||||
}
|
}
|
||||||
|
@ -15,12 +15,24 @@ const DEFAULT_HEIGHT: i32 = 480;
|
|||||||
const DEFAULT_WIDTH: i32 = 640;
|
const DEFAULT_WIDTH: i32 = 640;
|
||||||
|
|
||||||
pub struct Browser {
|
pub struct Browser {
|
||||||
|
// 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>,
|
||||||
// Extras
|
// Extras
|
||||||
// db: db::Browser,
|
// db: db::Browser,
|
||||||
widget: ApplicationWindow,
|
widget: ApplicationWindow,
|
||||||
// Components
|
// Components
|
||||||
// header: Arc<Header>,
|
header: Arc<Header>,
|
||||||
// main: Arc<Main>,
|
main: Arc<Main>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Browser {
|
impl Browser {
|
||||||
@ -77,106 +89,128 @@ impl Browser {
|
|||||||
.default_width(DEFAULT_WIDTH)
|
.default_width(DEFAULT_WIDTH)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
widget.add_action(action_debug.as_ref());
|
// Return new Browser
|
||||||
widget.add_action(action_quit.as_ref());
|
Self {
|
||||||
widget.add_action(action_update.as_ref());
|
// Actions
|
||||||
|
action_debug,
|
||||||
|
action_quit,
|
||||||
|
action_update,
|
||||||
|
action_tab_append,
|
||||||
|
action_tab_close,
|
||||||
|
action_tab_close_all,
|
||||||
|
action_tab_page_navigation_base,
|
||||||
|
action_tab_page_navigation_history_back,
|
||||||
|
action_tab_page_navigation_history_forward,
|
||||||
|
action_tab_page_navigation_reload,
|
||||||
|
action_tab_pin,
|
||||||
|
// db,
|
||||||
|
widget,
|
||||||
|
// Components
|
||||||
|
header,
|
||||||
|
main,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
widget.add_action(action_tab_append.as_ref());
|
// Actions
|
||||||
widget.add_action(action_tab_close.as_ref());
|
pub fn activate(&self) {
|
||||||
widget.add_action(action_tab_close_all.as_ref());
|
// Assign actions
|
||||||
widget.add_action(action_tab_page_navigation_base.as_ref());
|
self.widget.add_action(self.action_debug.as_ref());
|
||||||
widget.add_action(action_tab_page_navigation_history_back.as_ref());
|
self.widget.add_action(self.action_quit.as_ref());
|
||||||
widget.add_action(action_tab_page_navigation_history_forward.as_ref());
|
self.widget.add_action(self.action_update.as_ref());
|
||||||
widget.add_action(action_tab_page_navigation_reload.as_ref());
|
self.widget.add_action(self.action_tab_append.as_ref());
|
||||||
widget.add_action(action_tab_pin.as_ref());
|
self.widget.add_action(self.action_tab_close.as_ref());
|
||||||
|
self.widget.add_action(self.action_tab_close_all.as_ref());
|
||||||
|
self.widget
|
||||||
|
.add_action(self.action_tab_page_navigation_base.as_ref());
|
||||||
|
self.widget
|
||||||
|
.add_action(self.action_tab_page_navigation_history_back.as_ref());
|
||||||
|
self.widget
|
||||||
|
.add_action(self.action_tab_page_navigation_history_forward.as_ref());
|
||||||
|
self.widget
|
||||||
|
.add_action(self.action_tab_page_navigation_reload.as_ref());
|
||||||
|
self.widget.add_action(self.action_tab_pin.as_ref());
|
||||||
|
|
||||||
// Init events
|
// Events
|
||||||
action_debug.connect_activate({
|
self.action_debug.connect_activate({
|
||||||
let widget = widget.clone();
|
let widget = self.widget.clone();
|
||||||
move |_, _| {
|
move |_, _| {
|
||||||
widget.emit_enable_debugging(true);
|
widget.emit_enable_debugging(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
action_quit.connect_activate({
|
self.action_quit.connect_activate({
|
||||||
let widget = widget.clone();
|
let widget = self.widget.clone();
|
||||||
move |_, _| {
|
move |_, _| {
|
||||||
widget.close();
|
widget.close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
action_update.connect_activate({
|
self.action_update.connect_activate({
|
||||||
let header = header.clone();
|
let header = self.header.clone();
|
||||||
let main = main.clone();
|
let main = self.main.clone();
|
||||||
move |_, _| {
|
move |_, _| {
|
||||||
main.update();
|
main.update();
|
||||||
header.update(main.tab_page_title(), main.tab_page_description());
|
header.update(main.tab_page_title(), main.tab_page_description());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
action_tab_append.connect_activate({
|
self.action_tab_append.connect_activate({
|
||||||
let main = main.clone();
|
let main = self.main.clone();
|
||||||
move |_, _| {
|
move |_, _| {
|
||||||
main.tab_append(None);
|
main.tab_append(None);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
action_tab_close.connect_activate({
|
self.action_tab_close.connect_activate({
|
||||||
let main = main.clone();
|
let main = self.main.clone();
|
||||||
move |_, _| {
|
move |_, _| {
|
||||||
main.tab_close();
|
main.tab_close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
action_tab_close_all.connect_activate({
|
self.action_tab_close_all.connect_activate({
|
||||||
let main = main.clone();
|
let main = self.main.clone();
|
||||||
move |_, _| {
|
move |_, _| {
|
||||||
main.tab_close_all();
|
main.tab_close_all();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
action_tab_page_navigation_base.connect_activate({
|
self.action_tab_page_navigation_base.connect_activate({
|
||||||
let main = main.clone();
|
let main = self.main.clone();
|
||||||
move |_, _| {
|
move |_, _| {
|
||||||
main.tab_page_navigation_base();
|
main.tab_page_navigation_base();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
action_tab_page_navigation_history_back.connect_activate({
|
self.action_tab_page_navigation_history_back
|
||||||
let main = main.clone();
|
.connect_activate({
|
||||||
move |_, _| {
|
let main = self.main.clone();
|
||||||
main.tab_page_navigation_history_back();
|
move |_, _| {
|
||||||
}
|
main.tab_page_navigation_history_back();
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
action_tab_page_navigation_history_forward.connect_activate({
|
self.action_tab_page_navigation_history_forward
|
||||||
let main = main.clone();
|
.connect_activate({
|
||||||
move |_, _| {
|
let main = self.main.clone();
|
||||||
main.tab_page_navigation_history_forward();
|
move |_, _| {
|
||||||
}
|
main.tab_page_navigation_history_forward();
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
action_tab_page_navigation_reload.connect_activate({
|
self.action_tab_page_navigation_reload.connect_activate({
|
||||||
let main = main.clone();
|
let main = self.main.clone();
|
||||||
move |_, _| {
|
move |_, _| {
|
||||||
main.tab_page_navigation_reload();
|
main.tab_page_navigation_reload();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
action_tab_pin.connect_activate({
|
self.action_tab_pin.connect_activate({
|
||||||
let main = main.clone();
|
let main = self.main.clone();
|
||||||
move |_, _| {
|
move |_, _| {
|
||||||
main.tab_pin();
|
main.tab_pin();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Return activated browser struct
|
|
||||||
Self {
|
|
||||||
// db,
|
|
||||||
widget,
|
|
||||||
// header,
|
|
||||||
// main,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
|
@ -27,5 +27,5 @@ fn main() -> ExitCode {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Start application
|
// Start application
|
||||||
App::new(profile_database_connection).run()
|
App::new(profile_database_connection).activate().run()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user