Skip to content
Snippets Groups Projects
Commit 57d3fe0e authored by Hachem_Muche's avatar Hachem_Muche
Browse files

Fixes a bug that can cause incorrect tabs to be pre-selected (possibly causing...

Fixes a bug that can cause incorrect tabs to be pre-selected (possibly causing a crash) when the Inventory dialog is re-invoked.
(This is triggered when the new dialog instance is missing some tabs present in the previous instance.)

Tabs carried over from re-instantiation are matched by the "kind" field instead of by tab number, with special handling to ensure that all tabs are selected if the "all" tag (if present), was selected.
parent accfd911
No related branches found
No related tags found
1 merge request!351Inventory Dialog Fix
......@@ -75,12 +75,26 @@ function _M:generate()
end
self.c_tabs.no_keyboard_focus = true
if _M._last_tabs then
for _, l in ipairs(_M._last_tabs) do self.c_tabs.dlist[l[1]][l[2]].selected = true end
if _M._last_tabs_i then self.c_tabs.sel_i = _M._last_tabs_i end
else
local found_tab = false
if _M._last_tabs then -- reselect previously selected tabs if possible
local sel_all = _M._last_tabs.all
local last_kinds = {}
for _, lt in ipairs(_M._last_tabs) do if lt.kind then last_kinds[lt.kind] = true end end
for j, row in ipairs(self.c_tabs.dlist) do for i, item in ipairs(row) do
if sel_all or last_kinds[item.data.kind] then
item.selected = true
found_tab = true
self.c_tabs.sel_i, self.c_tabs.sel_j = i, j
if sel_all and item.data.filter=="all" then _M._last_tabs_i = i end
end
end end
end
if not found_tab then
self.c_tabs.sel_i, self.c_tabs.sel_j = 1, 1
self.c_tabs.dlist[1][1].selected = true
end
self.uis[#self.uis+1] = {x=0, y=0, ui=self.c_tabs}
self.c_tabs.on_focus_change = function(ui_self, status)
if status == true then
......@@ -241,14 +255,17 @@ function _M:updateTabFilterList(list)
return false
end
-- Save for next dialogs
-- Save for next dialog
if not self.dont_update_last_tabs then
_M._last_tabs = self.c_tabs:getAllSelectedKeys()
if not is_all then
local i = 1
for _, d in ipairs(_M._last_tabs) do i = math.max(i, d[2]) end
for _, d in ipairs(_M._last_tabs) do
i = math.max(i, d[2]) d.kind = self.c_tabs.dlist[d[1]][d[2]].data.kind
end
_M._last_tabs_i = i
else
_M._last_tabs.all = true
_M._last_tabs_i = #self.tabslist
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment