summaryrefslogtreecommitdiffstats
path: root/src/commands/delete_files.rs
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2019-04-24 22:36:09 -0400
committerJiayi Zhao <jeff.no.zhao@gmail.com>2019-04-24 23:15:13 -0400
commit2be79f4cd0ee0e89c5cadf5121a8b979391d0d51 (patch)
treeadbd77abb51ea2a4613c78d210896f1ed55b4498 /src/commands/delete_files.rs
parentc3919c91a866a7fd520d7dcb8b99c7d4aafbbb93 (diff)
major refactoring
- removed parent_list from JoshutoTab struct - parent_list will behave much like previewing now where the contents will be retrieved from the dictionary - completely remove DirHistory struct in favour of trait implemenation on top of HashMap
Diffstat (limited to 'src/commands/delete_files.rs')
-rw-r--r--src/commands/delete_files.rs56
1 files changed, 27 insertions, 29 deletions
diff --git a/src/commands/delete_files.rs b/src/commands/delete_files.rs
index 035099d..e8d688a 100644
--- a/src/commands/delete_files.rs
+++ b/src/commands/delete_files.rs
@@ -32,42 +32,21 @@ impl DeleteFiles {
}
Ok(())
}
-}
-
-impl JoshutoCommand for DeleteFiles {}
-
-impl std::fmt::Display for DeleteFiles {
- fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
- f.write_str(Self::command())
- }
-}
-impl JoshutoRunnable for DeleteFiles {
- fn execute(
- &self,
- context: &mut JoshutoContext,
- view: &JoshutoView,
- ) -> Result<(), JoshutoError> {
+ fn delete_files(context: &mut JoshutoContext, view: &JoshutoView) -> Result<(), std::io::Error> {
ui::wprint_msg(&view.bot_win, "Delete selected files? (Y/n)");
ncurses::timeout(-1);
ncurses::doupdate();
+ let curr_tab = &mut context.tabs[context.curr_tab_index];
let ch: i32 = ncurses::getch();
if ch == 'y' as i32 || ch == keymap::ENTER as i32 {
- if let Some(s) = context.tabs[context.curr_tab_index].curr_list.as_ref() {
- if let Some(paths) = s.get_selected_paths() {
- match Self::remove_files(paths) {
- Ok(_) => ui::wprint_msg(&view.bot_win, "Deleted files"),
- Err(e) => return Err(JoshutoError::IO(e)),
- }
- }
+ if let Some(paths) = curr_tab.curr_list.get_selected_paths() {
+ Self::remove_files(paths)?;
+ ui::wprint_msg(&view.bot_win, "Deleted files");
}
- let curr_tab = &mut context.tabs[context.curr_tab_index];
- match curr_tab.reload_contents(&context.config_t.sort_option) {
- Err(e) => return Err(JoshutoError::IO(e)),
- _ => {}
- }
+ curr_tab.reload_contents(&context.config_t.sort_option)?;
curr_tab.refresh(
&view,
&context.config_t,
@@ -75,7 +54,6 @@ impl JoshutoRunnable for DeleteFiles {
&context.hostname,
);
} else {
- let curr_tab = &context.tabs[context.curr_tab_index];
curr_tab.refresh_file_status(&view.bot_win);
curr_tab.refresh_path_status(
&view.top_win,
@@ -84,9 +62,29 @@ impl JoshutoRunnable for DeleteFiles {
context.config_t.tilde_in_titlebar,
);
}
- let curr_tab = &mut context.tabs[context.curr_tab_index];
preview::preview_file(curr_tab, &view, &context.config_t);
ncurses::doupdate();
Ok(())
}
}
+
+impl JoshutoCommand for DeleteFiles {}
+
+impl std::fmt::Display for DeleteFiles {
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+ f.write_str(Self::command())
+ }
+}
+
+impl JoshutoRunnable for DeleteFiles {
+ fn execute(
+ &self,
+ context: &mut JoshutoContext,
+ view: &JoshutoView,
+ ) -> Result<(), JoshutoError> {
+ match Self::delete_files(context, view) {
+ Ok(_) => Ok(()),
+ Err(e) => Err(JoshutoError::IO(e)),
+ }
+ }
+}