summaryrefslogtreecommitdiffstats
path: root/src/commands/reload.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands/reload.rs')
-rw-r--r--src/commands/reload.rs122
1 files changed, 52 insertions, 70 deletions
diff --git a/src/commands/reload.rs b/src/commands/reload.rs
index bee7754..4134272 100644
--- a/src/commands/reload.rs
+++ b/src/commands/reload.rs
@@ -1,55 +1,44 @@
use crate::context::AppContext;
use crate::error::AppResult;
-use crate::history::create_dirlist_with_history;
+use crate::history::{create_dirlist_with_history, DirectoryHistory};
use uuid::Uuid;
// reload only if we have a queued reload
pub fn soft_reload(context: &mut AppContext, id: &Uuid) -> std::io::Result<()> {
- let mut paths = Vec::with_capacity(3);
+ let mut dirlists = Vec::with_capacity(3);
if let Some(curr_tab) = context.tab_context_ref().tab_ref(id) {
- if let Some(curr_list) = curr_tab.curr_list_ref() {
- if curr_list.need_update() {
- paths.push(curr_list.file_path().to_path_buf());
- }
- }
- if let Some(curr_list) = curr_tab.parent_list_ref() {
- if curr_list.need_update() {
- paths.push(curr_list.file_path().to_path_buf());
- }
- }
- if let Some(curr_list) = curr_tab.child_list_ref() {
- if curr_list.need_update() {
- paths.push(curr_list.file_path().to_path_buf());
- }
- }
- }
-
- if !paths.is_empty() {
- let config = context.config_ref().clone();
- let options = context.config_ref().display_options_ref().clone();
- let tab_options = context
- .tab_context_ref()
- .curr_tab_ref()
- .option_ref()
- .clone();
- if let Some(history) = context
- .tab_context_mut()
- .tab_mut(id)
- .map(|t| t.history_mut())
+ let config = context.config_ref();
+ let display_options = context.config_ref().display_options_ref();
+ let tab_options = context.tab_context_ref().curr_tab_ref().option_ref();
+ let history = curr_tab.history_ref();
+ for curr_list in [
+ curr_tab.parent_list_ref(),
+ curr_tab.curr_list_ref(),
+ curr_tab.child_list_ref(),
+ ]
+ .into_iter()
+ .flatten()
{
- for path in paths {
+ if curr_list.need_update() {
let new_dirlist = create_dirlist_with_history(
history,
- path.as_path(),
- &config,
- &options,
- &tab_options,
+ curr_list.file_path(),
+ display_options,
+ tab_options,
)?;
- history.insert(path, new_dirlist);
+ dirlists.push(new_dirlist);
}
}
}
+
+ if let Some(history) = context
+ .tab_context_mut()
+ .tab_mut(id)
+ .map(|t| t.history_mut())
+ {
+ history.insert_entries(dirlists);
+ }
Ok(())
}
@@ -59,43 +48,36 @@ pub fn soft_reload_curr_tab(context: &mut AppContext) -> std::io::Result<()> {
}
pub fn reload(context: &mut AppContext, id: &Uuid) -> std::io::Result<()> {
- let mut paths = Vec::with_capacity(3);
+ let mut dirlists = Vec::with_capacity(3);
if let Some(curr_tab) = context.tab_context_ref().tab_ref(id) {
- if let Some(curr_list) = curr_tab.curr_list_ref() {
- paths.push(curr_list.file_path().to_path_buf());
- }
- if let Some(curr_list) = curr_tab.parent_list_ref() {
- paths.push(curr_list.file_path().to_path_buf());
- }
- if let Some(curr_list) = curr_tab.child_list_ref() {
- paths.push(curr_list.file_path().to_path_buf());
+ let config = context.config_ref();
+ let display_options = context.config_ref().display_options_ref();
+ let tab_options = context.tab_context_ref().curr_tab_ref().option_ref();
+ let history = curr_tab.history_ref();
+ for curr_list in [
+ curr_tab.parent_list_ref(),
+ curr_tab.curr_list_ref(),
+ curr_tab.child_list_ref(),
+ ]
+ .into_iter()
+ .flatten()
+ {
+ let new_dirlist = create_dirlist_with_history(
+ history,
+ curr_list.file_path(),
+ display_options,
+ tab_options,
+ )?;
+ dirlists.push(new_dirlist);
}
}
- if !paths.is_empty() {
- let config = context.config_ref().clone();
- let options = context.config_ref().display_options_ref().clone();
- let tab_options = context
- .tab_context_ref()
- .curr_tab_ref()
- .option_ref()
- .clone();
- if let Some(history) = context
- .tab_context_mut()
- .tab_mut(id)
- .map(|t| t.history_mut())
- {
- for path in paths {
- let new_dirlist = create_dirlist_with_history(
- history,
- path.as_path(),
- &config,
- &options,
- &tab_options,
- )?;
- history.insert(path, new_dirlist);
- }
- }
+ if let Some(history) = context
+ .tab_context_mut()
+ .tab_mut(id)
+ .map(|t| t.history_mut())
+ {
+ history.insert_entries(dirlists);
}
context
.message_queue_mut()