Skip to content

Commit

Permalink
add support for reverse check
Browse files Browse the repository at this point in the history
  • Loading branch information
tsl0922 committed Jan 12, 2024
1 parent 93467c6 commit 50eabe8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ The menu syntax is similar to [mpv.net](https://github.com/mpvnet-player/mpv.net
- `number`: not zero
- `table`: not empty
- none of above: not `nil`
- `#@prop:check!` is the reverse form of `#@prop:check`
- use `_` if no keybinding
- use `ignore` if no command

Expand Down
9 changes: 6 additions & 3 deletions lua/dyn_menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
-- #@playlist playlist
-- #@profiles profile list
--
-- #@prop:check check menu item based on property value
-- #@prop:check check menu item if property is true
-- #@prop:check! check menu item if property is false

local opts = require('mp.options')
local utils = require('mp.utils')
Expand Down Expand Up @@ -339,7 +340,7 @@ end

-- handle #@prop:check
function update_check_status(item, keyword)
local prop = keyword:match('^([%w-]+):check$')
local prop, e = keyword:match('^([%w-]+):check(!?)$')
if not prop then return false end

local function check(v)
Expand All @@ -351,7 +352,9 @@ function update_check_status(item, keyword)
return v ~= nil
end
mp.observe_property(prop, 'native', function(name, value)
item.state = check(value) and { 'checked' } or {}
local ok = check(value)
if e == '!' then ok = not ok end
item.state = ok and { 'checked' } or {}
menu_items_dirty = true
end)

Expand Down

0 comments on commit 50eabe8

Please sign in to comment.