mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
uimanager(fix): handle stack change in close
This commit is contained in:
@@ -95,7 +95,6 @@ function ReaderDictionary:stardictLookup(word, box)
|
||||
definition = _("No definition found."),
|
||||
}
|
||||
}
|
||||
DEBUG("dummy result table:", word, results)
|
||||
self:showDict(word, results, box)
|
||||
end
|
||||
end
|
||||
@@ -103,7 +102,7 @@ end
|
||||
|
||||
function ReaderDictionary:showDict(word, results, box)
|
||||
if results and results[1] then
|
||||
DEBUG("showing quick lookup window")
|
||||
DEBUG("showing quick lookup window", word, results)
|
||||
self.dict_window = DictQuickLookup:new{
|
||||
ui = self.ui,
|
||||
highlight = self.highlight,
|
||||
|
||||
@@ -182,10 +182,13 @@ function UIManager:close(widget, refreshtype, refreshregion)
|
||||
end
|
||||
dbg("close widget", widget.id)
|
||||
local dirty = false
|
||||
-- first send close event to widget
|
||||
widget:handleEvent(Event:new("CloseWidget"))
|
||||
-- then remove all reference to that widget on stack and update
|
||||
-- disable_double_tap accordingly
|
||||
Input.disable_double_tap = false
|
||||
for i = #self._window_stack, 1, -1 do
|
||||
if self._window_stack[i].widget == widget then
|
||||
-- tell the widget that it is closed now
|
||||
widget:handleEvent(Event:new("CloseWidget"))
|
||||
table.remove(self._window_stack, i)
|
||||
dirty = true
|
||||
elseif self._window_stack[i].widget.disable_double_tap then
|
||||
@@ -315,7 +318,7 @@ end
|
||||
dbg:guard(UIManager, 'setDirty',
|
||||
nil,
|
||||
function(self, widget, refreshtype, refreshregion)
|
||||
if not widget then return end
|
||||
if not widget or widget == "all" then return end
|
||||
-- when debugging, we check if we get handed a valid widget,
|
||||
-- which would be a dialog that was previously passed via show()
|
||||
local found = false
|
||||
@@ -562,9 +565,8 @@ function UIManager:_repaint()
|
||||
end
|
||||
self._refresh_func_stack = {}
|
||||
|
||||
-- we should have at least one refresh if we did repaint.
|
||||
-- If we don't, we add one now and print a warning if we
|
||||
-- are debugging
|
||||
-- we should have at least one refresh if we did repaint. If we don't, we
|
||||
-- add one now and log a warning if we are debugging
|
||||
if dirty and #self._refresh_stack == 0 then
|
||||
dbg("WARNING: no refresh got enqueued. Will do a partial full screen refresh, which might be inefficient")
|
||||
self:_refresh("partial")
|
||||
|
||||
@@ -345,4 +345,23 @@ describe("UIManager spec", function()
|
||||
UIManager:broadcastEvent("foo")
|
||||
assert.is.same(#UIManager._window_stack, 0)
|
||||
end)
|
||||
|
||||
it("should handle stack change when closing widgets", function()
|
||||
local widget_1 = {handleEvent = function()end}
|
||||
local widget_2 = {
|
||||
handleEvent = function()
|
||||
UIManager:close(widget_1)
|
||||
end
|
||||
}
|
||||
local widget_3 = {handleEvent = function()end}
|
||||
UIManager._window_stack = {
|
||||
{widget = widget_1},
|
||||
{widget = widget_2},
|
||||
{widget = widget_3},
|
||||
}
|
||||
UIManager:close(widget_2)
|
||||
|
||||
assert.is.same(1, #UIManager._window_stack)
|
||||
assert.is.same(widget_3, UIManager._window_stack[1].widget)
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user