@@ -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,6 +97,15 @@ 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| {
@@ -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