create separated wrappers for history, close action group

This commit is contained in:
yggverse 2024-11-10 11:53:43 +02:00
parent 4afa2c204c
commit 8113022cd4
22 changed files with 557 additions and 335 deletions

View file

@ -10,10 +10,7 @@ use crate::app::browser::action::Action as BrowserAction;
use crate::app::browser::window::action::Action as WindowAction;
use crate::app::browser::window::tab::action::Action as TabAction;
use adw::{TabPage, TabView};
use gtk::{
gio::SimpleAction,
glib::{uuid_string_random, GString},
};
use gtk::glib::{uuid_string_random, GString};
use sqlite::Transaction;
use std::rc::Rc;
@ -30,13 +27,10 @@ impl Item {
// Construct
pub fn new_rc(
tab_view: &TabView,
// Global actions
// Actions
browser_action: Rc<BrowserAction>,
window_action: Rc<WindowAction>,
tab_action: Rc<TabAction>,
// @TODO
action_page_history_back: SimpleAction,
action_page_history_forward: SimpleAction,
// Options
position: Option<i32>,
is_pinned: bool,
@ -52,8 +46,6 @@ impl Item {
browser_action,
window_action,
tab_action,
action_page_history_back.clone(),
action_page_history_forward.clone(),
);
let widget = Widget::new_rc(
@ -133,8 +125,6 @@ impl Item {
browser_action: Rc<BrowserAction>,
window_action: Rc<WindowAction>,
tab_action: Rc<TabAction>,
action_page_history_back: SimpleAction,
action_page_history_forward: SimpleAction,
) -> Result<Vec<Rc<Item>>, String> {
let mut items = Vec::new();
@ -148,8 +138,6 @@ impl Item {
browser_action.clone(),
window_action.clone(),
tab_action.clone(),
action_page_history_back.clone(),
action_page_history_forward.clone(),
// Options
None,
record.is_pinned,

View file

@ -60,8 +60,6 @@ impl Page {
browser_action: Rc<BrowserAction>,
window_action: Rc<WindowAction>,
tab_action: Rc<TabAction>,
action_page_history_back: SimpleAction,
action_page_history_forward: SimpleAction,
) -> Rc<Self> {
// Init local actions
let action_page_load = SimpleAction::new(&uuid_string_random(), None);
@ -74,8 +72,6 @@ impl Page {
let navigation = Navigation::new_rc(
browser_action.clone(),
window_action.clone(),
action_page_history_back.clone(),
action_page_history_forward.clone(),
action_page_open.clone(),
);

View file

@ -33,13 +33,11 @@ impl Navigation {
pub fn new_rc(
browser_action: Rc<BrowserAction>,
window_action: Rc<WindowAction>,
action_page_history_back: SimpleAction,
action_page_history_forward: SimpleAction,
action_page_open: SimpleAction,
) -> Rc<Self> {
// Init components
let home = Home::new_rc(window_action.clone());
let history = History::new_rc(action_page_history_back, action_page_history_forward);
let history = History::new_rc(window_action.clone());
let reload = Reload::new_rc(window_action);
let request = Request::new_rc(browser_action, action_page_open.clone());
let bookmark = Bookmark::new_rc();

View file

@ -6,7 +6,8 @@ use back::Back;
use forward::Forward;
use widget::Widget;
use gtk::{gio::SimpleAction, glib::GString, Box};
use crate::app::browser::window::action::Action as WindowAction;
use gtk::{glib::GString, Box};
use std::{cell::RefCell, rc::Rc};
struct Memory {
@ -27,13 +28,10 @@ pub struct History {
impl History {
// Construct
pub fn new_rc(
action_page_history_back: SimpleAction,
action_page_history_forward: SimpleAction,
) -> Rc<Self> {
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> {
// init components
let back = Back::new_rc(action_page_history_back);
let forward = Forward::new_rc(action_page_history_forward);
let back = Back::new_rc(window_action.clone());
let forward = Forward::new_rc(window_action);
// Init widget
let widget = Widget::new_rc(back.gobject(), forward.gobject());

View file

@ -2,28 +2,32 @@ mod widget;
use widget::Widget;
use gtk::{gio::SimpleAction, Button};
use crate::app::browser::window::action::Action as WindowAction;
use gtk::Button;
use std::rc::Rc;
pub struct Back {
action_page_history_back: SimpleAction,
window_action: Rc<WindowAction>,
widget: Rc<Widget>,
}
impl Back {
// Construct
pub fn new_rc(action_page_history_back: SimpleAction) -> Rc<Self> {
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> {
// Return activated struct
Rc::new(Self {
action_page_history_back: action_page_history_back.clone(),
widget: Widget::new_rc(action_page_history_back),
window_action: window_action.clone(),
widget: Widget::new_rc(window_action),
})
}
// Actions
pub fn update(&self, status: bool) {
// Update actions
self.action_page_history_back.set_enabled(status);
self.window_action
.history_back()
.gobject()
.set_enabled(status);
// Update child components
self.widget.update(status);

View file

@ -1,6 +1,6 @@
use crate::app::browser::window::action::Action as WindowAction;
use gtk::{
gio::SimpleAction,
prelude::{ActionExt, ButtonExt, WidgetExt},
prelude::{ButtonExt, WidgetExt},
Button,
};
use std::rc::Rc;
@ -11,7 +11,7 @@ pub struct Widget {
impl Widget {
// Construct
pub fn new_rc(action_page_history_back: SimpleAction) -> Rc<Self> {
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> {
// Init gobject
let gobject = Button::builder()
.icon_name("go-previous-symbolic")
@ -21,9 +21,9 @@ impl Widget {
// Init events
gobject.connect_clicked({
let action_page_history_back = action_page_history_back.clone();
let window_action = window_action.clone();
move |_| {
action_page_history_back.activate(None);
window_action.history_back().activate();
}
});

View file

@ -2,28 +2,32 @@ mod widget;
use widget::Widget;
use gtk::{gio::SimpleAction, Button};
use crate::app::browser::window::action::Action as WindowAction;
use gtk::Button;
use std::rc::Rc;
pub struct Forward {
action_page_history_forward: SimpleAction,
window_action: Rc<WindowAction>,
widget: Rc<Widget>,
}
impl Forward {
// Construct
pub fn new_rc(action_page_history_forward: SimpleAction) -> Rc<Self> {
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> {
// Return activated struct
Rc::new(Self {
action_page_history_forward: action_page_history_forward.clone(),
widget: Widget::new_rc(action_page_history_forward),
window_action: window_action.clone(),
widget: Widget::new_rc(window_action),
})
}
// Actions
pub fn update(&self, status: bool) {
// Update actions
self.action_page_history_forward.set_enabled(status);
self.window_action
.history_forward()
.gobject()
.set_enabled(status);
// Update child components
self.widget.update(status);

View file

@ -1,6 +1,6 @@
use crate::app::browser::window::action::Action as WindowAction;
use gtk::{
gio::SimpleAction,
prelude::{ActionExt, ButtonExt, WidgetExt},
prelude::{ButtonExt, WidgetExt},
Button,
};
use std::rc::Rc;
@ -11,7 +11,7 @@ pub struct Widget {
impl Widget {
// Construct
pub fn new_rc(action_page_history_forward: SimpleAction) -> Rc<Self> {
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> {
// Init gobject
let gobject = Button::builder()
.icon_name("go-next-symbolic")
@ -21,9 +21,9 @@ impl Widget {
// Init events
gobject.connect_clicked({
let action_page_history_forward = action_page_history_forward.clone();
let window_action = window_action.clone();
move |_| {
action_page_history_forward.activate(None);
window_action.history_forward().activate();
}
});

View file

@ -1,7 +1,5 @@
use std::rc::Rc;
use crate::app::browser::window::action::Action as WindowAction;
use gtk::{gio::SimpleAction, prelude::ActionExt};
use std::rc::Rc;
/// Context menu wrapper
///
@ -14,13 +12,7 @@ impl Menu {
// Constructors
/// Create new `Self`
pub fn new(
window_action: Rc<WindowAction>,
action_page_close_all: SimpleAction,
action_page_close: SimpleAction,
action_page_history_back: SimpleAction,
action_page_history_forward: SimpleAction,
) -> Self {
pub fn new(window_action: Rc<WindowAction>) -> Self {
let main = gtk::gio::Menu::new();
main.append(
@ -58,12 +50,20 @@ impl Menu {
history.append(
Some("Back"),
Some(&detailed_action_name(action_page_history_back)),
Some(&format!(
"{}.{}",
window_action.id(),
window_action.history_back().id()
)),
);
history.append(
Some("Forward"),
Some(&detailed_action_name(action_page_history_forward)),
Some(&format!(
"{}.{}",
window_action.id(),
window_action.history_forward().id()
)),
);
main.append_submenu(Some("History"), &history);
@ -72,12 +72,20 @@ impl Menu {
close.append(
Some("Current"),
Some(&detailed_action_name(action_page_close)),
Some(&format!(
"{}.{}",
window_action.id(),
window_action.close().id()
)),
);
close.append(
Some("All"),
Some(&detailed_action_name(action_page_close_all)),
Some(&format!(
"{}.{}",
window_action.id(),
window_action.close_all().id()
)),
);
main.append_submenu(Some("Close"), &close);
@ -90,11 +98,3 @@ impl Menu {
&self.gobject
}
}
// Private helpers
fn detailed_action_name(action: SimpleAction) -> String {
format!("win.{}", action.name()) // @TODO find the way to ident parent group
// without application-wide dependencies import
// see also src/app/action.rs
}