fix #1682 by closing all dict windows when holding close icon

pull/2114/head
chrox 8 years ago
parent 71bf9efc7c
commit 1c5c7d3a7c

@ -12,6 +12,7 @@ local T = require("ffi/util").template
local ReaderDictionary = InputContainer:new{ local ReaderDictionary = InputContainer:new{
data_dir = nil, data_dir = nil,
dict_window_list = {},
} }
function ReaderDictionary:init() function ReaderDictionary:init()
@ -104,6 +105,7 @@ function ReaderDictionary:showDict(word, results, box)
if results and results[1] then if results and results[1] then
DEBUG("showing quick lookup window", word, results) DEBUG("showing quick lookup window", word, results)
self.dict_window = DictQuickLookup:new{ self.dict_window = DictQuickLookup:new{
window_list = self.dict_window_list,
ui = self.ui, ui = self.ui,
highlight = self.highlight, highlight = self.highlight,
dialog = self.dialog, dialog = self.dialog,
@ -116,6 +118,7 @@ function ReaderDictionary:showDict(word, results, box)
-- differentiate between dict and wiki -- differentiate between dict and wiki
wiki = self.wiki, wiki = self.wiki,
} }
table.insert(self.dict_window_list, self.dict_window)
UIManager:show(self.dict_window) UIManager:show(self.dict_window)
end end
end end

@ -52,10 +52,27 @@ function CloseButton:init()
}, },
doc = "Tap on close button", doc = "Tap on close button",
} }
self.ges_events.HoldClose = {
GestureRange:new{
ges = "hold_release",
range = function() return self.dimen end,
},
doc = "Hold on close button",
}
end end
function CloseButton:onClose() function CloseButton:onClose()
self.window:onClose() if self.window.onClose then
self.window:onClose()
end
return true
end
function CloseButton:onHoldClose()
if self.window.onHoldClose then
self.window:onHoldClose()
end
return true return true
end end

@ -88,7 +88,7 @@ function DictQuickLookup:init()
-- callback function when HoldWord is handled as args -- callback function when HoldWord is handled as args
args = function(word) args = function(word)
self.ui:handleEvent( self.ui:handleEvent(
Event:new("LookupWord", word, self.word_box)) Event:new("LookupWord", word, self.word_box, self.highlight))
end end
}, },
} }
@ -384,8 +384,24 @@ end
function DictQuickLookup:onClose() function DictQuickLookup:onClose()
UIManager:close(self) UIManager:close(self)
for i = #self.window_list, 1, -1 do
local window = self.window_list[i]
if window == self then
table.remove(self.window_list, i)
end
end
if self.highlight then if self.highlight then
self.highlight:handleEvent(Event:new("Tap")) self.highlight:clear()
end
return true
end
function DictQuickLookup:onHoldClose()
self:onClose()
for i = #self.window_list, 1, -1 do
local window = self.window_list[i]
UIManager:close(window)
table.remove(self.window_list, i)
end end
return true return true
end end

Loading…
Cancel
Save