diff --git a/CHANGELOG.md b/CHANGELOG.md index d1e8cb59..280879fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/): - New `fs.access()` API to access the filesystem ([#3668]) - New `relay-notify-push` DDS event to customize the notification handler ([#3642]) - New `ind-app-title` DDS event to customize the app title ([#3684]) +- New `ind-hidden` and `key-hidden` DDS events to change hidden status in Lua ([#3748]) - New `marker_symbol` option to specify the symbol used for marking files ([#3689]) - New `fs.unique()` creates a unique file or directory ([#3677]) - New `download` DDS event fires when remote files are downloaded ([#3687]) @@ -1678,3 +1679,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/): [#3728]: https://github.com/sxyazi/yazi/pull/3728 [#3733]: https://github.com/sxyazi/yazi/pull/3733 [#3744]: https://github.com/sxyazi/yazi/pull/3744 +[#3748]: https://github.com/sxyazi/yazi/pull/3748 diff --git a/yazi-actor/src/mgr/hidden.rs b/yazi-actor/src/mgr/hidden.rs index 1e42ee7d..1553833e 100644 --- a/yazi-actor/src/mgr/hidden.rs +++ b/yazi-actor/src/mgr/hidden.rs @@ -1,9 +1,10 @@ use anyhow::Result; use yazi_core::tab::Folder; +use yazi_dds::spark::SparkKind; use yazi_fs::FolderStage; use yazi_macro::{act, render, render_and, succ}; use yazi_parser::mgr::HiddenOpt; -use yazi_shared::data::Data; +use yazi_shared::{Source, data::Data}; use crate::{Actor, Ctx}; @@ -50,4 +51,12 @@ impl Actor for Hidden { succ!() } + + fn hook(cx: &Ctx, _: &Self::Options) -> Option { + match cx.source() { + Source::Ind => Some(SparkKind::IndHidden), + Source::Key => Some(SparkKind::KeyHidden), + _ => None, + } + } } diff --git a/yazi-dds/src/spark/kind.rs b/yazi-dds/src/spark/kind.rs index ba71afd0..ad323327 100644 --- a/yazi-dds/src/spark/kind.rs +++ b/yazi-dds/src/spark/kind.rs @@ -5,6 +5,9 @@ pub enum SparkKind { // app:title IndAppTitle, + // mgr:hidden + KeyHidden, + IndHidden, // mgr:sort KeySort, IndSort, @@ -27,6 +30,9 @@ impl AsRef for SparkKind { // app:title Self::IndAppTitle => "ind-app-title", + // mgr:hidden + Self::KeyHidden => "key-hidden", + Self::IndHidden => "ind-hidden", // mgr:sort Self::KeySort => "key-sort", Self::IndSort => "ind-sort", diff --git a/yazi-dds/src/spark/spark.rs b/yazi-dds/src/spark/spark.rs index e2d16fdd..19184f76 100644 --- a/yazi-dds/src/spark/spark.rs +++ b/yazi-dds/src/spark/spark.rs @@ -161,6 +161,9 @@ impl<'a> Spark<'a> { // app:title IndAppTitle => Self::AppTitle(<_>::from_lua(value, lua)?), + // mgr:hidden + KeyHidden => Self::Hidden(<_>::from_lua(value, lua)?), + IndHidden => Self::Hidden(<_>::from_lua(value, lua)?), // mgr:sort KeySort => Self::Sort(<_>::from_lua(value, lua)?), IndSort => Self::Sort(<_>::from_lua(value, lua)?), diff --git a/yazi-parser/src/mgr/hidden.rs b/yazi-parser/src/mgr/hidden.rs index 190b540a..c80e1e27 100644 --- a/yazi-parser/src/mgr/hidden.rs +++ b/yazi-parser/src/mgr/hidden.rs @@ -1,10 +1,11 @@ use std::str::FromStr; -use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; +use mlua::{FromLua, IntoLua, Lua, LuaSerdeExt, Value}; use serde::{Deserialize, Serialize}; +use yazi_binding::SER_OPT; use yazi_shared::event::ActionCow; -#[derive(Debug, Default)] +#[derive(Debug, Default, Deserialize, Serialize)] pub struct HiddenOpt { pub state: HiddenOptState, } @@ -18,11 +19,11 @@ impl TryFrom for HiddenOpt { } impl FromLua for HiddenOpt { - fn from_lua(_: Value, _: &Lua) -> mlua::Result { Err("unsupported".into_lua_err()) } + fn from_lua(value: Value, lua: &Lua) -> mlua::Result { lua.from_value(value) } } impl IntoLua for HiddenOpt { - fn into_lua(self, _: &Lua) -> mlua::Result { Err("unsupported".into_lua_err()) } + fn into_lua(self, lua: &Lua) -> mlua::Result { lua.to_value_with(&self, SER_OPT) } } // --- State