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