mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-02-11 02:44:15 +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
|
// Init components
|
||||||
let content = Arc::new(Content::new(action_page_open.clone()));
|
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_base.clone(),
|
||||||
action_tab_page_navigation_history_back.clone(),
|
action_tab_page_navigation_history_back.clone(),
|
||||||
action_tab_page_navigation_history_forward.clone(),
|
action_tab_page_navigation_history_forward.clone(),
|
||||||
action_tab_page_navigation_reload.clone(),
|
action_tab_page_navigation_reload.clone(),
|
||||||
action_update.clone(),
|
action_update.clone(),
|
||||||
));
|
);
|
||||||
let widget = Widget::new_arc(
|
let widget = Widget::new_arc(
|
||||||
action_page_open.clone(),
|
action_page_open.clone(),
|
||||||
&name, // ID
|
&name, // ID
|
||||||
|
@ -4,6 +4,7 @@ mod database;
|
|||||||
mod history;
|
mod history;
|
||||||
mod reload;
|
mod reload;
|
||||||
mod request;
|
mod request;
|
||||||
|
mod widget;
|
||||||
|
|
||||||
use base::Base;
|
use base::Base;
|
||||||
use bookmark::Bookmark;
|
use bookmark::Bookmark;
|
||||||
@ -11,73 +12,61 @@ use database::Database;
|
|||||||
use history::History;
|
use history::History;
|
||||||
use reload::Reload;
|
use reload::Reload;
|
||||||
use request::Request;
|
use request::Request;
|
||||||
|
use widget::Widget;
|
||||||
|
|
||||||
use gtk::{
|
use gtk::{gio::SimpleAction, glib::GString, prelude::WidgetExt, Box};
|
||||||
gio::SimpleAction,
|
|
||||||
glib::GString,
|
|
||||||
prelude::{BoxExt, WidgetExt},
|
|
||||||
Box, DirectionType, Orientation,
|
|
||||||
};
|
|
||||||
use sqlite::Transaction;
|
use sqlite::Transaction;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub struct Navigation {
|
pub struct Navigation {
|
||||||
// GTK
|
base: Arc<Base>,
|
||||||
widget: Box,
|
bookmark: Arc<Bookmark>,
|
||||||
// Components
|
history: Arc<History>,
|
||||||
base: Base,
|
reload: Arc<Reload>,
|
||||||
history: History,
|
|
||||||
reload: Reload,
|
|
||||||
request: Arc<Request>,
|
request: Arc<Request>,
|
||||||
bookmark: Bookmark,
|
widget: Arc<Widget>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Navigation {
|
impl Navigation {
|
||||||
pub fn new(
|
pub fn new_arc(
|
||||||
action_tab_page_navigation_base: Arc<SimpleAction>,
|
action_tab_page_navigation_base: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_reload: Arc<SimpleAction>,
|
action_tab_page_navigation_reload: Arc<SimpleAction>,
|
||||||
action_update: Arc<SimpleAction>,
|
action_update: Arc<SimpleAction>,
|
||||||
) -> Self {
|
) -> Arc<Self> {
|
||||||
// Init components
|
// Init components
|
||||||
let base = Base::new(action_tab_page_navigation_base);
|
let base = Base::new_arc(action_tab_page_navigation_base);
|
||||||
let history = History::new(
|
let history = History::new_arc(
|
||||||
action_tab_page_navigation_history_back,
|
action_tab_page_navigation_history_back,
|
||||||
action_tab_page_navigation_history_forward,
|
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(
|
let request = Request::new_arc(
|
||||||
action_update.clone(),
|
action_update.clone(),
|
||||||
action_tab_page_navigation_reload.clone(),
|
action_tab_page_navigation_reload.clone(),
|
||||||
);
|
);
|
||||||
let bookmark = Bookmark::new();
|
let bookmark = Bookmark::new_arc();
|
||||||
|
|
||||||
// Init widget
|
// Init widget
|
||||||
let widget = Box::builder()
|
let widget = Widget::new_arc(
|
||||||
.orientation(Orientation::Horizontal)
|
base.gobject(),
|
||||||
.spacing(8)
|
history.gobject(),
|
||||||
.margin_start(6)
|
reload.gobject(),
|
||||||
.margin_end(6)
|
request.gobject(),
|
||||||
.margin_bottom(6)
|
bookmark.gobject(),
|
||||||
.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
|
|
||||||
|
|
||||||
// Result
|
// Result
|
||||||
Self {
|
Arc::new(Self {
|
||||||
widget,
|
widget,
|
||||||
base,
|
base,
|
||||||
history,
|
history,
|
||||||
reload,
|
reload,
|
||||||
request,
|
request,
|
||||||
bookmark,
|
bookmark,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
@ -171,14 +160,14 @@ impl Navigation {
|
|||||||
// Setters
|
// Setters
|
||||||
pub fn set_request_text(&self, value: &GString) {
|
pub fn set_request_text(&self, value: &GString) {
|
||||||
// Focus out from content area on activate the link @TODO
|
// Focus out from content area on activate the link @TODO
|
||||||
self.widget.child_focus(DirectionType::Right);
|
self.widget.focus();
|
||||||
|
|
||||||
self.request.set_text(value);
|
self.request.set_text(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
pub fn gobject(&self) -> &Box {
|
pub fn gobject(&self) -> &Box {
|
||||||
&self.widget
|
&self.widget.gobject()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn base_url(&self) -> Option<GString> {
|
pub fn base_url(&self) -> Option<GString> {
|
||||||
|
@ -1,64 +1,51 @@
|
|||||||
|
mod widget;
|
||||||
|
|
||||||
|
use widget::Widget;
|
||||||
|
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gio::SimpleAction,
|
gio::SimpleAction,
|
||||||
glib::{gformat, GString, Uri},
|
glib::{gformat, GString, Uri},
|
||||||
prelude::{ActionExt, ButtonExt, WidgetExt},
|
|
||||||
Button,
|
Button,
|
||||||
};
|
};
|
||||||
use std::{cell::RefCell, sync::Arc};
|
use std::{cell::RefCell, sync::Arc};
|
||||||
|
|
||||||
pub struct Base {
|
pub struct Base {
|
||||||
// Actions
|
|
||||||
action_tab_page_navigation_base: Arc<SimpleAction>,
|
action_tab_page_navigation_base: Arc<SimpleAction>,
|
||||||
// Mutable URI cache (parsed on update)
|
|
||||||
uri: RefCell<Option<Uri>>,
|
uri: RefCell<Option<Uri>>,
|
||||||
// GTK
|
widget: Arc<Widget>,
|
||||||
widget: Button,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Base {
|
impl Base {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new(action_tab_page_navigation_base: Arc<SimpleAction>) -> Self {
|
pub fn new_arc(action_tab_page_navigation_base: Arc<SimpleAction>) -> Arc<Self> {
|
||||||
// Init widget
|
Arc::new(Self {
|
||||||
let widget = Button::builder()
|
action_tab_page_navigation_base: action_tab_page_navigation_base.clone(),
|
||||||
.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,
|
|
||||||
uri: RefCell::new(None),
|
uri: RefCell::new(None),
|
||||||
widget,
|
widget: Widget::new_arc(action_tab_page_navigation_base),
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
pub fn update(&self, uri: Option<Uri>) {
|
pub fn update(&self, uri: Option<Uri>) {
|
||||||
// Update sensitivity
|
// Detect sensitivity value
|
||||||
let status = match &uri {
|
let status = match &uri {
|
||||||
Some(uri) => "/" != uri.path(),
|
Some(uri) => "/" != uri.path(),
|
||||||
None => false,
|
None => false,
|
||||||
};
|
};
|
||||||
|
|
||||||
self.action_tab_page_navigation_base.set_enabled(status);
|
|
||||||
self.widget.set_sensitive(status);
|
|
||||||
|
|
||||||
// Update parsed cache
|
// Update parsed cache
|
||||||
self.uri.replace(uri);
|
self.uri.replace(uri);
|
||||||
|
|
||||||
|
// Update action status
|
||||||
|
self.action_tab_page_navigation_base.set_enabled(status);
|
||||||
|
|
||||||
|
// Update child components
|
||||||
|
self.widget.update(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
pub fn widget(&self) -> &Button {
|
pub fn gobject(&self) -> &Button {
|
||||||
&self.widget
|
&self.widget.gobject()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn url(&self) -> Option<GString> {
|
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 gtk::Button;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub struct Bookmark {
|
pub struct Bookmark {
|
||||||
widget: Button,
|
widget: Arc<Widget>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Bookmark {
|
impl Bookmark {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new() -> Self {
|
pub fn new_arc() -> Arc<Self> {
|
||||||
Self {
|
Arc::new(Self {
|
||||||
widget: Button::builder()
|
widget: Widget::new_arc(),
|
||||||
.icon_name("starred-symbolic")
|
})
|
||||||
.tooltip_text("Bookmark")
|
|
||||||
.sensitive(false)
|
|
||||||
.build(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
@ -22,7 +23,7 @@ impl Bookmark {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
pub fn widget(&self) -> &Button {
|
pub fn gobject(&self) -> &Button {
|
||||||
&self.widget
|
&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 back;
|
||||||
mod forward;
|
mod forward;
|
||||||
|
mod widget;
|
||||||
|
|
||||||
use back::Back;
|
use back::Back;
|
||||||
use forward::Forward;
|
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};
|
use std::{cell::RefCell, sync::Arc};
|
||||||
|
|
||||||
struct Memory {
|
struct Memory {
|
||||||
@ -14,35 +16,27 @@ struct Memory {
|
|||||||
|
|
||||||
pub struct History {
|
pub struct History {
|
||||||
// Components
|
// Components
|
||||||
back: Back,
|
back: Arc<Back>,
|
||||||
forward: Forward,
|
forward: Arc<Forward>,
|
||||||
// Extras
|
// Extras
|
||||||
memory: RefCell<Vec<Memory>>,
|
memory: RefCell<Vec<Memory>>,
|
||||||
index: RefCell<Option<usize>>,
|
index: RefCell<Option<usize>>,
|
||||||
// GTK
|
// GTK
|
||||||
widget: Box,
|
widget: Arc<Widget>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl History {
|
impl History {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new(
|
pub fn new_arc(
|
||||||
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
||||||
) -> Self {
|
) -> Arc<Self> {
|
||||||
// init components
|
// init components
|
||||||
let back = Back::new(action_tab_page_navigation_history_back);
|
let back = Back::new_arc(action_tab_page_navigation_history_back);
|
||||||
let forward = Forward::new(action_tab_page_navigation_history_forward);
|
let forward = Forward::new_arc(action_tab_page_navigation_history_forward);
|
||||||
|
|
||||||
// Init widget
|
// Init widget
|
||||||
let widget = Box::builder()
|
let widget = Widget::new_arc(back.gobject(), forward.gobject());
|
||||||
.orientation(Orientation::Horizontal)
|
|
||||||
.css_classes([
|
|
||||||
"linked", // merge childs
|
|
||||||
])
|
|
||||||
.build();
|
|
||||||
|
|
||||||
widget.append(back.widget());
|
|
||||||
widget.append(forward.widget());
|
|
||||||
|
|
||||||
// Init memory
|
// Init memory
|
||||||
let memory = RefCell::new(Vec::new());
|
let memory = RefCell::new(Vec::new());
|
||||||
@ -50,16 +44,13 @@ impl History {
|
|||||||
// Init index
|
// Init index
|
||||||
let index = RefCell::new(None);
|
let index = RefCell::new(None);
|
||||||
|
|
||||||
Self {
|
Arc::new(Self {
|
||||||
// Actions
|
|
||||||
back,
|
back,
|
||||||
forward,
|
forward,
|
||||||
// Extras
|
|
||||||
memory,
|
memory,
|
||||||
index,
|
index,
|
||||||
// GTK
|
|
||||||
widget,
|
widget,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
@ -133,7 +124,7 @@ impl History {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
pub fn widget(&self) -> &Box {
|
pub fn gobject(&self) -> &Box {
|
||||||
&self.widget
|
&self.widget.gobject()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,50 +1,38 @@
|
|||||||
use gtk::{
|
mod widget;
|
||||||
gio::SimpleAction,
|
|
||||||
prelude::{ActionExt, ButtonExt, WidgetExt},
|
use widget::Widget;
|
||||||
Button,
|
|
||||||
};
|
use gtk::{gio::SimpleAction, Button};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub struct Back {
|
pub struct Back {
|
||||||
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
||||||
widget: Button,
|
widget: Arc<Widget>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Back {
|
impl Back {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new(action_tab_page_navigation_history_back: Arc<SimpleAction>) -> Self {
|
pub fn new_arc(action_tab_page_navigation_history_back: Arc<SimpleAction>) -> Arc<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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Return activated struct
|
// Return activated struct
|
||||||
Self {
|
Arc::new(Self {
|
||||||
action_tab_page_navigation_history_back,
|
action_tab_page_navigation_history_back: action_tab_page_navigation_history_back
|
||||||
widget,
|
.clone(),
|
||||||
}
|
widget: Widget::new_arc(action_tab_page_navigation_history_back),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
pub fn update(&self, status: bool) {
|
pub fn update(&self, status: bool) {
|
||||||
|
// Update actions
|
||||||
self.action_tab_page_navigation_history_back
|
self.action_tab_page_navigation_history_back
|
||||||
.set_enabled(status);
|
.set_enabled(status);
|
||||||
self.widget.set_sensitive(status);
|
|
||||||
|
// Update child components
|
||||||
|
self.widget.update(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
pub fn widget(&self) -> &Button {
|
pub fn gobject(&self) -> &Button {
|
||||||
&self.widget
|
&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::{
|
mod widget;
|
||||||
prelude::{ActionExt, ButtonExt, WidgetExt},
|
|
||||||
{gio::SimpleAction, Button},
|
use widget::Widget;
|
||||||
};
|
|
||||||
|
use gtk::{gio::SimpleAction, Button};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub struct Forward {
|
pub struct Forward {
|
||||||
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
||||||
widget: Button,
|
widget: Arc<Widget>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Forward {
|
impl Forward {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new(action_tab_page_navigation_history_forward: Arc<SimpleAction>) -> Self {
|
pub fn new_arc(action_tab_page_navigation_history_forward: Arc<SimpleAction>) -> Arc<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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Return activated struct
|
// Return activated struct
|
||||||
Self {
|
Arc::new(Self {
|
||||||
action_tab_page_navigation_history_forward,
|
action_tab_page_navigation_history_forward: action_tab_page_navigation_history_forward
|
||||||
widget,
|
.clone(),
|
||||||
}
|
widget: Widget::new_arc(action_tab_page_navigation_history_forward),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
pub fn update(&self, status: bool) {
|
pub fn update(&self, status: bool) {
|
||||||
|
// Update actions
|
||||||
self.action_tab_page_navigation_history_forward
|
self.action_tab_page_navigation_history_forward
|
||||||
.set_enabled(status);
|
.set_enabled(status);
|
||||||
self.widget.set_sensitive(status);
|
|
||||||
|
// Update child components
|
||||||
|
self.widget.update(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
pub fn widget(&self) -> &Button {
|
pub fn gobject(&self) -> &Button {
|
||||||
&self.widget
|
&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::{
|
mod widget;
|
||||||
gio::SimpleAction,
|
|
||||||
prelude::{ActionExt, ButtonExt, WidgetExt},
|
use widget::Widget;
|
||||||
Button,
|
|
||||||
};
|
use gtk::{gio::SimpleAction, Button};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub struct Reload {
|
pub struct Reload {
|
||||||
action_tab_page_navigation_reload: Arc<SimpleAction>,
|
action_tab_page_navigation_reload: Arc<SimpleAction>,
|
||||||
widget: Button,
|
widget: Arc<Widget>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Reload {
|
impl Reload {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new(action_tab_page_navigation_reload: Arc<SimpleAction>) -> Self {
|
pub fn new_arc(action_tab_page_navigation_reload: Arc<SimpleAction>) -> Arc<Self> {
|
||||||
// Init widget
|
Arc::new(Self {
|
||||||
let widget = Button::builder()
|
action_tab_page_navigation_reload: action_tab_page_navigation_reload.clone(),
|
||||||
.icon_name("view-refresh-symbolic")
|
widget: Widget::new_arc(action_tab_page_navigation_reload),
|
||||||
.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,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
pub fn update(&self, is_enabled: bool) {
|
pub fn update(&self, is_enabled: bool) {
|
||||||
|
// Update actions
|
||||||
self.action_tab_page_navigation_reload
|
self.action_tab_page_navigation_reload
|
||||||
.set_enabled(is_enabled);
|
.set_enabled(is_enabled);
|
||||||
self.widget.set_sensitive(is_enabled);
|
|
||||||
|
// Update child components
|
||||||
|
self.widget.update(is_enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
pub fn widget(&self) -> &Button {
|
pub fn gobject(&self) -> &Button {
|
||||||
&self.widget
|
&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