From 1c5c7d3a7ca75f0f26a689d6aa12114a246e8fcf Mon Sep 17 00:00:00 2001 From: chrox Date: Wed, 29 Jun 2016 00:35:00 +0800 Subject: [PATCH] fix #1682 by closing all dict windows when holding close icon --- .../apps/reader/modules/readerdictionary.lua | 3 +++ frontend/ui/widget/closebutton.lua | 19 +++++++++++++++++- frontend/ui/widget/dictquicklookup.lua | 20 +++++++++++++++++-- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/frontend/apps/reader/modules/readerdictionary.lua b/frontend/apps/reader/modules/readerdictionary.lua index 881d5e195..3d2104247 100644 --- a/frontend/apps/reader/modules/readerdictionary.lua +++ b/frontend/apps/reader/modules/readerdictionary.lua @@ -12,6 +12,7 @@ local T = require("ffi/util").template local ReaderDictionary = InputContainer:new{ data_dir = nil, + dict_window_list = {}, } function ReaderDictionary:init() @@ -104,6 +105,7 @@ function ReaderDictionary:showDict(word, results, box) if results and results[1] then DEBUG("showing quick lookup window", word, results) self.dict_window = DictQuickLookup:new{ + window_list = self.dict_window_list, ui = self.ui, highlight = self.highlight, dialog = self.dialog, @@ -116,6 +118,7 @@ function ReaderDictionary:showDict(word, results, box) -- differentiate between dict and wiki wiki = self.wiki, } + table.insert(self.dict_window_list, self.dict_window) UIManager:show(self.dict_window) end end diff --git a/frontend/ui/widget/closebutton.lua b/frontend/ui/widget/closebutton.lua index 8e81fc994..7b19cb7b0 100644 --- a/frontend/ui/widget/closebutton.lua +++ b/frontend/ui/widget/closebutton.lua @@ -52,10 +52,27 @@ function CloseButton:init() }, 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 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 end diff --git a/frontend/ui/widget/dictquicklookup.lua b/frontend/ui/widget/dictquicklookup.lua index 6ed37c0d0..d27aa6438 100644 --- a/frontend/ui/widget/dictquicklookup.lua +++ b/frontend/ui/widget/dictquicklookup.lua @@ -88,7 +88,7 @@ function DictQuickLookup:init() -- callback function when HoldWord is handled as args args = function(word) self.ui:handleEvent( - Event:new("LookupWord", word, self.word_box)) + Event:new("LookupWord", word, self.word_box, self.highlight)) end }, } @@ -384,8 +384,24 @@ end function DictQuickLookup:onClose() 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 - 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 return true end