From 4b357f822921d6a91eeae5e7e9a1cd922127ed14 Mon Sep 17 00:00:00 2001 From: yggverse Date: Mon, 16 Dec 2024 16:49:19 +0200 Subject: [PATCH] close search on escape action --- src/app/browser/window/tab/item/page.rs | 6 +++++- .../browser/window/tab/item/page/content.rs | 18 +++++++++++++----- .../window/tab/item/page/content/text.rs | 17 ++++++++++++++--- .../tab/item/page/content/text/gemini.rs | 10 ++++++++-- 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index f0aafe6f..8a5e1496 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -61,7 +61,11 @@ impl Page { ), ) -> Self { // Init components - let content = Rc::new(Content::new((window_action.clone(), tab_action.clone()))); + let content = Rc::new(Content::new(( + browser_action.clone(), + window_action.clone(), + tab_action.clone(), + ))); let navigation = Rc::new(Navigation::new( profile.clone(), diff --git a/src/app/browser/window/tab/item/page/content.rs b/src/app/browser/window/tab/item/page/content.rs index b232210a..cfc6c228 100644 --- a/src/app/browser/window/tab/item/page/content.rs +++ b/src/app/browser/window/tab/item/page/content.rs @@ -5,7 +5,7 @@ mod text; use image::Image; use text::Text; -use super::{TabAction, WindowAction}; +use super::{BrowserAction, TabAction, WindowAction}; use adw::StatusPage; use gtk::{ gdk::Paintable, @@ -17,6 +17,7 @@ use gtk::{ use std::{rc::Rc, time::Duration}; pub struct Content { + browser_action: Rc, window_action: Rc, tab_action: Rc, pub g_box: Box, @@ -26,11 +27,18 @@ impl Content { // Construct /// Create new container for different components - pub fn new(action: (Rc, Rc)) -> Self { + pub fn new( + (browser_action, window_action, tab_action): ( + Rc, + Rc, + Rc, + ), + ) -> Self { Self { g_box: Box::builder().orientation(Orientation::Vertical).build(), - window_action: action.0, - tab_action: action.1, + browser_action, + window_action, + tab_action, } } @@ -125,7 +133,7 @@ impl Content { let text = Text::new_gemini( data, base, - (self.window_action.clone(), self.tab_action.clone()), + (&self.browser_action, &self.window_action, &self.tab_action), ); self.g_box.append(&text.g_box); text diff --git a/src/app/browser/window/tab/item/page/content/text.rs b/src/app/browser/window/tab/item/page/content/text.rs index ee32c4c8..6fe923b2 100644 --- a/src/app/browser/window/tab/item/page/content/text.rs +++ b/src/app/browser/window/tab/item/page/content/text.rs @@ -6,7 +6,7 @@ use gemini::Gemini; use search::Search; use source::Source; -use super::{TabAction, WindowAction}; +use super::{BrowserAction, TabAction, WindowAction}; use adw::Clamp; use gtk::{ glib::Uri, @@ -31,10 +31,14 @@ impl Text { pub fn new_gemini( gemtext: &str, base: &Uri, - (window_action, tab_action): (Rc, Rc), + (browser_action, window_action, tab_action): ( + &Rc, + &Rc, + &Rc, + ), ) -> Self { // Init components - let gemini = Gemini::new(gemtext, base, (window_action.clone(), tab_action)); + let gemini = Gemini::new(gemtext, base, (window_action, tab_action)); let search = Rc::new(Search::new(&gemini.reader.buffer)); // Init main widget @@ -55,6 +59,13 @@ impl Text { ); // Connect events + browser_action.escape.connect_activate({ + let close = search.close.clone(); + move || { + close.activate(); + } + }); + window_action.find.connect_activate({ let search = search.clone(); move |_| { diff --git a/src/app/browser/window/tab/item/page/content/text/gemini.rs b/src/app/browser/window/tab/item/page/content/text/gemini.rs index 4e4fd594..62ca88fe 100644 --- a/src/app/browser/window/tab/item/page/content/text/gemini.rs +++ b/src/app/browser/window/tab/item/page/content/text/gemini.rs @@ -15,9 +15,15 @@ pub struct Gemini { impl Gemini { // Construct - pub fn new(gemtext: &str, base: &Uri, actions: (Rc, Rc)) -> Self { + pub fn new( + gemtext: &str, + base: &Uri, + (window_action, tab_action): (&Rc, &Rc), + ) -> Self { // Init components - let reader = Rc::new(Reader::new(gemtext, base, actions).unwrap()); // @TODO handle errors + let reader = Rc::new( + Reader::new(gemtext, base, (window_action.clone(), tab_action.clone())).unwrap(), + ); // @TODO handle errors let widget = Rc::new(Widget::new(&reader.widget.text_view)); // Result