-
-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trash screen (which you obtain with `:open_trash` on compatible platforms) now has 2 optional columns: one for the size and one for the deletion date. Those internals work as expected: `:toggle_date`, `:toggle_size`, `:sort_by_date`, `:sort_by_size`.
- Loading branch information
Showing
13 changed files
with
360 additions
and
90 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,39 @@ | ||
|
||
#[cfg(feature = "trash")] | ||
mod trash_sort; | ||
mod trash_state; | ||
mod trash_state_cols; | ||
|
||
#[cfg(feature = "trash")] | ||
pub use trash_state::*; | ||
|
||
use { | ||
trash::{ | ||
self as trash_crate, | ||
TrashItem, | ||
TrashItemSize, | ||
}, | ||
}; | ||
|
||
/// Determine whether an item in the trash is a directory. | ||
/// | ||
/// There's probably a simpler solution in the trash crate, but I didn't found it. | ||
fn item_is_dir(item: &TrashItem) -> bool { | ||
match trash_crate::os_limited::metadata(item) { | ||
Ok(metadata) => { | ||
match metadata.size { | ||
TrashItemSize::Bytes(_) => false, | ||
TrashItemSize::Entries(_) => true, | ||
} | ||
} | ||
Err(_) => false, | ||
} | ||
} | ||
|
||
/// Return either the byte size or the number of entries of a trash item. | ||
/// | ||
/// Return None when it couldn't be determined. | ||
fn item_unified_size(item: &TrashItem) -> Option<u64> { | ||
match trash_crate::os_limited::metadata(item).ok()?.size { | ||
TrashItemSize::Bytes(v) => Some(v), | ||
TrashItemSize::Entries(v) => v.try_into().ok(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use { | ||
super::*, | ||
crate::{ | ||
tree::*, | ||
}, | ||
trash::{ | ||
TrashItem, | ||
}, | ||
}; | ||
|
||
/// Sort trash items according to the current tree options. | ||
pub fn sort( | ||
items: &mut [TrashItem], | ||
tree_options: &TreeOptions, | ||
) { | ||
info!("sorting itemsi by {:?}", tree_options.sort); | ||
match tree_options.sort { | ||
Sort::Date => items.sort_by_key(|item| std::cmp::Reverse(item.time_deleted)), | ||
Sort::Size => items.sort_by_key(|item| std::cmp::Reverse( | ||
item_unified_size(item).unwrap_or(0) | ||
)), | ||
_ => items.sort_by_key(|item| (item.name.clone(), item.original_parent.clone())), | ||
} | ||
|
||
} |
Oops, something went wrong.