update key controller router, init navigation methods

This commit is contained in:
yggverse 2025-03-10 23:53:25 +02:00
parent 0948a6c93a
commit b716fb1f78
2 changed files with 51 additions and 16 deletions

View File

@ -43,24 +43,42 @@ impl Request {
let suggestion = Rc::new(Suggestion::build(profile, &entry)); let suggestion = Rc::new(Suggestion::build(profile, &entry));
entry.add_controller({ entry.add_controller({
use gtk::{gdk::Key, glib::Propagation}; use gtk::{
fn is_up(k: Key) -> bool { gdk::{Key, ModifierType},
matches!(k, Key::Up | Key::KP_Up | Key::Page_Up | Key::KP_Page_Up) glib::Propagation,
} };
fn is_down(k: Key) -> bool { let c = gtk::EventControllerKey::builder().build();
matches!( c.connect_key_pressed({
k, let entry = entry.clone();
Key::Down | Key::KP_Down | Key::Page_Down | Key::KP_Page_Down let suggestion = suggestion.clone();
) move |_, k, _, m| {
} if suggestion.is_visible()
let controller = gtk::EventControllerKey::builder().build(); && !matches!(
controller.connect_key_pressed(|_, k, _, _| { m,
if is_up(k) || is_down(k) { ModifierType::SHIFT_MASK
return Propagation::Stop; // @TODO | ModifierType::ALT_MASK
| ModifierType::CONTROL_MASK
)
{
if matches!(k, Key::Up | Key::KP_Up | Key::Page_Up | Key::KP_Page_Up) {
if !suggestion.to_back() {
entry.error_bell()
}
return Propagation::Stop;
} else if matches!(
k,
Key::Down | Key::KP_Down | Key::Page_Down | Key::KP_Page_Down
) {
if !suggestion.to_next() {
entry.error_bell()
}
return Propagation::Stop;
}
}
Propagation::Proceed
} }
Propagation::Proceed
}); });
controller c
}); });
entry.connect_icon_release({ entry.connect_icon_release({

View File

@ -169,4 +169,21 @@ impl Suggestion {
pub fn hide(&self) { pub fn hide(&self) {
self.popover.popdown() self.popover.popdown()
} }
pub fn to_back(&self) -> bool {
false // @TODO
}
pub fn to_next(&self) -> bool {
false // @TODO
}
// Getters
pub fn is_visible(&self) -> bool {
self.popover.is_visible()
}
/*pub fn total(&self) -> u32 {
self.list_store.n_items()
}*/
} }