diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-05-30 22:15:35 -0400 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-05-30 22:15:35 -0400 |
commit | 70c8251b479e745edeb080058c1b95bf677684e1 (patch) | |
tree | a654e33e23fa6aa17ca8977807753209c312b39e /src/commands/reload_dir.rs | |
parent | 5980d762dba38b003dbe54506cdd58ee85f97c8c (diff) |
move reloading of directory content into reload_dir.rs rather than tab.rs
Diffstat (limited to 'src/commands/reload_dir.rs')
-rw-r--r-- | src/commands/reload_dir.rs | 60 |
1 files changed, 45 insertions, 15 deletions
diff --git a/src/commands/reload_dir.rs b/src/commands/reload_dir.rs index fc0dd78..bd7c913 100644 --- a/src/commands/reload_dir.rs +++ b/src/commands/reload_dir.rs @@ -1,8 +1,11 @@ use crate::commands::{JoshutoCommand, JoshutoRunnable}; use crate::context::JoshutoContext; use crate::error::JoshutoError; +use crate::structs::JoshutoDirList; use crate::window::JoshutoView; +use std::collections::hash_map::Entry; + #[derive(Clone, Debug)] pub struct ReloadDirList; @@ -14,20 +17,45 @@ impl ReloadDirList { "reload_dir_list" } - pub fn reload(context: &mut JoshutoContext, view: &JoshutoView) -> Result<(), std::io::Error> { - let curr_tab = &mut context.tabs[context.curr_tab_index]; - let dir_len = curr_tab.curr_list.contents.len(); - match curr_tab.curr_list.index { - None => {} - Some(s) => { - curr_tab.curr_list.pagestate.update_page_state( - s, - view.mid_win.rows, - dir_len, - context.config_t.scroll_offset, - ); - curr_tab.reload_contents(&context.config_t.sort_option)?; - curr_tab.refresh(view, &context.config_t); + pub fn reload( + index: usize, + context: &mut JoshutoContext, + view: &JoshutoView, + ) -> Result<(), std::io::Error> { + let curr_tab = &mut context.tabs[index]; + let sort_option = &context.config_t.sort_option; + curr_tab.curr_list.update_contents(sort_option)?; + if let Some(s) = curr_tab.curr_list.index { + let dir_len = curr_tab.curr_list.contents.len(); + curr_tab.curr_list.pagestate.update_page_state( + s, + view.mid_win.rows, + dir_len, + context.config_t.scroll_offset, + ); + curr_tab.curr_list.outdated = false; + } + + if let Some(parent) = curr_tab.curr_list.path.parent() { + match curr_tab.history.entry(parent.to_path_buf().clone()) { + Entry::Occupied(mut entry) => { + let dirlist = entry.get_mut(); + dirlist.update_contents(sort_option)?; + if let Some(s) = dirlist.index { + let dir_len = dirlist.contents.len(); + dirlist.pagestate.update_page_state( + s, + view.mid_win.rows, + dir_len, + context.config_t.scroll_offset, + ); + dirlist.outdated = false; + } + } + Entry::Vacant(entry) => { + let s = JoshutoDirList::new(parent.to_path_buf().clone(), sort_option)?; + entry.insert(s); + } } } Ok(()) @@ -48,8 +76,10 @@ impl JoshutoRunnable for ReloadDirList { context: &mut JoshutoContext, view: &JoshutoView, ) -> Result<(), JoshutoError> { - match Self::reload(context, view) { + match Self::reload(context.curr_tab_index, context, view) { Ok(_) => { + let curr_tab = &mut context.tabs[context.curr_tab_index]; + curr_tab.refresh(view, &context.config_t); ncurses::doupdate(); Ok(()) } |