feat: new force option added for the remove command, which does not show the confirmation dialog on trashing/deleting (#173)

This commit is contained in:
三咲雅 · Misaki Masa 2023-09-21 12:39:38 +08:00 committed by GitHub
parent afab7879dd
commit 1793d635eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 13 deletions

View File

@ -110,7 +110,9 @@ impl Executor {
}
"remove" => {
let targets = cx.manager.selected().into_iter().map(|f| f.url_owned()).collect();
cx.tasks.file_remove(targets, exec.named.contains_key("permanently"))
let force = exec.named.contains_key("force");
let permanently = exec.named.contains_key("permanently");
cx.tasks.file_remove(targets, force, permanently)
}
"create" => cx.manager.create(),
"rename" => cx.manager.rename(),

View File

@ -60,6 +60,7 @@
- remove: Move the files to the trash/recycle bin.
- `--force`: Don't show the confirmation dialog, and trash/delete the files directly.
- `--permanently`: Permanently delete the files.
- create: Create a file or directory (ends with `/` for directories).

View File

@ -156,30 +156,41 @@ impl Tasks {
}
pub fn file_cut(&self, src: &HashSet<Url>, dest: Url, force: bool) -> bool {
for p in src {
let to = dest.join(p.file_name().unwrap());
if force && p == &to {
for u in src {
let to = dest.join(u.file_name().unwrap());
if force && u == &to {
trace!("file_cut: same file, skipping {:?}", to);
} else {
self.scheduler.file_cut(p.clone(), to, force);
self.scheduler.file_cut(u.clone(), to, force);
}
}
false
}
pub fn file_copy(&self, src: &HashSet<Url>, dest: Url, force: bool, follow: bool) -> bool {
for p in src {
let to = dest.join(p.file_name().unwrap());
if force && p == &to {
for u in src {
let to = dest.join(u.file_name().unwrap());
if force && u == &to {
trace!("file_copy: same file, skipping {:?}", to);
} else {
self.scheduler.file_copy(p.clone(), to, force, follow);
self.scheduler.file_copy(u.clone(), to, force, follow);
}
}
false
}
pub fn file_remove(&self, targets: Vec<Url>, permanently: bool) -> bool {
pub fn file_remove(&self, targets: Vec<Url>, force: bool, permanently: bool) -> bool {
if force {
for u in targets {
if permanently {
self.scheduler.file_delete(u);
} else {
self.scheduler.file_trash(u);
}
}
return false;
}
let scheduler = self.scheduler.clone();
tokio::spawn(async move {
let s = if targets.len() > 1 { "s" } else { "" };
@ -193,11 +204,11 @@ impl Tasks {
if choice != "y" && choice != "Y" {
return;
}
for p in targets {
for u in targets {
if permanently {
scheduler.file_delete(p);
scheduler.file_delete(u);
} else {
scheduler.file_trash(p);
scheduler.file_trash(u);
}
}
}