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 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<WindowAction>, Rc<TabAction>),
(window_action, tab_action): (Rc<WindowAction>, Rc<TabAction>),
) -> 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(),

View File

@ -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 }
}

View File

@ -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<Input>,
pub navigation: Rc<Navigation>,
}
impl Find {
impl Search {
// Construct
pub fn new(text_buffer: &TextBuffer) -> Self {
// Init components