mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-02-10 10:24:13 +00:00
implement separated mods for navigation widgets
This commit is contained in:
parent
2e8d907c22
commit
2d9eec9b02
@ -55,13 +55,13 @@ impl Page {
|
||||
|
||||
// Init components
|
||||
let content = Arc::new(Content::new(action_page_open.clone()));
|
||||
let navigation = Arc::new(Navigation::new(
|
||||
let navigation = Navigation::new_arc(
|
||||
action_tab_page_navigation_base.clone(),
|
||||
action_tab_page_navigation_history_back.clone(),
|
||||
action_tab_page_navigation_history_forward.clone(),
|
||||
action_tab_page_navigation_reload.clone(),
|
||||
action_update.clone(),
|
||||
));
|
||||
);
|
||||
let widget = Widget::new_arc(
|
||||
action_page_open.clone(),
|
||||
&name, // ID
|
||||
|
@ -4,6 +4,7 @@ mod database;
|
||||
mod history;
|
||||
mod reload;
|
||||
mod request;
|
||||
mod widget;
|
||||
|
||||
use base::Base;
|
||||
use bookmark::Bookmark;
|
||||
@ -11,73 +12,61 @@ use database::Database;
|
||||
use history::History;
|
||||
use reload::Reload;
|
||||
use request::Request;
|
||||
use widget::Widget;
|
||||
|
||||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
glib::GString,
|
||||
prelude::{BoxExt, WidgetExt},
|
||||
Box, DirectionType, Orientation,
|
||||
};
|
||||
use gtk::{gio::SimpleAction, glib::GString, prelude::WidgetExt, Box};
|
||||
use sqlite::Transaction;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct Navigation {
|
||||
// GTK
|
||||
widget: Box,
|
||||
// Components
|
||||
base: Base,
|
||||
history: History,
|
||||
reload: Reload,
|
||||
base: Arc<Base>,
|
||||
bookmark: Arc<Bookmark>,
|
||||
history: Arc<History>,
|
||||
reload: Arc<Reload>,
|
||||
request: Arc<Request>,
|
||||
bookmark: Bookmark,
|
||||
widget: Arc<Widget>,
|
||||
}
|
||||
|
||||
impl Navigation {
|
||||
pub fn new(
|
||||
pub fn new_arc(
|
||||
action_tab_page_navigation_base: Arc<SimpleAction>,
|
||||
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
||||
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
||||
action_tab_page_navigation_reload: Arc<SimpleAction>,
|
||||
action_update: Arc<SimpleAction>,
|
||||
) -> Self {
|
||||
) -> Arc<Self> {
|
||||
// Init components
|
||||
let base = Base::new(action_tab_page_navigation_base);
|
||||
let history = History::new(
|
||||
let base = Base::new_arc(action_tab_page_navigation_base);
|
||||
let history = History::new_arc(
|
||||
action_tab_page_navigation_history_back,
|
||||
action_tab_page_navigation_history_forward,
|
||||
);
|
||||
let reload = Reload::new(action_tab_page_navigation_reload.clone());
|
||||
let reload = Reload::new_arc(action_tab_page_navigation_reload.clone());
|
||||
let request = Request::new_arc(
|
||||
action_update.clone(),
|
||||
action_tab_page_navigation_reload.clone(),
|
||||
);
|
||||
let bookmark = Bookmark::new();
|
||||
let bookmark = Bookmark::new_arc();
|
||||
|
||||
// Init widget
|
||||
let widget = Box::builder()
|
||||
.orientation(Orientation::Horizontal)
|
||||
.spacing(8)
|
||||
.margin_start(6)
|
||||
.margin_end(6)
|
||||
.margin_bottom(6)
|
||||
.build();
|
||||
|
||||
widget.append(base.widget());
|
||||
widget.append(history.widget());
|
||||
widget.append(reload.widget());
|
||||
widget.append(request.gobject());
|
||||
widget.append(bookmark.widget()); // @TODO update api to gobject
|
||||
let widget = Widget::new_arc(
|
||||
base.gobject(),
|
||||
history.gobject(),
|
||||
reload.gobject(),
|
||||
request.gobject(),
|
||||
bookmark.gobject(),
|
||||
);
|
||||
|
||||
// Result
|
||||
Self {
|
||||
Arc::new(Self {
|
||||
widget,
|
||||
base,
|
||||
history,
|
||||
reload,
|
||||
request,
|
||||
bookmark,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Actions
|
||||
@ -171,14 +160,14 @@ impl Navigation {
|
||||
// Setters
|
||||
pub fn set_request_text(&self, value: &GString) {
|
||||
// Focus out from content area on activate the link @TODO
|
||||
self.widget.child_focus(DirectionType::Right);
|
||||
self.widget.focus();
|
||||
|
||||
self.request.set_text(value);
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn gobject(&self) -> &Box {
|
||||
&self.widget
|
||||
&self.widget.gobject()
|
||||
}
|
||||
|
||||
pub fn base_url(&self) -> Option<GString> {
|
||||
|
@ -1,64 +1,51 @@
|
||||
mod widget;
|
||||
|
||||
use widget::Widget;
|
||||
|
||||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
glib::{gformat, GString, Uri},
|
||||
prelude::{ActionExt, ButtonExt, WidgetExt},
|
||||
Button,
|
||||
};
|
||||
use std::{cell::RefCell, sync::Arc};
|
||||
|
||||
pub struct Base {
|
||||
// Actions
|
||||
action_tab_page_navigation_base: Arc<SimpleAction>,
|
||||
// Mutable URI cache (parsed on update)
|
||||
uri: RefCell<Option<Uri>>,
|
||||
// GTK
|
||||
widget: Button,
|
||||
widget: Arc<Widget>,
|
||||
}
|
||||
|
||||
impl Base {
|
||||
// Construct
|
||||
pub fn new(action_tab_page_navigation_base: Arc<SimpleAction>) -> Self {
|
||||
// Init widget
|
||||
let widget = Button::builder()
|
||||
.icon_name("go-home-symbolic")
|
||||
.tooltip_text("Base")
|
||||
.sensitive(false)
|
||||
.build();
|
||||
|
||||
// Init events
|
||||
widget.connect_clicked({
|
||||
let action_tab_page_navigation_base = action_tab_page_navigation_base.clone();
|
||||
move |_| {
|
||||
action_tab_page_navigation_base.activate(None);
|
||||
}
|
||||
});
|
||||
|
||||
// Return activated struct
|
||||
Self {
|
||||
action_tab_page_navigation_base,
|
||||
pub fn new_arc(action_tab_page_navigation_base: Arc<SimpleAction>) -> Arc<Self> {
|
||||
Arc::new(Self {
|
||||
action_tab_page_navigation_base: action_tab_page_navigation_base.clone(),
|
||||
uri: RefCell::new(None),
|
||||
widget,
|
||||
}
|
||||
widget: Widget::new_arc(action_tab_page_navigation_base),
|
||||
})
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn update(&self, uri: Option<Uri>) {
|
||||
// Update sensitivity
|
||||
// Detect sensitivity value
|
||||
let status = match &uri {
|
||||
Some(uri) => "/" != uri.path(),
|
||||
None => false,
|
||||
};
|
||||
|
||||
self.action_tab_page_navigation_base.set_enabled(status);
|
||||
self.widget.set_sensitive(status);
|
||||
|
||||
// Update parsed cache
|
||||
self.uri.replace(uri);
|
||||
|
||||
// Update action status
|
||||
self.action_tab_page_navigation_base.set_enabled(status);
|
||||
|
||||
// Update child components
|
||||
self.widget.update(status);
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn widget(&self) -> &Button {
|
||||
&self.widget
|
||||
pub fn gobject(&self) -> &Button {
|
||||
&self.widget.gobject()
|
||||
}
|
||||
|
||||
pub fn url(&self) -> Option<GString> {
|
||||
|
@ -0,0 +1,43 @@
|
||||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
prelude::{ActionExt, ButtonExt, WidgetExt},
|
||||
Button,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct Widget {
|
||||
gobject: Button,
|
||||
}
|
||||
|
||||
impl Widget {
|
||||
// Construct
|
||||
pub fn new_arc(action_tab_page_navigation_base: Arc<SimpleAction>) -> Arc<Self> {
|
||||
// Init gobject
|
||||
let gobject = Button::builder()
|
||||
.icon_name("go-home-symbolic")
|
||||
.tooltip_text("Base")
|
||||
.sensitive(false)
|
||||
.build();
|
||||
|
||||
// Init events
|
||||
gobject.connect_clicked({
|
||||
let action_tab_page_navigation_base = action_tab_page_navigation_base.clone();
|
||||
move |_| {
|
||||
action_tab_page_navigation_base.activate(None);
|
||||
}
|
||||
});
|
||||
|
||||
// Return activated struct
|
||||
Arc::new(Self { gobject })
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn update(&self, is_sensitive: bool) {
|
||||
self.gobject.set_sensitive(is_sensitive);
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn gobject(&self) -> &Button {
|
||||
&self.gobject
|
||||
}
|
||||
}
|
@ -1,19 +1,20 @@
|
||||
mod widget;
|
||||
|
||||
use widget::Widget;
|
||||
|
||||
use gtk::Button;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct Bookmark {
|
||||
widget: Button,
|
||||
widget: Arc<Widget>,
|
||||
}
|
||||
|
||||
impl Bookmark {
|
||||
// Construct
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
widget: Button::builder()
|
||||
.icon_name("starred-symbolic")
|
||||
.tooltip_text("Bookmark")
|
||||
.sensitive(false)
|
||||
.build(),
|
||||
}
|
||||
pub fn new_arc() -> Arc<Self> {
|
||||
Arc::new(Self {
|
||||
widget: Widget::new_arc(),
|
||||
})
|
||||
}
|
||||
|
||||
// Actions
|
||||
@ -22,7 +23,7 @@ impl Bookmark {
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn widget(&self) -> &Button {
|
||||
&self.widget
|
||||
pub fn gobject(&self) -> &Button {
|
||||
&self.widget.gobject()
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
use gtk::Button;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct Widget {
|
||||
gobject: Button,
|
||||
}
|
||||
|
||||
impl Widget {
|
||||
// Construct
|
||||
pub fn new_arc() -> Arc<Self> {
|
||||
Arc::new(Self {
|
||||
gobject: Button::builder()
|
||||
.icon_name("starred-symbolic")
|
||||
.tooltip_text("Bookmark")
|
||||
.sensitive(false)
|
||||
.build(),
|
||||
})
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn gobject(&self) -> &Button {
|
||||
&self.gobject
|
||||
}
|
||||
}
|
@ -1,10 +1,12 @@
|
||||
mod back;
|
||||
mod forward;
|
||||
mod widget;
|
||||
|
||||
use back::Back;
|
||||
use forward::Forward;
|
||||
use widget::Widget;
|
||||
|
||||
use gtk::{gio::SimpleAction, glib::GString, prelude::BoxExt, Box, Orientation};
|
||||
use gtk::{gio::SimpleAction, glib::GString, Box};
|
||||
use std::{cell::RefCell, sync::Arc};
|
||||
|
||||
struct Memory {
|
||||
@ -14,35 +16,27 @@ struct Memory {
|
||||
|
||||
pub struct History {
|
||||
// Components
|
||||
back: Back,
|
||||
forward: Forward,
|
||||
back: Arc<Back>,
|
||||
forward: Arc<Forward>,
|
||||
// Extras
|
||||
memory: RefCell<Vec<Memory>>,
|
||||
index: RefCell<Option<usize>>,
|
||||
// GTK
|
||||
widget: Box,
|
||||
widget: Arc<Widget>,
|
||||
}
|
||||
|
||||
impl History {
|
||||
// Construct
|
||||
pub fn new(
|
||||
pub fn new_arc(
|
||||
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
||||
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
||||
) -> Self {
|
||||
) -> Arc<Self> {
|
||||
// init components
|
||||
let back = Back::new(action_tab_page_navigation_history_back);
|
||||
let forward = Forward::new(action_tab_page_navigation_history_forward);
|
||||
let back = Back::new_arc(action_tab_page_navigation_history_back);
|
||||
let forward = Forward::new_arc(action_tab_page_navigation_history_forward);
|
||||
|
||||
// Init widget
|
||||
let widget = Box::builder()
|
||||
.orientation(Orientation::Horizontal)
|
||||
.css_classes([
|
||||
"linked", // merge childs
|
||||
])
|
||||
.build();
|
||||
|
||||
widget.append(back.widget());
|
||||
widget.append(forward.widget());
|
||||
let widget = Widget::new_arc(back.gobject(), forward.gobject());
|
||||
|
||||
// Init memory
|
||||
let memory = RefCell::new(Vec::new());
|
||||
@ -50,16 +44,13 @@ impl History {
|
||||
// Init index
|
||||
let index = RefCell::new(None);
|
||||
|
||||
Self {
|
||||
// Actions
|
||||
Arc::new(Self {
|
||||
back,
|
||||
forward,
|
||||
// Extras
|
||||
memory,
|
||||
index,
|
||||
// GTK
|
||||
widget,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Actions
|
||||
@ -133,7 +124,7 @@ impl History {
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn widget(&self) -> &Box {
|
||||
&self.widget
|
||||
pub fn gobject(&self) -> &Box {
|
||||
&self.widget.gobject()
|
||||
}
|
||||
}
|
||||
|
@ -1,50 +1,38 @@
|
||||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
prelude::{ActionExt, ButtonExt, WidgetExt},
|
||||
Button,
|
||||
};
|
||||
mod widget;
|
||||
|
||||
use widget::Widget;
|
||||
|
||||
use gtk::{gio::SimpleAction, Button};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct Back {
|
||||
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
||||
widget: Button,
|
||||
widget: Arc<Widget>,
|
||||
}
|
||||
|
||||
impl Back {
|
||||
// Construct
|
||||
pub fn new(action_tab_page_navigation_history_back: Arc<SimpleAction>) -> Self {
|
||||
// Init widget
|
||||
let widget = Button::builder()
|
||||
.icon_name("go-previous-symbolic")
|
||||
.tooltip_text("Back")
|
||||
.sensitive(false)
|
||||
.build();
|
||||
|
||||
// Init events
|
||||
widget.connect_clicked({
|
||||
let action_tab_page_navigation_history_back =
|
||||
action_tab_page_navigation_history_back.clone();
|
||||
move |_| {
|
||||
action_tab_page_navigation_history_back.activate(None);
|
||||
}
|
||||
});
|
||||
|
||||
pub fn new_arc(action_tab_page_navigation_history_back: Arc<SimpleAction>) -> Arc<Self> {
|
||||
// Return activated struct
|
||||
Self {
|
||||
action_tab_page_navigation_history_back,
|
||||
widget,
|
||||
}
|
||||
Arc::new(Self {
|
||||
action_tab_page_navigation_history_back: action_tab_page_navigation_history_back
|
||||
.clone(),
|
||||
widget: Widget::new_arc(action_tab_page_navigation_history_back),
|
||||
})
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn update(&self, status: bool) {
|
||||
// Update actions
|
||||
self.action_tab_page_navigation_history_back
|
||||
.set_enabled(status);
|
||||
self.widget.set_sensitive(status);
|
||||
|
||||
// Update child components
|
||||
self.widget.update(status);
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn widget(&self) -> &Button {
|
||||
&self.widget
|
||||
pub fn gobject(&self) -> &Button {
|
||||
&self.widget.gobject()
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,44 @@
|
||||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
prelude::{ActionExt, ButtonExt, WidgetExt},
|
||||
Button,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct Widget {
|
||||
gobject: Button,
|
||||
}
|
||||
|
||||
impl Widget {
|
||||
// Construct
|
||||
pub fn new_arc(action_tab_page_navigation_history_back: Arc<SimpleAction>) -> Arc<Self> {
|
||||
// Init gobject
|
||||
let gobject = Button::builder()
|
||||
.icon_name("go-previous-symbolic")
|
||||
.tooltip_text("Back")
|
||||
.sensitive(false)
|
||||
.build();
|
||||
|
||||
// Init events
|
||||
gobject.connect_clicked({
|
||||
let action_tab_page_navigation_history_back =
|
||||
action_tab_page_navigation_history_back.clone();
|
||||
move |_| {
|
||||
action_tab_page_navigation_history_back.activate(None);
|
||||
}
|
||||
});
|
||||
|
||||
// Return activated struct
|
||||
Arc::new(Self { gobject })
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn update(&self, is_sensitive: bool) {
|
||||
self.gobject.set_sensitive(is_sensitive);
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn gobject(&self) -> &Button {
|
||||
&self.gobject
|
||||
}
|
||||
}
|
@ -1,49 +1,38 @@
|
||||
use gtk::{
|
||||
prelude::{ActionExt, ButtonExt, WidgetExt},
|
||||
{gio::SimpleAction, Button},
|
||||
};
|
||||
mod widget;
|
||||
|
||||
use widget::Widget;
|
||||
|
||||
use gtk::{gio::SimpleAction, Button};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct Forward {
|
||||
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
||||
widget: Button,
|
||||
widget: Arc<Widget>,
|
||||
}
|
||||
|
||||
impl Forward {
|
||||
// Construct
|
||||
pub fn new(action_tab_page_navigation_history_forward: Arc<SimpleAction>) -> Self {
|
||||
// Init widget
|
||||
let widget = Button::builder()
|
||||
.icon_name("go-next-symbolic")
|
||||
.tooltip_text("Forward")
|
||||
.sensitive(false)
|
||||
.build();
|
||||
|
||||
// Init events
|
||||
widget.connect_clicked({
|
||||
let action_tab_page_navigation_history_forward =
|
||||
action_tab_page_navigation_history_forward.clone();
|
||||
move |_| {
|
||||
action_tab_page_navigation_history_forward.activate(None);
|
||||
}
|
||||
});
|
||||
|
||||
pub fn new_arc(action_tab_page_navigation_history_forward: Arc<SimpleAction>) -> Arc<Self> {
|
||||
// Return activated struct
|
||||
Self {
|
||||
action_tab_page_navigation_history_forward,
|
||||
widget,
|
||||
}
|
||||
Arc::new(Self {
|
||||
action_tab_page_navigation_history_forward: action_tab_page_navigation_history_forward
|
||||
.clone(),
|
||||
widget: Widget::new_arc(action_tab_page_navigation_history_forward),
|
||||
})
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn update(&self, status: bool) {
|
||||
// Update actions
|
||||
self.action_tab_page_navigation_history_forward
|
||||
.set_enabled(status);
|
||||
self.widget.set_sensitive(status);
|
||||
|
||||
// Update child components
|
||||
self.widget.update(status);
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn widget(&self) -> &Button {
|
||||
&self.widget
|
||||
pub fn gobject(&self) -> &Button {
|
||||
&self.widget.gobject()
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,44 @@
|
||||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
prelude::{ActionExt, ButtonExt, WidgetExt},
|
||||
Button,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct Widget {
|
||||
gobject: Button,
|
||||
}
|
||||
|
||||
impl Widget {
|
||||
// Construct
|
||||
pub fn new_arc(action_tab_page_navigation_history_forward: Arc<SimpleAction>) -> Arc<Self> {
|
||||
// Init gobject
|
||||
let gobject = Button::builder()
|
||||
.icon_name("go-next-symbolic")
|
||||
.tooltip_text("Forward")
|
||||
.sensitive(false)
|
||||
.build();
|
||||
|
||||
// Init events
|
||||
gobject.connect_clicked({
|
||||
let action_tab_page_navigation_history_forward =
|
||||
action_tab_page_navigation_history_forward.clone();
|
||||
move |_| {
|
||||
action_tab_page_navigation_history_forward.activate(None);
|
||||
}
|
||||
});
|
||||
|
||||
// Return activated struct
|
||||
Arc::new(Self { gobject })
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn update(&self, is_sensitive: bool) {
|
||||
self.gobject.set_sensitive(is_sensitive);
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn gobject(&self) -> &Button {
|
||||
&self.gobject
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
use gtk::{prelude::BoxExt, Box, Button, Orientation};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct Widget {
|
||||
gobject: Box,
|
||||
}
|
||||
|
||||
impl Widget {
|
||||
// Construct
|
||||
pub fn new_arc(back: &Button, forward: &Button) -> Arc<Self> {
|
||||
// Init widget
|
||||
let gobject = Box::builder()
|
||||
.orientation(Orientation::Horizontal)
|
||||
.css_classes([
|
||||
"linked", // merge childs
|
||||
])
|
||||
.build();
|
||||
|
||||
// Compose childs
|
||||
gobject.append(back);
|
||||
gobject.append(forward);
|
||||
|
||||
// Return activated struct
|
||||
Arc::new(Self { gobject })
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn gobject(&self) -> &Box {
|
||||
&self.gobject
|
||||
}
|
||||
}
|
@ -1,49 +1,36 @@
|
||||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
prelude::{ActionExt, ButtonExt, WidgetExt},
|
||||
Button,
|
||||
};
|
||||
mod widget;
|
||||
|
||||
use widget::Widget;
|
||||
|
||||
use gtk::{gio::SimpleAction, Button};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct Reload {
|
||||
action_tab_page_navigation_reload: Arc<SimpleAction>,
|
||||
widget: Button,
|
||||
widget: Arc<Widget>,
|
||||
}
|
||||
|
||||
impl Reload {
|
||||
// Construct
|
||||
pub fn new(action_tab_page_navigation_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({
|
||||
let action_tab_page_navigation_reload = action_tab_page_navigation_reload.clone();
|
||||
move |_| {
|
||||
action_tab_page_navigation_reload.activate(None);
|
||||
}
|
||||
});
|
||||
|
||||
// Return activated struct
|
||||
Self {
|
||||
action_tab_page_navigation_reload,
|
||||
widget,
|
||||
}
|
||||
pub fn new_arc(action_tab_page_navigation_reload: Arc<SimpleAction>) -> Arc<Self> {
|
||||
Arc::new(Self {
|
||||
action_tab_page_navigation_reload: action_tab_page_navigation_reload.clone(),
|
||||
widget: Widget::new_arc(action_tab_page_navigation_reload),
|
||||
})
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn update(&self, is_enabled: bool) {
|
||||
// Update actions
|
||||
self.action_tab_page_navigation_reload
|
||||
.set_enabled(is_enabled);
|
||||
self.widget.set_sensitive(is_enabled);
|
||||
|
||||
// Update child components
|
||||
self.widget.update(is_enabled);
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn widget(&self) -> &Button {
|
||||
&self.widget
|
||||
pub fn gobject(&self) -> &Button {
|
||||
&self.widget.gobject()
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,43 @@
|
||||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
prelude::{ActionExt, ButtonExt, WidgetExt},
|
||||
Button,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct Widget {
|
||||
gobject: Button,
|
||||
}
|
||||
|
||||
impl Widget {
|
||||
// Construct
|
||||
pub fn new_arc(action_tab_page_navigation_reload: Arc<SimpleAction>) -> Arc<Self> {
|
||||
// Init gobject
|
||||
let gobject = Button::builder()
|
||||
.icon_name("view-refresh-symbolic")
|
||||
.tooltip_text("Reload")
|
||||
.sensitive(false)
|
||||
.build();
|
||||
|
||||
// Init events
|
||||
gobject.connect_clicked({
|
||||
let action_tab_page_navigation_reload = action_tab_page_navigation_reload.clone();
|
||||
move |_| {
|
||||
action_tab_page_navigation_reload.activate(None);
|
||||
}
|
||||
});
|
||||
|
||||
// Return activated struct
|
||||
Arc::new(Self { gobject })
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn update(&self, is_sensitive: bool) {
|
||||
self.gobject.set_sensitive(is_sensitive);
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn gobject(&self) -> &Button {
|
||||
&self.gobject
|
||||
}
|
||||
}
|
46
src/app/browser/window/tab/item/page/navigation/widget.rs
Normal file
46
src/app/browser/window/tab/item/page/navigation/widget.rs
Normal file
@ -0,0 +1,46 @@
|
||||
use gtk::{
|
||||
prelude::{BoxExt, WidgetExt},
|
||||
Box, Button, DirectionType, Entry, Orientation,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct Widget {
|
||||
gobject: Box,
|
||||
}
|
||||
|
||||
impl Widget {
|
||||
// Construct
|
||||
pub fn new_arc(
|
||||
base: &Button,
|
||||
history: &Box,
|
||||
reload: &Button,
|
||||
request: &Entry,
|
||||
bookmark: &Button,
|
||||
) -> Arc<Self> {
|
||||
let gobject = Box::builder()
|
||||
.orientation(Orientation::Horizontal)
|
||||
.spacing(8)
|
||||
.margin_start(6)
|
||||
.margin_end(6)
|
||||
.margin_bottom(6)
|
||||
.build();
|
||||
|
||||
gobject.append(base);
|
||||
gobject.append(history);
|
||||
gobject.append(reload);
|
||||
gobject.append(request);
|
||||
gobject.append(bookmark);
|
||||
|
||||
Arc::new(Self { gobject })
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn focus(&self) {
|
||||
self.gobject.child_focus(DirectionType::Right);
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn gobject(&self) -> &Box {
|
||||
&self.gobject
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user