create separated wrapper for home action

This commit is contained in:
yggverse 2024-11-10 10:46:46 +02:00
parent b4dee17768
commit 4afa2c204c
15 changed files with 136 additions and 62 deletions

View file

@ -35,7 +35,6 @@ impl Item {
window_action: Rc<WindowAction>,
tab_action: Rc<TabAction>,
// @TODO
action_page_home: SimpleAction,
action_page_history_back: SimpleAction,
action_page_history_forward: SimpleAction,
// Options
@ -53,7 +52,6 @@ impl Item {
browser_action,
window_action,
tab_action,
action_page_home.clone(),
action_page_history_back.clone(),
action_page_history_forward.clone(),
);
@ -135,7 +133,6 @@ impl Item {
browser_action: Rc<BrowserAction>,
window_action: Rc<WindowAction>,
tab_action: Rc<TabAction>,
action_page_home: SimpleAction,
action_page_history_back: SimpleAction,
action_page_history_forward: SimpleAction,
) -> Result<Vec<Rc<Item>>, String> {
@ -151,7 +148,6 @@ impl Item {
browser_action.clone(),
window_action.clone(),
tab_action.clone(),
action_page_home.clone(),
action_page_history_back.clone(),
action_page_history_forward.clone(),
// Options

View file

@ -60,7 +60,6 @@ impl Page {
browser_action: Rc<BrowserAction>,
window_action: Rc<WindowAction>,
tab_action: Rc<TabAction>,
action_page_home: SimpleAction,
action_page_history_back: SimpleAction,
action_page_history_forward: SimpleAction,
) -> Rc<Self> {
@ -75,7 +74,6 @@ impl Page {
let navigation = Navigation::new_rc(
browser_action.clone(),
window_action.clone(),
action_page_home.clone(),
action_page_history_back.clone(),
action_page_history_forward.clone(),
action_page_open.clone(),

View file

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

View file

@ -2,26 +2,26 @@ mod widget;
use widget::Widget;
use crate::app::browser::window::action::Action as WindowAction;
use gtk::{
gio::SimpleAction,
glib::{gformat, GString, Uri},
Button,
};
use std::{cell::RefCell, rc::Rc};
pub struct Home {
action_page_home: SimpleAction,
window_action: Rc<WindowAction>,
uri: RefCell<Option<Uri>>,
widget: Rc<Widget>,
}
impl Home {
// Construct
pub fn new_rc(action_page_home: SimpleAction) -> Rc<Self> {
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> {
Rc::new(Self {
action_page_home: action_page_home.clone(),
window_action: window_action.clone(),
uri: RefCell::new(None),
widget: Widget::new_rc(action_page_home),
widget: Widget::new_rc(window_action),
})
}
@ -37,7 +37,7 @@ impl Home {
self.uri.replace(uri);
// Update action status
self.action_page_home.set_enabled(status);
self.window_action.home().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_home: SimpleAction) -> Rc<Self> {
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> {
// Init gobject
let gobject = Button::builder()
.icon_name("go-home-symbolic")
@ -20,12 +20,7 @@ impl Widget {
.build();
// Init events
gobject.connect_clicked({
let action_page_home = action_page_home.clone();
move |_| {
action_page_home.activate(None);
}
});
gobject.connect_clicked(move |_| window_action.home().activate());
// Return activated struct
Rc::new(Self { gobject })

View file

@ -20,7 +20,6 @@ impl Menu {
action_page_close: SimpleAction,
action_page_history_back: SimpleAction,
action_page_history_forward: SimpleAction,
action_page_home: SimpleAction,
) -> Self {
let main = gtk::gio::Menu::new();
@ -44,7 +43,14 @@ impl Menu {
let navigation = gtk::gio::Menu::new();
navigation.append(Some("Home"), Some(&detailed_action_name(action_page_home)));
navigation.append(
Some("Home"),
Some(&format!(
"{}.{}",
window_action.id(),
window_action.home().id()
)),
);
main.append_section(None, &navigation);