feat: Extract archive to a specified location

This commit is contained in:
johnoye742 2025-03-17 13:01:08 +01:00
parent 37efa077e8
commit c7a411d3de

View file

@ -110,6 +110,7 @@ pub enum Action {
#[cfg(feature = "desktop")]
ExecEntryAction(usize),
ExtractHere,
ExtractTo,
Gallery,
HistoryNext,
HistoryPrevious,
@ -172,6 +173,7 @@ impl Action {
}
Action::EmptyTrash => Message::TabMessage(None, tab::Message::EmptyTrash),
Action::ExtractHere => Message::ExtractHere(entity_opt),
Action::ExtractTo => Message::ExtractTo(entity_opt),
#[cfg(feature = "desktop")]
Action::ExecEntryAction(action) => {
Message::TabMessage(entity_opt, tab::Message::ExecEntryAction(None, *action))
@ -293,6 +295,7 @@ pub enum Message {
DialogUpdate(DialogPage),
DialogUpdateComplete(DialogPage),
ExtractHere(Option<Entity>),
ExtractTo(Option<Entity>),
#[cfg(all(feature = "desktop", feature = "wayland"))]
Focused(window::Id),
Key(Modifiers, Key, Option<SmolStr>),
@ -430,6 +433,11 @@ pub enum DialogPage {
archive_type: ArchiveType,
password: Option<String>,
},
ExtractTo {
paths: Vec<PathBuf>,
to: PathBuf,
password: Option<String>
},
EmptyTrash,
FailedOperation(u64),
ExtractPassword {
@ -2211,6 +2219,13 @@ impl Application for App {
DialogPage::EmptyTrash => {
self.operation(Operation::EmptyTrash);
}
DialogPage::ExtractTo { paths, to, password } => {
self.operation(Operation::Extract {
paths,
to,
password: None,
});
},
DialogPage::FailedOperation(id) => {
log::warn!("TODO: retry operation {}", id);
}
@ -2358,6 +2373,21 @@ impl Application for App {
});
}
}
Message::ExtractTo(entity_opt) => {
let paths = self.selected_paths(entity_opt);
if let Some(destination) = paths
.first()
.and_then(|first| first.parent())
.map(|parent| parent.to_path_buf())
{
self.dialog_pages.push_back(DialogPage::ExtractTo {
paths,
to: destination,
password: None,
});
};
}
Message::Key(modifiers, key, text) => {
let entity = self.tab_model.active();
for (key_bind, action) in self.key_binds.iter() {
@ -4059,6 +4089,24 @@ impl Application for App {
.secondary_action(
widget::button::standard(fl!("cancel")).on_press(Message::DialogCancel),
),
DialogPage::ExtractTo { paths, to, password } => {
widget::dialog()
.title(fl!("extract-to"))
.body(fl!("extract-to-prompt"))
.control(widget::text_input("Enter the path to extract to", to.to_string_lossy()).on_input(
move |to| {
Message::DialogUpdate(DialogPage::ExtractTo { paths: paths.clone(), to: PathBuf::from(to), password: password.clone() })
},
))
.primary_action(
widget::button::suggested(fl!("extract-here"))
.on_press(Message::DialogComplete),
)
.secondary_action(
widget::button::standard(fl!("cancel")).on_press(Message::DialogCancel),
)
}
DialogPage::FailedOperation(id) => {
//TODO: try next dialog page (making sure index is used by Dialog messages)?
let (operation, _, err) = self.failed_operations.get(id)?;