summaryrefslogtreecommitdiffstats
path: root/src/commands/reload.rs
diff options
context:
space:
mode:
authorJeff Zhao <jeff.no.zhao@gmail.com>2022-08-31 11:11:06 -0400
committerGitHub <noreply@github.com>2022-08-31 11:11:06 -0400
commit0ca4ffd657f1a2884ca8422be8a78baa42f00de4 (patch)
tree408c91b138707942b4c7736893e4ecbefbe9a544 /src/commands/reload.rs
parentcd838711107303e4c6076df5bc38b2b74c819480 (diff)
use hashmap and uuid to store tabs (#194)
This is preliminary changes in order to track preview threads and progress. The current setup is we just kick off a new thread to load the given directory whenever we see the directory content does not exist in history. We don't track these threads or which tab these requests came from. When the result is returned, we just assign it to the current tab, instead of the tab that actually initiated the request. By adding uuid, we can now track which tab requested the preview and assign it accordingly. This will also allow us to track the status of the preview, so we can display to the user a loading state, when a directory is taking longer than usual to load. This will also solve the problem of kicking off multiple threads to read the same directory for the same tab. Now these threads can be stored and tracked. - side: fix reload not honouring tab sort options - use tab specific options whenever we need to reload stuff
Diffstat (limited to 'src/commands/reload.rs')
-rw-r--r--src/commands/reload.rs21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/commands/reload.rs b/src/commands/reload.rs
index fa12565..f7197c1 100644
--- a/src/commands/reload.rs
+++ b/src/commands/reload.rs
@@ -2,10 +2,12 @@ use crate::context::AppContext;
use crate::error::JoshutoResult;
use crate::history::create_dirlist_with_history;
+use uuid::Uuid;
+
// reload only if we have a queued reload
-pub fn soft_reload(index: usize, context: &mut AppContext) -> std::io::Result<()> {
+pub fn soft_reload(context: &mut AppContext, id: &Uuid) -> 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_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());
@@ -32,7 +34,7 @@ pub fn soft_reload(index: usize, context: &mut AppContext) -> std::io::Result<()
.clone();
if let Some(history) = context
.tab_context_mut()
- .tab_mut(index)
+ .tab_mut(id)
.map(|t| t.history_mut())
{
for path in paths {
@@ -45,9 +47,14 @@ pub fn soft_reload(index: usize, context: &mut AppContext) -> std::io::Result<()
Ok(())
}
-pub fn reload(context: &mut AppContext, index: usize) -> std::io::Result<()> {
+pub fn soft_reload_curr_tab(context: &mut AppContext) -> std::io::Result<()> {
+ let curr_tab_id = context.tab_context_ref().curr_tab_id();
+ soft_reload(context, &curr_tab_id)
+}
+
+pub fn reload(context: &mut AppContext, id: &Uuid) -> 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_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());
}
@@ -68,7 +75,7 @@ pub fn reload(context: &mut AppContext, index: usize) -> std::io::Result<()> {
.clone();
if let Some(history) = context
.tab_context_mut()
- .tab_mut(index)
+ .tab_mut(id)
.map(|t| t.history_mut())
{
for path in paths {
@@ -85,6 +92,6 @@ pub fn reload(context: &mut AppContext, index: usize) -> std::io::Result<()> {
}
pub fn reload_dirlist(context: &mut AppContext) -> JoshutoResult {
- reload(context, context.tab_context_ref().index)?;
+ reload(context, &context.tab_context_ref().curr_tab_id())?;
Ok(())
}