refactor: Migrated the handle_table_events macro into a trait for better IDE support, created a TableEventAdapter wrapper for the KeyEventHandlers to make it so that the trait can be used properly and a simple function to replace the previous call to the handle_table_events macro

This commit is contained in:
2025-12-04 16:03:58 -07:00
parent 71240373c0
commit 35dce0bf01
42 changed files with 1425 additions and 756 deletions
+14 -13
View File
@@ -1,10 +1,8 @@
use crate::app::App;
use crate::event::Key;
use crate::handle_table_events;
use crate::handlers::KeyEventHandler;
use crate::handlers::table_handler::TableHandlingConfig;
use crate::handlers::table_handler::{TableHandlingConfig, handle_table};
use crate::models::servarr_data::ActiveKeybindingBlock;
use crate::models::servarr_models::KeybindingItem;
#[cfg(test)]
#[path = "keybinding_handler_tests.rs"]
@@ -15,20 +13,15 @@ pub(super) struct KeybindingHandler<'a, 'b> {
app: &'a mut App<'b>,
}
impl KeybindingHandler<'_, '_> {
handle_table_events!(
self,
keybindings,
self.app.keymapping_table.as_mut().unwrap(),
KeybindingItem
);
}
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveKeybindingBlock> for KeybindingHandler<'a, 'b> {
fn handle(&mut self) {
let keybinding_table_handling_config = TableHandlingConfig::new(self.app.get_current_route());
if !self.handle_keybindings_table_events(keybinding_table_handling_config) {
if !handle_table(
self,
|app| app.keymapping_table.as_mut().unwrap(),
keybinding_table_handling_config,
) {
self.handle_key_event();
}
}
@@ -77,4 +70,12 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveKeybindingBlock> for KeybindingHandle
}
fn handle_char_key_event(&mut self) {}
fn app_mut(&mut self) -> &mut App<'b> {
self.app
}
fn current_route(&self) -> crate::models::Route {
self.app.get_current_route()
}
}