implement response send

This commit is contained in:
yggverse 2024-10-16 18:37:01 +03:00
parent 5d63f49987
commit 2f423c5d7e
6 changed files with 59 additions and 17 deletions

View file

@ -11,7 +11,7 @@ use widget::Widget;
use gtk::{
gio::SimpleAction,
glib::{uuid_string_random, Uri, UriHideFlags},
prelude::WidgetExt,
prelude::{ActionExt, ToVariant, WidgetExt},
Box,
};
use std::sync::Arc;
@ -23,12 +23,18 @@ pub struct Default {
impl Default {
// Construct
pub fn new_arc(base: Uri, title: Option<&str>, size_limit: Option<usize>) -> Arc<Self> {
// Init local action
pub fn new_arc(
action_page_open: Arc<SimpleAction>,
base: Uri,
title: Option<&str>,
size_limit: Option<usize>,
) -> Arc<Self> {
// Init local actions
let action_update = Arc::new(SimpleAction::new(&uuid_string_random(), None));
let action_send = Arc::new(SimpleAction::new(&uuid_string_random(), None));
// Init components
let control = Control::new_arc();
let control = Control::new_arc(action_send.clone());
let response = Response::new_arc(action_update.clone());
let title = Title::new_arc(title);
@ -37,6 +43,7 @@ impl Default {
// Init events
action_update.connect_activate({
let base = base.clone();
let control = control.clone();
let response = response.clone();
move |_, _| {
@ -52,6 +59,20 @@ impl Default {
}
});
action_send.connect_activate({
let response = response.clone();
move |_, _| {
action_page_open.activate(Some(
&format!(
"{}?{}",
base.to_string_partial(UriHideFlags::QUERY),
Uri::escape_string(response.text().as_str(), None, false),
)
.to_variant(),
));
}
});
widget.gobject().connect_realize(move |_| response.focus());
// Return activated struct