Skip to content

Commit

Permalink
Fix error when creating or removing a text
Browse files Browse the repository at this point in the history
  • Loading branch information
nebularg committed Nov 15, 2019
1 parent 31c5f40 commit 656c77f
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions Options/LayoutEditor/Texts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ local CURRENT_CUSTOM_TEXT_MODULE
local CURRENT_TEXT_PROVIDER_MODULE
local CURRENT_TEXT_PROVIDER_ID

-- Helper function in lieu of doing a single loop iteration
local function get_module_of_type(...)
local iter, types = PitBull4:IterateModulesOfType(...)
local _, module = iter(types)
return module
end

--- Return the DB dictionary for the current text for the current layout selected in the options frame.
-- TextProvider modules should be calling this and manipulating data within it.
-- @usage local db = PitBull.Options.GetTextLayoutDB(); db.some_option = "something"
Expand Down Expand Up @@ -121,7 +128,9 @@ function PitBull4.Options.get_layout_editor_text_options()
return L["Must be at least 3 characters long."]
end

local has_module = false
for id, module in PitBull4:IterateModulesOfType("text_provider") do
has_module = true
local texts_db = GetLayoutDB(module).elements

for name in pairs(texts_db) do
Expand All @@ -131,7 +140,7 @@ function PitBull4.Options.get_layout_editor_text_options()
end
end

if next(PitBull4:IterateModulesOfType("text_provider")) then
if has_module then
return true -- found a module
end
return L["You have no enabled text providers."]
Expand All @@ -147,8 +156,7 @@ function PitBull4.Options.get_layout_editor_text_options()
local module = CURRENT_TEXT_PROVIDER_MODULE

if not module then
local _
_, module = next(PitBull4:IterateModulesOfType("text_provider"))
module = get_module_of_type("text_provider")
assert(module) -- the validate function should verify that at least one module exists
end

Expand Down Expand Up @@ -242,7 +250,7 @@ function PitBull4.Options.get_layout_editor_text_options()
end

if not CURRENT_TEXT_PROVIDER_ID then
local _, module = next(PitBull4:IterateModulesOfType("custom_text"))
local module = get_module_of_type("custom_text")
if module then
CURRENT_CUSTOM_TEXT_MODULE = module
end
Expand Down

0 comments on commit 656c77f

Please sign in to comment.