|
|
|
@ -1,8 +1,4 @@
|
|
|
|
|
use crate::app::DirectoryBuffer;
|
|
|
|
|
use crate::app::ExplorerConfig;
|
|
|
|
|
use crate::app::Node;
|
|
|
|
|
use crate::app::Task;
|
|
|
|
|
use crate::app::{InternalMsg, MsgIn};
|
|
|
|
|
use crate::app::{DirectoryBuffer, ExplorerConfig, ExternalMsg, InternalMsg, MsgIn, Node, Task};
|
|
|
|
|
use std::fs;
|
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
use std::sync::mpsc::Sender;
|
|
|
|
@ -20,39 +16,49 @@ pub fn explore(
|
|
|
|
|
let config_cloned = config.clone();
|
|
|
|
|
|
|
|
|
|
thread::spawn(move || {
|
|
|
|
|
let nodes: Vec<Node> = fs::read_dir(&path)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.filter_map(|d| {
|
|
|
|
|
d.ok().map(|e| {
|
|
|
|
|
e.path()
|
|
|
|
|
.file_name()
|
|
|
|
|
.map(|n| n.to_string_lossy().to_string())
|
|
|
|
|
.unwrap_or_default()
|
|
|
|
|
fs::read_dir(&path)
|
|
|
|
|
.map(|dirs| {
|
|
|
|
|
dirs.filter_map(|d| {
|
|
|
|
|
d.ok().map(|e| {
|
|
|
|
|
e.path()
|
|
|
|
|
.file_name()
|
|
|
|
|
.map(|n| n.to_string_lossy().to_string())
|
|
|
|
|
.unwrap_or_default()
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
.map(|name| Node::new(parent.clone(), name))
|
|
|
|
|
.filter(|n| config.apply(n))
|
|
|
|
|
.collect::<Vec<Node>>()
|
|
|
|
|
})
|
|
|
|
|
.map(|name| Node::new(parent.clone(), name))
|
|
|
|
|
.filter(|n| config.apply(n))
|
|
|
|
|
.collect();
|
|
|
|
|
.map(|nodes| {
|
|
|
|
|
let focus_index = if let Some(focus) = focused_path {
|
|
|
|
|
nodes
|
|
|
|
|
.iter()
|
|
|
|
|
.enumerate()
|
|
|
|
|
.find(|(_, n)| n.relative_path == focus)
|
|
|
|
|
.map(|(i, _)| i)
|
|
|
|
|
.unwrap_or(0)
|
|
|
|
|
} else {
|
|
|
|
|
0
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let focus_index = if let Some(focus) = focused_path {
|
|
|
|
|
nodes
|
|
|
|
|
.iter()
|
|
|
|
|
.enumerate()
|
|
|
|
|
.find(|(_, n)| n.relative_path == focus)
|
|
|
|
|
.map(|(i, _)| i)
|
|
|
|
|
.unwrap_or(0)
|
|
|
|
|
} else {
|
|
|
|
|
0
|
|
|
|
|
};
|
|
|
|
|
let dir = DirectoryBuffer::new(parent.clone(), nodes, focus_index);
|
|
|
|
|
|
|
|
|
|
let dir = DirectoryBuffer::new(parent.clone(), nodes, focus_index);
|
|
|
|
|
|
|
|
|
|
tx.send(Task::new(
|
|
|
|
|
1,
|
|
|
|
|
MsgIn::Internal(InternalMsg::AddDirectory(parent, dir)),
|
|
|
|
|
None,
|
|
|
|
|
))
|
|
|
|
|
.unwrap();
|
|
|
|
|
tx.send(Task::new(
|
|
|
|
|
1,
|
|
|
|
|
MsgIn::Internal(InternalMsg::AddDirectory(parent, dir)),
|
|
|
|
|
None,
|
|
|
|
|
))
|
|
|
|
|
.unwrap();
|
|
|
|
|
})
|
|
|
|
|
.unwrap_or_else(|e| {
|
|
|
|
|
tx.send(Task::new(
|
|
|
|
|
1,
|
|
|
|
|
MsgIn::External(ExternalMsg::LogError(e.to_string())),
|
|
|
|
|
None,
|
|
|
|
|
))
|
|
|
|
|
.unwrap();
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if let Some(grand_parent) = path_cloned.parent() {
|
|
|
|
|