update actions

This commit is contained in:
yggverse 2024-11-11 05:11:48 +02:00
parent a5fc2a7475
commit a6ef61486d
24 changed files with 190 additions and 294 deletions

View file

@ -2,7 +2,6 @@ mod widget;
use widget::Widget;
use gtk::Button;
use std::rc::Rc;
pub struct Bookmark {
@ -23,7 +22,8 @@ impl Bookmark {
}
// Getters
pub fn gobject(&self) -> &Button {
self.widget.gobject()
pub fn widget(&self) -> &Rc<Widget> {
&self.widget
}
}

View file

@ -7,7 +7,7 @@ use forward::Forward;
use widget::Widget;
use crate::app::browser::window::action::Action as WindowAction;
use gtk::{glib::GString, Box};
use gtk::glib::GString;
use std::{cell::RefCell, rc::Rc};
struct Memory {
@ -34,7 +34,10 @@ impl History {
let forward = Rc::new(Forward::new(window_action));
// Init widget
let widget = Rc::new(Widget::new(back.gobject(), forward.gobject()));
let widget = Rc::new(Widget::new(
back.widget().gobject(),
forward.widget().gobject(),
));
// Init memory
let memory = RefCell::new(Vec::new());
@ -122,7 +125,8 @@ impl History {
}
// Getters
pub fn gobject(&self) -> &Box {
self.widget.gobject()
pub fn widget(&self) -> &Rc<Widget> {
&self.widget
}
}

View file

@ -3,7 +3,6 @@ mod widget;
use widget::Widget;
use crate::app::browser::window::action::Action as WindowAction;
use gtk::Button;
use std::rc::Rc;
pub struct Back {
@ -12,7 +11,8 @@ pub struct Back {
}
impl Back {
// Construct
// Constructors
pub fn new(window_action: Rc<WindowAction>) -> Self {
Self {
window_action: window_action.clone(),
@ -21,6 +21,7 @@ impl Back {
}
// Actions
pub fn update(&self, status: bool) {
// Update actions
self.window_action
@ -33,7 +34,8 @@ impl Back {
}
// Getters
pub fn gobject(&self) -> &Button {
self.widget.gobject()
pub fn widget(&self) -> &Rc<Widget> {
&self.widget
}
}

View file

@ -3,7 +3,6 @@ mod widget;
use widget::Widget;
use crate::app::browser::window::action::Action as WindowAction;
use gtk::Button;
use std::rc::Rc;
pub struct Forward {
@ -33,7 +32,8 @@ impl Forward {
}
// Getters
pub fn gobject(&self) -> &Button {
self.widget.gobject()
pub fn widget(&self) -> &Rc<Widget> {
&self.widget
}
}

View file

@ -3,10 +3,7 @@ mod widget;
use widget::Widget;
use crate::app::browser::window::action::Action as WindowAction;
use gtk::{
glib::{gformat, GString, Uri},
Button,
};
use gtk::glib::{gformat, GString, Uri};
use std::{cell::RefCell, rc::Rc};
pub struct Home {
@ -44,8 +41,8 @@ impl Home {
}
// Getters
pub fn gobject(&self) -> &Button {
self.widget.gobject()
pub fn widget(&self) -> &Rc<Widget> {
&self.widget
}
pub fn url(&self) -> Option<GString> {

View file

@ -3,7 +3,6 @@ mod widget;
use widget::Widget;
use crate::app::browser::window::action::Action as WindowAction;
use gtk::Button;
use std::rc::Rc;
pub struct Reload {
@ -21,6 +20,7 @@ impl Reload {
}
// Actions
pub fn update(&self, is_enabled: bool) {
// Update actions
self.window_action
@ -33,7 +33,8 @@ impl Reload {
}
// Getters
pub fn gobject(&self) -> &Button {
self.widget.gobject()
pub fn widget(&self) -> &Rc<Widget> {
&self.widget
}
}

View file

@ -4,9 +4,8 @@ mod widget;
use database::Database;
use widget::Widget;
use crate::app::browser::action::Action as BrowserAction;
use crate::app::browser::{window::tab::item::Action as TabAction, Action as BrowserAction};
use gtk::{
gio::SimpleAction,
glib::{Uri, UriFlags},
prelude::EditableExt,
};
@ -23,10 +22,10 @@ impl Request {
pub fn new(
// Actions
browser_action: Rc<BrowserAction>,
action_page_reload: SimpleAction, // @TODO local `action_page_open`?
tab_action: Rc<TabAction>,
) -> Self {
Self {
widget: Rc::new(Widget::new(browser_action, action_page_reload)),
widget: Rc::new(Widget::new(browser_action, tab_action)),
}
}

View file

@ -2,11 +2,10 @@ mod database;
use database::Database;
use crate::app::browser::action::Action as BrowserAction;
use crate::app::browser::{window::tab::item::Action as TabAction, Action as BrowserAction};
use gtk::{
gio::SimpleAction,
glib::{timeout_add_local, ControlFlow, SourceId},
prelude::{ActionExt, EditableExt, EntryExt, ToVariant, WidgetExt},
prelude::{EditableExt, EntryExt, WidgetExt},
Entry, StateFlags,
};
use sqlite::Transaction;
@ -30,7 +29,7 @@ pub struct Widget {
impl Widget {
// Construct
pub fn new(browser_action: Rc<BrowserAction>, action_page_open: SimpleAction) -> Self {
pub fn new(browser_action: Rc<BrowserAction>, tab_action: Rc<TabAction>) -> Self {
// Init animated progress bar state
let progress = Rc::new(Progress {
fraction: RefCell::new(0.0),
@ -49,7 +48,7 @@ impl Widget {
});
gobject.connect_activate(move |this| {
action_page_open.activate(Some(&this.text().to_variant()));
tab_action.load().activate(Some(&this.text()));
});
gobject.connect_state_flags_changed({