mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 17:20:08 +00:00
update actions
This commit is contained in:
parent
a5fc2a7475
commit
a6ef61486d
@ -35,7 +35,7 @@ impl Browser {
|
||||
|
||||
// Init widget
|
||||
let widget = Rc::new(Widget::new(
|
||||
window.gobject(),
|
||||
window.widget().gobject(),
|
||||
&[
|
||||
// Connect action groups (to apply accels)
|
||||
(
|
||||
@ -48,11 +48,6 @@ impl Browser {
|
||||
window.action().id(),
|
||||
window.action().gobject().clone(),
|
||||
),
|
||||
(
|
||||
// Tab
|
||||
window.tab().action().id(),
|
||||
window.tab().action().gobject().clone(),
|
||||
),
|
||||
],
|
||||
));
|
||||
|
||||
@ -60,7 +55,7 @@ impl Browser {
|
||||
action.about().connect_activate({
|
||||
let window = window.clone();
|
||||
move || {
|
||||
About::new().present(Some(window.gobject()));
|
||||
About::new().present(Some(window.widget().gobject()));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -12,13 +12,12 @@ use tab::Tab;
|
||||
use widget::Widget;
|
||||
|
||||
use crate::app::browser::action::Action as BrowserAction;
|
||||
use gtk::{glib::GString, Box};
|
||||
use gtk::glib::GString;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct Window {
|
||||
//header: Rc<Header>,
|
||||
tab: Rc<Tab>,
|
||||
action: Rc<Action>,
|
||||
tab: Rc<Tab>,
|
||||
widget: Rc<Widget>,
|
||||
}
|
||||
|
||||
@ -33,10 +32,10 @@ impl Window {
|
||||
|
||||
// Init components
|
||||
let tab = Rc::new(Tab::new(browser_action.clone(), action.clone()));
|
||||
let header = Header::new(browser_action, action.clone(), tab.gobject());
|
||||
let header = Header::new(browser_action, action.clone(), tab.widget().gobject());
|
||||
|
||||
// GTK
|
||||
let widget = Rc::new(Widget::new(header.gobject(), tab.gobject()));
|
||||
let widget = Rc::new(Widget::new(header.gobject(), tab.widget().gobject()));
|
||||
|
||||
// Init events
|
||||
action.append().connect_activate({
|
||||
@ -91,9 +90,8 @@ impl Window {
|
||||
|
||||
// Init struct
|
||||
Self {
|
||||
//header,
|
||||
tab,
|
||||
action,
|
||||
tab,
|
||||
widget,
|
||||
}
|
||||
}
|
||||
@ -163,12 +161,8 @@ impl Window {
|
||||
&self.action
|
||||
}
|
||||
|
||||
pub fn tab(&self) -> &Rc<Tab> {
|
||||
&self.tab
|
||||
}
|
||||
|
||||
pub fn gobject(&self) -> &Box {
|
||||
self.widget.gobject()
|
||||
pub fn widget(&self) -> &Rc<Widget> {
|
||||
&self.widget
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,8 @@
|
||||
mod action;
|
||||
mod database;
|
||||
mod item;
|
||||
mod menu;
|
||||
mod widget;
|
||||
|
||||
use action::Action;
|
||||
use database::Database;
|
||||
use item::Item;
|
||||
use menu::Menu;
|
||||
@ -12,7 +10,6 @@ use widget::Widget;
|
||||
|
||||
use crate::app::browser::action::Action as BrowserAction;
|
||||
use crate::app::browser::window::action::Action as WindowAction;
|
||||
use adw::TabView;
|
||||
use gtk::{
|
||||
glib::{GString, Propagation},
|
||||
prelude::WidgetExt,
|
||||
@ -22,22 +19,16 @@ use std::{cell::RefCell, collections::HashMap, rc::Rc};
|
||||
|
||||
// Main
|
||||
pub struct Tab {
|
||||
// Actions
|
||||
browser_action: Rc<BrowserAction>,
|
||||
window_action: Rc<WindowAction>,
|
||||
// Dynamically allocated reference index
|
||||
index: Rc<RefCell<HashMap<GString, Rc<Item>>>>,
|
||||
action: Rc<Action>,
|
||||
widget: Rc<Widget>,
|
||||
}
|
||||
|
||||
impl Tab {
|
||||
// Construct
|
||||
pub fn new(browser_action: Rc<BrowserAction>, window_action: Rc<WindowAction>) -> Self {
|
||||
// Init local actions
|
||||
let action = Rc::new(Action::new());
|
||||
|
||||
// Init empty HashMap index as no tabs appended yet
|
||||
// Init empty HashMap index
|
||||
let index: Rc<RefCell<HashMap<GString, Rc<Item>>>> = Rc::new(RefCell::new(HashMap::new()));
|
||||
|
||||
// Init context menu
|
||||
@ -98,29 +89,11 @@ impl Tab {
|
||||
}
|
||||
});
|
||||
|
||||
action.open().connect_activate({
|
||||
let index = index.clone();
|
||||
let widget = widget.clone();
|
||||
move |request| {
|
||||
if let Some(value) = request {
|
||||
if let Some(page) = widget.page(None) {
|
||||
if let Some(id) = page.keyword() {
|
||||
if let Some(item) = index.borrow().get(&id) {
|
||||
item.set_page_navigation_request_text(value.as_str());
|
||||
item.page().reload();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}); // @TODO fix new item on middle click
|
||||
|
||||
// Return activated `Self`
|
||||
Self {
|
||||
browser_action,
|
||||
window_action,
|
||||
index,
|
||||
action,
|
||||
widget,
|
||||
}
|
||||
}
|
||||
@ -128,19 +101,20 @@ impl Tab {
|
||||
// Actions
|
||||
pub fn append(&self, position: Option<i32>) -> Rc<Item> {
|
||||
// Init new tab item
|
||||
let item = Item::new_rc(
|
||||
self.gobject(),
|
||||
let item = Rc::new(Item::new(
|
||||
self.widget.gobject(),
|
||||
self.browser_action.clone(),
|
||||
self.window_action.clone(),
|
||||
self.action.clone(),
|
||||
// Options
|
||||
position,
|
||||
false,
|
||||
true,
|
||||
);
|
||||
));
|
||||
|
||||
// Register dynamically created tab components in the HashMap index
|
||||
self.index.borrow_mut().insert(item.id(), item.clone());
|
||||
self.index
|
||||
.borrow_mut()
|
||||
.insert(item.id().clone(), item.clone());
|
||||
|
||||
item.page()
|
||||
.navigation()
|
||||
@ -220,8 +194,10 @@ impl Tab {
|
||||
item.update();
|
||||
|
||||
// Update tab title on loading indicator inactive
|
||||
if !item.page_is_loading() {
|
||||
item.gobject().set_title(item.page_meta_title().as_str())
|
||||
if !item.page().is_loading() {
|
||||
item.widget()
|
||||
.gobject()
|
||||
.set_title(item.page().meta().title().as_str())
|
||||
}
|
||||
}
|
||||
// Update all tabs on ID not found @TODO change initial update method
|
||||
@ -231,8 +207,10 @@ impl Tab {
|
||||
item.update();
|
||||
|
||||
// Update tab title on loading indicator inactive
|
||||
if !item.page_is_loading() {
|
||||
item.gobject().set_title(item.page_meta_title().as_str())
|
||||
if !item.page().is_loading() {
|
||||
item.widget()
|
||||
.gobject()
|
||||
.set_title(item.page().meta().title().as_str())
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -273,17 +251,18 @@ impl Tab {
|
||||
Ok(records) => {
|
||||
for record in records {
|
||||
match Item::restore(
|
||||
self.gobject(),
|
||||
self.widget.gobject(),
|
||||
transaction,
|
||||
&record.id,
|
||||
self.browser_action.clone(),
|
||||
self.window_action.clone(),
|
||||
self.action.clone(),
|
||||
) {
|
||||
Ok(items) => {
|
||||
for item in items {
|
||||
// Register dynamically created tab item in the HashMap index
|
||||
self.index.borrow_mut().insert(item.id(), item.clone());
|
||||
self.index
|
||||
.borrow_mut()
|
||||
.insert(item.id().clone(), item.clone());
|
||||
}
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
@ -311,9 +290,9 @@ impl Tab {
|
||||
item.save(
|
||||
transaction,
|
||||
&id,
|
||||
&self.widget.gobject().page_position(item.gobject()),
|
||||
&item.gobject().is_pinned(),
|
||||
&item.gobject().is_selected(),
|
||||
&self.widget.gobject().page_position(item.widget().gobject()),
|
||||
&item.widget().gobject().is_pinned(),
|
||||
&item.widget().gobject().is_selected(),
|
||||
)?;
|
||||
}
|
||||
}
|
||||
@ -334,12 +313,8 @@ impl Tab {
|
||||
|
||||
// Getters
|
||||
|
||||
pub fn action(&self) -> &Rc<Action> {
|
||||
&self.action
|
||||
}
|
||||
|
||||
pub fn gobject(&self) -> &TabView {
|
||||
self.widget.gobject()
|
||||
pub fn widget(&self) -> &Rc<Widget> {
|
||||
&self.widget
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,15 +1,15 @@
|
||||
mod action;
|
||||
mod database;
|
||||
mod page;
|
||||
mod widget;
|
||||
|
||||
use action::Action;
|
||||
use database::Database;
|
||||
use page::Page;
|
||||
use widget::Widget;
|
||||
|
||||
use crate::app::browser::action::Action as BrowserAction;
|
||||
use crate::app::browser::window::action::Action as WindowAction;
|
||||
use crate::app::browser::window::tab::action::Action as TabAction;
|
||||
use adw::{TabPage, TabView};
|
||||
use crate::app::browser::{window::Action as WindowAction, Action as BrowserAction};
|
||||
use adw::TabView;
|
||||
use gtk::{
|
||||
glib::{uuid_string_random, GString},
|
||||
prelude::EditableExt,
|
||||
@ -22,47 +22,70 @@ pub struct Item {
|
||||
// useful as widget name in GTK actions callback
|
||||
id: GString,
|
||||
// Components
|
||||
action: Rc<Action>,
|
||||
page: Rc<Page>,
|
||||
widget: Rc<Widget>,
|
||||
}
|
||||
|
||||
impl Item {
|
||||
// Construct
|
||||
pub fn new_rc(
|
||||
pub fn new(
|
||||
tab_view: &TabView,
|
||||
// Actions
|
||||
browser_action: Rc<BrowserAction>,
|
||||
window_action: Rc<WindowAction>,
|
||||
tab_action: Rc<TabAction>,
|
||||
// Options
|
||||
position: Option<i32>,
|
||||
is_pinned: bool,
|
||||
is_selected: bool,
|
||||
) -> Rc<Self> {
|
||||
) -> Self {
|
||||
// Generate unique ID for new page components
|
||||
let id = uuid_string_random();
|
||||
|
||||
// Init components
|
||||
let page = Page::new_rc(
|
||||
|
||||
let action = Rc::new(Action::new());
|
||||
|
||||
let page = Rc::new(Page::new(
|
||||
id.clone(),
|
||||
// Actions
|
||||
browser_action,
|
||||
window_action,
|
||||
tab_action,
|
||||
);
|
||||
action.clone(),
|
||||
));
|
||||
|
||||
let widget = Rc::new(Widget::new(
|
||||
id.as_str(),
|
||||
tab_view,
|
||||
page.gobject(),
|
||||
page.widget().gobject(),
|
||||
None,
|
||||
position,
|
||||
is_pinned,
|
||||
is_selected,
|
||||
)); // @TODO
|
||||
));
|
||||
|
||||
// Return struct
|
||||
Rc::new(Self { id, page, widget })
|
||||
// Init events
|
||||
|
||||
action.load().connect_activate({
|
||||
let page = page.clone();
|
||||
move |request| {
|
||||
if let Some(text) = request {
|
||||
page.navigation()
|
||||
.request()
|
||||
.widget()
|
||||
.gobject()
|
||||
.set_text(&text);
|
||||
}
|
||||
page.load(true);
|
||||
}
|
||||
});
|
||||
|
||||
// Done
|
||||
Self {
|
||||
id,
|
||||
action,
|
||||
page,
|
||||
widget,
|
||||
}
|
||||
}
|
||||
|
||||
// Actions
|
||||
@ -71,7 +94,7 @@ impl Item {
|
||||
self.page.update();
|
||||
|
||||
// Update tab loading indicator
|
||||
self.widget.gobject().set_loading(self.page_is_loading());
|
||||
self.widget.gobject().set_loading(self.page().is_loading());
|
||||
}
|
||||
|
||||
pub fn clean(
|
||||
@ -107,7 +130,6 @@ impl Item {
|
||||
// Actions
|
||||
browser_action: Rc<BrowserAction>,
|
||||
window_action: Rc<WindowAction>,
|
||||
tab_action: Rc<TabAction>,
|
||||
) -> Result<Vec<Rc<Item>>, String> {
|
||||
let mut items = Vec::new();
|
||||
|
||||
@ -115,17 +137,16 @@ impl Item {
|
||||
Ok(records) => {
|
||||
for record in records {
|
||||
// Construct new item object
|
||||
let item = Item::new_rc(
|
||||
let item = Rc::new(Item::new(
|
||||
tab_view,
|
||||
// Actions
|
||||
browser_action.clone(),
|
||||
window_action.clone(),
|
||||
tab_action.clone(),
|
||||
// Options
|
||||
None,
|
||||
record.is_pinned,
|
||||
record.is_selected,
|
||||
);
|
||||
));
|
||||
|
||||
// Delegate restore action to the item childs
|
||||
item.page.restore(transaction, &record.id)?;
|
||||
@ -169,36 +190,18 @@ impl Item {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Setters
|
||||
pub fn set_page_navigation_request_text(&self, value: &str) {
|
||||
self.page
|
||||
.navigation()
|
||||
.request()
|
||||
.widget()
|
||||
.gobject()
|
||||
.set_text(value);
|
||||
}
|
||||
|
||||
// Getters
|
||||
|
||||
pub fn id(&self) -> GString {
|
||||
self.id.clone()
|
||||
pub fn id(&self) -> &GString {
|
||||
&self.id
|
||||
}
|
||||
|
||||
pub fn page(&self) -> &Rc<Page> {
|
||||
&self.page
|
||||
}
|
||||
|
||||
pub fn page_is_loading(&self) -> bool {
|
||||
self.page.is_loading()
|
||||
}
|
||||
|
||||
pub fn page_meta_title(&self) -> GString {
|
||||
self.page.meta_title()
|
||||
}
|
||||
|
||||
pub fn gobject(&self) -> &TabPage {
|
||||
self.widget.gobject()
|
||||
pub fn widget(&self) -> &Rc<Widget> {
|
||||
&self.widget
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
mod open;
|
||||
|
||||
use open::Open;
|
||||
mod load;
|
||||
use load::Load;
|
||||
|
||||
use gtk::{
|
||||
gio::SimpleActionGroup,
|
||||
@ -12,7 +11,7 @@ use std::rc::Rc;
|
||||
/// [SimpleActionGroup](https://docs.gtk.org/gio/class.SimpleActionGroup.html) wrapper for `Browser` actions
|
||||
pub struct Action {
|
||||
// Actions
|
||||
open: Rc<Open>,
|
||||
load: Rc<Load>,
|
||||
// Group
|
||||
id: GString,
|
||||
gobject: SimpleActionGroup,
|
||||
@ -24,7 +23,7 @@ impl Action {
|
||||
/// Create new `Self`
|
||||
pub fn new() -> Self {
|
||||
// Init actions
|
||||
let open = Rc::new(Open::new());
|
||||
let load = Rc::new(Load::new());
|
||||
|
||||
// Generate unique group ID
|
||||
let id = uuid_string_random();
|
||||
@ -33,17 +32,17 @@ impl Action {
|
||||
let gobject = SimpleActionGroup::new();
|
||||
|
||||
// Add action to given group
|
||||
gobject.add_action(open.gobject());
|
||||
gobject.add_action(load.gobject());
|
||||
|
||||
// Done
|
||||
Self { open, id, gobject }
|
||||
Self { load, id, gobject }
|
||||
}
|
||||
|
||||
// Getters
|
||||
|
||||
/// Get reference `Open` action
|
||||
pub fn open(&self) -> &Rc<Open> {
|
||||
&self.open
|
||||
/// Get reference to `Load` action
|
||||
pub fn load(&self) -> &Rc<Load> {
|
||||
&self.load
|
||||
}
|
||||
|
||||
/// Get auto-generated name for action group
|
@ -4,12 +4,12 @@ use gtk::{
|
||||
prelude::{ActionExt, StaticVariantType, ToVariant},
|
||||
};
|
||||
|
||||
/// [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) wrapper for `Open` action of `Browser` group
|
||||
pub struct Open {
|
||||
/// [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) wrapper for `Load` action of `Item` group
|
||||
pub struct Load {
|
||||
gobject: SimpleAction,
|
||||
}
|
||||
|
||||
impl Open {
|
||||
impl Load {
|
||||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
@ -23,9 +23,9 @@ impl Open {
|
||||
|
||||
/// Emit [activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal
|
||||
/// with formatted for this action [Variant](https://docs.gtk.org/glib/struct.Variant.html) value
|
||||
pub fn activate(&self, tab_item_id: Option<&str>) {
|
||||
pub fn activate(&self, request: Option<&str>) {
|
||||
self.gobject.activate(Some(
|
||||
&match tab_item_id {
|
||||
&match request {
|
||||
Some(value) => String::from(value),
|
||||
None => String::new(),
|
||||
}
|
||||
@ -39,14 +39,14 @@ impl Open {
|
||||
/// [SimpleAction::activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal
|
||||
pub fn connect_activate(&self, callback: impl Fn(Option<GString>) + 'static) {
|
||||
self.gobject.connect_activate(move |_, variant| {
|
||||
let tab_item_id = variant
|
||||
.expect("Variant required to call this action")
|
||||
let request = variant
|
||||
.expect("Parameter value required")
|
||||
.get::<String>()
|
||||
.expect("Parameter type does not match `String`");
|
||||
|
||||
callback(match tab_item_id.is_empty() {
|
||||
callback(match request.is_empty() {
|
||||
true => None,
|
||||
false => Some(tab_item_id.into()),
|
||||
false => Some(request.into()),
|
||||
})
|
||||
});
|
||||
}
|
||||
@ -57,10 +57,4 @@ impl Open {
|
||||
pub fn gobject(&self) -> &SimpleAction {
|
||||
&self.gobject
|
||||
}
|
||||
|
||||
/* @TODO not in use
|
||||
/// Get auto-generated [action name](https://docs.gtk.org/gio/property.SimpleAction.name.html)
|
||||
pub fn id(&self) -> GString {
|
||||
self.gobject.name()
|
||||
} */
|
||||
}
|
@ -12,24 +12,18 @@ use meta::{Meta, Status};
|
||||
use navigation::Navigation;
|
||||
use widget::Widget;
|
||||
|
||||
use crate::app::browser::action::Action as BrowserAction;
|
||||
use crate::app::browser::window::action::Action as WindowAction;
|
||||
use crate::app::browser::window::tab::action::Action as TabAction;
|
||||
use crate::app::browser::{
|
||||
window::{tab::item::Action as TabAction, Action as WindowAction},
|
||||
Action as BrowserAction,
|
||||
};
|
||||
use gtk::{
|
||||
gdk_pixbuf::Pixbuf,
|
||||
gio::{
|
||||
Cancellable, SimpleAction, SocketClient, SocketClientEvent, SocketProtocol,
|
||||
TlsCertificateFlags,
|
||||
},
|
||||
gio::{Cancellable, SocketClient, SocketClientEvent, SocketProtocol, TlsCertificateFlags},
|
||||
glib::{
|
||||
gformat, uuid_string_random, Bytes, GString, Priority, Regex, RegexCompileFlags,
|
||||
RegexMatchFlags, Uri, UriFlags, UriHideFlags,
|
||||
gformat, Bytes, GString, Priority, Regex, RegexCompileFlags, RegexMatchFlags, Uri,
|
||||
UriFlags, UriHideFlags,
|
||||
},
|
||||
prelude::{
|
||||
ActionExt, CancellableExt, EditableExt, IOStreamExt, OutputStreamExt, SocketClientExt,
|
||||
StaticVariantType,
|
||||
},
|
||||
Box,
|
||||
prelude::{CancellableExt, EditableExt, IOStreamExt, OutputStreamExt, SocketClientExt},
|
||||
};
|
||||
use sqlite::Transaction;
|
||||
use std::{cell::RefCell, rc::Rc, time::Duration};
|
||||
@ -39,47 +33,38 @@ pub struct Page {
|
||||
cancellable: RefCell<Cancellable>,
|
||||
// Actions
|
||||
browser_action: Rc<BrowserAction>,
|
||||
window_action: Rc<WindowAction>,
|
||||
tab_action: Rc<TabAction>,
|
||||
action_page_load: SimpleAction,
|
||||
// Components
|
||||
navigation: Rc<Navigation>,
|
||||
content: Rc<Content>,
|
||||
input: Rc<Input>,
|
||||
// Extras
|
||||
meta: Rc<Meta>,
|
||||
// GTK
|
||||
widget: Rc<Widget>,
|
||||
}
|
||||
|
||||
impl Page {
|
||||
// Constructors
|
||||
|
||||
/// Create new activated `Rc<Self>`
|
||||
pub fn new_rc(
|
||||
pub fn new(
|
||||
id: GString,
|
||||
browser_action: Rc<BrowserAction>,
|
||||
window_action: Rc<WindowAction>,
|
||||
tab_action: Rc<TabAction>,
|
||||
) -> Rc<Self> {
|
||||
// Init local actions
|
||||
let action_page_load = SimpleAction::new(&uuid_string_random(), None);
|
||||
let action_page_open =
|
||||
SimpleAction::new(&uuid_string_random(), Some(&String::static_variant_type()));
|
||||
|
||||
) -> Self {
|
||||
// Init components
|
||||
let content = Rc::new(Content::new(tab_action.clone(), action_page_open.clone()));
|
||||
let content = Rc::new(Content::new(window_action.clone(), tab_action.clone()));
|
||||
|
||||
let navigation = Rc::new(Navigation::new(
|
||||
browser_action.clone(),
|
||||
window_action.clone(),
|
||||
action_page_open.clone(),
|
||||
tab_action.clone(),
|
||||
));
|
||||
|
||||
let input = Rc::new(Input::new());
|
||||
|
||||
let widget = Rc::new(Widget::new(
|
||||
&id,
|
||||
action_page_open.clone(),
|
||||
navigation.widget().gobject(),
|
||||
content.gobject(),
|
||||
input.gobject(),
|
||||
@ -87,48 +72,21 @@ impl Page {
|
||||
|
||||
let meta = Rc::new(Meta::new(Status::New, gformat!("New page")));
|
||||
|
||||
// Init `Self`
|
||||
let this = Rc::new(Self {
|
||||
// Done
|
||||
Self {
|
||||
cancellable: RefCell::new(Cancellable::new()),
|
||||
id,
|
||||
// Actions
|
||||
browser_action,
|
||||
window_action,
|
||||
tab_action,
|
||||
action_page_load: action_page_load.clone(),
|
||||
// Components
|
||||
content,
|
||||
navigation,
|
||||
input,
|
||||
// Extras
|
||||
meta,
|
||||
// GTK
|
||||
widget,
|
||||
});
|
||||
|
||||
// Init events
|
||||
action_page_load.connect_activate({
|
||||
let this = this.clone();
|
||||
move |_, _| this.load(false)
|
||||
});
|
||||
|
||||
action_page_open.connect_activate({
|
||||
let this = this.clone();
|
||||
move |_, request| {
|
||||
// Set request value from action parameter
|
||||
this.navigation().request().widget().gobject().set_text(
|
||||
&request
|
||||
.expect("Parameter required for this action")
|
||||
.get::<String>()
|
||||
.expect("Parameter does not match `String`"),
|
||||
);
|
||||
|
||||
// Reload page
|
||||
this.load(true);
|
||||
}
|
||||
});
|
||||
|
||||
// Return activated `Self`
|
||||
this
|
||||
}
|
||||
}
|
||||
|
||||
// Actions
|
||||
@ -138,7 +96,7 @@ impl Page {
|
||||
pub fn home(&self) {
|
||||
if let Some(url) = self.navigation.home().url() {
|
||||
// Update with history record
|
||||
self.tab_action.open().activate(Some(&url));
|
||||
self.tab_action.load().activate(Some(&url));
|
||||
}
|
||||
}
|
||||
|
||||
@ -432,21 +390,16 @@ impl Page {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn meta_title(&self) -> GString {
|
||||
self.meta.title()
|
||||
}
|
||||
|
||||
/*
|
||||
pub fn meta(&self) -> &Rc<Meta> {
|
||||
&self.meta
|
||||
} */
|
||||
}
|
||||
|
||||
pub fn navigation(&self) -> &Rc<Navigation> {
|
||||
&self.navigation
|
||||
}
|
||||
|
||||
pub fn gobject(&self) -> &Box {
|
||||
self.widget.gobject()
|
||||
pub fn widget(&self) -> &Rc<Widget> {
|
||||
&self.widget
|
||||
}
|
||||
|
||||
// Private helpers @TODO move outside
|
||||
@ -457,7 +410,6 @@ impl Page {
|
||||
// Init shared objects (async)
|
||||
let cancellable = self.cancellable.borrow().clone();
|
||||
let update = self.browser_action.update().clone();
|
||||
let action_page_load = self.action_page_load.clone();
|
||||
let tab_action = self.tab_action.clone();
|
||||
let content = self.content.clone();
|
||||
let id = self.id.clone();
|
||||
@ -799,7 +751,7 @@ impl Page {
|
||||
.set_title("Redirect");
|
||||
|
||||
// Reload page to apply redirection
|
||||
action_page_load.activate(None);
|
||||
tab_action.load().activate(None);
|
||||
}
|
||||
},
|
||||
Err(reason) => {
|
||||
|
@ -6,10 +6,9 @@ use image::Image;
|
||||
use status::Status;
|
||||
use text::Text;
|
||||
|
||||
use crate::app::browser::window::tab::action::Action as TabAction;
|
||||
use crate::app::browser::window::{tab::item::Action as TabAction, Action as WindowAction};
|
||||
use gtk::{
|
||||
gdk_pixbuf::Pixbuf,
|
||||
gio::SimpleAction,
|
||||
glib::Uri,
|
||||
prelude::{BoxExt, WidgetExt},
|
||||
Box, Orientation,
|
||||
@ -17,22 +16,20 @@ use gtk::{
|
||||
use std::{rc::Rc, time::Duration};
|
||||
|
||||
pub struct Content {
|
||||
// GTK
|
||||
gobject: Box,
|
||||
// Actions
|
||||
window_action: Rc<WindowAction>,
|
||||
tab_action: Rc<TabAction>,
|
||||
action_page_open: SimpleAction,
|
||||
gobject: Box,
|
||||
}
|
||||
|
||||
impl Content {
|
||||
// Construct
|
||||
|
||||
/// Create new container for different components
|
||||
pub fn new(tab_action: Rc<TabAction>, action_page_open: SimpleAction) -> Self {
|
||||
pub fn new(window_action: Rc<WindowAction>, tab_action: Rc<TabAction>) -> Self {
|
||||
Self {
|
||||
gobject: Box::builder().orientation(Orientation::Vertical).build(),
|
||||
window_action,
|
||||
tab_action,
|
||||
action_page_open,
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,8 +85,8 @@ impl Content {
|
||||
let text = Text::gemini(
|
||||
data,
|
||||
base,
|
||||
self.window_action.clone(),
|
||||
self.tab_action.clone(),
|
||||
self.action_page_open.clone(),
|
||||
);
|
||||
self.gobject.append(text.gobject());
|
||||
text
|
||||
|
@ -2,9 +2,8 @@ mod gemini;
|
||||
|
||||
use gemini::Gemini;
|
||||
|
||||
use crate::app::browser::window::tab::action::Action as TabAction;
|
||||
use crate::app::browser::window::{tab::item::Action as TabAction, Action as WindowAction};
|
||||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
glib::{GString, Uri},
|
||||
ScrolledWindow,
|
||||
};
|
||||
@ -24,11 +23,11 @@ impl Text {
|
||||
pub fn gemini(
|
||||
gemtext: &str,
|
||||
base: &Uri,
|
||||
window_action: Rc<WindowAction>,
|
||||
tab_action: Rc<TabAction>,
|
||||
action_page_open: SimpleAction,
|
||||
) -> Self {
|
||||
// Init components
|
||||
let gemini = Gemini::new(gemtext, base, tab_action, action_page_open);
|
||||
let gemini = Gemini::new(gemtext, base, window_action, tab_action);
|
||||
|
||||
// Init meta
|
||||
let meta = Meta {
|
||||
|
@ -4,12 +4,9 @@ mod widget;
|
||||
use reader::Reader;
|
||||
use widget::Widget;
|
||||
|
||||
use crate::app::browser::window::tab::action::Action as TabAction;
|
||||
use crate::app::browser::window::{tab::item::Action as TabAction, Action as WindowAction};
|
||||
use adw::ClampScrollable;
|
||||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
glib::{GString, Uri},
|
||||
};
|
||||
use gtk::glib::{GString, Uri};
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct Gemini {
|
||||
@ -22,11 +19,11 @@ impl Gemini {
|
||||
pub fn new(
|
||||
gemtext: &str,
|
||||
base: &Uri,
|
||||
window_action: Rc<WindowAction>,
|
||||
tab_action: Rc<TabAction>,
|
||||
action_page_open: SimpleAction,
|
||||
) -> Self {
|
||||
// Init components
|
||||
let reader = Rc::new(Reader::new(gemtext, base, tab_action, action_page_open));
|
||||
let reader = Rc::new(Reader::new(gemtext, base, window_action, tab_action));
|
||||
let widget = Rc::new(Widget::new(reader.gobject()));
|
||||
|
||||
// Result
|
||||
|
@ -4,7 +4,7 @@ mod widget;
|
||||
use tag::Tag;
|
||||
use widget::Widget;
|
||||
|
||||
use crate::app::browser::window::tab::action::Action as TabAction;
|
||||
use crate::app::browser::window::{tab::item::Action as TabAction, Action as WindowAction};
|
||||
use adw::StyleManager;
|
||||
use gemtext::line::{
|
||||
code::Code,
|
||||
@ -15,9 +15,9 @@ use gemtext::line::{
|
||||
};
|
||||
use gtk::{
|
||||
gdk::{BUTTON_MIDDLE, BUTTON_PRIMARY},
|
||||
gio::{Cancellable, SimpleAction},
|
||||
gio::Cancellable,
|
||||
glib::{GString, TimeZone, Uri},
|
||||
prelude::{ActionExt, TextBufferExt, TextBufferExtManual, TextViewExt, ToVariant, WidgetExt},
|
||||
prelude::{TextBufferExt, TextBufferExtManual, TextViewExt, WidgetExt},
|
||||
EventControllerMotion, GestureClick, TextBuffer, TextTag, TextView, TextWindowType,
|
||||
UriLauncher, Window, WrapMode,
|
||||
};
|
||||
@ -33,8 +33,8 @@ impl Reader {
|
||||
pub fn new(
|
||||
gemtext: &str,
|
||||
base: &Uri,
|
||||
window_action: Rc<WindowAction>,
|
||||
tab_action: Rc<TabAction>,
|
||||
action_page_open: SimpleAction,
|
||||
) -> Self {
|
||||
// Init default values
|
||||
let mut title = None;
|
||||
@ -232,7 +232,7 @@ impl Reader {
|
||||
|
||||
// Init events
|
||||
primary_button_controller.connect_released({
|
||||
let action_page_open = action_page_open.clone();
|
||||
let tab_action = tab_action.clone();
|
||||
let gobject = widget.gobject().clone();
|
||||
let _links_ = links.clone(); // is copy
|
||||
move |_, _, window_x, window_y| {
|
||||
@ -251,7 +251,7 @@ impl Reader {
|
||||
return match uri.scheme().as_str() {
|
||||
"gemini" => {
|
||||
// Open new page in browser
|
||||
action_page_open.activate(Some(&uri.to_str().to_variant()));
|
||||
tab_action.load().activate(Some(&uri.to_str()));
|
||||
}
|
||||
// Scheme not supported, delegate
|
||||
_ => UriLauncher::new(&uri.to_str()).launch(
|
||||
@ -259,8 +259,7 @@ impl Reader {
|
||||
None::<&Cancellable>,
|
||||
|result| {
|
||||
if let Err(error) = result {
|
||||
// @TODO
|
||||
println!("Could not delegate launch action: {error}")
|
||||
println!("{error}")
|
||||
}
|
||||
},
|
||||
),
|
||||
@ -289,7 +288,7 @@ impl Reader {
|
||||
return match uri.scheme().as_str() {
|
||||
"gemini" => {
|
||||
// Open new page in browser
|
||||
tab_action.open().activate(Some(&uri.to_string()));
|
||||
window_action.append().activate();
|
||||
}
|
||||
// Scheme not supported, delegate
|
||||
_ => UriLauncher::new(&uri.to_str()).launch(
|
||||
@ -297,8 +296,7 @@ impl Reader {
|
||||
None::<&Cancellable>,
|
||||
|result| {
|
||||
if let Err(error) = result {
|
||||
// @TODO
|
||||
println!("Could not delegate launch action: {error}")
|
||||
println!("{error}")
|
||||
}
|
||||
},
|
||||
),
|
||||
|
@ -6,7 +6,7 @@ use response::Response;
|
||||
use sensitive::Sensitive;
|
||||
use widget::Widget;
|
||||
|
||||
use crate::app::browser::window::tab::action::Action as TabAction;
|
||||
use crate::app::browser::window::tab::item::Action as TabAction;
|
||||
use adw::Clamp;
|
||||
use gtk::glib::Uri;
|
||||
use std::rc::Rc;
|
||||
|
@ -8,7 +8,7 @@ use form::Form;
|
||||
use title::Title;
|
||||
use widget::Widget;
|
||||
|
||||
use crate::app::browser::window::tab::action::Action as TabAction;
|
||||
use crate::app::browser::window::tab::item::action::Action as TabAction;
|
||||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
glib::{uuid_string_random, Uri, UriHideFlags},
|
||||
@ -63,7 +63,7 @@ impl Response {
|
||||
action_send.connect_activate({
|
||||
let form = form.clone();
|
||||
move |_, _| {
|
||||
tab_action.open().activate(Some(&format!(
|
||||
tab_action.load().activate(Some(&format!(
|
||||
"{}?{}",
|
||||
base.to_string_partial(UriHideFlags::QUERY),
|
||||
Uri::escape_string(form.text().as_str(), None, false),
|
||||
|
@ -4,7 +4,7 @@ mod widget;
|
||||
use form::Form;
|
||||
use widget::Widget;
|
||||
|
||||
use crate::app::browser::window::tab::action::Action as TabAction;
|
||||
use crate::app::browser::window::tab::item::action::Action as TabAction;
|
||||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
glib::{uuid_string_random, Uri, UriHideFlags},
|
||||
@ -44,7 +44,7 @@ impl Sensitive {
|
||||
action_send.connect_activate({
|
||||
let form = form.clone();
|
||||
move |_, _| {
|
||||
tab_action.open().activate(Some(&format!(
|
||||
tab_action.load().activate(Some(&format!(
|
||||
"{}?{}",
|
||||
base.to_string_partial(UriHideFlags::QUERY),
|
||||
Uri::escape_string(form.text().as_str(), None, false),
|
||||
|
@ -14,9 +14,10 @@ use reload::Reload;
|
||||
use request::Request;
|
||||
use widget::Widget;
|
||||
|
||||
use crate::app::browser::action::Action as BrowserAction;
|
||||
use crate::app::browser::window::action::Action as WindowAction;
|
||||
use gtk::{gio::SimpleAction, prelude::EditableExt};
|
||||
use crate::app::browser::window::tab::item::Action as TabAction;
|
||||
use crate::app::browser::window::Action as WindowAction;
|
||||
use crate::app::browser::Action as BrowserAction;
|
||||
use gtk::prelude::EditableExt;
|
||||
use sqlite::Transaction;
|
||||
use std::rc::Rc;
|
||||
|
||||
@ -33,22 +34,22 @@ impl Navigation {
|
||||
pub fn new(
|
||||
browser_action: Rc<BrowserAction>,
|
||||
window_action: Rc<WindowAction>,
|
||||
action_page_open: SimpleAction,
|
||||
tab_action: Rc<TabAction>,
|
||||
) -> Self {
|
||||
// Init components
|
||||
let home = Rc::new(Home::new(window_action.clone()));
|
||||
let history = Rc::new(History::new(window_action.clone()));
|
||||
let reload = Rc::new(Reload::new(window_action));
|
||||
let request = Rc::new(Request::new(browser_action, action_page_open.clone()));
|
||||
let request = Rc::new(Request::new(browser_action, tab_action));
|
||||
let bookmark = Rc::new(Bookmark::new());
|
||||
|
||||
// Init widget
|
||||
let widget = Rc::new(Widget::new(
|
||||
home.gobject(),
|
||||
history.gobject(),
|
||||
reload.gobject(),
|
||||
home.widget().gobject(),
|
||||
history.widget().gobject(),
|
||||
reload.widget().gobject(),
|
||||
request.widget().gobject(),
|
||||
bookmark.gobject(),
|
||||
bookmark.widget().gobject(),
|
||||
));
|
||||
|
||||
// Done
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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> {
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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({
|
||||
|
@ -1,7 +1,5 @@
|
||||
use gtk::{
|
||||
gio::{SimpleAction, SimpleActionGroup},
|
||||
glib::uuid_string_random,
|
||||
prelude::{ActionMapExt, BoxExt, IsA, WidgetExt},
|
||||
prelude::{BoxExt, IsA},
|
||||
Box, Orientation,
|
||||
};
|
||||
|
||||
@ -13,17 +11,11 @@ impl Widget {
|
||||
// Construct
|
||||
pub fn new(
|
||||
name: &str,
|
||||
// Actions
|
||||
action_page_open: SimpleAction,
|
||||
// Components
|
||||
navigation: &impl IsA<gtk::Widget>,
|
||||
content: &impl IsA<gtk::Widget>,
|
||||
input: &impl IsA<gtk::Widget>,
|
||||
) -> Self {
|
||||
// Init additional action group
|
||||
let action_group = SimpleActionGroup::new();
|
||||
action_group.add_action(&action_page_open);
|
||||
|
||||
// Init self
|
||||
let gobject = Box::builder()
|
||||
.orientation(Orientation::Vertical)
|
||||
@ -34,8 +26,6 @@ impl Widget {
|
||||
gobject.append(content);
|
||||
gobject.append(input);
|
||||
|
||||
gobject.insert_action_group(&uuid_string_random(), Some(&action_group));
|
||||
|
||||
Self { gobject }
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user