mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-28 12:04:13 +00:00
move actions connect into the search component
This commit is contained in:
parent
8b65df99f4
commit
dd5d79bac4
@ -64,11 +64,7 @@ impl Page {
|
||||
),
|
||||
) -> Self {
|
||||
// Init components
|
||||
let content = Rc::new(Content::new((
|
||||
browser_action.clone(),
|
||||
window_action.clone(),
|
||||
tab_action.clone(),
|
||||
)));
|
||||
let content = Rc::new(Content::new((window_action.clone(), tab_action.clone())));
|
||||
|
||||
let search = Rc::new(Search::new());
|
||||
|
||||
|
@ -5,7 +5,7 @@ mod text;
|
||||
use image::Image;
|
||||
use text::Text;
|
||||
|
||||
use super::{BrowserAction, TabAction, WindowAction};
|
||||
use super::{TabAction, WindowAction};
|
||||
use adw::StatusPage;
|
||||
use gtk::{
|
||||
gdk::Paintable,
|
||||
@ -17,7 +17,6 @@ use gtk::{
|
||||
use std::{rc::Rc, time::Duration};
|
||||
|
||||
pub struct Content {
|
||||
browser_action: Rc<BrowserAction>,
|
||||
window_action: Rc<WindowAction>,
|
||||
tab_action: Rc<TabAction>,
|
||||
pub g_box: Box,
|
||||
@ -27,16 +26,9 @@ impl Content {
|
||||
// Construct
|
||||
|
||||
/// Create new container for different components
|
||||
pub fn new(
|
||||
(browser_action, window_action, tab_action): (
|
||||
Rc<BrowserAction>,
|
||||
Rc<WindowAction>,
|
||||
Rc<TabAction>,
|
||||
),
|
||||
) -> Self {
|
||||
pub fn new((window_action, tab_action): (Rc<WindowAction>, Rc<TabAction>)) -> Self {
|
||||
Self {
|
||||
g_box: Box::builder().orientation(Orientation::Vertical).build(),
|
||||
browser_action,
|
||||
window_action,
|
||||
tab_action,
|
||||
}
|
||||
@ -130,11 +122,7 @@ impl Content {
|
||||
/// * could be useful to extract document title parsed from Gemtext
|
||||
pub fn to_text_gemini(&self, base: &Uri, data: &str) -> Text {
|
||||
self.clean();
|
||||
let text = Text::new_gemini(
|
||||
data,
|
||||
base,
|
||||
(&self.browser_action, &self.window_action, &self.tab_action),
|
||||
);
|
||||
let text = Text::new_gemini(data, base, (&self.window_action, &self.tab_action));
|
||||
self.g_box.append(&text.g_box);
|
||||
text
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ mod source;
|
||||
use gemini::Gemini;
|
||||
use source::Source;
|
||||
|
||||
use super::{BrowserAction, TabAction, WindowAction};
|
||||
use super::{TabAction, WindowAction};
|
||||
use gtk::{
|
||||
glib::Uri,
|
||||
prelude::{BoxExt, Cast},
|
||||
@ -28,11 +28,7 @@ impl Text {
|
||||
pub fn new_gemini(
|
||||
gemtext: &str,
|
||||
base: &Uri,
|
||||
(browser_action, window_action, tab_action): (
|
||||
&Rc<BrowserAction>,
|
||||
&Rc<WindowAction>,
|
||||
&Rc<TabAction>,
|
||||
),
|
||||
(window_action, tab_action): (&Rc<WindowAction>, &Rc<TabAction>),
|
||||
) -> Self {
|
||||
// Init components
|
||||
let gemini = Gemini::new(gemtext, base, (window_action, tab_action));
|
||||
@ -46,50 +42,6 @@ impl Text {
|
||||
.build(),
|
||||
);
|
||||
|
||||
// Connect events
|
||||
/* @TODO
|
||||
browser_action.escape.connect_activate({
|
||||
let close = search.close.clone();
|
||||
move || {
|
||||
close.activate();
|
||||
}
|
||||
});
|
||||
|
||||
window_action.find.connect_activate({
|
||||
let search = search.clone();
|
||||
move |_| {
|
||||
search.g_box.set_visible(true);
|
||||
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, true, 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, true, 0.0, 0.0);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
search.close.connect_clicked({
|
||||
let search = search.clone();
|
||||
move |_| {
|
||||
search.g_box.set_visible(false);
|
||||
}
|
||||
});*/
|
||||
|
||||
Self {
|
||||
text_view: gemini.reader.widget.text_view.clone().upcast::<TextView>(),
|
||||
meta: Meta {
|
||||
|
@ -7,8 +7,8 @@ use placeholder::Placeholder;
|
||||
use subject::Subject;
|
||||
|
||||
use gtk::{
|
||||
prelude::{BoxExt, WidgetExt},
|
||||
Align, Box, Orientation, TextBuffer, TextView,
|
||||
prelude::{BoxExt, ButtonExt, WidgetExt},
|
||||
Align, Box, Orientation, TextView,
|
||||
};
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
|
||||
@ -40,6 +40,13 @@ impl Search {
|
||||
g_box.append(&form.g_box);
|
||||
g_box.append(&placeholder.label);
|
||||
|
||||
// Connect events
|
||||
|
||||
form.close.connect_clicked({
|
||||
let g_box = g_box.clone();
|
||||
move |_| g_box.set_visible(false)
|
||||
});
|
||||
|
||||
// Done
|
||||
Self {
|
||||
subject,
|
||||
@ -51,6 +58,10 @@ impl Search {
|
||||
|
||||
// Actions
|
||||
|
||||
pub fn escape(&self) {
|
||||
self.hide()
|
||||
}
|
||||
|
||||
pub fn show(&self) {
|
||||
if self.subject.borrow().is_some() {
|
||||
self.form.show();
|
||||
|
@ -11,11 +11,13 @@ use gtk::{
|
||||
prelude::{
|
||||
BoxExt, ButtonExt, CheckButtonExt, EditableExt, TextBufferExt, TextViewExt, WidgetExt,
|
||||
},
|
||||
Align, Box, Orientation, TextIter, TextSearchFlags,
|
||||
Align, Box, Button, Orientation, TextIter, TextSearchFlags,
|
||||
};
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
|
||||
pub struct Form {
|
||||
pub close: Button,
|
||||
pub input: Rc<Input>,
|
||||
pub g_box: Box,
|
||||
}
|
||||
|
||||
@ -23,7 +25,7 @@ impl Form {
|
||||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn new(buffer: &Rc<RefCell<Option<Subject>>>) -> Self {
|
||||
pub fn new(subject: &Rc<RefCell<Option<Subject>>>) -> Self {
|
||||
// Init components
|
||||
let close = close::new();
|
||||
let input = Rc::new(Input::new());
|
||||
@ -53,10 +55,10 @@ impl Form {
|
||||
let input = input.clone();
|
||||
let match_case = match_case.clone();
|
||||
let navigation = navigation.clone();
|
||||
let buffer = buffer.clone();
|
||||
let subject = subject.clone();
|
||||
move |_| {
|
||||
navigation.update(find(
|
||||
&buffer,
|
||||
&subject,
|
||||
input.entry.text().as_str(),
|
||||
match_case.is_active(),
|
||||
));
|
||||
@ -67,22 +69,63 @@ impl Form {
|
||||
match_case.connect_toggled({
|
||||
let input = input.clone();
|
||||
let navigation = navigation.clone();
|
||||
let buffer = buffer.clone();
|
||||
let subject = subject.clone();
|
||||
move |this| {
|
||||
navigation.update(find(&buffer, input.entry.text().as_str(), this.is_active()));
|
||||
navigation.update(find(
|
||||
&subject,
|
||||
input.entry.text().as_str(),
|
||||
this.is_active(),
|
||||
));
|
||||
input.update(navigation.is_match());
|
||||
}
|
||||
});
|
||||
|
||||
// Connect events
|
||||
navigation.back.button.connect_clicked({
|
||||
let subject = subject.clone();
|
||||
let navigation = navigation.clone();
|
||||
move |_| match subject.borrow().as_ref() {
|
||||
Some(subject) => match navigation.back(subject) {
|
||||
Some((mut start, _)) => {
|
||||
subject
|
||||
.text_view
|
||||
.scroll_to_iter(&mut start, 0.0, true, 0.0, 0.0);
|
||||
}
|
||||
None => todo!(),
|
||||
},
|
||||
None => todo!(),
|
||||
}
|
||||
});
|
||||
|
||||
navigation.forward.button.connect_clicked({
|
||||
let subject = subject.clone();
|
||||
let navigation = navigation.clone();
|
||||
move |_| match subject.borrow().as_ref() {
|
||||
Some(subject) => match navigation.forward(subject) {
|
||||
Some((mut start, _)) => {
|
||||
subject
|
||||
.text_view
|
||||
.scroll_to_iter(&mut start, 0.0, true, 0.0, 0.0);
|
||||
}
|
||||
None => todo!(),
|
||||
},
|
||||
None => todo!(),
|
||||
}
|
||||
});
|
||||
|
||||
// Done
|
||||
Self { g_box }
|
||||
Self {
|
||||
close,
|
||||
g_box,
|
||||
input,
|
||||
}
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
pub fn show(&self) {
|
||||
//self.buffer.get_mut().is_none()
|
||||
self.g_box.set_visible(true)
|
||||
self.g_box.set_visible(true);
|
||||
self.input.entry.grab_focus();
|
||||
}
|
||||
|
||||
pub fn hide(&self) {
|
||||
|
@ -4,9 +4,10 @@ mod forward;
|
||||
use back::Back;
|
||||
use forward::Forward;
|
||||
|
||||
use super::Subject;
|
||||
use gtk::{
|
||||
prelude::{BoxExt, TextBufferExt},
|
||||
Box, Orientation, TextBuffer, TextIter, TextTag,
|
||||
prelude::{BoxExt, TextBufferExt, TextViewExt},
|
||||
Box, Orientation, TextIter,
|
||||
};
|
||||
use std::{
|
||||
cell::{Cell, RefCell},
|
||||
@ -68,55 +69,60 @@ impl Navigation {
|
||||
self.back.update(self.is_match());
|
||||
self.forward.update(self.is_match());
|
||||
}
|
||||
/*
|
||||
pub fn back(&self) -> Option<(TextIter, TextIter)> {
|
||||
self.text_buffer.remove_tag(
|
||||
&self.current_tag,
|
||||
&self.text_buffer.start_iter(),
|
||||
&self.text_buffer.end_iter(),
|
||||
);
|
||||
|
||||
let index = self.index.take();
|
||||
match self.matches.borrow().get(back(index)) {
|
||||
Some((start, end)) => {
|
||||
self.text_buffer.apply_tag(&self.current_tag, start, end);
|
||||
self.index.replace(if index == 0 {
|
||||
len_to_index(self.matches.borrow().len())
|
||||
} else {
|
||||
index
|
||||
});
|
||||
Some((*start, *end))
|
||||
}
|
||||
None => {
|
||||
self.index
|
||||
.replace(len_to_index(self.matches.borrow().len())); // go last
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn back(&self, subject: &Subject) -> Option<(TextIter, TextIter)> {
|
||||
let buffer = subject.text_view.buffer();
|
||||
|
||||
pub fn forward(&self) -> Option<(TextIter, TextIter)> {
|
||||
self.text_buffer.remove_tag(
|
||||
&self.current_tag,
|
||||
&self.text_buffer.start_iter(),
|
||||
&self.text_buffer.end_iter(),
|
||||
);
|
||||
buffer.remove_tag(
|
||||
&subject.tag.current,
|
||||
&buffer.start_iter(),
|
||||
&buffer.end_iter(),
|
||||
);
|
||||
|
||||
let index = self.index.take();
|
||||
|
||||
match self.matches.borrow().get(back(index)) {
|
||||
Some((start, end)) => {
|
||||
buffer.apply_tag(&subject.tag.current, start, end);
|
||||
self.index.replace(if index == 0 {
|
||||
len_to_index(self.matches.borrow().len())
|
||||
} else {
|
||||
index
|
||||
});
|
||||
Some((*start, *end))
|
||||
}
|
||||
None => {
|
||||
self.index
|
||||
.replace(len_to_index(self.matches.borrow().len())); // go last
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn forward(&self, subject: &Subject) -> Option<(TextIter, TextIter)> {
|
||||
let buffer = subject.text_view.buffer();
|
||||
|
||||
buffer.remove_tag(
|
||||
&subject.tag.current,
|
||||
&buffer.start_iter(),
|
||||
&buffer.end_iter(),
|
||||
);
|
||||
|
||||
let index = self.index.take();
|
||||
let next = forward(index);
|
||||
match self.matches.borrow().get(next) {
|
||||
Some((start, end)) => {
|
||||
buffer.apply_tag(&subject.tag.current, start, end);
|
||||
self.index.replace(next);
|
||||
Some((*start, *end))
|
||||
}
|
||||
None => {
|
||||
self.index.replace(0);
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let index = self.index.take();
|
||||
let next = forward(index);
|
||||
match self.matches.borrow().get(next) {
|
||||
Some((start, end)) => {
|
||||
self.text_buffer.apply_tag(&self.current_tag, start, end);
|
||||
self.index.replace(next);
|
||||
Some((*start, *end))
|
||||
}
|
||||
None => {
|
||||
self.index.replace(0);
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
// Getters
|
||||
|
||||
pub fn is_match(&self) -> bool {
|
||||
|
Loading…
x
Reference in New Issue
Block a user