Pass application context to GUI. #11
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -303,6 +303,7 @@ dependencies = [
|
||||
"syntect",
|
||||
"tui-logger",
|
||||
"tui-tree-widget",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@ -17,6 +17,7 @@ tui-tree-widget = "0.24.0"
|
||||
tui-logger = "0.18.1"
|
||||
edtui = "0.11.1"
|
||||
strum = "0.27.2"
|
||||
uuid = { version = "1.19.0", features = ["v4"] }
|
||||
|
||||
[build-dependencies]
|
||||
# The link_qt_object_files feature is required for statically linking Qt 6.
|
||||
|
||||
@ -39,23 +39,24 @@ impl<'a> Explorer<'a> {
|
||||
|
||||
fn build_tree_from_path(path: PathBuf) -> Result<TreeItem<'static, String>> {
|
||||
let mut children = vec![];
|
||||
if let Ok(entries) = fs::read_dir(&path) {
|
||||
let clean_path = fs::canonicalize(path)?;
|
||||
if let Ok(entries) = fs::read_dir(&clean_path) {
|
||||
let mut paths = entries
|
||||
.map(|res| res.map(|e| e.path()))
|
||||
.collect::<Result<Vec<_>, std::io::Error>>()
|
||||
.context(format!(
|
||||
"Failed to build vector of paths under directory: {:?}",
|
||||
path
|
||||
clean_path
|
||||
))?;
|
||||
paths.sort();
|
||||
for path in paths {
|
||||
if path.is_dir() {
|
||||
children.push(Self::build_tree_from_path(path)?);
|
||||
} else {
|
||||
if let Ok(path) = std::path::absolute(&path) {
|
||||
if let Ok(path) = fs::canonicalize(&path) {
|
||||
let path_str = path.to_string_lossy().to_string();
|
||||
children.push(TreeItem::new_leaf(
|
||||
path_str,
|
||||
path_str + uuid::Uuid::new_v4().to_string().as_str(),
|
||||
path.file_name()
|
||||
.context("Failed to get file name from path.")?
|
||||
.to_string_lossy()
|
||||
@ -66,22 +67,16 @@ impl<'a> Explorer<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
let abs = std::path::absolute(&path)
|
||||
.context(format!(
|
||||
"Failed to find absolute path for TreeItem: {:?}",
|
||||
path
|
||||
))?
|
||||
.to_string_lossy()
|
||||
.to_string();
|
||||
TreeItem::new(
|
||||
abs,
|
||||
path.file_name()
|
||||
.expect("Failed to get file name from path.")
|
||||
clean_path.to_string_lossy().to_string() + uuid::Uuid::new_v4().to_string().as_str(),
|
||||
clean_path
|
||||
.file_name()
|
||||
.context(format!("Failed to get file name from path: {clean_path:?}"))?
|
||||
.to_string_lossy()
|
||||
.to_string(),
|
||||
children,
|
||||
)
|
||||
.context("Failed to build tree from path.")
|
||||
.context(format!("Failed to build tree from path: {clean_path:?}"))
|
||||
}
|
||||
|
||||
pub fn selected(&self) -> Result<String> {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user