mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Simplify the code
This commit is contained in:
parent
dab892e77c
commit
3dc80e28c8
5 changed files with 14 additions and 21 deletions
|
|
@ -180,7 +180,7 @@ delete_offset = [ 0, 5, 70, 20 ]
|
||||||
|
|
||||||
# overwrite
|
# overwrite
|
||||||
overwrite_title = "Are you sure?"
|
overwrite_title = "Are you sure?"
|
||||||
overwrite_content = "Overwrite existing file: {file}?"
|
overwrite_content = "Will overwrite existing file: {url}"
|
||||||
overwrite_origin = "top-center"
|
overwrite_origin = "top-center"
|
||||||
overwrite_offset = [ 0, 2, 50, 20 ]
|
overwrite_offset = [ 0, 2, 50, 20 ]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
use yazi_shared::fs::Url;
|
||||||
|
|
||||||
use super::{Offset, Position};
|
use super::{Offset, Position};
|
||||||
use crate::{CONFIRM, INPUT, SELECT};
|
use crate::{CONFIRM, INPUT, SELECT};
|
||||||
|
|
||||||
|
|
@ -127,10 +129,10 @@ impl ConfirmCfg {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn overwrite(file: &str) -> Self {
|
pub fn overwrite(url: &Url) -> Self {
|
||||||
Self {
|
Self {
|
||||||
title: CONFIRM.overwrite_title.to_owned(),
|
title: CONFIRM.overwrite_title.to_owned(),
|
||||||
content: CONFIRM.overwrite_content.replace("{file}", file),
|
content: CONFIRM.overwrite_content.replace("{url}", &url.to_string()),
|
||||||
position: Position::new(CONFIRM.overwrite_origin, CONFIRM.overwrite_offset),
|
position: Position::new(CONFIRM.overwrite_origin, CONFIRM.overwrite_offset),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,11 +31,11 @@ impl Manager {
|
||||||
}
|
}
|
||||||
|
|
||||||
let new = cwd.join(&name);
|
let new = cwd.join(&name);
|
||||||
if !opt.force && maybe_exists(&new).await {
|
if !opt.force
|
||||||
match ConfirmProxy::show(ConfirmCfg::overwrite(&new.to_string())).await {
|
&& maybe_exists(&new).await
|
||||||
Ok(c) if c => (),
|
&& !ConfirmProxy::show(ConfirmCfg::overwrite(&new)).await
|
||||||
_ => return Ok(()),
|
{
|
||||||
}
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
Self::create_do(new, opt.dir || name.ends_with('/') || name.ends_with('\\')).await
|
Self::create_do(new, opt.dir || name.ends_with('/') || name.ends_with('\\')).await
|
||||||
|
|
|
||||||
|
|
@ -52,13 +52,9 @@ impl Manager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// recv(&mut result);
|
if result.await {
|
||||||
|
|
||||||
if let Ok(choice) = result.await {
|
|
||||||
if choice {
|
|
||||||
emit!(Quit(opt));
|
emit!(Quit(opt));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -88,18 +88,13 @@ impl Utils {
|
||||||
|
|
||||||
ya.raw_set(
|
ya.raw_set(
|
||||||
"confirm",
|
"confirm",
|
||||||
lua.create_async_function(|lua, t: Table| async move {
|
lua.create_async_function(|_, t: Table| async move {
|
||||||
let result = ConfirmProxy::show(ConfirmCfg {
|
let result = ConfirmProxy::show(ConfirmCfg {
|
||||||
title: t.raw_get("title")?,
|
title: t.raw_get("title")?,
|
||||||
content: t.raw_get("content")?,
|
content: t.raw_get("content")?,
|
||||||
position: Position::try_from(t.raw_get::<_, Table>("position")?)?.into(),
|
position: Position::try_from(t.raw_get::<_, Table>("position")?)?.into(),
|
||||||
});
|
});
|
||||||
|
Ok(result.await)
|
||||||
if let Ok(_answer) = result.await {
|
|
||||||
true.into_lua_multi(lua)
|
|
||||||
} else {
|
|
||||||
false.into_lua_multi(lua)
|
|
||||||
}
|
|
||||||
})?,
|
})?,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue