When a command is performed with parameters, those are now passed to the predicate. The predicate can then return, after the validity boolean, any other value that will then be passed to the actual command. If the predicate only returns the validity boolean, the original parameters are passed through to the actual command. This allows predicates to manipulate the received parameters, and allows them to pass the result of an expensive computation to the actual command, which won't have to recalculate it. String and table predicates will now also return `core.active_view`.
31 lines
943 B
Lua
31 lines
943 B
Lua
local core = require "core"
|
|
local command = require "core.command"
|
|
local common = require "core.common"
|
|
|
|
command.add("core.nagview", {
|
|
["dialog:previous-entry"] = function(v)
|
|
local hover = v.hovered_item or 1
|
|
v:change_hovered(hover == 1 and #v.options or hover - 1)
|
|
end,
|
|
["dialog:next-entry"] = function(v)
|
|
local hover = v.hovered_item or 1
|
|
v:change_hovered(hover == #v.options and 1 or hover + 1)
|
|
end,
|
|
["dialog:select-yes"] = function(v)
|
|
if v ~= core.nag_view then return end
|
|
v:change_hovered(common.find_index(v.options, "default_yes"))
|
|
command.perform "dialog:select"
|
|
end,
|
|
["dialog:select-no"] = function(v)
|
|
if v ~= core.nag_view then return end
|
|
v:change_hovered(common.find_index(v.options, "default_no"))
|
|
command.perform "dialog:select"
|
|
end,
|
|
["dialog:select"] = function(v)
|
|
if v.hovered_item then
|
|
v.on_selected(v.options[v.hovered_item])
|
|
v:next()
|
|
end
|
|
end
|
|
})
|