mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-02-05 07:54:14 +00:00
implement response send
This commit is contained in:
parent
5d63f49987
commit
2f423c5d7e
@ -167,6 +167,7 @@ impl Page {
|
||||
let content = self.content.clone();
|
||||
let input = self.input.clone();
|
||||
let meta = self.meta.clone();
|
||||
let action_page_open = self.action_page_open.clone();
|
||||
let action_update = self.action_update.clone();
|
||||
|
||||
// Update
|
||||
@ -280,7 +281,7 @@ impl Page {
|
||||
let description = gformat!("{placeholder}");
|
||||
|
||||
// Make input form
|
||||
input.set_default(uri, Some(&description), Some(1024));
|
||||
input.set_default(action_page_open, uri, Some(&description), Some(1024));
|
||||
|
||||
// Update meta
|
||||
meta.borrow_mut().status = Some(status);
|
||||
|
@ -2,7 +2,7 @@ mod default;
|
||||
mod widget;
|
||||
|
||||
use default::Default;
|
||||
use gtk::glib::Uri;
|
||||
use gtk::{gio::SimpleAction, glib::Uri};
|
||||
use widget::Widget;
|
||||
|
||||
use adw::Clamp;
|
||||
@ -23,9 +23,16 @@ impl Input {
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn set_default(&self, base: Uri, title: Option<&str>, size_limit: Option<usize>) {
|
||||
self.widget
|
||||
.update(Some(&Default::new_arc(base, title, size_limit).gobject()));
|
||||
pub fn set_default(
|
||||
&self,
|
||||
action_page_open: Arc<SimpleAction>,
|
||||
base: Uri,
|
||||
title: Option<&str>,
|
||||
size_limit: Option<usize>,
|
||||
) {
|
||||
self.widget.update(Some(
|
||||
&Default::new_arc(action_page_open, base, title, size_limit).gobject(),
|
||||
));
|
||||
}
|
||||
|
||||
// Getters
|
||||
|
@ -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
|
||||
|
@ -6,7 +6,7 @@ use left::Left;
|
||||
use send::Send;
|
||||
use widget::Widget;
|
||||
|
||||
use gtk::Box;
|
||||
use gtk::{gio::SimpleAction, Box};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct Control {
|
||||
@ -17,10 +17,10 @@ pub struct Control {
|
||||
|
||||
impl Control {
|
||||
// Construct
|
||||
pub fn new_arc() -> Arc<Self> {
|
||||
pub fn new_arc(action_send: Arc<SimpleAction>) -> Arc<Self> {
|
||||
// Init components
|
||||
let left = Left::new_arc();
|
||||
let send = Send::new_arc();
|
||||
let send = Send::new_arc(action_send);
|
||||
|
||||
// Init widget
|
||||
let widget = Widget::new_arc(left.gobject(), send.gobject());
|
||||
|
@ -2,7 +2,7 @@ mod widget;
|
||||
|
||||
use widget::Widget;
|
||||
|
||||
use gtk::Button;
|
||||
use gtk::{gio::SimpleAction, Button};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct Send {
|
||||
@ -11,9 +11,9 @@ pub struct Send {
|
||||
|
||||
impl Send {
|
||||
// Construct
|
||||
pub fn new_arc() -> Arc<Self> {
|
||||
pub fn new_arc(action_send: Arc<SimpleAction>) -> Arc<Self> {
|
||||
// Init widget
|
||||
let widget = Widget::new_arc();
|
||||
let widget = Widget::new_arc(action_send);
|
||||
|
||||
// Result
|
||||
Arc::new(Self { widget })
|
||||
|
@ -1,4 +1,8 @@
|
||||
use gtk::{prelude::WidgetExt, Button};
|
||||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
prelude::{ActionExt, ButtonExt, WidgetExt},
|
||||
Button,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct Widget {
|
||||
@ -7,12 +11,21 @@ pub struct Widget {
|
||||
|
||||
impl Widget {
|
||||
// Construct
|
||||
pub fn new_arc() -> Arc<Self> {
|
||||
pub fn new_arc(action_send: Arc<SimpleAction>) -> Arc<Self> {
|
||||
// Init gobject
|
||||
let gobject = Button::builder()
|
||||
//.css_classes(["accent"])
|
||||
.label("Send")
|
||||
.build();
|
||||
|
||||
// Init events
|
||||
gobject.connect_clicked({
|
||||
move |_| {
|
||||
action_send.activate(None);
|
||||
}
|
||||
});
|
||||
|
||||
// Return activated struct
|
||||
Arc::new(Self { gobject })
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user