use anyhow::Result; use strum_macros::{Display, EnumIter, EnumString}; use crate::app::Status; use crate::config::Bindings; use crate::event::EventAction; use crate::modes::LeaveMode; /// Different kind of action which can be mapped to a key. /// All those actions are mapped to a key and this enum /// makes the junction between received Key events and /// actions in the application. #[derive(Clone, Debug, Display, EnumString, EnumIter)] pub enum ActionMap { Action, Back, BackTab, Backspace, Bulk, Cd, Chmod, ClearFlags, CliMenu, Compress, Context, CopyFilename, CopyFilepath, CopyPaste, CutPaste, Delete, DeleteFile, DisplayFlagged, EncryptedDrive, End, Enter, Exec, Filter, FlagAll, FuzzyFind, FuzzyFindHelp, FuzzyFindLine, GoRoot, GoStart, Help, History, Home, Jump, KeyHome, LazyGit, Log, MarksJump, MarksNew, MocpAddToPlayList, MocpClearPlaylist, MocpGoToSong, MocpNext, MocpPrevious, MocpTogglePause, MoveDown, MoveLeft, MoveRight, MoveUp, Ncdu, NextSibling, NewDir, NewFile, Nothing, NvimFilepicker, NvimSetAddress, OpenConfig, OpenFile, OpenAll, PageDown, PageUp, Preview, PreviousSibling, Quit, RefreshIfNeeded, RefreshView, RegexMatch, RemoteMount, RemovableDevices, Rename, ResetMode, ReverseFlags, Search, SearchNext, Shell, ShellCommand, TuiMenu, Shortcut, Sort, Symlink, Tab, ToggleDisplayFull, ToggleDualPane, ToggleFlag, ToggleHidden, TogglePreviewSecond, TrashEmpty, TrashMoveFile, TrashOpen, TrashRestoreFile, Tree, TreeFold, TreeFoldAll, TreeUnFoldAll, Custom(String), } impl ActionMap { /// Makes the junction between `Actions` and `Events`. /// Every Action links to a different `EventExec` method. pub fn matcher(&self, status: &mut Status, binds: &Bindings) -> Result<()> { let current_tab = status.current_tab_mut(); match self { Self::Action => EventAction::action(status), Self::Back => EventAction::back(status), Self::BackTab => EventAction::backtab(status), Self::Backspace => EventAction::backspace(status), Self::Bulk => EventAction::bulk(status), Self::Chmod => EventAction::chmod(status), Self::ClearFlags => EventAction::clear_flags(status), Self::CliMenu => EventAction::cli_menu(status), Self::Compress => EventAction::compress(status), Self::Context => EventAction::context(status), Self::CopyFilename => EventAction::copy_filename(status), Self::CopyFilepath => EventAction::copy_filepath(status), Self::CopyPaste => EventAction::copy_paste(status), Self::CutPaste => EventAction::cut_paste(status), Self::Delete => EventAction::delete(status), Self::DeleteFile => EventAction::delete_file(status), Self::DisplayFlagged => EventAction::display_flagged(status), Self::EncryptedDrive => EventAction::encrypted_drive(status), Self::End => EventAction::end(status), Self::Enter => EventAction::enter(status, binds), Self::Exec => EventAction::exec(status), Self::Filter => EventAction::filter(status), Self::FlagAll => EventAction::flag_all(status), Self::FuzzyFind => EventAction::fuzzyfind(status), Self::FuzzyFindHelp => EventAction::fuzzyfind_help(status, binds), Self::FuzzyFindLine => EventAction::fuzzyfind_line(status), Self::GoRoot => EventAction::go_root(status), Self::GoStart => EventAction::go_start(status), Self::Cd => EventAction::cd(status), Self::Help => EventAction::help(status, binds), Self::History => EventAction::history(status), Self::Home => EventAction::home(status), Self::Jump => EventAction::jump(status), Self::KeyHome => EventAction::key_home(status), Self::Log => EventAction::log(current_tab), Self::LazyGit => EventAction::lazygit(status), Self::MarksJump => EventAction::marks_jump(status), Self::MarksNew => EventAction::marks_new(status), Self::MocpAddToPlayList => EventAction::mocp_add_to_playlist(current_tab), Self::MocpClearPlaylist => EventAction::mocp_clear_playlist(), Self::MocpGoToSong => EventAction::mocp_go_to_song(status), Self::MocpNext => EventAction::mocp_next(), Self::MocpPrevious => EventAction::mocp_previous(), Self::MocpTogglePause => EventAction::mocp_toggle_pause(status), Self::MoveDown => EventAction::move_down(status), Self::MoveLeft => EventAction::move_left(status), Self::MoveRight => EventAction::move_right(status), Self::MoveUp => EventAction::move_up(status), Self::NextSibling => EventAction::next_sibling(current_tab), Self::Ncdu => EventAction::ncdu(status), Self::NewDir => EventAction::new_dir(status), Self::NewFile => EventAction::new_file(status), Self::NvimFilepicker => EventAction::nvim_filepicker(status), Self::NvimSetAddress => EventAction::set_nvim_server(status), Self::OpenConfig => EventAction::open_config(status), Self::OpenFile => EventAction::open_file(status), Self::OpenAll => EventAction::open_all(status), Self::PageDown => EventAction::page_down(status), Self::PageUp => EventAction::page_up(status), Self::Preview => EventAction::preview(current_tab), Self::PreviousSibling => EventAction::previous_sibling(current_tab), Self::Quit => EventAction::quit(status), Self::RefreshIfNeeded => EventAction::refresh_if_needed(current_tab), Self::RefreshView => EventAction::refresh_view(status), Self::RegexMatch => EventAction::regex_match(status), Self::RemoteMount => EventAction::remote_mount(status), Self::RemovableDevices => EventAction::removable_devices(status), Self::Rename => EventAction::rename(status), Self::ResetMode => EventAction::reset_mode(status), Self::ReverseFlags => EventAction::reverse_flags(status), Self::Search => EventAction::search(status), Self::SearchNext => EventAction::search_next(status), Self::Shell => EventAction::shell(status), Self::ShellCommand => EventAction::shell_command(status), Self::Shortcut => EventAction::shortcut(status), Self::Sort => EventAction::sort(status), Self::Symlink => EventAction::symlink(status), Self::Tab => EventAction::tab(status), Self::ToggleDisplayFull => EventAction::toggle_display_full(status), Self::ToggleDualPane => EventAction::toggle_dualpane(status), Self::ToggleFlag => EventAction::toggle_flag(status), Self::ToggleHidden => EventAction::toggle_hidden(current_tab), Self::TogglePreviewSecond => EventAction::toggle_preview_second(status), Self::TrashEmpty => EventAction::trash_empty(status), Self::TrashMoveFile => EventAction::trash_move_file(status), Self::TrashOpen => EventAction::trash_open(status), Self::TrashRestoreFile => LeaveMode::trash(status), Self::Tree => EventAction::tree(status), Self::TreeFold => EventAction::tree_fold(current_tab), Self::TreeFoldAll => EventAction::tree_fold_all(current_tab), Self::TreeUnFoldAll => EventAction::tree_unfold_all(current_tab), Self::TuiMenu => EventAction::tui_menu(status), Self::Custom(string) => EventAction::custom(status, string), Self::Nothing => Ok(()), } } }