mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 17:20:08 +00:00
move browser actions to destination submod level
This commit is contained in:
parent
33d8746ca3
commit
6030df6328
@ -170,9 +170,7 @@ Quick start guide and maintenance protocol
|
|||||||
* massive structures
|
* massive structures
|
||||||
* structures with implementation
|
* structures with implementation
|
||||||
* Every module must:
|
* Every module must:
|
||||||
* encapsulate it members: compose childs and stay composable for parents
|
* encapsulate members - use objects, not static names (unlike native GTK actions API)
|
||||||
* 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
|
|
||||||
* implement only one public API `struct` per file (same as one file for one class)
|
* implement only one public API `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:
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
mod browser;
|
|
||||||
pub use browser::Browser;
|
|
90
src/app.rs
90
src/app.rs
@ -4,7 +4,7 @@ mod database;
|
|||||||
use browser::Browser;
|
use browser::Browser;
|
||||||
use database::Database;
|
use database::Database;
|
||||||
|
|
||||||
use crate::{action::Browser as BrowserAction, profile::Profile};
|
use crate::profile::Profile;
|
||||||
use adw::Application;
|
use adw::Application;
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gio::SimpleAction,
|
gio::SimpleAction,
|
||||||
@ -29,9 +29,6 @@ impl App {
|
|||||||
// Init profile
|
// Init profile
|
||||||
let profile = Rc::new(Profile::new());
|
let profile = Rc::new(Profile::new());
|
||||||
|
|
||||||
// Init actions
|
|
||||||
let browser_action = Rc::new(BrowserAction::new());
|
|
||||||
|
|
||||||
// @TODO
|
// @TODO
|
||||||
let default_state = (-1).to_variant();
|
let default_state = (-1).to_variant();
|
||||||
|
|
||||||
@ -55,51 +52,9 @@ impl App {
|
|||||||
.application_id(APPLICATION_ID)
|
.application_id(APPLICATION_ID)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Init accels
|
|
||||||
let accels_config = &[
|
|
||||||
// Browser actions
|
|
||||||
(
|
|
||||||
gformat!("win.{}", browser_action.debug().name()),
|
|
||||||
&["<Primary>i"],
|
|
||||||
),
|
|
||||||
(
|
|
||||||
gformat!("win.{}", browser_action.quit().name()),
|
|
||||||
&["<Primary>Escape"],
|
|
||||||
),
|
|
||||||
(
|
|
||||||
gformat!("win.{}", browser_action.update().name()),
|
|
||||||
&["<Primary>u"],
|
|
||||||
),
|
|
||||||
// Other
|
|
||||||
(
|
|
||||||
gformat!("win.{}", action_page_reload.name()),
|
|
||||||
&["<Primary>r"],
|
|
||||||
),
|
|
||||||
(
|
|
||||||
gformat!("win.{}", action_page_close.name()),
|
|
||||||
&["<Primary>q"],
|
|
||||||
),
|
|
||||||
(
|
|
||||||
gformat!("win.{}", action_page_history_back.name()),
|
|
||||||
&["<Primary>Left"],
|
|
||||||
),
|
|
||||||
(
|
|
||||||
gformat!("win.{}", action_page_history_forward.name()),
|
|
||||||
&["<Primary>Right"],
|
|
||||||
),
|
|
||||||
(gformat!("win.{}", action_page_home.name()), &["<Primary>h"]),
|
|
||||||
(gformat!("win.{}", action_page_new.name()), &["<Primary>t"]),
|
|
||||||
(gformat!("win.{}", action_page_pin.name()), &["<Primary>p"]),
|
|
||||||
]; // @TODO config
|
|
||||||
|
|
||||||
for (detailed_action_name, &accels) in accels_config {
|
|
||||||
gobject.set_accels_for_action(detailed_action_name, &accels);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Init components
|
// Init components
|
||||||
let browser = Rc::new(Browser::new(
|
let browser = Rc::new(Browser::new(
|
||||||
profile.clone(),
|
profile.clone(),
|
||||||
browser_action.clone(),
|
|
||||||
action_page_new.clone(),
|
action_page_new.clone(),
|
||||||
action_page_close.clone(),
|
action_page_close.clone(),
|
||||||
action_page_close_all.clone(),
|
action_page_close_all.clone(),
|
||||||
@ -112,7 +67,7 @@ impl App {
|
|||||||
|
|
||||||
// Init events
|
// Init events
|
||||||
gobject.connect_activate({
|
gobject.connect_activate({
|
||||||
let update = browser_action.update().clone();
|
let update = browser.action().update().clone();
|
||||||
move |_| {
|
move |_| {
|
||||||
// Make initial update
|
// Make initial update
|
||||||
update.activate(Some(&"".to_variant())); // @TODO
|
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()),
|
||||||
|
&["<Primary>i"],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
gformat!("win.{}", browser.action().quit().name()),
|
||||||
|
&["<Primary>Escape"],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
gformat!("win.{}", browser.action().update().name()),
|
||||||
|
&["<Primary>u"],
|
||||||
|
),
|
||||||
|
// Other
|
||||||
|
(
|
||||||
|
gformat!("win.{}", action_page_reload.name()),
|
||||||
|
&["<Primary>r"],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
gformat!("win.{}", action_page_close.name()),
|
||||||
|
&["<Primary>q"],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
gformat!("win.{}", action_page_history_back.name()),
|
||||||
|
&["<Primary>Left"],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
gformat!("win.{}", action_page_history_forward.name()),
|
||||||
|
&["<Primary>Right"],
|
||||||
|
),
|
||||||
|
(gformat!("win.{}", action_page_home.name()), &["<Primary>h"]),
|
||||||
|
(gformat!("win.{}", action_page_new.name()), &["<Primary>t"]),
|
||||||
|
(gformat!("win.{}", action_page_pin.name()), &["<Primary>p"]),
|
||||||
|
]; // @TODO config
|
||||||
|
|
||||||
|
for (detailed_action_name, &accels) in accels_config {
|
||||||
|
gobject.set_accels_for_action(detailed_action_name, &accels);
|
||||||
|
}
|
||||||
|
|
||||||
// Return activated App struct
|
// Return activated App struct
|
||||||
Self { profile, gobject }
|
Self { profile, gobject }
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
mod about;
|
mod about;
|
||||||
|
mod action;
|
||||||
mod database;
|
mod database;
|
||||||
mod widget;
|
mod widget;
|
||||||
mod window;
|
mod window;
|
||||||
|
|
||||||
use about::About;
|
use about::About;
|
||||||
|
use action::Action;
|
||||||
use database::Database;
|
use database::Database;
|
||||||
use widget::Widget;
|
use widget::Widget;
|
||||||
use window::Window;
|
use window::Window;
|
||||||
|
|
||||||
use crate::{action::Browser as BrowserAction, profile::Profile};
|
use crate::profile::Profile;
|
||||||
use adw::ApplicationWindow;
|
use adw::ApplicationWindow;
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gio::{Cancellable, File, SimpleAction},
|
gio::{Cancellable, File, SimpleAction},
|
||||||
@ -20,15 +22,15 @@ use sqlite::Transaction;
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
pub struct Browser {
|
pub struct Browser {
|
||||||
window: Rc<Window>,
|
action: Rc<Action>,
|
||||||
widget: Rc<Widget>,
|
widget: Rc<Widget>,
|
||||||
|
window: Rc<Window>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Browser {
|
impl Browser {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new(
|
pub fn new(
|
||||||
profile: Rc<Profile>,
|
profile: Rc<Profile>,
|
||||||
browser_action: Rc<BrowserAction>,
|
|
||||||
action_page_new: SimpleAction,
|
action_page_new: SimpleAction,
|
||||||
action_page_close: SimpleAction,
|
action_page_close: SimpleAction,
|
||||||
action_page_close_all: SimpleAction,
|
action_page_close_all: SimpleAction,
|
||||||
@ -38,9 +40,12 @@ impl Browser {
|
|||||||
action_page_reload: SimpleAction,
|
action_page_reload: SimpleAction,
|
||||||
action_page_pin: SimpleAction,
|
action_page_pin: SimpleAction,
|
||||||
) -> Browser {
|
) -> Browser {
|
||||||
|
// Init actions
|
||||||
|
let action = Rc::new(Action::new());
|
||||||
|
|
||||||
// Init components
|
// Init components
|
||||||
let window = Rc::new(Window::new(
|
let window = Rc::new(Window::new(
|
||||||
browser_action.clone(),
|
action.clone(),
|
||||||
action_page_new.clone(),
|
action_page_new.clone(),
|
||||||
action_page_close.clone(),
|
action_page_close.clone(),
|
||||||
action_page_close_all.clone(),
|
action_page_close_all.clone(),
|
||||||
@ -55,11 +60,11 @@ impl Browser {
|
|||||||
let widget = Rc::new(Widget::new(
|
let widget = Rc::new(Widget::new(
|
||||||
window.gobject(),
|
window.gobject(),
|
||||||
&[
|
&[
|
||||||
browser_action.about().clone(),
|
action.about().clone(),
|
||||||
browser_action.debug().clone(),
|
action.debug().clone(),
|
||||||
browser_action.profile().clone(),
|
action.profile().clone(),
|
||||||
browser_action.quit().clone(),
|
action.quit().clone(),
|
||||||
browser_action.update().clone(),
|
action.update().clone(),
|
||||||
action_page_new.clone(),
|
action_page_new.clone(),
|
||||||
action_page_close.clone(),
|
action_page_close.clone(),
|
||||||
action_page_close_all.clone(),
|
action_page_close_all.clone(),
|
||||||
@ -74,21 +79,21 @@ impl Browser {
|
|||||||
// Init events
|
// Init events
|
||||||
|
|
||||||
// Browser actions
|
// Browser actions
|
||||||
browser_action.about().connect_activate({
|
action.about().connect_activate({
|
||||||
let window = window.clone();
|
let window = window.clone();
|
||||||
move |_, _| {
|
move |_, _| {
|
||||||
About::new().present(Some(window.gobject()));
|
About::new().present(Some(window.gobject()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
browser_action.debug().connect_activate({
|
action.debug().connect_activate({
|
||||||
let widget = widget.clone();
|
let widget = widget.clone();
|
||||||
move |_, _| {
|
move |_, _| {
|
||||||
widget.gobject().emit_enable_debugging(true);
|
widget.gobject().emit_enable_debugging(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
browser_action.profile().connect_activate({
|
action.profile().connect_activate({
|
||||||
move |_, _| {
|
move |_, _| {
|
||||||
FileLauncher::new(Some(&File::for_path(profile.config_path()))).launch(
|
FileLauncher::new(Some(&File::for_path(profile.config_path()))).launch(
|
||||||
None::<>k::Window>,
|
None::<>k::Window>,
|
||||||
@ -103,14 +108,14 @@ impl Browser {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
browser_action.quit().connect_activate({
|
action.quit().connect_activate({
|
||||||
let widget = widget.clone();
|
let widget = widget.clone();
|
||||||
move |_, _| {
|
move |_, _| {
|
||||||
widget.gobject().close();
|
widget.gobject().close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
browser_action.update().connect_activate({
|
action.update().connect_activate({
|
||||||
let window = window.clone();
|
let window = window.clone();
|
||||||
move |_, this| window.update(string_from_variant(this).as_str())
|
move |_, this| window.update(string_from_variant(this).as_str())
|
||||||
});
|
});
|
||||||
@ -172,13 +177,14 @@ impl Browser {
|
|||||||
|
|
||||||
// Return new activated `Self`
|
// Return new activated `Self`
|
||||||
Self {
|
Self {
|
||||||
|
action,
|
||||||
widget,
|
widget,
|
||||||
// header,
|
|
||||||
window,
|
window,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
|
|
||||||
pub fn clean(&self, transaction: &Transaction, app_id: &i64) -> Result<(), String> {
|
pub fn clean(&self, transaction: &Transaction, app_id: &i64) -> Result<(), String> {
|
||||||
match Database::records(transaction, app_id) {
|
match Database::records(transaction, app_id) {
|
||||||
Ok(records) => {
|
Ok(records) => {
|
||||||
@ -243,6 +249,11 @@ impl Browser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
|
|
||||||
|
pub fn action(&self) -> &Rc<Action> {
|
||||||
|
&self.action
|
||||||
|
}
|
||||||
|
|
||||||
pub fn gobject(&self) -> &ApplicationWindow {
|
pub fn gobject(&self) -> &ApplicationWindow {
|
||||||
self.widget.gobject()
|
self.widget.gobject()
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use gtk::{gio::SimpleAction, glib::uuid_string_random, prelude::StaticVariantType};
|
use gtk::{gio::SimpleAction, glib::uuid_string_random, prelude::StaticVariantType};
|
||||||
|
|
||||||
pub struct Browser {
|
pub struct Action {
|
||||||
about: SimpleAction,
|
about: SimpleAction,
|
||||||
debug: SimpleAction,
|
debug: SimpleAction,
|
||||||
profile: SimpleAction,
|
profile: SimpleAction,
|
||||||
@ -8,7 +8,7 @@ pub struct Browser {
|
|||||||
update: SimpleAction,
|
update: SimpleAction,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Browser {
|
impl Action {
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
@ -9,7 +9,7 @@ use sqlite::Transaction;
|
|||||||
use tab::Tab;
|
use tab::Tab;
|
||||||
use widget::Widget;
|
use widget::Widget;
|
||||||
|
|
||||||
use crate::action::Browser as BrowserAction;
|
use crate::app::browser::action::Action as BrowserAction;
|
||||||
use gtk::{gio::SimpleAction, Box};
|
use gtk::{gio::SimpleAction, Box};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ mod widget;
|
|||||||
use bar::Bar;
|
use bar::Bar;
|
||||||
use widget::Widget;
|
use widget::Widget;
|
||||||
|
|
||||||
use crate::action::Browser as BrowserAction;
|
use crate::app::browser::action::Action as BrowserAction;
|
||||||
use adw::{TabView, ToolbarView};
|
use adw::{TabView, ToolbarView};
|
||||||
use gtk::gio::SimpleAction;
|
use gtk::gio::SimpleAction;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
@ -8,7 +8,7 @@ use menu::Menu;
|
|||||||
use tab::Tab;
|
use tab::Tab;
|
||||||
use widget::Widget;
|
use widget::Widget;
|
||||||
|
|
||||||
use crate::action::Browser as BrowserAction;
|
use crate::app::browser::action::Action as BrowserAction;
|
||||||
use adw::TabView;
|
use adw::TabView;
|
||||||
use gtk::{gio::SimpleAction, Box};
|
use gtk::{gio::SimpleAction, Box};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
@ -2,7 +2,7 @@ mod widget;
|
|||||||
|
|
||||||
use widget::Widget;
|
use widget::Widget;
|
||||||
|
|
||||||
use crate::action::Browser as BrowserAction;
|
use crate::app::browser::action::Action as BrowserAction;
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gio::{self, SimpleAction},
|
gio::{self, SimpleAction},
|
||||||
glib::{gformat, GString},
|
glib::{gformat, GString},
|
||||||
|
@ -8,7 +8,7 @@ use item::Item;
|
|||||||
use menu::Menu;
|
use menu::Menu;
|
||||||
use widget::Widget;
|
use widget::Widget;
|
||||||
|
|
||||||
use crate::action::Browser as BrowserAction;
|
use crate::app::browser::action::Action as BrowserAction;
|
||||||
use adw::TabView;
|
use adw::TabView;
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gio::SimpleAction,
|
gio::SimpleAction,
|
||||||
|
@ -6,7 +6,7 @@ use database::Database;
|
|||||||
use page::Page;
|
use page::Page;
|
||||||
use widget::Widget;
|
use widget::Widget;
|
||||||
|
|
||||||
use crate::action::Browser as BrowserAction;
|
use crate::app::browser::action::Action as BrowserAction;
|
||||||
use adw::{TabPage, TabView};
|
use adw::{TabPage, TabView};
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gio::SimpleAction,
|
gio::SimpleAction,
|
||||||
|
@ -12,7 +12,7 @@ use meta::{Meta, Status};
|
|||||||
use navigation::Navigation;
|
use navigation::Navigation;
|
||||||
use widget::Widget;
|
use widget::Widget;
|
||||||
|
|
||||||
use crate::action::Browser as BrowserAction;
|
use crate::app::browser::action::Action as BrowserAction;
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gdk_pixbuf::Pixbuf,
|
gdk_pixbuf::Pixbuf,
|
||||||
gio::{
|
gio::{
|
||||||
|
@ -14,7 +14,7 @@ use reload::Reload;
|
|||||||
use request::Request;
|
use request::Request;
|
||||||
use widget::Widget;
|
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 gtk::{gio::SimpleAction, glib::GString, prelude::WidgetExt, Box};
|
||||||
use sqlite::Transaction;
|
use sqlite::Transaction;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
@ -4,7 +4,7 @@ mod widget;
|
|||||||
use database::Database;
|
use database::Database;
|
||||||
use widget::Widget;
|
use widget::Widget;
|
||||||
|
|
||||||
use crate::action::Browser as BrowserAction;
|
use crate::app::browser::action::Action as BrowserAction;
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gio::SimpleAction,
|
gio::SimpleAction,
|
||||||
glib::{GString, Uri, UriFlags},
|
glib::{GString, Uri, UriFlags},
|
||||||
|
@ -2,7 +2,7 @@ mod database;
|
|||||||
|
|
||||||
use database::Database;
|
use database::Database;
|
||||||
|
|
||||||
use crate::action::Browser as BrowserAction;
|
use crate::app::browser::action::Action as BrowserAction;
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gio::SimpleAction,
|
gio::SimpleAction,
|
||||||
glib::{timeout_add_local, ControlFlow, GString, SourceId},
|
glib::{timeout_add_local, ControlFlow, GString, SourceId},
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
mod action;
|
|
||||||
mod app;
|
mod app;
|
||||||
mod profile;
|
mod profile;
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
mod database;
|
mod database;
|
||||||
pub use database::Database;
|
use database::Database;
|
||||||
|
|
||||||
use gtk::glib::user_config_dir;
|
use gtk::glib::user_config_dir;
|
||||||
use std::{
|
use std::{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user