@@ -15,6 +15,8 @@ pub enum SortMode {
1515 MTimeAscending ,
1616 CountDescending ,
1717 CountAscending ,
18+ NameDescending ,
19+ NameAscending ,
1820}
1921
2022impl SortMode {
@@ -44,6 +46,15 @@ impl SortMode {
4446 _ => CountDescending ,
4547 }
4648 }
49+
50+ pub fn toggle_name ( & mut self ) {
51+ use SortMode :: * ;
52+ * self = match self {
53+ NameAscending => NameDescending ,
54+ NameDescending => NameAscending ,
55+ _ => NameAscending ,
56+ }
57+ }
4758}
4859
4960pub struct EntryDataBundle {
@@ -86,17 +97,26 @@ pub fn sorted_entries(
8697 . cmp ( & r. entry_count )
8798 . then_with ( || l. name . cmp ( & r. name ) )
8899 }
100+ fn cmp_name ( l : & EntryDataBundle , r : & EntryDataBundle ) -> Ordering {
101+ if l. is_dir && !r. is_dir {
102+ Ordering :: Less
103+ } else if !l. is_dir && r. is_dir {
104+ Ordering :: Greater
105+ } else {
106+ l. name . cmp ( & r. name )
107+ }
108+ }
89109 tree. neighbors_directed ( node_idx, Direction :: Outgoing )
90110 . filter_map ( |idx| {
91111 tree. node_weight ( idx) . map ( |entry| {
92- let use_glob_path = glob_root. map_or ( false , |glob_root| glob_root == node_idx) ;
112+ let use_glob_path = glob_root. is_some_and ( |glob_root| glob_root == node_idx) ;
93113 let ( path, exists, is_dir) = {
94114 let path = path_of ( tree, idx, glob_root) ;
95115 if matches ! ( check, EntryCheck :: Disabled ) || glob_root == Some ( node_idx) {
96116 ( path, true , entry. is_dir )
97117 } else {
98118 let meta = path. symlink_metadata ( ) ;
99- ( path, meta. is_ok ( ) , meta. ok ( ) . map_or ( false , |m| m. is_dir ( ) ) )
119+ ( path, meta. is_ok ( ) , meta. ok ( ) . is_some_and ( |m| m. is_dir ( ) ) )
100120 }
101121 } ;
102122 EntryDataBundle {
@@ -121,6 +141,8 @@ pub fn sorted_entries(
121141 MTimeDescending => r. mtime . cmp ( & l. mtime ) ,
122142 CountAscending => cmp_count ( l, r) ,
123143 CountDescending => cmp_count ( l, r) . reverse ( ) ,
144+ NameAscending => cmp_name ( l, r) ,
145+ NameDescending => cmp_name ( l, r) . reverse ( ) ,
124146 } )
125147 . collect ( )
126148}
0 commit comments