diff --git a/README.md b/README.md index 9e1aa7eb..bc7c6baa 100644 --- a/README.md +++ b/README.md @@ -170,9 +170,7 @@ Quick start guide and maintenance protocol * massive structures * structures with implementation * Every module must: - * encapsulate it members: compose childs and stay composable for parents - * access 1 level of childs, never parents (e.g. through `super`) - * if some feature require new global data type, it must be implemented as the local or external `crate` extension + * encapsulate members - use objects, not static names (unlike native GTK actions API) * implement only one public API `struct` per file (same as one file for one class) * implementable `struct` is public, where it members - private * contain main `struct` implementation: diff --git a/src/action.rs b/src/action.rs deleted file mode 100644 index 9c220d1e..00000000 --- a/src/action.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod browser; -pub use browser::Browser; diff --git a/src/app.rs b/src/app.rs index 21801b51..c0b9da42 100644 --- a/src/app.rs +++ b/src/app.rs @@ -4,7 +4,7 @@ mod database; use browser::Browser; use database::Database; -use crate::{action::Browser as BrowserAction, profile::Profile}; +use crate::profile::Profile; use adw::Application; use gtk::{ gio::SimpleAction, @@ -29,9 +29,6 @@ impl App { // Init profile let profile = Rc::new(Profile::new()); - // Init actions - let browser_action = Rc::new(BrowserAction::new()); - // @TODO let default_state = (-1).to_variant(); @@ -55,51 +52,9 @@ impl App { .application_id(APPLICATION_ID) .build(); - // Init accels - let accels_config = &[ - // Browser actions - ( - gformat!("win.{}", browser_action.debug().name()), - &["i"], - ), - ( - gformat!("win.{}", browser_action.quit().name()), - &["Escape"], - ), - ( - gformat!("win.{}", browser_action.update().name()), - &["u"], - ), - // Other - ( - gformat!("win.{}", action_page_reload.name()), - &["r"], - ), - ( - gformat!("win.{}", action_page_close.name()), - &["q"], - ), - ( - gformat!("win.{}", action_page_history_back.name()), - &["Left"], - ), - ( - gformat!("win.{}", action_page_history_forward.name()), - &["Right"], - ), - (gformat!("win.{}", action_page_home.name()), &["h"]), - (gformat!("win.{}", action_page_new.name()), &["t"]), - (gformat!("win.{}", action_page_pin.name()), &["p"]), - ]; // @TODO config - - for (detailed_action_name, &accels) in accels_config { - gobject.set_accels_for_action(detailed_action_name, &accels); - } - // Init components let browser = Rc::new(Browser::new( profile.clone(), - browser_action.clone(), action_page_new.clone(), action_page_close.clone(), action_page_close_all.clone(), @@ -112,7 +67,7 @@ impl App { // Init events gobject.connect_activate({ - let update = browser_action.update().clone(); + let update = browser.action().update().clone(); move |_| { // Make initial update update.activate(Some(&"".to_variant())); // @TODO @@ -218,6 +173,47 @@ impl App { } }); + // Init accels + let accels_config = &[ + // Browser actions + ( + gformat!("win.{}", browser.action().debug().name()), + &["i"], + ), + ( + gformat!("win.{}", browser.action().quit().name()), + &["Escape"], + ), + ( + gformat!("win.{}", browser.action().update().name()), + &["u"], + ), + // Other + ( + gformat!("win.{}", action_page_reload.name()), + &["r"], + ), + ( + gformat!("win.{}", action_page_close.name()), + &["q"], + ), + ( + gformat!("win.{}", action_page_history_back.name()), + &["Left"], + ), + ( + gformat!("win.{}", action_page_history_forward.name()), + &["Right"], + ), + (gformat!("win.{}", action_page_home.name()), &["h"]), + (gformat!("win.{}", action_page_new.name()), &["t"]), + (gformat!("win.{}", action_page_pin.name()), &["p"]), + ]; // @TODO config + + for (detailed_action_name, &accels) in accels_config { + gobject.set_accels_for_action(detailed_action_name, &accels); + } + // Return activated App struct Self { profile, gobject } } diff --git a/src/app/browser.rs b/src/app/browser.rs index 3260778a..9d6a7c16 100644 --- a/src/app/browser.rs +++ b/src/app/browser.rs @@ -1,14 +1,16 @@ mod about; +mod action; mod database; mod widget; mod window; use about::About; +use action::Action; use database::Database; use widget::Widget; use window::Window; -use crate::{action::Browser as BrowserAction, profile::Profile}; +use crate::profile::Profile; use adw::ApplicationWindow; use gtk::{ gio::{Cancellable, File, SimpleAction}, @@ -20,15 +22,15 @@ use sqlite::Transaction; use std::rc::Rc; pub struct Browser { - window: Rc, + action: Rc, widget: Rc, + window: Rc, } impl Browser { // Construct pub fn new( profile: Rc, - browser_action: Rc, action_page_new: SimpleAction, action_page_close: SimpleAction, action_page_close_all: SimpleAction, @@ -38,9 +40,12 @@ impl Browser { action_page_reload: SimpleAction, action_page_pin: SimpleAction, ) -> Browser { + // Init actions + let action = Rc::new(Action::new()); + // Init components let window = Rc::new(Window::new( - browser_action.clone(), + action.clone(), action_page_new.clone(), action_page_close.clone(), action_page_close_all.clone(), @@ -55,11 +60,11 @@ impl Browser { let widget = Rc::new(Widget::new( window.gobject(), &[ - browser_action.about().clone(), - browser_action.debug().clone(), - browser_action.profile().clone(), - browser_action.quit().clone(), - browser_action.update().clone(), + action.about().clone(), + action.debug().clone(), + action.profile().clone(), + action.quit().clone(), + action.update().clone(), action_page_new.clone(), action_page_close.clone(), action_page_close_all.clone(), @@ -74,21 +79,21 @@ impl Browser { // Init events // Browser actions - browser_action.about().connect_activate({ + action.about().connect_activate({ let window = window.clone(); move |_, _| { About::new().present(Some(window.gobject())); } }); - browser_action.debug().connect_activate({ + action.debug().connect_activate({ let widget = widget.clone(); move |_, _| { widget.gobject().emit_enable_debugging(true); } }); - browser_action.profile().connect_activate({ + action.profile().connect_activate({ move |_, _| { FileLauncher::new(Some(&File::for_path(profile.config_path()))).launch( None::<>k::Window>, @@ -103,14 +108,14 @@ impl Browser { } }); - browser_action.quit().connect_activate({ + action.quit().connect_activate({ let widget = widget.clone(); move |_, _| { widget.gobject().close(); } }); - browser_action.update().connect_activate({ + action.update().connect_activate({ let window = window.clone(); move |_, this| window.update(string_from_variant(this).as_str()) }); @@ -172,13 +177,14 @@ impl Browser { // Return new activated `Self` Self { + action, widget, - // header, window, } } // Actions + pub fn clean(&self, transaction: &Transaction, app_id: &i64) -> Result<(), String> { match Database::records(transaction, app_id) { Ok(records) => { @@ -243,6 +249,11 @@ impl Browser { } // Getters + + pub fn action(&self) -> &Rc { + &self.action + } + pub fn gobject(&self) -> &ApplicationWindow { self.widget.gobject() } diff --git a/src/action/browser.rs b/src/app/browser/action.rs similarity index 96% rename from src/action/browser.rs rename to src/app/browser/action.rs index 28e812bb..2add47e3 100644 --- a/src/action/browser.rs +++ b/src/app/browser/action.rs @@ -1,6 +1,6 @@ use gtk::{gio::SimpleAction, glib::uuid_string_random, prelude::StaticVariantType}; -pub struct Browser { +pub struct Action { about: SimpleAction, debug: SimpleAction, profile: SimpleAction, @@ -8,7 +8,7 @@ pub struct Browser { update: SimpleAction, } -impl Browser { +impl Action { // Constructors pub fn new() -> Self { diff --git a/src/app/browser/window.rs b/src/app/browser/window.rs index 5d209225..9ead5b71 100644 --- a/src/app/browser/window.rs +++ b/src/app/browser/window.rs @@ -9,7 +9,7 @@ use sqlite::Transaction; use tab::Tab; use widget::Widget; -use crate::action::Browser as BrowserAction; +use crate::app::browser::action::Action as BrowserAction; use gtk::{gio::SimpleAction, Box}; use std::rc::Rc; diff --git a/src/app/browser/window/header.rs b/src/app/browser/window/header.rs index e80ef37b..b8176afe 100644 --- a/src/app/browser/window/header.rs +++ b/src/app/browser/window/header.rs @@ -4,7 +4,7 @@ mod widget; use bar::Bar; use widget::Widget; -use crate::action::Browser as BrowserAction; +use crate::app::browser::action::Action as BrowserAction; use adw::{TabView, ToolbarView}; use gtk::gio::SimpleAction; use std::rc::Rc; diff --git a/src/app/browser/window/header/bar.rs b/src/app/browser/window/header/bar.rs index 620bffa2..e3f43323 100644 --- a/src/app/browser/window/header/bar.rs +++ b/src/app/browser/window/header/bar.rs @@ -8,7 +8,7 @@ use menu::Menu; use tab::Tab; use widget::Widget; -use crate::action::Browser as BrowserAction; +use crate::app::browser::action::Action as BrowserAction; use adw::TabView; use gtk::{gio::SimpleAction, Box}; use std::rc::Rc; diff --git a/src/app/browser/window/header/bar/menu.rs b/src/app/browser/window/header/bar/menu.rs index f14b688f..b3c7f9fd 100644 --- a/src/app/browser/window/header/bar/menu.rs +++ b/src/app/browser/window/header/bar/menu.rs @@ -2,7 +2,7 @@ mod widget; use widget::Widget; -use crate::action::Browser as BrowserAction; +use crate::app::browser::action::Action as BrowserAction; use gtk::{ gio::{self, SimpleAction}, glib::{gformat, GString}, diff --git a/src/app/browser/window/tab.rs b/src/app/browser/window/tab.rs index 0f4ef32f..e5ff814e 100644 --- a/src/app/browser/window/tab.rs +++ b/src/app/browser/window/tab.rs @@ -8,7 +8,7 @@ use item::Item; use menu::Menu; use widget::Widget; -use crate::action::Browser as BrowserAction; +use crate::app::browser::action::Action as BrowserAction; use adw::TabView; use gtk::{ gio::SimpleAction, diff --git a/src/app/browser/window/tab/item.rs b/src/app/browser/window/tab/item.rs index 624da494..a4011b29 100644 --- a/src/app/browser/window/tab/item.rs +++ b/src/app/browser/window/tab/item.rs @@ -6,7 +6,7 @@ use database::Database; use page::Page; use widget::Widget; -use crate::action::Browser as BrowserAction; +use crate::app::browser::action::Action as BrowserAction; use adw::{TabPage, TabView}; use gtk::{ gio::SimpleAction, diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index 03435dee..44731bfc 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -12,7 +12,7 @@ use meta::{Meta, Status}; use navigation::Navigation; use widget::Widget; -use crate::action::Browser as BrowserAction; +use crate::app::browser::action::Action as BrowserAction; use gtk::{ gdk_pixbuf::Pixbuf, gio::{ diff --git a/src/app/browser/window/tab/item/page/navigation.rs b/src/app/browser/window/tab/item/page/navigation.rs index 1668ccb5..f97b399b 100644 --- a/src/app/browser/window/tab/item/page/navigation.rs +++ b/src/app/browser/window/tab/item/page/navigation.rs @@ -14,7 +14,7 @@ use reload::Reload; use request::Request; use widget::Widget; -use crate::action::Browser as BrowserAction; +use crate::app::browser::action::Action as BrowserAction; use gtk::{gio::SimpleAction, glib::GString, prelude::WidgetExt, Box}; use sqlite::Transaction; use std::rc::Rc; diff --git a/src/app/browser/window/tab/item/page/navigation/request.rs b/src/app/browser/window/tab/item/page/navigation/request.rs index e092b92d..6b95af0f 100644 --- a/src/app/browser/window/tab/item/page/navigation/request.rs +++ b/src/app/browser/window/tab/item/page/navigation/request.rs @@ -4,7 +4,7 @@ mod widget; use database::Database; use widget::Widget; -use crate::action::Browser as BrowserAction; +use crate::app::browser::action::Action as BrowserAction; use gtk::{ gio::SimpleAction, glib::{GString, Uri, UriFlags}, diff --git a/src/app/browser/window/tab/item/page/navigation/request/widget.rs b/src/app/browser/window/tab/item/page/navigation/request/widget.rs index 3d6cac33..15024f69 100644 --- a/src/app/browser/window/tab/item/page/navigation/request/widget.rs +++ b/src/app/browser/window/tab/item/page/navigation/request/widget.rs @@ -2,7 +2,7 @@ mod database; use database::Database; -use crate::action::Browser as BrowserAction; +use crate::app::browser::action::Action as BrowserAction; use gtk::{ gio::SimpleAction, glib::{timeout_add_local, ControlFlow, GString, SourceId}, diff --git a/src/main.rs b/src/main.rs index d8267714..a03c3a7c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,3 @@ -mod action; mod app; mod profile; diff --git a/src/profile.rs b/src/profile.rs index 342a0484..11c903c1 100644 --- a/src/profile.rs +++ b/src/profile.rs @@ -1,5 +1,5 @@ mod database; -pub use database::Database; +use database::Database; use gtk::glib::user_config_dir; use std::{