From ff2073d302a036a07e8b2f4a7102548bedf0b72a Mon Sep 17 00:00:00 2001 From: yggverse Date: Sat, 28 Sep 2024 02:06:04 +0300 Subject: [PATCH] integrate simple action object --- src/browser/header/tray.rs | 3 ++- src/browser/header/tray/tab.rs | 27 ++++++++++++++++++--------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/browser/header/tray.rs b/src/browser/header/tray.rs index ab5dd564..e2f1e7b0 100644 --- a/src/browser/header/tray.rs +++ b/src/browser/header/tray.rs @@ -31,7 +31,8 @@ impl Tray { action_tab_page_reload, action_tab_pin, ); - let tab = Tab::new(); + + let tab = Tab::new(action_tab_append); // Init widget let widget = Box::builder() diff --git a/src/browser/header/tray/tab.rs b/src/browser/header/tray/tab.rs index 787c58fe..22f07221 100644 --- a/src/browser/header/tray/tab.rs +++ b/src/browser/header/tray/tab.rs @@ -1,4 +1,4 @@ -use gtk::Button; +use gtk::{gio::SimpleAction, prelude::ActionExt, prelude::ButtonExt, Button}; pub struct Tab { pub widget: Button, @@ -6,14 +6,23 @@ pub struct Tab { impl Tab { // Construct - pub fn new() -> Self { - Self { - widget: Button::builder() - .action_name("win.tab_append") - .icon_name("tab-new-symbolic") - .tooltip_text("New tab") - .build(), - } + pub fn new(action_tab_append: &SimpleAction) -> Self { + // Init widget + let widget = Button::builder() + .icon_name("tab-new-symbolic") + .tooltip_text("New tab") + .build(); + + // Init events + widget.connect_clicked({ + let action_tab_append = action_tab_append.clone(); + move |_| { + action_tab_append.activate(None); + } + }); + + // Return activated struct + Self { widget } } // Getters