define actions in arc container

This commit is contained in:
yggverse 2024-09-28 03:10:07 +03:00
parent 7c78396328
commit 9a3ad366af
10 changed files with 138 additions and 77 deletions

View file

@ -11,11 +11,14 @@ use reload::Reload;
use request::Request;
use gtk::{
gio::SimpleAction,
glib::GString,
prelude::{BoxExt, WidgetExt},
Box, DirectionType, Orientation,
};
use std::sync::Arc;
pub struct Navigation {
// GTK
widget: Box,
@ -28,11 +31,15 @@ pub struct Navigation {
}
impl Navigation {
pub fn new(request_text: Option<GString>) -> Self {
pub fn new(
request_text: Option<GString>,
action_tab_page_reload: Arc<SimpleAction>,
action_update: Arc<SimpleAction>,
) -> Self {
// Init components
let base = Base::new();
let history = History::new();
let reload = Reload::new();
let reload = Reload::new(action_tab_page_reload);
let request = Request::new(request_text);
let bookmark = Bookmark::new();

View file

@ -1,4 +1,9 @@
use gtk::{prelude::WidgetExt, Button};
use gtk::{
gio::SimpleAction,
prelude::{ActionExt, ButtonExt, WidgetExt},
Button,
};
use std::sync::Arc;
pub struct Reload {
widget: Button,
@ -6,20 +11,27 @@ pub struct Reload {
impl Reload {
// Construct
pub fn new() -> Self {
Self {
widget: Button::builder()
.action_name("win.tab_page_reload")
.icon_name("view-refresh-symbolic")
.tooltip_text("Reload")
.sensitive(false)
.build(),
}
pub fn new(action_tab_page_reload: Arc<SimpleAction>) -> Self {
// Init widget
let widget = Button::builder()
.icon_name("view-refresh-symbolic")
.tooltip_text("Reload")
.sensitive(false)
.build();
// Init events
widget.connect_clicked(move |_| {
action_tab_page_reload.activate(None);
});
// Return activated struct
Self { widget }
}
// Actions
pub fn update(&self, is_enabled: bool) {
self.widget.set_sensitive(is_enabled);
// @TODO deactivate action
}
// Getters