blob: fa12565c5edb6292441f503ea8c4e82ddd821c19 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
use crate::context::AppContext;
use crate::error::JoshutoResult;
use crate::history::create_dirlist_with_history;
// reload only if we have a queued reload
pub fn soft_reload(index: usize, context: &mut AppContext) -> std::io::Result<()> {
let mut paths = Vec::with_capacity(3);
if let Some(curr_tab) = context.tab_context_ref().tab_ref(index) {
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 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(index)
.map(|t| t.history_mut())
{
for path in paths {
let new_dirlist =
create_dirlist_with_history(history, path.as_path(), &options, &tab_options)?;
history.insert(path, new_dirlist);
}
}
}
Ok(())
}
pub fn reload(context: &mut AppContext, index: usize) -> std::io::Result<()> {
let mut paths = Vec::with_capacity(3);
if let Some(curr_tab) = context.tab_context_ref().tab_ref(index) {
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());
}
}
if !paths.is_empty() {
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(index)
.map(|t| t.history_mut())
{
for path in paths {
let new_dirlist =
create_dirlist_with_history(history, path.as_path(), &options, &tab_options)?;
history.insert(path, new_dirlist);
}
}
}
context
.message_queue_mut()
.push_success("Directory listing reloaded!".to_string());
Ok(())
}
pub fn reload_dirlist(context: &mut AppContext) -> JoshutoResult {
reload(context, context.tab_context_ref().index)?;
Ok(())
}
|