Enable extracting zip files to current folder

This commit is contained in:
Nathan Rowe 2024-08-15 12:32:12 -05:00
parent e4c65883fd
commit ef23ff77e1
6 changed files with 360 additions and 0 deletions

View file

@ -9,6 +9,7 @@ use cosmic::{
widget::menu::{self, key_bind::KeyBind, ItemHeight, ItemWidth, MenuBar},
Element,
};
use mime_guess::Mime;
use std::collections::HashMap;
use crate::{
@ -79,6 +80,7 @@ pub fn context_menu<'a>(
let mut selected_dir = 0;
let mut selected = 0;
let mut selected_types: Vec<Mime> = vec![];
tab.items_opt().map(|items| {
for item in items.iter() {
if item.selected {
@ -86,9 +88,12 @@ pub fn context_menu<'a>(
if item.metadata.is_dir() {
selected_dir += 1;
}
selected_types.push(item.mime.clone());
}
}
});
selected_types.sort_unstable();
selected_types.dedup();
let mut children: Vec<Element<_>> = Vec::new();
match tab.location {
@ -119,6 +124,16 @@ pub fn context_menu<'a>(
children.push(menu_item(fl!("rename"), Action::Rename).into());
children.push(menu_item(fl!("cut"), Action::Cut).into());
children.push(menu_item(fl!("copy"), Action::Copy).into());
let supported_archive_types = ["application/x-tar", "application/zip"]
.iter()
.filter_map(|mime_type| mime_type.parse::<Mime>().ok())
.collect::<Vec<_>>();
selected_types.retain(|t| !supported_archive_types.contains(t));
if selected_types.is_empty() {
children.push(menu_item(fl!("extract-here"), Action::ExtractHere).into());
}
//TODO: Print?
children.push(container(horizontal_rule(1)).padding([0, 8]).into());
children.push(menu_item(fl!("show-details"), Action::Properties).into());