mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-09-10 22:11:52 +00:00
remove extra action with its event listener loop
This commit is contained in:
parent
e0e21b4926
commit
c092c5244c
@ -9,9 +9,8 @@ use title::Title;
|
||||
use super::ItemAction;
|
||||
use gtk::{
|
||||
Box, Label, Orientation, TextView,
|
||||
gio::SimpleAction,
|
||||
glib::{Uri, UriHideFlags, uuid_string_random},
|
||||
prelude::{ActionExt, BoxExt, DisplayExt, TextBufferExt, TextViewExt, WidgetExt},
|
||||
glib::{Uri, UriHideFlags},
|
||||
prelude::{BoxExt, ButtonExt, DisplayExt, TextBufferExt, TextViewExt, WidgetExt},
|
||||
};
|
||||
use std::rc::Rc;
|
||||
|
||||
@ -37,11 +36,8 @@ impl Response for Box {
|
||||
title: Option<&str>,
|
||||
size_limit: Option<usize>,
|
||||
) -> Self {
|
||||
// Init local actions
|
||||
let action_send = SimpleAction::new(&uuid_string_random(), None);
|
||||
|
||||
// Init components
|
||||
let control = Rc::new(Control::build(action_send.clone()));
|
||||
let control = Rc::new(Control::build());
|
||||
let text_view = TextView::form();
|
||||
let title = Label::title(title);
|
||||
|
||||
@ -77,9 +73,11 @@ impl Response for Box {
|
||||
}
|
||||
});
|
||||
|
||||
action_send.connect_activate({
|
||||
control.send.connect_clicked({
|
||||
let text_view = text_view.clone();
|
||||
move |_, _| {
|
||||
move |this| {
|
||||
this.set_sensitive(false);
|
||||
this.set_label("sending..");
|
||||
item_action.load.activate(
|
||||
Some(&format!(
|
||||
"{}?{}",
|
||||
@ -93,17 +91,13 @@ impl Response for Box {
|
||||
|
||||
text_view.add_controller({
|
||||
const SHORTCUT: &str = "<Primary>Return"; // @TODO optional
|
||||
|
||||
/*control
|
||||
.send
|
||||
.set_tooltip_text(Some(&format!("Shortcut: {SHORTCUT}")));*/
|
||||
let c = gtk::ShortcutController::new();
|
||||
c.add_shortcut(
|
||||
gtk::Shortcut::builder()
|
||||
.trigger(>k::ShortcutTrigger::parse_string(SHORTCUT).unwrap())
|
||||
.action(>k::CallbackAction::new(move |_, _| {
|
||||
if control.send.is_sensitive() {
|
||||
action_send.activate(None);
|
||||
control.send.emit_activate();
|
||||
} else {
|
||||
control.send.display().beep();
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ mod counter;
|
||||
mod send;
|
||||
|
||||
use counter::Counter;
|
||||
use gtk::{Align, Box, Button, Label, Orientation, gio::SimpleAction, prelude::BoxExt};
|
||||
use gtk::{Align, Box, Button, Label, Orientation, prelude::BoxExt};
|
||||
use send::Send;
|
||||
|
||||
const SPACING: i32 = 8;
|
||||
@ -17,10 +17,10 @@ impl Control {
|
||||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
pub fn build(action_send: SimpleAction) -> Self {
|
||||
pub fn build() -> Self {
|
||||
// Init components
|
||||
let counter = Label::counter();
|
||||
let send = Button::send(action_send);
|
||||
let send = Button::send();
|
||||
|
||||
// Init main widget
|
||||
let g_box = Box::builder()
|
||||
|
@ -1,11 +1,7 @@
|
||||
use gtk::{
|
||||
Button,
|
||||
gio::SimpleAction,
|
||||
prelude::{ActionExt, ButtonExt, WidgetExt},
|
||||
};
|
||||
use gtk::{Button, prelude::WidgetExt};
|
||||
|
||||
pub trait Send {
|
||||
fn send(action_send: SimpleAction) -> Self;
|
||||
fn send() -> Self;
|
||||
fn update(&self, is_sensitive: bool);
|
||||
}
|
||||
|
||||
@ -13,25 +9,12 @@ impl Send for Button {
|
||||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
fn send(action_send: SimpleAction) -> Self {
|
||||
// Init main widget
|
||||
let button = Button::builder()
|
||||
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`
|
||||
button
|
||||
.build()
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
Loading…
x
Reference in New Issue
Block a user