Skip to content

Commit

Permalink
Added directory sorting.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrueger committed Jan 6, 2025
1 parent 612e9e1 commit edc51f2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
5 changes: 4 additions & 1 deletion crates/icy_view_gui/src/items/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{
path::{Path, PathBuf},
};

use super::{zip::ZipFile, Item, ItemType, SixteenFolder};
use super::{sort_folder, zip::ZipFile, Item, ItemType, SixteenFolder};

pub struct ItemFolder {
pub path: PathBuf,
Expand Down Expand Up @@ -135,6 +135,9 @@ fn read_folder(path: &Path) -> Result<Vec<Box<dyn Item>>, std::io::Error> {
}
}
}
sort_folder(&mut directories);
sort_folder(&mut files);

#[cfg(windows)]
{
let drives = get_drives();
Expand Down
4 changes: 4 additions & 0 deletions crates/icy_view_gui/src/items/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,7 @@ impl dyn Item {
}
}
}

pub fn sort_folder(directories: &mut Vec<Box<dyn Item>>) {
directories.sort_by(|a, b| a.get_label().to_lowercase().cmp(&b.get_label().to_lowercase()));
}
4 changes: 2 additions & 2 deletions crates/icy_view_gui/src/items/sixteencolors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{path::PathBuf, str::FromStr};

use i18n_embed_fl::fl;

use super::{zip::ZipFile, Item, ItemType};
use super::{sort_folder, zip::ZipFile, Item, ItemType};

pub struct SixteenFolder {}

Expand Down Expand Up @@ -162,7 +162,7 @@ impl Item for SixteenFiles {
result.push(Box::new(SixteenFile::new(filename, location, uri)));
}
}
result.reverse();
sort_folder(&mut result);
}
Err(err) => {
log::error!("Error parsing json: {}", err);
Expand Down
3 changes: 2 additions & 1 deletion crates/icy_view_gui/src/items/zip.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{Item, ItemType};
use super::{sort_folder, Item, ItemType};
use std::{io::Read, path::PathBuf};

pub struct ZipFile {
Expand Down Expand Up @@ -58,6 +58,7 @@ impl Item for ZipFile {
log::error!("Error reading zip file: {:?}", self.get_file_path());
}
}
sort_folder(&mut files);
Some(files)
}
}
Expand Down

0 comments on commit edc51f2

Please sign in to comment.