Skip to content

Commit

Permalink
Fix current path display on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
fluxxcode committed Jan 30, 2024
1 parent 0eac7a9 commit 4e141f7
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/file_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,42 @@ impl FileDialog {
let mut path = PathBuf::new();

if let Some(data) = self.current_directory() {
#[cfg(windows)]
let mut drive_letter = String::from("\\");

for (i, segment) in data.iter().enumerate() {
path.push(segment);

#[cfg(windows)]
let mut file_name = segment.to_str().unwrap_or("<ERR>");

#[cfg(windows)] {
// Skip the path namespace prefix generated by
// fs::canonicalize() on Windows
if i == 0 && file_name.contains(r"\\?\") {
drive_letter = file_name.replace(r"\\?\", "");
continue;
}

// Replace the root segment with the disk letter
if i == 1 && segment == "\\" {
file_name = drive_letter.as_str();
} else if i != 0 {
ui.label(">");
}
}

#[cfg(not(windows))]
let file_name = segment.to_str().unwrap_or("<ERR>");

#[cfg(not(windows))]
if i != 0 {
ui.label(">");
}

// TODO: Maybe use selectable_label instead of button?
// TODO: Write current directory (last item) in bold text
if ui.button(segment.to_str().unwrap_or("<ERR>")).clicked()
if ui.button(file_name).clicked()
{
let _ = self.load_directory(path.as_path());
return;
Expand Down

0 comments on commit 4e141f7

Please sign in to comment.