diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-04-24 10:36:49 -0400 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-04-24 10:36:49 -0400 |
commit | 6e95a6600679e6787a56ec5ef2a88fe0fbcf031f (patch) | |
tree | 4495e3a2bbb12b96b0b767ab1b844040c7cc4c71 /src/commands/tab_switch.rs | |
parent | e9a0d00d46ba4955f7d45d12aa412462e3daab39 (diff) |
add more error handling
- optimize/cleanup code
Diffstat (limited to 'src/commands/tab_switch.rs')
-rw-r--r-- | src/commands/tab_switch.rs | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/src/commands/tab_switch.rs b/src/commands/tab_switch.rs index cc6a6fb..d5c349b 100644 --- a/src/commands/tab_switch.rs +++ b/src/commands/tab_switch.rs @@ -24,29 +24,34 @@ impl TabSwitch { new_index: usize, context: &mut JoshutoContext, view: &JoshutoView, - ) -> Result<(), JoshutoError> { + ) -> Result<(), std::io::Error> { context.curr_tab_index = new_index; let path = &context.curr_tab_ref().curr_path; - match env::set_current_dir(path) { - Ok(_) => { - { - let curr_tab = &mut context.tabs[context.curr_tab_index]; - curr_tab.reload_contents(&context.config_t.sort_option); - curr_tab.refresh( - view, - &context.config_t, - &context.username, - &context.hostname, - ); + env::set_current_dir(path)?; + { + let curr_tab = &mut context.tabs[context.curr_tab_index]; + if let Some(s) = curr_tab.curr_list.as_mut() { + if s.need_update() { + s.update_contents(&context.config_t.sort_option)?; } - ui::redraw_tab_view(&view.tab_win, &context); - let curr_tab = &mut context.tabs[context.curr_tab_index]; - preview::preview_file(curr_tab, view, &context.config_t); - ncurses::doupdate(); - Ok(()) } - Err(e) => Err(JoshutoError::IO(e)), + if let Some(s) = curr_tab.parent_list.as_mut() { + if s.need_update() { + s.update_contents(&context.config_t.sort_option)?; + } + } + curr_tab.refresh( + view, + &context.config_t, + &context.username, + &context.hostname, + ); } + ui::redraw_tab_view(&view.tab_win, &context); + let curr_tab = &mut context.tabs[context.curr_tab_index]; + preview::preview_file(curr_tab, view, &context.config_t); + ncurses::doupdate(); + Ok(()) } } @@ -73,6 +78,9 @@ impl JoshutoRunnable for TabSwitch { new_index -= tab_len; } let new_index = new_index as usize; - Self::tab_switch(new_index, context, view) + match Self::tab_switch(new_index, context, view) { + Ok(_) => Ok(()), + Err(e) => Err(JoshutoError::IO(e)), + } } } |