mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 09:10:08 +00:00
implement search begin / continue on activate entry
This commit is contained in:
parent
e6583a602d
commit
093ee87b1f
@ -8,7 +8,8 @@ use navigation::Navigation;
|
|||||||
|
|
||||||
use gtk::{
|
use gtk::{
|
||||||
prelude::{
|
prelude::{
|
||||||
BoxExt, ButtonExt, CheckButtonExt, EditableExt, TextBufferExt, TextViewExt, WidgetExt,
|
BoxExt, ButtonExt, CheckButtonExt, EditableExt, EntryExt, TextBufferExt, TextViewExt,
|
||||||
|
WidgetExt,
|
||||||
},
|
},
|
||||||
Align, Box, Orientation, TextIter, TextSearchFlags,
|
Align, Box, Orientation, TextIter, TextSearchFlags,
|
||||||
};
|
};
|
||||||
@ -49,7 +50,7 @@ impl Form {
|
|||||||
let subject = subject.clone();
|
let subject = subject.clone();
|
||||||
move |_| {
|
move |_| {
|
||||||
let matches = find(
|
let matches = find(
|
||||||
&subject,
|
subject.borrow().as_ref().unwrap(), // @TODO handle
|
||||||
input.entry.text().as_str(),
|
input.entry.text().as_str(),
|
||||||
match_case.is_active(),
|
match_case.is_active(),
|
||||||
);
|
);
|
||||||
@ -58,12 +59,40 @@ impl Form {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
input.entry.connect_activate({
|
||||||
|
let input = input.clone();
|
||||||
|
let match_case = match_case.clone();
|
||||||
|
let navigation = navigation.clone();
|
||||||
|
let subject = subject.clone();
|
||||||
|
move |_| {
|
||||||
|
// try continue
|
||||||
|
if navigation
|
||||||
|
.forward(subject.borrow().as_ref().unwrap()) // @TODO handle
|
||||||
|
.is_none()
|
||||||
|
{
|
||||||
|
// begin new search
|
||||||
|
let matches = find(
|
||||||
|
subject.borrow().as_ref().unwrap(), // @TODO handle
|
||||||
|
input.entry.text().as_str(),
|
||||||
|
match_case.is_active(),
|
||||||
|
);
|
||||||
|
input.update(!matches.is_empty());
|
||||||
|
navigation.update(matches);
|
||||||
|
navigation.forward(subject.borrow().as_ref().unwrap()); // @TODO handle
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
match_case.connect_toggled({
|
match_case.connect_toggled({
|
||||||
let input = input.clone();
|
let input = input.clone();
|
||||||
let navigation = navigation.clone();
|
let navigation = navigation.clone();
|
||||||
let subject = subject.clone();
|
let subject = subject.clone();
|
||||||
move |this| {
|
move |this| {
|
||||||
let matches = find(&subject, input.entry.text().as_str(), this.is_active());
|
let matches = find(
|
||||||
|
subject.borrow().as_ref().unwrap(), // @TODO handle
|
||||||
|
input.entry.text().as_str(),
|
||||||
|
this.is_active(),
|
||||||
|
);
|
||||||
input.update(!matches.is_empty());
|
input.update(!matches.is_empty());
|
||||||
navigation.update(matches);
|
navigation.update(matches);
|
||||||
}
|
}
|
||||||
@ -123,49 +152,39 @@ impl Form {
|
|||||||
|
|
||||||
// Tools
|
// Tools
|
||||||
|
|
||||||
fn find(
|
fn find(subject: &Subject, request: &str, is_match_case: bool) -> Vec<(TextIter, TextIter)> {
|
||||||
subject: &Rc<RefCell<Option<Subject>>>,
|
|
||||||
request: &str,
|
|
||||||
is_match_case: bool,
|
|
||||||
) -> Vec<(TextIter, TextIter)> {
|
|
||||||
// Init matches holder
|
// Init matches holder
|
||||||
let mut result = Vec::new();
|
let mut result = Vec::new();
|
||||||
|
|
||||||
// Borrow buffer
|
// Get iters
|
||||||
match subject.borrow().as_ref() {
|
let (buffer_start, buffer_end) = subject.text_view.buffer().bounds();
|
||||||
Some(subject) => {
|
|
||||||
// Get iters
|
|
||||||
let (buffer_start, buffer_end) = subject.text_view.buffer().bounds();
|
|
||||||
|
|
||||||
// Cleanup previous search highlights
|
// Cleanup previous search highlights
|
||||||
subject
|
subject
|
||||||
.text_view
|
.text_view
|
||||||
.buffer()
|
.buffer()
|
||||||
.remove_tag(&subject.tag.current, &buffer_start, &buffer_end);
|
.remove_tag(&subject.tag.current, &buffer_start, &buffer_end);
|
||||||
subject
|
subject
|
||||||
.text_view
|
.text_view
|
||||||
.buffer()
|
.buffer()
|
||||||
.remove_tag(&subject.tag.found, &buffer_start, &buffer_end);
|
.remove_tag(&subject.tag.found, &buffer_start, &buffer_end);
|
||||||
|
|
||||||
// Begin new search
|
// Begin new search
|
||||||
let mut next = buffer_start;
|
let mut next = buffer_start;
|
||||||
while let Some((match_start, match_end)) = next.forward_search(
|
while let Some((match_start, match_end)) = next.forward_search(
|
||||||
request,
|
request,
|
||||||
match is_match_case {
|
match is_match_case {
|
||||||
true => TextSearchFlags::TEXT_ONLY,
|
true => TextSearchFlags::TEXT_ONLY,
|
||||||
false => TextSearchFlags::CASE_INSENSITIVE,
|
false => TextSearchFlags::CASE_INSENSITIVE,
|
||||||
},
|
},
|
||||||
None, // unlimited
|
None, // unlimited
|
||||||
) {
|
) {
|
||||||
subject
|
subject
|
||||||
.text_view
|
.text_view
|
||||||
.buffer()
|
.buffer()
|
||||||
.apply_tag(&subject.tag.found, &match_start, &match_end);
|
.apply_tag(&subject.tag.found, &match_start, &match_end);
|
||||||
next = match_end;
|
next = match_end;
|
||||||
result.push((match_start, match_end));
|
result.push((match_start, match_end));
|
||||||
}
|
|
||||||
result
|
|
||||||
}
|
|
||||||
None => todo!(), // unexpected
|
|
||||||
}
|
}
|
||||||
|
result
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user