mirror of
https://github.com/sxyazi/yazi.git
synced 2024-12-24 17:23:21 +03:00
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:
parent
afab7879dd
commit
1793d635eb
@ -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(),
|
||||
|
@ -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).
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user