mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-03-13 06:01:21 +00:00
draft page open action
This commit is contained in:
parent
fa95f7ffdd
commit
8bff9ce719
@ -5,8 +5,8 @@ use parser::link::Link;
|
||||
use parser::plain::Plain;
|
||||
|
||||
use gtk::{
|
||||
glib::{GString, Uri},
|
||||
prelude::{StyleContextExt, WidgetExt},
|
||||
glib::{GString, Propagation, Uri},
|
||||
prelude::{StyleContextExt, ToVariant, WidgetExt},
|
||||
Align, CssProvider, Label, STYLE_PROVIDER_PRIORITY_APPLICATION,
|
||||
};
|
||||
|
||||
@ -76,6 +76,12 @@ impl Reader {
|
||||
.style_context()
|
||||
.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
|
||||
Self { title, css, widget }
|
||||
}
|
||||
|
@ -7,11 +7,14 @@ use meta::{Meta, Mime};
|
||||
use navigation::Navigation;
|
||||
|
||||
use gtk::{
|
||||
gio::{Cancellable, SocketClient, SocketProtocol, TlsCertificateFlags},
|
||||
gio::{
|
||||
ActionEntry, Cancellable, SimpleActionGroup, SocketClient, SocketProtocol,
|
||||
TlsCertificateFlags,
|
||||
},
|
||||
glib::{gformat, GString, Priority, Regex, RegexCompileFlags, RegexMatchFlags, Uri, UriFlags},
|
||||
prelude::{
|
||||
BoxExt, IOStreamExt, InputStreamExtManual, OutputStreamExtManual, SocketClientExt,
|
||||
WidgetExt,
|
||||
ActionMapExtManual, BoxExt, IOStreamExt, InputStreamExtManual, OutputStreamExtManual,
|
||||
SocketClientExt, StaticVariantType, WidgetExt,
|
||||
},
|
||||
Box, Orientation,
|
||||
};
|
||||
@ -43,6 +46,30 @@ impl Page {
|
||||
widget.append(navigation.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
|
||||
let meta = Arc::new(RefCell::new(Meta::new()));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user