diff options
author | qkzk <qu3nt1n@gmail.com> | 2022-10-27 06:45:37 +0200 |
---|---|---|
committer | qkzk <qu3nt1n@gmail.com> | 2022-10-27 06:45:37 +0200 |
commit | a874cb05a0e25ec08b54576a498171146f46b159 (patch) | |
tree | ff8075756ca0ba0fb994ddbdd4ac46d75e6ce8a5 /src/actioner.rs | |
parent | 58fbfe5bff750b27935bcaf46d7241511b4dc9bc (diff) |
use correct name for status in actioner. Copy filename/filepath to clipboardcopy-clipboard
Diffstat (limited to 'src/actioner.rs')
-rw-r--r-- | src/actioner.rs | 215 |
1 files changed, 116 insertions, 99 deletions
diff --git a/src/actioner.rs b/src/actioner.rs index 5e4877a..04eef1f 100644 --- a/src/actioner.rs +++ b/src/actioner.rs @@ -58,54 +58,56 @@ impl Actioner { Self { binds, term } } /// Reaction to received events. - pub fn read_event(&self, tabs: &mut Status, ev: Event) -> FmResult<()> { + pub fn read_event(&self, status: &mut Status, ev: Event) -> FmResult<()> { match ev { - Event::Key(Key::ESC) => self.escape(tabs), - Event::Key(Key::Up) => self.up(tabs), - Event::Key(Key::Down) => self.down(tabs), - Event::Key(Key::Left) => self.left(tabs), - Event::Key(Key::Right) => self.right(tabs), - Event::Key(Key::Backspace) => self.backspace(tabs), - Event::Key(Key::Ctrl('d')) => self.delete(tabs), - Event::Key(Key::Ctrl('q')) => self.escape(tabs), - Event::Key(Key::Delete) => self.delete(tabs), - Event::Key(Key::Insert) => self.insert(tabs), - Event::Key(Key::Char(c)) => self.char(tabs, c), - Event::Key(Key::Home) => self.home(tabs), - Event::Key(Key::End) => self.end(tabs), - Event::Key(Key::PageDown) => self.page_down(tabs), - Event::Key(Key::PageUp) => self.page_up(tabs), - Event::Key(Key::Enter) => self.enter(tabs), - Event::Key(Key::Tab) => self.tab(tabs), - Event::Key(Key::WheelUp(_, _, _)) => self.up(tabs), - Event::Key(Key::WheelDown(_, _, _)) => self.down(tabs), + Event::Key(Key::ESC) => self.escape(status), + Event::Key(Key::Up) => self.up(status), + Event::Key(Key::Down) => self.down(status), + Event::Key(Key::Left) => self.left(status), + Event::Key(Key::Right) => self.right(status), + Event::Key(Key::Backspace) => self.backspace(status), + Event::Key(Key::Ctrl('d')) => self.delete(status), + Event::Key(Key::Ctrl('q')) => self.escape(status), + Event::Key(Key::Delete) => self.delete(status), + Event::Key(Key::Insert) => self.insert(status), + Event::Key(Key::Char(c)) => self.char(status, c), + Event::Key(Key::Home) => self.home(status), + Event::Key(Key::End) => self.end(status), + Event::Key(Key::PageDown) => self.page_down(status), + Event::Key(Key::PageUp) => self.page_up(status), + Event::Key(Key::Enter) => self.enter(status), + Event::Key(Key::Tab) => self.tab(status), + Event::Key(Key::WheelUp(_, _, _)) => self.up(status), + Event::Key(Key::WheelDown(_, _, _)) => self.down(status), Event::Key(Key::SingleClick(MouseButton::Left, row, _)) => { - self.left_click(tabs, row); + self.left_click(status, row); Ok(()) } Event::Key(Key::SingleClick(MouseButton::Right, row, _)) => { - self.right_click(tabs, row); + self.right_click(status, row); Ok(()) } - Event::Key(Key::Ctrl('f')) => self.ctrl_f(tabs), + Event::Key(Key::Ctrl('f')) => self.ctrl_f(status), + Event::Key(Key::Ctrl('c')) => self.ctrl_c(status), + Event::Key(Key::Ctrl('p')) => self.ctrl_p(status), _ => Ok(()), } } /// Leaving a mode reset the window - fn escape(&self, tabs: &mut Status) -> FmResult<()> { - tabs.selected().event_normal() + fn escape(&self, status: &mut Status) -> FmResult<()> { + status.selected().event_normal() } /// Move one line up - fn up(&self, tabs: &mut Status) -> FmResult<()> { - match tabs.selected().mode { - Mode::Normal | Mode::Preview | Mode::Help => tabs.selected().event_up_one_row(), - Mode::Jump => tabs.event_jumplist_prev(), - Mode::History => tabs.selected().event_history_prev(), - Mode::Shortcut => tabs.selected().event_shortcut_prev(), + fn up(&self, status: &mut Status) -> FmResult<()> { + match status.selected().mode { + Mode::Normal | Mode::Preview | Mode::Help => status.selected().event_up_one_row(), + Mode::Jump => status.event_jumplist_prev(), + Mode::History => status.selected().event_history_prev(), + Mode::Shortcut => status.selected().event_shortcut_prev(), Mode::Goto | Mode::Exec | Mode::Search => { - tabs.selected().completion.prev(); + status.selected().completion.prev(); } _ => (), }; @@ -113,14 +115,14 @@ impl Actioner { } /// Move one line down - fn down(&self, tabs: &mut Status) -> FmResult<()> { - match tabs.selected().mode { - Mode::Normal | Mode::Preview | Mode::Help => tabs.selected().event_down_one_row(), - Mode::Jump => tabs.event_jumplist_next(), - Mode::History => tabs.selected().event_history_next(), - Mode::Shortcut => tabs.selected().event_shortcut_next(), + fn down(&self, status: &mut Status) -> FmResult<()> { + match status.selected().mode { + Mode::Normal | Mode::Preview | Mode::Help => status.selected().event_down_one_row(), + Mode::Jump => status.event_jumplist_next(), + Mode::History => status.selected().event_history_next(), + Mode::Shortcut => status.selected().event_shortcut_next(), Mode::Goto | Mode::Exec | Mode::Search => { - tabs.selected().completion.next(); + status.selected().completion.next(); } _ => (), }; @@ -128,9 +130,9 @@ impl Actioner { } /// Move left in a string, move to parent in normal mode - fn left(&self, tabs: &mut Status) -> FmResult<()> { - match tabs.selected().mode { - Mode::Normal => tabs.selected().event_move_to_parent(), + fn left(&self, status: &mut Status) -> FmResult<()> { + match status.selected().mode { + Mode::Normal => status.selected().event_move_to_parent(), Mode::Rename | Mode::Chmod | Mode::Newdir @@ -138,7 +140,7 @@ impl Actioner { | Mode::Exec | Mode::Search | Mode::Goto => { - tabs.selected().event_move_cursor_left(); + status.selected().event_move_cursor_left(); Ok(()) } @@ -147,9 +149,9 @@ impl Actioner { } /// Move right in a string, move to children in normal mode. - fn right(&self, tabs: &mut Status) -> FmResult<()> { - match tabs.selected().mode { - Mode::Normal => tabs.selected().event_go_to_child(), + fn right(&self, status: &mut Status) -> FmResult<()> { + match status.selected().mode { + Mode::Normal => status.selected().event_go_to_child(), Mode::Rename | Mode::Chmod | Mode::Newdir @@ -157,7 +159,7 @@ impl Actioner { | Mode::Exec | Mode::Search | Mode::Goto => { - tabs.selected().event_move_cursor_right(); + status.selected().event_move_cursor_right(); Ok(()) } _ => Ok(()), @@ -165,8 +167,8 @@ impl Actioner { } /// Deletes a char in input string - fn backspace(&self, tabs: &mut Status) -> FmResult<()> { - match tabs.selected().mode { + fn backspace(&self, status: &mut Status) -> FmResult<()> { + match status.selected().mode { Mode::Rename | Mode::Newdir | Mode::Chmod @@ -174,7 +176,7 @@ impl Actioner { | Mode::Exec | Mode::Search | Mode::Goto => { - tabs.selected().event_delete_char_left(); + status.selected().event_delete_char_left(); Ok(()) } Mode::Normal => Ok(()), @@ -184,8 +186,8 @@ impl Actioner { /// Deletes chars right of cursor in input string. /// Remove current tab in normal mode. - fn delete(&self, tabs: &mut Status) -> FmResult<()> { - match tabs.selected().mode { + fn delete(&self, status: &mut Status) -> FmResult<()> { + match status.selected().mode { Mode::Rename | Mode::Newdir | Mode::Chmod @@ -193,12 +195,12 @@ impl Actioner { | Mode::Exec | Mode::Search | Mode::Goto => { - tabs.selected().event_delete_chars_right(); + status.selected().event_delete_chars_right(); Ok(()) } Mode::Normal => { - tabs.drop_tab(); + status.drop_tab(); Ok(()) } _ => Ok(()), @@ -206,63 +208,63 @@ impl Actioner { } /// Insert a new tab in normal mode - fn insert(&self, tabs: &mut Status) -> FmResult<()> { - if let Mode::Normal = tabs.selected().mode { - tabs.new_tab() + fn insert(&self, status: &mut Status) -> FmResult<()> { + if let Mode::Normal = status.selected().mode { + status.new_tab() }; Ok(()) } /// Move to top or beggining of line. - fn home(&self, tabs: &mut Status) -> FmResult<()> { - match tabs.selected().mode { - Mode::Normal | Mode::Preview | Mode::Help => tabs.selected().event_go_top(), - _ => tabs.selected().event_cursor_home(), + fn home(&self, status: &mut Status) -> FmResult<()> { + match status.selected().mode { + Mode::Normal | Mode::Preview | Mode::Help => status.selected().event_go_top(), + _ => status.selected().event_cursor_home(), }; Ok(()) } /// Move to end or end of line. - fn end(&self, tabs: &mut Status) -> FmResult<()> { - match tabs.selected().mode { - Mode::Normal | Mode::Preview | Mode::Help => tabs.selected().event_go_bottom(), - _ => tabs.selected().event_cursor_end(), + fn end(&self, status: &mut Status) -> FmResult<()> { + match status.selected().mode { + Mode::Normal | Mode::Preview | Mode::Help => status.selected().event_go_bottom(), + _ => status.selected().event_cursor_end(), }; Ok(()) } /// Move down 10 rows - fn page_down(&self, tabs: &mut Status) -> FmResult<()> { - match tabs.selected().mode { - Mode::Normal | Mode::Preview | Mode::Help => tabs.selected().event_page_down(), + fn page_down(&self, status: &mut Status) -> FmResult<()> { + match status.selected().mode { + Mode::Normal | Mode::Preview | Mode::Help => status.selected().event_page_down(), _ => (), }; Ok(()) } /// Move up 10 rows - fn page_up(&self, tabs: &mut Status) -> FmResult<()> { - match tabs.selected().mode { - Mode::Normal | Mode::Preview | Mode::Help => tabs.selected().event_page_up(), + fn page_up(&self, status: &mut Status) -> FmResult<()> { + match status.selected().mode { + Mode::Normal | Mode::Preview | Mode::Help => status.selected().event_page_up(), _ => (), }; Ok(()) } /// Execute a command - fn enter(&self, tabs: &mut Status) -> FmResult<()> { - match tabs.selected().mode { - Mode::Rename => tabs.selected().exec_rename()?, - Mode::Newfile => tabs.selected().exec_newfile()?, - Mode::Newdir => tabs.selected().exec_newdir()?, - Mode::Chmod => tabs.exec_chmod()?, - Mode::Exec => tabs.selected().exec_exec()?, - Mode::Search => tabs.selected().exec_search(), - Mode::Goto => tabs.selected().exec_goto()?, - Mode::RegexMatch => tabs.exec_regex()?, - Mode::Jump => tabs.exec_jump()?, - Mode::History => tabs.selected().exec_history()?, - Mode::Shortcut => tabs.selected().exec_shortcut()?, + fn enter(&self, status: &mut Status) -> FmResult<()> { + match status.selected().mode { + Mode::Rename => status.selected().exec_rename()?, + Mode::Newfile => status.selected().exec_newfile()?, + Mode::Newdir => status.selected().exec_newdir()?, + Mode::Chmod => status.exec_chmod()?, + Mode::Exec => status.selected().exec_exec()?, + Mode::Search => status.selected().exec_search(), + Mode::Goto => status.selected().exec_goto()?, + Mode::RegexMatch => status.exec_regex()?, + Mode::Jump => status.exec_jump()?, + Mode::History => status.selected().exec_history()?, + Mode::Shortcut => status.selected().exec_shortcut()?, Mode::Normal | Mode::NeedConfirmation | Mode::Help @@ -271,45 +273,60 @@ impl Actioner { | Mode::Marks(_) => (), } - tabs.selected().input.reset(); - tabs.selected().mode = Mode::Normal; + status.selected().input.reset(); + status.selected().mode = Mode::Normal; Ok(()) } /// Select this file - fn left_click(&self, tabs: &mut Status, row: u16) { - if let Mode::Normal = tabs.selected().mode { - tabs.selected().event_select_row(row) + fn left_click(&self, status: &mut Status, row: u16) { + if let Mode::Normal = status.selected().mode { + status.selected().event_select_row(row) } } /// Open a directory or a file - fn right_click(&self, tabs: &mut Status, row: u16) { - if let Mode::Normal = tabs.selected().mode { - let _ = tabs.selected().event_right_click(row); + fn right_click(&self, status: &mut Status, row: u16) { + if let Mode::Normal = status.selected().mode { + let _ = status.selected().event_right_click(row); } } /// Select next completion and insert it - fn tab(&self, tabs: &mut Status) -> FmResult<()> { - match tabs.selected().mode { + fn tab(&self, status: &mut Status) -> FmResult<()> { + match status.selected().mode { Mode::Goto | Mode::Exec | Mode::Search => { - tabs.selected().event_replace_input_with_completion() + status.selected().event_replace_input_with_completion() } - Mode::Normal => tabs.next(), + Mode::Normal => status.next(), _ => (), }; Ok(()) } - fn ctrl_f(&self, tabs: &mut Status) -> FmResult<()> { + fn ctrl_f(&self, status: &mut Status) -> FmResult<()> { let output = Skimer::new(self.term.clone()).no_source( - tabs.selected_non_mut() + status + .selected_non_mut() .path_str() .ok_or_else(|| FmError::new("skim error"))?, ); let _ = self.term.clear(); - tabs.create_tabs_from_skim(output); + status.create_tabs_from_skim(output); + Ok(()) + } + + fn ctrl_c(&self, status: &mut Status) -> FmResult<()> { + if let Mode::Normal = status.selected_non_mut().mode { + return status.selected_non_mut().event_filename_to_clipboard(); + } + Ok(()) + } + + fn ctrl_p(&self, status: &mut Status) -> FmResult<()> { + if let Mode::Normal = status.selected_non_mut().mode { + return status.selected_non_mut().event_filepath_to_clipboard(); + } Ok(()) } |