use crossterm::event::{KeyModifiers, MouseButton, MouseEvent, MouseEventKind};
use tokio::sync::mpsc;
use crate::state::{AppState, PackageItem, PkgbuildCheckRequest, QueryInput};
mod details;
mod filters;
pub mod menu_options;
pub mod menus;
mod modals;
mod panes;
#[cfg(test)]
mod tests;
#[allow(clippy::too_many_arguments)]
pub fn handle_mouse_event_with_pkgbuild_checks(
m: MouseEvent,
app: &mut AppState,
details_tx: &mpsc::UnboundedSender<PackageItem>,
preview_tx: &mpsc::UnboundedSender<PackageItem>,
_add_tx: &mpsc::UnboundedSender<PackageItem>,
pkgb_tx: &mpsc::UnboundedSender<PackageItem>,
comments_tx: &mpsc::UnboundedSender<String>,
query_tx: &mpsc::UnboundedSender<QueryInput>,
pkgb_check_tx: &mpsc::UnboundedSender<PkgbuildCheckRequest>,
) -> bool {
crate::util::ensure_mouse_capture();
if !app.mouse_capture_enabled {
app.mouse_capture_enabled = true;
}
let mx = m.column;
let my = m.row;
let is_left_down = matches!(m.kind, MouseEventKind::Down(MouseButton::Left));
let ctrl = m.modifiers.contains(KeyModifiers::CONTROL);
let shift = m.modifiers.contains(KeyModifiers::SHIFT);
app.last_mouse_pos = Some((mx, my));
if let Some(handled) = modals::handle_modal_mouse(m, mx, my, is_left_down, app) {
return handled;
}
if !matches!(app.modal, crate::state::Modal::None) {
return false;
}
if let Some(handled) = details::handle_details_mouse(
m,
mx,
my,
is_left_down,
ctrl,
shift,
app,
pkgb_tx,
comments_tx,
pkgb_check_tx,
) {
return handled;
}
if is_left_down && let Some(handled) = menus::handle_menus_mouse(mx, my, app, details_tx) {
return handled;
}
if is_left_down && let Some(handled) = filters::handle_filters_mouse(mx, my, app) {
return handled;
}
if is_left_down
&& let Some((x, y, w, h)) = app.fuzzy_indicator_rect
&& mx >= x
&& mx < x + w
&& my >= y
&& my < y + h
{
app.fuzzy_search_enabled = !app.fuzzy_search_enabled;
crate::theme::save_fuzzy_search(app.fuzzy_search_enabled);
app.search_cache_query = None;
app.search_cache_results = None;
crate::logic::send_query(app, query_tx);
return false;
}
if let Some(handled) = panes::handle_panes_mouse(
m,
mx,
my,
is_left_down,
app,
details_tx,
preview_tx,
comments_tx,
) {
return handled;
}
false
}
pub use menus::{handle_news_button, handle_updates_button};