diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-04-24 22:36:09 -0400 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-04-24 23:15:13 -0400 |
commit | 2be79f4cd0ee0e89c5cadf5121a8b979391d0d51 (patch) | |
tree | adbd77abb51ea2a4613c78d210896f1ed55b4498 /src/commands/rename_file.rs | |
parent | c3919c91a866a7fd520d7dcb8b99c7d4aafbbb93 (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/rename_file.rs')
-rw-r--r-- | src/commands/rename_file.rs | 44 |
1 files changed, 18 insertions, 26 deletions
diff --git a/src/commands/rename_file.rs b/src/commands/rename_file.rs index 2c4ea00..6fbc7c8 100644 --- a/src/commands/rename_file.rs +++ b/src/commands/rename_file.rs @@ -35,7 +35,7 @@ impl RenameFile { context: &mut JoshutoContext, view: &JoshutoView, start_str: String, - ) -> Result<(), JoshutoError> { + ) -> Result<(), std::io::Error> { const PROMPT: &str = ":rename_file "; let (term_rows, term_cols) = ui::getmaxyx(); let user_input: Option<String> = { @@ -68,20 +68,14 @@ impl RenameFile { std::io::ErrorKind::AlreadyExists, "Filename already exists", ); - return Err(JoshutoError::IO(err)); - } - match fs::rename(&path, &new_path) { - Ok(_) => { - let curr_tab = &mut context.tabs[context.curr_tab_index]; - if let Some(ref mut s) = curr_tab.curr_list { - s.update_contents(&context.config_t.sort_option).unwrap(); - } - curr_tab.refresh_curr(&view.mid_win, context.config_t.scroll_offset); - } - Err(e) => { - return Err(JoshutoError::IO(e)); - } + return Err(err); } + std::fs::rename(&path, &new_path)?; + let curr_tab = &mut context.tabs[context.curr_tab_index]; + curr_tab + .curr_list + .update_contents(&context.config_t.sort_option)?; + curr_tab.refresh_curr(&view.mid_win, context.config_t.scroll_offset); } else { let curr_tab = &context.tabs[context.curr_tab_index]; curr_tab.refresh_file_status(&view.bot_win); @@ -107,23 +101,21 @@ impl JoshutoRunnable for RenameFile { let mut path: Option<path::PathBuf> = None; let mut file_name: Option<String> = None; - if let Some(s) = context.tabs[context.curr_tab_index].curr_list.as_ref() { - if let Some(s) = s.get_curr_ref() { - path = Some(s.path.clone()); - file_name = Some(s.file_name_as_string.clone()); - } + let curr_list = &context.tabs[context.curr_tab_index].curr_list; + if let Some(s) = curr_list.get_curr_ref() { + path = Some(s.path.clone()); + file_name = Some(s.file_name_as_string.clone()); } if let Some(file_name) = file_name { if let Some(path) = path { - let res = self.rename_file(&path, context, view, file_name.clone()); - preview::preview_file( - &mut context.tabs[context.curr_tab_index], - view, - &context.config_t, - ); + match self.rename_file(&path, context, view, file_name.clone()) { + Ok(_) => {}, + Err(e) => return Err(JoshutoError::IO(e)), + } + let curr_tab = &mut context.tabs[context.curr_tab_index]; + preview::preview_file(curr_tab, view, &context.config_t); ncurses::doupdate(); - return res; } } return Ok(()); |