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

@ -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 })