diff --git a/crates/icy_view_gui/src/items/files.rs b/crates/icy_view_gui/src/items/files.rs index 39401cd..484e6ef 100644 --- a/crates/icy_view_gui/src/items/files.rs +++ b/crates/icy_view_gui/src/items/files.rs @@ -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, @@ -135,6 +135,9 @@ fn read_folder(path: &Path) -> Result>, std::io::Error> { } } } + sort_folder(&mut directories); + sort_folder(&mut files); + #[cfg(windows)] { let drives = get_drives(); diff --git a/crates/icy_view_gui/src/items/mod.rs b/crates/icy_view_gui/src/items/mod.rs index 82ac773..6b71fc5 100644 --- a/crates/icy_view_gui/src/items/mod.rs +++ b/crates/icy_view_gui/src/items/mod.rs @@ -110,3 +110,7 @@ impl dyn Item { } } } + +pub fn sort_folder(directories: &mut Vec>) { + directories.sort_by(|a, b| a.get_label().to_lowercase().cmp(&b.get_label().to_lowercase())); +} diff --git a/crates/icy_view_gui/src/items/sixteencolors.rs b/crates/icy_view_gui/src/items/sixteencolors.rs index ed41ee7..71036b8 100644 --- a/crates/icy_view_gui/src/items/sixteencolors.rs +++ b/crates/icy_view_gui/src/items/sixteencolors.rs @@ -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 {} @@ -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); diff --git a/crates/icy_view_gui/src/items/zip.rs b/crates/icy_view_gui/src/items/zip.rs index 97cde38..b04ad6b 100644 --- a/crates/icy_view_gui/src/items/zip.rs +++ b/crates/icy_view_gui/src/items/zip.rs @@ -1,4 +1,4 @@ -use super::{Item, ItemType}; +use super::{sort_folder, Item, ItemType}; use std::{io::Read, path::PathBuf}; pub struct ZipFile { @@ -58,6 +58,7 @@ impl Item for ZipFile { log::error!("Error reading zip file: {:?}", self.get_file_path()); } } + sort_folder(&mut files); Some(files) } }