Fix undeclared NagView findindex() by moving it to common.
This commit is contained in:
parent
98164f6d4f
commit
e070dbebc1
|
@ -1,5 +1,6 @@
|
|||
local core = require "core"
|
||||
local command = require "core.command"
|
||||
local common = require "core.common"
|
||||
|
||||
command.add("core.nagview", {
|
||||
["dialog:previous-entry"] = function()
|
||||
|
@ -15,13 +16,13 @@ command.add("core.nagview", {
|
|||
["dialog:select-yes"] = function()
|
||||
local v = core.active_view
|
||||
if v ~= core.nag_view then return end
|
||||
v:change_hovered(findindex(v.options, "default_yes"))
|
||||
v:change_hovered(common.find_index(v.options, "default_yes"))
|
||||
command.perform "dialog:select"
|
||||
end,
|
||||
["dialog:select-no"] = function()
|
||||
local v = core.active_view
|
||||
if v ~= core.nag_view then return end
|
||||
v:change_hovered(findindex(v.options, "default_no"))
|
||||
v:change_hovered(common.find_index(v.options, "default_no"))
|
||||
command.perform "dialog:select"
|
||||
end,
|
||||
["dialog:select"] = function()
|
||||
|
|
|
@ -22,6 +22,13 @@ function common.round(n)
|
|||
end
|
||||
|
||||
|
||||
function common.find_index(tbl, prop)
|
||||
for i, o in ipairs(tbl) do
|
||||
if o[prop] then return i end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function common.lerp(a, b, t)
|
||||
if type(a) ~= "table" then
|
||||
return a + (b - a) * t
|
||||
|
|
|
@ -170,12 +170,6 @@ function NagView:draw()
|
|||
end
|
||||
end
|
||||
|
||||
local function findindex(tbl, prop)
|
||||
for i, o in ipairs(tbl) do
|
||||
if o[prop] then return i end
|
||||
end
|
||||
end
|
||||
|
||||
function NagView:get_message_height()
|
||||
local h = 0
|
||||
for str in string.gmatch(self.message, "(.-)\n") do
|
||||
|
@ -196,7 +190,7 @@ function NagView:next()
|
|||
-- self.target_height is the nagview height needed to display the message and
|
||||
-- the buttons, excluding the top and bottom padding space.
|
||||
self.target_height = math.max(message_height, self:get_buttons_height())
|
||||
self:change_hovered(findindex(self.options, "default_yes"))
|
||||
self:change_hovered(common.find_index(self.options, "default_yes"))
|
||||
end
|
||||
self.force_focus = self.message ~= nil
|
||||
core.set_active_view(self.message ~= nil and self or core.last_active_view)
|
||||
|
|
Loading…
Reference in New Issue