From c092c5244c4d80ffef0c7b03d185e5621cc3344e Mon Sep 17 00:00:00 2001 From: yggverse Date: Tue, 18 Mar 2025 17:40:43 +0200 Subject: [PATCH] remove extra action with its event listener loop --- .../window/tab/item/page/input/response.rs | 22 ++++++--------- .../tab/item/page/input/response/control.rs | 6 ++--- .../item/page/input/response/control/send.rs | 27 ++++--------------- 3 files changed, 16 insertions(+), 39 deletions(-) diff --git a/src/app/browser/window/tab/item/page/input/response.rs b/src/app/browser/window/tab/item/page/input/response.rs index da154ae6..95903e0c 100644 --- a/src/app/browser/window/tab/item/page/input/response.rs +++ b/src/app/browser/window/tab/item/page/input/response.rs @@ -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, ) -> 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 = "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(); } diff --git a/src/app/browser/window/tab/item/page/input/response/control.rs b/src/app/browser/window/tab/item/page/input/response/control.rs index 2251339d..62e0392d 100644 --- a/src/app/browser/window/tab/item/page/input/response/control.rs +++ b/src/app/browser/window/tab/item/page/input/response/control.rs @@ -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() diff --git a/src/app/browser/window/tab/item/page/input/response/control/send.rs b/src/app/browser/window/tab/item/page/input/response/control/send.rs index 432ed0c1..a7e416fe 100644 --- a/src/app/browser/window/tab/item/page/input/response/control/send.rs +++ b/src/app/browser/window/tab/item/page/input/response/control/send.rs @@ -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