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