diff options
author | quentin konieczko <konieczko@gmail.com> | 2023-03-03 13:40:48 +0100 |
---|---|---|
committer | quentin konieczko <konieczko@gmail.com> | 2023-03-03 13:40:48 +0100 |
commit | 3e32e6672d772be7a001687f5d2c7dde2414b721 (patch) | |
tree | 33c7a074427fb4bf99f79dac0d90817475c9f2db | |
parent | 72f4ee4eec753a6c2fa959fe1994f74c6c8b76ed (diff) |
menu for bulk - incomplete
-rw-r--r-- | src/action_map.rs | 2 | ||||
-rw-r--r-- | src/bulkrename.rs | 26 | ||||
-rw-r--r-- | src/event_exec.rs | 17 | ||||
-rw-r--r-- | src/help.rs | 3 | ||||
-rw-r--r-- | src/keybindings.rs | 1 | ||||
-rw-r--r-- | src/mode.rs | 3 | ||||
-rw-r--r-- | src/status.rs | 4 | ||||
-rw-r--r-- | src/term_manager.rs | 17 |
8 files changed, 72 insertions, 1 deletions
diff --git a/src/action_map.rs b/src/action_map.rs index b96e23e..d645a7e 100644 --- a/src/action_map.rs +++ b/src/action_map.rs @@ -14,6 +14,7 @@ pub enum ActionMap { Back, BackTab, Backspace, + Bulk, Bulkrename, Bulknew, Chmod, @@ -102,6 +103,7 @@ impl ActionMap { ActionMap::Back => EventExec::event_back(status, colors), ActionMap::BackTab => EventExec::backtab(status), ActionMap::Backspace => EventExec::event_backspace(status), + ActionMap::Bulk => EventExec::event_bulk(status), ActionMap::Bulkrename => EventExec::event_bulkrename(status), ActionMap::Bulknew => EventExec::event_bulknew(status), ActionMap::Chmod => EventExec::event_chmod(status), diff --git a/src/bulkrename.rs b/src/bulkrename.rs index 5db7a89..6603ae6 100644 --- a/src/bulkrename.rs +++ b/src/bulkrename.rs @@ -7,7 +7,9 @@ use std::time::{Duration, SystemTime}; use crate::constant_strings_paths::TMP_FOLDER_PATH; use crate::fm_error::{FmError, FmResult}; +use crate::impl_selectable_content; use crate::opener::Opener; +use crate::status::Status; /// Struct holding informations about files about to be renamed. /// We only need to know which are the original filenames and which @@ -186,3 +188,27 @@ impl<'a> Bulkrename<'a> { Ok(()) } } + +pub struct Bulk { + pub content: Vec<String>, + index: usize, +} + +impl Bulk { + pub fn default() -> Self { + Self { + content: vec!["Rename".to_owned(), "New".to_owned()], + index: 0, + } + } + + pub fn execute_bulk(&self, status: &Status) -> FmResult<()> { + if self.index == 0 { + Bulkrename::renamer(status.filtered_flagged_files())?.rename(&status.opener) + } else { + Bulkrename::creator(status.selected_path_str())?.create(&status.opener) + } + } +} + +impl_selectable_content!(String, Bulk); diff --git a/src/event_exec.rs b/src/event_exec.rs index 59dad0e..7723c43 100644 --- a/src/event_exec.rs +++ b/src/event_exec.rs @@ -246,6 +246,22 @@ impl EventExec { status.selected().refresh_view() } + pub fn event_bulk(status: &mut Status) -> FmResult<()> { + status.selected().refresh_view() + } + + pub fn event_bulk_prev(status: &mut Status) { + status.bulk.prev() + } + + pub fn event_bulk_next(status: &mut Status) { + status.bulk.next() + } + + pub fn exec_bulk(status: &mut Status) -> FmResult<()> { + status.bulk.execute_bulk(status) + } + /// Copy the flagged file to current directory. /// A progress bar is displayed and a notification is sent once it's done. pub fn exec_copy_paste(status: &mut Status) -> FmResult<()> { @@ -1365,6 +1381,7 @@ impl EventExec { Mode::Navigate(Navigate::History) => EventExec::exec_history(status.selected())?, Mode::Navigate(Navigate::Shortcut) => EventExec::exec_shortcut(status.selected())?, Mode::Navigate(Navigate::Trash) => EventExec::event_trash_restore_file(status)?, + Mode::Navigate(Navigate::Bulk) => EventExec::exec_bulk(status)?, Mode::Navigate(Navigate::EncryptedDrive) => (), Mode::InputCompleted(InputCompleted::Exec) => EventExec::exec_exec(status.selected())?, Mode::InputCompleted(InputCompleted::Search) => { diff --git a/src/help.rs b/src/help.rs index aad5c07..b31ee12 100644 --- a/src/help.rs +++ b/src/help.rs @@ -55,7 +55,8 @@ static HELP_TO_FORMAT: &str = " {ReverseFlags}: reverse flags {Symlink}: symlink files {Bulkrename}: bulkrename files -{Bulknew}: bulknew files +{Bulkrename}: bulkrename files +{Bulk}: bulknew files {CopyPaste}: copy to current dir {CutPaste}: move to current dir {DeleteFile}: delete files permanently diff --git a/src/keybindings.rs b/src/keybindings.rs index e2baff9..0004cef 100644 --- a/src/keybindings.rs +++ b/src/keybindings.rs @@ -47,6 +47,7 @@ impl Bindings { (Key::Char(':'), ActionMap::Command), (Key::Char('B'), ActionMap::Bulkrename), (Key::Ctrl('b'), ActionMap::Bulknew), + (Key::Alt('b'), ActionMap::Bulk), (Key::Char('C'), ActionMap::Compress), (Key::Char('E'), ActionMap::EncryptedDrive), (Key::Char('F'), ActionMap::Filter), diff --git a/src/mode.rs b/src/mode.rs index 8bcf3ea..e1748ce 100644 --- a/src/mode.rs +++ b/src/mode.rs @@ -98,6 +98,8 @@ pub enum Navigate { Marks(MarkAction), /// Pick a compression method Compress, + /// + Bulk, } /// Different mode in which the application can be. @@ -150,6 +152,7 @@ impl fmt::Display for Mode { Mode::Navigate(Navigate::History) => write!(f, "History :"), Mode::Navigate(Navigate::Shortcut) => write!(f, "Shortcut :"), Mode::Navigate(Navigate::Trash) => write!(f, "Trash :"), + Mode::Navigate(Navigate::Bulk) => write!(f, "Bulk :"), Mode::Navigate(Navigate::Compress) => write!(f, "Compress :"), Mode::Navigate(Navigate::EncryptedDrive) => { write!(f, "Encrypted devices :") diff --git a/src/status.rs b/src/status.rs index 67665cc..cd4abbb 100644 --- a/src/status.rs +++ b/src/status.rs @@ -10,6 +10,7 @@ use tuikit::term::Term; use users::UsersCache; use crate::args::Args; +use crate::bulkrename::Bulk; use crate::compress::Compresser; use crate::config::Colors; use crate::constant_strings_paths::OPENER_PATH; @@ -69,6 +70,7 @@ pub struct Status { /// NVIM RPC server address pub nvim_server: String, pub force_clear: bool, + pub bulk: Bulk, } impl Status { @@ -104,6 +106,7 @@ impl Status { let trash = Trash::new()?; let compression = Compresser::default(); let force_clear = false; + let bulk = Bulk::default(); Ok(Self { tabs: [left_tab, right_tab], @@ -123,6 +126,7 @@ impl Status { compression, nvim_server, force_clear, + bulk, }) } diff --git a/src/term_manager.rs b/src/term_manager.rs index 57467e8..3e1b679 100644 --- a/src/term_manager.rs +++ b/src/term_manager.rs @@ -396,6 +396,7 @@ impl<'a> Draw for WinSecondary<'a> { Mode::Navigate(Navigate::Shortcut) => self.destination(canvas, &self.tab.shortcut), Mode::Navigate(Navigate::Trash) => self.trash(canvas, &self.status.trash), Mode::Navigate(Navigate::Compress) => self.compress(canvas, &self.status.compression), + Mode::Navigate(Navigate::Bulk) => self.bulk(canvas, &self.status.bulk), Mode::Navigate(Navigate::EncryptedDrive) => { self.encrypted_devices(self.status, self.tab, canvas) } @@ -527,6 +528,22 @@ impl<'a> WinSecondary<'a> { Ok(()) } + fn bulk( + &self, + canvas: &mut dyn Canvas, + selectable: &impl SelectableContent<String>, + ) -> FmResult<()> { + canvas.print(0, 0, "Action...")?; + for (row, text) in selectable.content().iter().enumerate() { + let mut attr = Attr::default(); + if row == selectable.index() { + attr.effect |= Effect::REVERSE; + } + let _ = canvas.print_with_attr(row + ContentWindow::WINDOW_MARGIN_TOP, 4, text, attr); + } + Ok(()) + } + fn trash( &self, canvas: &mut dyn Canvas, |