summaryrefslogtreecommitdiffstats
path: root/src/event/action_map.rs
blob: a64f28db80a8d0d66e5b42debf7479f7236d54ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
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(()),
        }
    }
}