INNER CODE UNIT · Rust
preview_file
abenz1267/walker · src/preview/mod.rs:204
pub fn preview_file(&mut self, file_path: &str) -> Result<(), Box<dyn std::error::Error>> {
// Providers (e.g. the clipboard) may hand us a `file://` URI rather than a
// plain path; strip the scheme so Path::exists()/mime detection/drag source
// all operate on a real filesystem path.
let file_path = file_path.strip_prefix("file://").unwrap_or(file_path);
self.current_content = format!("file{}", file_path);
self.clear_preview();
if Path::new(file_path).is_absolute() {
self.box_widget
.add_controller(create_drag_source(file_path));
}
if !Path::new(file_path).exists() {
return Err(format!("File does not exist: {}", file_path).into());
}
let Some(guess) = new_mime_guess::from_path(file_path).first() else {