draft page open action

This commit is contained in:
yggverse 2024-09-27 04:07:43 +03:00
parent fa95f7ffdd
commit 8bff9ce719
2 changed files with 38 additions and 5 deletions

View file

@ -5,8 +5,8 @@ use parser::link::Link;
use parser::plain::Plain; use parser::plain::Plain;
use gtk::{ use gtk::{
glib::{GString, Uri}, glib::{GString, Propagation, Uri},
prelude::{StyleContextExt, WidgetExt}, prelude::{StyleContextExt, ToVariant, WidgetExt},
Align, CssProvider, Label, STYLE_PROVIDER_PRIORITY_APPLICATION, Align, CssProvider, Label, STYLE_PROVIDER_PRIORITY_APPLICATION,
}; };
@ -76,6 +76,12 @@ impl Reader {
.style_context() .style_context()
.add_provider(&css, STYLE_PROVIDER_PRIORITY_APPLICATION); .add_provider(&css, STYLE_PROVIDER_PRIORITY_APPLICATION);
// Connect actions @TODO move actions init outside
widget.connect_activate_link(|label, uri| {
let _ = label.activate_action("page.open", Some(&uri.to_variant()));
Propagation::Stop // |Proceed @TODO parse external scheme
});
// Result // Result
Self { title, css, widget } Self { title, css, widget }
} }

View file

@ -7,11 +7,14 @@ use meta::{Meta, Mime};
use navigation::Navigation; use navigation::Navigation;
use gtk::{ use gtk::{
gio::{Cancellable, SocketClient, SocketProtocol, TlsCertificateFlags}, gio::{
ActionEntry, Cancellable, SimpleActionGroup, SocketClient, SocketProtocol,
TlsCertificateFlags,
},
glib::{gformat, GString, Priority, Regex, RegexCompileFlags, RegexMatchFlags, Uri, UriFlags}, glib::{gformat, GString, Priority, Regex, RegexCompileFlags, RegexMatchFlags, Uri, UriFlags},
prelude::{ prelude::{
BoxExt, IOStreamExt, InputStreamExtManual, OutputStreamExtManual, SocketClientExt, ActionMapExtManual, BoxExt, IOStreamExt, InputStreamExtManual, OutputStreamExtManual,
WidgetExt, SocketClientExt, StaticVariantType, WidgetExt,
}, },
Box, Orientation, Box, Orientation,
}; };
@ -43,6 +46,30 @@ impl Page {
widget.append(navigation.widget()); widget.append(navigation.widget());
widget.append(content.widget()); widget.append(content.widget());
// Init actions @TODO move actions init outside
let action_open = ActionEntry::builder("open")
.parameter_type(Some(&String::static_variant_type()))
.activate({
let navigation = navigation.clone();
move |_, _, request| {
let uri = request
.expect("Parameter required for `page.open` action")
.get::<String>()
.expect("Parameter does not match `String`");
navigation.set_request_text(
&GString::from(uri),
true, // activate (page reload)
);
}
})
.build();
// Init action group
let actions = SimpleActionGroup::new();
actions.add_action_entries([action_open]);
widget.insert_action_group("page", Some(&actions));
// Init async mutable Meta object // Init async mutable Meta object
let meta = Arc::new(RefCell::new(Meta::new())); let meta = Arc::new(RefCell::new(Meta::new()));