remove extra action with its event listener loop

This commit is contained in:
yggverse 2025-03-18 17:40:43 +02:00
parent e0e21b4926
commit c092c5244c
3 changed files with 16 additions and 39 deletions

View File

@ -9,9 +9,8 @@ use title::Title;
use super::ItemAction; use super::ItemAction;
use gtk::{ use gtk::{
Box, Label, Orientation, TextView, Box, Label, Orientation, TextView,
gio::SimpleAction, glib::{Uri, UriHideFlags},
glib::{Uri, UriHideFlags, uuid_string_random}, prelude::{BoxExt, ButtonExt, DisplayExt, TextBufferExt, TextViewExt, WidgetExt},
prelude::{ActionExt, BoxExt, DisplayExt, TextBufferExt, TextViewExt, WidgetExt},
}; };
use std::rc::Rc; use std::rc::Rc;
@ -37,11 +36,8 @@ impl Response for Box {
title: Option<&str>, title: Option<&str>,
size_limit: Option<usize>, size_limit: Option<usize>,
) -> Self { ) -> Self {
// Init local actions
let action_send = SimpleAction::new(&uuid_string_random(), None);
// Init components // Init components
let control = Rc::new(Control::build(action_send.clone())); let control = Rc::new(Control::build());
let text_view = TextView::form(); let text_view = TextView::form();
let title = Label::title(title); 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(); let text_view = text_view.clone();
move |_, _| { move |this| {
this.set_sensitive(false);
this.set_label("sending..");
item_action.load.activate( item_action.load.activate(
Some(&format!( Some(&format!(
"{}?{}", "{}?{}",
@ -93,17 +91,13 @@ impl Response for Box {
text_view.add_controller({ text_view.add_controller({
const SHORTCUT: &str = "<Primary>Return"; // @TODO optional const SHORTCUT: &str = "<Primary>Return"; // @TODO optional
/*control
.send
.set_tooltip_text(Some(&format!("Shortcut: {SHORTCUT}")));*/
let c = gtk::ShortcutController::new(); let c = gtk::ShortcutController::new();
c.add_shortcut( c.add_shortcut(
gtk::Shortcut::builder() gtk::Shortcut::builder()
.trigger(&gtk::ShortcutTrigger::parse_string(SHORTCUT).unwrap()) .trigger(&gtk::ShortcutTrigger::parse_string(SHORTCUT).unwrap())
.action(&gtk::CallbackAction::new(move |_, _| { .action(&gtk::CallbackAction::new(move |_, _| {
if control.send.is_sensitive() { if control.send.is_sensitive() {
action_send.activate(None); control.send.emit_activate();
} else { } else {
control.send.display().beep(); control.send.display().beep();
} }

View File

@ -2,7 +2,7 @@ mod counter;
mod send; mod send;
use counter::Counter; 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; use send::Send;
const SPACING: i32 = 8; const SPACING: i32 = 8;
@ -17,10 +17,10 @@ impl Control {
// Constructors // Constructors
/// Build new `Self` /// Build new `Self`
pub fn build(action_send: SimpleAction) -> Self { pub fn build() -> Self {
// Init components // Init components
let counter = Label::counter(); let counter = Label::counter();
let send = Button::send(action_send); let send = Button::send();
// Init main widget // Init main widget
let g_box = Box::builder() let g_box = Box::builder()

View File

@ -1,11 +1,7 @@
use gtk::{ use gtk::{Button, prelude::WidgetExt};
Button,
gio::SimpleAction,
prelude::{ActionExt, ButtonExt, WidgetExt},
};
pub trait Send { pub trait Send {
fn send(action_send: SimpleAction) -> Self; fn send() -> Self;
fn update(&self, is_sensitive: bool); fn update(&self, is_sensitive: bool);
} }
@ -13,25 +9,12 @@ impl Send for Button {
// Constructors // Constructors
/// Build new `Self` /// Build new `Self`
fn send(action_send: SimpleAction) -> Self { fn send() -> Self {
// Init main widget Button::builder()
let button = Button::builder()
.css_classes(["accent"]) // | `suggested-action` .css_classes(["accent"]) // | `suggested-action`
.label("Send") .label("Send")
.sensitive(false) .sensitive(false)
.build(); .build()
// Init events
button.connect_clicked({
move |this| {
this.set_sensitive(false);
this.set_label("sending..");
action_send.activate(None);
}
});
// Return activated `Self`
button
} }
// Actions // Actions