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 3c0d2348..bf483d4b 100644 --- a/src/app/browser/window/tab/item/page/content/text.rs +++ b/src/app/browser/window/tab/item/page/content/text.rs @@ -1,11 +1,17 @@ mod gemini; +mod search; mod source; use gemini::Gemini; +use search::Search; use source::Source; -use crate::app::browser::window::{tab::item::Action as TabAction, Action as WindowAction}; -use gtk::{glib::Uri, prelude::BoxExt, Box, Orientation, ScrolledWindow}; +use super::{TabAction, WindowAction}; +use gtk::{ + glib::Uri, + prelude::{BoxExt, ButtonExt, TextViewExt,WidgetExt}, + Box, Orientation, ScrolledWindow, +}; use std::rc::Rc; pub struct Meta { @@ -23,10 +29,11 @@ impl Text { pub fn new_gemini( gemtext: &str, base: &Uri, - actions: (Rc, Rc), + (window_action, tab_action): (Rc, Rc), ) -> Self { // Init components - let gemini = Gemini::new(gemtext, base, actions); + let gemini = Gemini::new(gemtext, base, (window_action.clone(), tab_action)); + let search = Rc::new(Search::new(&gemini.reader.buffer)); // Init main widget let g_box = Box::builder().orientation(Orientation::Vertical).build(); @@ -36,6 +43,43 @@ impl Text { .build(), ); + // Connect events + window_action.find.connect_activate({ + let search = search.clone(); + let text_view = gemini.reader.widget.text_view.clone(); + move |_| { + // @TODO show + search.input.entry.grab_focus(); + } + }); + + search.navigation.back.button.connect_clicked({ + let text_view = gemini.reader.widget.text_view.clone(); + let navigation = search.navigation.clone(); + move |_| { + if let Some((mut start, _)) = navigation.back() { + text_view.scroll_to_iter(&mut start, 0.0, false, 0.0, 0.0); + } + } + }); + + search.navigation.forward.button.connect_clicked({ + let text_view = gemini.reader.widget.text_view.clone(); + let navigation = search.navigation.clone(); + move |_| { + if let Some((mut start, _)) = navigation.forward() { + text_view.scroll_to_iter(&mut start, 0.0, false, 0.0, 0.0); + } + } + }); + + search.close.connect_clicked({ + let text_view = gemini.reader.widget.text_view.clone(); + move |_| { + // @TODO hide + } + }); + Self { meta: Meta { title: gemini.reader.title.clone(), diff --git a/src/app/browser/window/tab/item/page/content/text/gemini/reader/widget.rs b/src/app/browser/window/tab/item/page/content/text/gemini/reader/widget.rs index 80a9bf60..ae9c5574 100644 --- a/src/app/browser/window/tab/item/page/content/text/gemini/reader/widget.rs +++ b/src/app/browser/window/tab/item/page/content/text/gemini/reader/widget.rs @@ -1,12 +1,8 @@ -mod find; use std::rc::Rc; -use find::Find; - use super::WindowAction; use gtk::{ - prelude::{ButtonExt, TextViewExt, WidgetExt}, - EventControllerMotion, GestureClick, TextBuffer, TextView, TextWindowType, WrapMode, + prelude::WidgetExt, EventControllerMotion, GestureClick, TextBuffer, TextView, WrapMode, }; const MARGIN: i32 = 8; @@ -26,9 +22,6 @@ impl Widget { middle_button_controller: &GestureClick, motion_controller: &EventControllerMotion, ) -> Self { - // Init components - let find = Rc::new(Find::new(buffer)); - // Init main widget let text_view = TextView::builder() .bottom_margin(MARGIN) @@ -46,41 +39,6 @@ impl Widget { text_view.add_controller(middle_button_controller.clone()); text_view.add_controller(motion_controller.clone()); - // Connect events - action.find.connect_activate({ - let find = find.clone(); - let text_view = text_view.clone(); - move |_| { - text_view.set_gutter(TextWindowType::Bottom, Some(&find.g_box)); - find.input.entry.grab_focus(); - } - }); - - find.navigation.back.button.connect_clicked({ - let text_view = text_view.clone(); - let navigation = find.navigation.clone(); - move |_| { - if let Some((mut start, _)) = navigation.back() { - text_view.scroll_to_iter(&mut start, 0.0, false, 0.0, 0.0); - } - } - }); - - find.navigation.forward.button.connect_clicked({ - let text_view = text_view.clone(); - let navigation = find.navigation.clone(); - move |_| { - if let Some((mut start, _)) = navigation.forward() { - text_view.scroll_to_iter(&mut start, 0.0, false, 0.0, 0.0); - } - } - }); - - find.close.connect_clicked({ - let text_view = text_view.clone(); - move |_| text_view.set_gutter(TextWindowType::Bottom, gtk::Widget::NONE) - }); - // Done Self { text_view } } diff --git a/src/app/browser/window/tab/item/page/content/text/gemini/reader/widget/find.rs b/src/app/browser/window/tab/item/page/content/text/search.rs similarity index 98% rename from src/app/browser/window/tab/item/page/content/text/gemini/reader/widget/find.rs rename to src/app/browser/window/tab/item/page/content/text/search.rs index 5798b26f..bf939779 100644 --- a/src/app/browser/window/tab/item/page/content/text/gemini/reader/widget/find.rs +++ b/src/app/browser/window/tab/item/page/content/text/search.rs @@ -14,14 +14,14 @@ use gtk::{ }; use std::rc::Rc; -pub struct Find { +pub struct Search { pub close: Button, pub g_box: Box, pub input: Rc, pub navigation: Rc, } -impl Find { +impl Search { // Construct pub fn new(text_buffer: &TextBuffer) -> Self { // Init components diff --git a/src/app/browser/window/tab/item/page/content/text/gemini/reader/widget/find/close.rs b/src/app/browser/window/tab/item/page/content/text/search/close.rs similarity index 100% rename from src/app/browser/window/tab/item/page/content/text/gemini/reader/widget/find/close.rs rename to src/app/browser/window/tab/item/page/content/text/search/close.rs diff --git a/src/app/browser/window/tab/item/page/content/text/gemini/reader/widget/find/input.rs b/src/app/browser/window/tab/item/page/content/text/search/input.rs similarity index 100% rename from src/app/browser/window/tab/item/page/content/text/gemini/reader/widget/find/input.rs rename to src/app/browser/window/tab/item/page/content/text/search/input.rs diff --git a/src/app/browser/window/tab/item/page/content/text/gemini/reader/widget/find/match_case.rs b/src/app/browser/window/tab/item/page/content/text/search/match_case.rs similarity index 100% rename from src/app/browser/window/tab/item/page/content/text/gemini/reader/widget/find/match_case.rs rename to src/app/browser/window/tab/item/page/content/text/search/match_case.rs diff --git a/src/app/browser/window/tab/item/page/content/text/gemini/reader/widget/find/navigation.rs b/src/app/browser/window/tab/item/page/content/text/search/navigation.rs similarity index 100% rename from src/app/browser/window/tab/item/page/content/text/gemini/reader/widget/find/navigation.rs rename to src/app/browser/window/tab/item/page/content/text/search/navigation.rs diff --git a/src/app/browser/window/tab/item/page/content/text/gemini/reader/widget/find/navigation/back.rs b/src/app/browser/window/tab/item/page/content/text/search/navigation/back.rs similarity index 100% rename from src/app/browser/window/tab/item/page/content/text/gemini/reader/widget/find/navigation/back.rs rename to src/app/browser/window/tab/item/page/content/text/search/navigation/back.rs diff --git a/src/app/browser/window/tab/item/page/content/text/gemini/reader/widget/find/navigation/forward.rs b/src/app/browser/window/tab/item/page/content/text/search/navigation/forward.rs similarity index 100% rename from src/app/browser/window/tab/item/page/content/text/gemini/reader/widget/find/navigation/forward.rs rename to src/app/browser/window/tab/item/page/content/text/search/navigation/forward.rs diff --git a/src/app/browser/window/tab/item/page/content/text/gemini/reader/widget/find/tag.rs b/src/app/browser/window/tab/item/page/content/text/search/tag.rs similarity index 100% rename from src/app/browser/window/tab/item/page/content/text/gemini/reader/widget/find/tag.rs rename to src/app/browser/window/tab/item/page/content/text/search/tag.rs diff --git a/src/app/browser/window/tab/item/page/content/text/gemini/reader/widget/find/tag/current.rs b/src/app/browser/window/tab/item/page/content/text/search/tag/current.rs similarity index 100% rename from src/app/browser/window/tab/item/page/content/text/gemini/reader/widget/find/tag/current.rs rename to src/app/browser/window/tab/item/page/content/text/search/tag/current.rs diff --git a/src/app/browser/window/tab/item/page/content/text/gemini/reader/widget/find/tag/found.rs b/src/app/browser/window/tab/item/page/content/text/search/tag/found.rs similarity index 100% rename from src/app/browser/window/tab/item/page/content/text/gemini/reader/widget/find/tag/found.rs rename to src/app/browser/window/tab/item/page/content/text/search/tag/found.rs