use anyhow::Result; use strum_macros::{Display, EnumIter, EnumString}; use crate::event_exec::{EventAction, LeaveMode}; use crate::status::Status; /// 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 { Back, BackTab, Backspace, Bulk, Chmod, ClearFlags, CliInfo, Command, Compress, CopyFilename, CopyFilepath, CopyPaste, CutPaste, Delete, DeleteFile, Diff, DragNDrop, EncryptedDrive, End, Enter, Exec, Filter, FlagAll, FuzzyFind, FuzzyFindHelp, FuzzyFindLine, GoRoot, GoStart, Goto, Help, History, Home, Jump, KeyHome, Log, MarksJump, MarksNew, MediaInfo, MocpAddToPlayList, MocpClearPlaylist, MocpGoToSong, MocpNext, MocpPrevious, MocpTogglePause, MoveDown, MoveLeft, MoveRight, MoveUp, NewDir, NewFile, Nothing, NvimFilepicker, NvimSetAddress, OpenConfig, OpenFile, PageDown, PageUp, Preview, Quit, RefreshIfNeeded, RefreshView, RegexMatch, RemoteMount, RemovableDevices, Rename, ResetMode, ReverseFlags, Search, SearchNext, SetWallpaper, Shell, ShellCommand, ShellMenu, 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) -> Result<()> { let current_tab = status.selected(); match self { ActionMap::Back => EventAction::back(current_tab), ActionMap::BackTab => EventAction::backtab(status), ActionMap::Backspace => EventAction::backspace(current_tab), ActionMap::Bulk => EventAction::bulk(status), ActionMap::Chmod => EventAction::chmod(status), ActionMap::ClearFlags => EventAction::clear_flags(status), ActionMap::CliInfo => EventAction::cli_info(status), ActionMap::Command => EventAction::command(current_tab), ActionMap::Compress => EventAction::compress(status), ActionMap::CopyFilename => EventAction::copy_filename(current_tab), ActionMap::CopyFilepath => EventAction::copy_filepath(current_tab), ActionMap::CopyPaste => EventAction::copy_paste(status), ActionMap::CutPaste => EventAction::cut_paste(status), ActionMap::Delete => EventAction::delete(status), ActionMap::DeleteFile => EventAction::delete_file(status), ActionMap::Diff => EventAction::diff(status), ActionMap::DragNDrop => EventAction::drag_n_drop(status), ActionMap::EncryptedDrive => EventAction::encrypted_drive(status), ActionMap::End => EventAction::end(status), ActionMap::Enter => EventAction::enter(status), ActionMap::Exec => EventAction::exec(current_tab), ActionMap::Filter => EventAction::filter(current_tab), ActionMap::FlagAll => EventAction::flag_all(status), ActionMap::FuzzyFind => EventAction::fuzzyfind(status), ActionMap::FuzzyFindHelp => EventAction::fuzzyfind_help(status), ActionMap::FuzzyFindLine => EventAction::fuzzyfind_line(status), ActionMap::GoRoot => EventAction::go_root(status), ActionMap::GoStart => EventAction::go_start(status), ActionMap::Goto => EventAction::goto(current_tab), ActionMap::Help => EventAction::help(status), ActionMap::History => EventAction::history(current_tab), ActionMap::Home => EventAction::home(status), ActionMap::Jump => EventAction::jump(status), ActionMap::KeyHome => EventAction::key_home(status), ActionMap::Log => EventAction::log(current_tab), ActionMap::MarksJump => EventAction::marks_jump(status), ActionMap::MarksNew => EventAction::marks_new(current_tab), ActionMap::MediaInfo => EventAction::mediainfo(current_tab), ActionMap::MocpAddToPlayList => EventAction::mocp_add_to_playlist(current_tab), ActionMap::MocpClearPlaylist => EventAction::mocp_clear_playlist(), ActionMap::MocpGoToSong => EventAction::mocp_go_to_song(status), ActionMap::MocpNext => EventAction::mocp_next(), ActionMap::MocpPrevious => EventAction::mocp_previous(), ActionMap::MocpTogglePause => EventAction::mocp_toggle_pause(status), ActionMap::MoveDown => EventAction::move_down(status), ActionMap::MoveLeft => EventAction::move_left(status), ActionMap::MoveRight => EventAction::move_right(status), ActionMap::MoveUp => EventAction::move_up(status), ActionMap::NewDir => EventAction::new_dir(current_tab), ActionMap::NewFile => EventAction::new_file(current_tab), ActionMap::NvimFilepicker => EventAction::nvim_filepicker(status), ActionMap::NvimSetAddress => EventAction::set_nvim_server(current_tab), ActionMap::OpenConfig => EventAction::open_config(status), ActionMap::OpenFile => EventAction::open_file(status), ActionMap::PageDown => EventAction::page_down(status), ActionMap::PageUp => EventAction::page_up(status), ActionMap::Preview => EventAction::preview(status), ActionMap::Quit => EventAction::quit(current_tab), ActionMap::RefreshIfNeeded => EventAction::refresh_if_needed(current_tab), ActionMap::RefreshView => EventAction::refreshview(status), ActionMap::RegexMatch => EventAction::regex_match(current_tab), ActionMap::RemoteMount => EventAction::remote_mount(current_tab), ActionMap::RemovableDevices => EventAction::removable_devices(status), ActionMap::Rename => EventAction::rename(current_tab), ActionMap::ResetMode => EventAction::reset_mode(current_tab), ActionMap::ReverseFlags => EventAction::reverse_flags(status), ActionMap::Search => EventAction::search(current_tab), ActionMap::SearchNext => EventAction::search_next(status), ActionMap::SetWallpaper => EventAction::set_wallpaper(current_tab), ActionMap::Shell => EventAction::shell(status), ActionMap::ShellCommand => EventAction::shell_command(current_tab), ActionMap::ShellMenu => EventAction::shell_menu(current_tab), ActionMap::Shortcut => EventAction::shortcut(current_tab), ActionMap::Sort => EventAction::sort(current_tab), ActionMap::Symlink => EventAction::symlink(status), ActionMap::Tab => EventAction::tab(status), ActionMap::ToggleDisplayFull => EventAction::toggle_display_full(status), ActionMap::ToggleDualPane => EventAction::toggle_dualpane(status), ActionMap::ToggleFlag => EventAction::toggle_flag(status), ActionMap::ToggleHidden => EventAction::toggle_hidden(status), ActionMap::TogglePreviewSecond => EventAction::toggle_preview_second(status), ActionMap::TrashEmpty => EventAction::trash_empty(status), ActionMap::TrashMoveFile => EventAction::trash_move_file(status), ActionMap::TrashOpen => EventAction::trash_open(status), ActionMap::TrashRestoreFile => LeaveMode::trash(status), ActionMap::Tree => EventAction::tree(status), ActionMap::TreeFold => EventAction::tree_fold(current_tab), ActionMap::TreeFoldAll => EventAction::tree_fold_all(current_tab), ActionMap::TreeUnFoldAll => EventAction::tree_unfold_all(current_tab), ActionMap::Custom(string) => EventAction::custom(status, string), ActionMap::Nothing => Ok(()), } } }