mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 09:35:28 +00:00
implement resend form ability on request failure
This commit is contained in:
parent
c4e8f2ff61
commit
afc33c1a03
8 changed files with 406 additions and 445 deletions
|
|
@ -2,16 +2,17 @@ mod counter;
|
|||
mod send;
|
||||
|
||||
use counter::Counter;
|
||||
use gtk::gio::SimpleAction;
|
||||
use gtk::{prelude::BoxExt, Align, Box, Orientation};
|
||||
use send::Send;
|
||||
use std::rc::Rc;
|
||||
use gtk::{
|
||||
prelude::{BoxExt, WidgetExt},
|
||||
Align, Box, Button, Label, Orientation,
|
||||
};
|
||||
pub use send::Send;
|
||||
|
||||
const SPACING: i32 = 8;
|
||||
|
||||
pub struct Control {
|
||||
pub counter: Rc<Counter>,
|
||||
pub send: Rc<Send>,
|
||||
pub counter: Label,
|
||||
pub send: Button,
|
||||
pub g_box: Box,
|
||||
}
|
||||
|
||||
|
|
@ -19,10 +20,10 @@ impl Control {
|
|||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
pub fn build(action_send: SimpleAction) -> Self {
|
||||
pub fn build() -> Self {
|
||||
// Init components
|
||||
let counter = Rc::new(Counter::new());
|
||||
let send = Rc::new(Send::build(action_send));
|
||||
let counter = Label::counter();
|
||||
let send = Button::send();
|
||||
|
||||
// Init main widget
|
||||
let g_box = Box::builder()
|
||||
|
|
@ -31,8 +32,8 @@ impl Control {
|
|||
.spacing(SPACING)
|
||||
.build();
|
||||
|
||||
g_box.append(&counter.label);
|
||||
g_box.append(&send.button);
|
||||
g_box.append(&counter);
|
||||
g_box.append(&send);
|
||||
|
||||
// Return activated struct
|
||||
Self {
|
||||
|
|
@ -43,10 +44,10 @@ impl Control {
|
|||
}
|
||||
|
||||
// Actions
|
||||
pub fn update(&self, bytes_total: Option<usize>) {
|
||||
pub fn update(&self, char_count: Option<i32>) {
|
||||
// Update children components
|
||||
self.counter.update(bytes_total);
|
||||
self.send.update(match bytes_total {
|
||||
self.counter.update(char_count);
|
||||
self.send.set_sensitive(match char_count {
|
||||
Some(total) => total > 0,
|
||||
None => false,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,31 +1,26 @@
|
|||
use gtk::{prelude::WidgetExt, Label};
|
||||
|
||||
pub struct Counter {
|
||||
pub label: Label,
|
||||
pub trait Counter {
|
||||
fn counter() -> Self;
|
||||
fn update(&self, char_count: Option<i32>);
|
||||
}
|
||||
|
||||
impl Default for Counter {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
impl Counter for Label {
|
||||
// Constructors
|
||||
|
||||
impl Counter {
|
||||
// Construct
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
label: Label::builder().css_classes(["dim-label"]).build(), // @TODO use `dimmed` in Adw 1.6,
|
||||
}
|
||||
fn counter() -> Self {
|
||||
Label::builder().css_classes(["dim-label"]).build() // @TODO use `dimmed` in Adw 1.6,
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn update(&self, bytes_total: Option<usize>) {
|
||||
match bytes_total {
|
||||
|
||||
fn update(&self, char_count: Option<i32>) {
|
||||
match char_count {
|
||||
Some(value) => {
|
||||
self.label.set_label(&value.to_string());
|
||||
self.label.set_visible(value > 0);
|
||||
self.set_label(&value.to_string());
|
||||
self.set_visible(value > 0);
|
||||
}
|
||||
None => self.label.set_visible(false),
|
||||
None => self.set_visible(false),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,40 +1,28 @@
|
|||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
prelude::{ActionExt, ButtonExt, WidgetExt},
|
||||
prelude::{ButtonExt, WidgetExt},
|
||||
Button,
|
||||
};
|
||||
|
||||
pub struct Send {
|
||||
pub button: Button,
|
||||
pub trait Send {
|
||||
fn send() -> Self;
|
||||
fn set_sending(&self);
|
||||
fn set_resend(&self);
|
||||
}
|
||||
|
||||
impl Send {
|
||||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
pub fn build(action_send: SimpleAction) -> Self {
|
||||
// Init main widget
|
||||
let button = Button::builder()
|
||||
impl Send for Button {
|
||||
fn send() -> Self {
|
||||
Button::builder()
|
||||
.css_classes(["accent"]) // | `suggested-action`
|
||||
.label("Send")
|
||||
.sensitive(false)
|
||||
.build();
|
||||
|
||||
// Init events
|
||||
button.connect_clicked({
|
||||
move |this| {
|
||||
this.set_sensitive(false);
|
||||
this.set_label("sending..");
|
||||
action_send.activate(None);
|
||||
}
|
||||
});
|
||||
|
||||
// Return activated `Self`
|
||||
Self { button }
|
||||
.build()
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn update(&self, is_sensitive: bool) {
|
||||
self.button.set_sensitive(is_sensitive);
|
||||
fn set_sending(&self) {
|
||||
self.set_sensitive(false);
|
||||
self.set_label("sending..");
|
||||
}
|
||||
fn set_resend(&self) {
|
||||
self.set_sensitive(true);
|
||||
self.set_label("Resend");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
glib::GString,
|
||||
prelude::{ActionExt, TextBufferExt, TextViewExt, WidgetExt},
|
||||
prelude::{TextBufferExt, TextViewExt, WidgetExt},
|
||||
TextView, WrapMode,
|
||||
};
|
||||
use libspelling::{Checker, TextBufferAdapter};
|
||||
|
|
@ -9,15 +8,16 @@ use sourceview::Buffer;
|
|||
|
||||
const MARGIN: i32 = 8;
|
||||
|
||||
pub struct Form {
|
||||
pub text_view: TextView,
|
||||
pub trait Form {
|
||||
fn form() -> Self;
|
||||
fn text(&self) -> GString;
|
||||
}
|
||||
|
||||
impl Form {
|
||||
impl Form for TextView {
|
||||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
pub fn build(action_update: SimpleAction) -> Self {
|
||||
fn form() -> Self {
|
||||
// Init [SourceView](https://gitlab.gnome.org/GNOME/gtksourceview) type buffer
|
||||
let buffer = Buffer::builder().build();
|
||||
|
||||
|
|
@ -43,22 +43,18 @@ impl Form {
|
|||
text_view.set_size_request(-1, 38); // @TODO [#635](https://gitlab.gnome.org/GNOME/pygobject/-/issues/635)
|
||||
|
||||
// Init events
|
||||
text_view.buffer().connect_changed(move |_| {
|
||||
action_update.activate(None);
|
||||
});
|
||||
|
||||
text_view.connect_realize(|this| {
|
||||
this.grab_focus();
|
||||
});
|
||||
|
||||
// Return activated `Self`
|
||||
Self { text_view }
|
||||
text_view
|
||||
}
|
||||
|
||||
// Getters
|
||||
|
||||
pub fn text(&self) -> GString {
|
||||
let buffer = self.text_view.buffer();
|
||||
fn text(&self) -> GString {
|
||||
let buffer = self.buffer();
|
||||
buffer.text(&buffer.start_iter(), &buffer.end_iter(), true)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,15 @@
|
|||
use gtk::{Align, Label};
|
||||
|
||||
pub struct Title {
|
||||
pub label: Label,
|
||||
pub trait Title {
|
||||
fn title(title: Option<&str>) -> Self;
|
||||
}
|
||||
|
||||
impl Title {
|
||||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
pub fn build(title: Option<&str>) -> Self {
|
||||
Self {
|
||||
label: Label::builder()
|
||||
.css_classes(["heading"])
|
||||
.halign(Align::Start)
|
||||
.label(title.unwrap_or("Titan input"))
|
||||
.build(),
|
||||
}
|
||||
impl Title for Label {
|
||||
fn title(title: Option<&str>) -> Self {
|
||||
Label::builder()
|
||||
.css_classes(["heading"])
|
||||
.halign(Align::Start)
|
||||
.label(title.unwrap_or("Titan input"))
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue