move find widget into the text shared search container

This commit is contained in:
yggverse 2024-12-16 12:52:12 +02:00
parent dc5bf1a400
commit 441bbc504f
12 changed files with 51 additions and 49 deletions

View File

@ -1,11 +1,17 @@
mod gemini; mod gemini;
mod search;
mod source; mod source;
use gemini::Gemini; use gemini::Gemini;
use search::Search;
use source::Source; use source::Source;
use crate::app::browser::window::{tab::item::Action as TabAction, Action as WindowAction}; use super::{TabAction, WindowAction};
use gtk::{glib::Uri, prelude::BoxExt, Box, Orientation, ScrolledWindow}; use gtk::{
glib::Uri,
prelude::{BoxExt, ButtonExt, TextViewExt,WidgetExt},
Box, Orientation, ScrolledWindow,
};
use std::rc::Rc; use std::rc::Rc;
pub struct Meta { pub struct Meta {
@ -23,10 +29,11 @@ impl Text {
pub fn new_gemini( pub fn new_gemini(
gemtext: &str, gemtext: &str,
base: &Uri, base: &Uri,
actions: (Rc<WindowAction>, Rc<TabAction>), (window_action, tab_action): (Rc<WindowAction>, Rc<TabAction>),
) -> Self { ) -> Self {
// Init components // 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 // Init main widget
let g_box = Box::builder().orientation(Orientation::Vertical).build(); let g_box = Box::builder().orientation(Orientation::Vertical).build();
@ -36,6 +43,43 @@ impl Text {
.build(), .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 { Self {
meta: Meta { meta: Meta {
title: gemini.reader.title.clone(), title: gemini.reader.title.clone(),

View File

@ -1,12 +1,8 @@
mod find;
use std::rc::Rc; use std::rc::Rc;
use find::Find;
use super::WindowAction; use super::WindowAction;
use gtk::{ use gtk::{
prelude::{ButtonExt, TextViewExt, WidgetExt}, prelude::WidgetExt, EventControllerMotion, GestureClick, TextBuffer, TextView, WrapMode,
EventControllerMotion, GestureClick, TextBuffer, TextView, TextWindowType, WrapMode,
}; };
const MARGIN: i32 = 8; const MARGIN: i32 = 8;
@ -26,9 +22,6 @@ impl Widget {
middle_button_controller: &GestureClick, middle_button_controller: &GestureClick,
motion_controller: &EventControllerMotion, motion_controller: &EventControllerMotion,
) -> Self { ) -> Self {
// Init components
let find = Rc::new(Find::new(buffer));
// Init main widget // Init main widget
let text_view = TextView::builder() let text_view = TextView::builder()
.bottom_margin(MARGIN) .bottom_margin(MARGIN)
@ -46,41 +39,6 @@ impl Widget {
text_view.add_controller(middle_button_controller.clone()); text_view.add_controller(middle_button_controller.clone());
text_view.add_controller(motion_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 // Done
Self { text_view } Self { text_view }
} }

View File

@ -14,14 +14,14 @@ use gtk::{
}; };
use std::rc::Rc; use std::rc::Rc;
pub struct Find { pub struct Search {
pub close: Button, pub close: Button,
pub g_box: Box, pub g_box: Box,
pub input: Rc<Input>, pub input: Rc<Input>,
pub navigation: Rc<Navigation>, pub navigation: Rc<Navigation>,
} }
impl Find { impl Search {
// Construct // Construct
pub fn new(text_buffer: &TextBuffer) -> Self { pub fn new(text_buffer: &TextBuffer) -> Self {
// Init components // Init components