From 893878647200c0afc06841120313ddeffbce6d13 Mon Sep 17 00:00:00 2001 From: Huang Xin Date: Mon, 19 Jun 2017 00:08:57 +0800 Subject: [PATCH] [fix] stop propagation of tap events when triggering reader menu (#2934) * [fix] stop propagation of tap events when triggering reader menu And also get rid of unnecessary screen refreshes on Kindle Voyage. The "progress" window for dict lookup is also eliminated as most of the time dict lookup is an instant process, and the "progress" window is preserved for wikipedia lookup as it may take longer time to show the result window. * [up] add an option to disable dictionary fuzzy search * [fix] tidy up require * [fix] fix read settings --- base | 2 +- .../apps/reader/modules/readerdictionary.lua | 50 ++++++++++++++++--- .../apps/reader/modules/readerhighlight.lua | 4 +- frontend/apps/reader/modules/readermenu.lua | 1 + .../apps/reader/modules/readerwikipedia.lua | 3 +- frontend/ui/elements/reader_menu_order.lua | 1 + 6 files changed, 48 insertions(+), 13 deletions(-) diff --git a/base b/base index 48a2ff599..4cecbeffc 160000 --- a/base +++ b/base @@ -1 +1 @@ -Subproject commit 48a2ff599799cc65bc7c815a5c9ee646c89a6770 +Subproject commit 4cecbeffc5089972fb7410d952bd8035c1b6007d diff --git a/frontend/apps/reader/modules/readerdictionary.lua b/frontend/apps/reader/modules/readerdictionary.lua index 71b463d5d..df96c448c 100644 --- a/frontend/apps/reader/modules/readerdictionary.lua +++ b/frontend/apps/reader/modules/readerdictionary.lua @@ -1,8 +1,9 @@ +local ConfirmBox = require("ui/widget/confirmbox") local DataStorage = require("datastorage") local Device = require("device") local DictQuickLookup = require("ui/widget/dictquicklookup") -local InputContainer = require("ui/widget/container/inputcontainer") local InfoMessage = require("ui/widget/infomessage") +local InputContainer = require("ui/widget/container/inputcontainer") local JSON = require("json") local UIManager = require("ui/uimanager") local logger = require("logger") @@ -35,6 +36,18 @@ function ReaderDictionary:addToMainMenu(menu_items) end, }, } + menu_items.disable_fuzzy_search = { + text = _("Disable dictionary fuzzy search"), + checked_func = function() + return self.disable_fuzzy_search == true + end, + callback = function() + self.disable_fuzzy_search = not self.disable_fuzzy_search + end, + hold_callback = function() + self:makeDisableFuzzyDefault(self.disable_fuzzy_search) + end, + } end function ReaderDictionary:onLookupWord(word, box, highlight) @@ -107,14 +120,14 @@ function ReaderDictionary:cleanSelection(text) return text end -function ReaderDictionary:onLookupStarted(word) +function ReaderDictionary:showLookupInfo(word) local text = T(self.lookup_msg, word) self.lookup_progress_msg = InfoMessage:new{text=text} UIManager:show(self.lookup_progress_msg) UIManager:forceRePaint() end -function ReaderDictionary:onLookupDone() +function ReaderDictionary:dismissLookupInfo() if self.lookup_progress_msg then UIManager:close(self.lookup_progress_msg) UIManager:forceRePaint() @@ -130,7 +143,9 @@ function ReaderDictionary:stardictLookup(word, box) if word == "" then return end - self:onLookupStarted(word) + if not self.disable_fuzzy_search then + self:showLookupInfo(word) + end local final_results = {} local seen_results = {} -- Allow for two sdcv calls : one in the classic data/dict, and @@ -153,19 +168,19 @@ function ReaderDictionary:stardictLookup(word, box) definition = _([[No dictionaries installed. Please search for "Dictionary support" in the KOReader Wiki to get more information about installing new dictionaries.]]), } } - self:onLookupDone() self:showDict(word, final_results, box) return end for _, dict_dir in ipairs(dict_dirs) do local results_str = nil + local common_options = self.disable_fuzzy_search and "-njf" or "-nj" if Device:isAndroid() then local A = require("android") results_str = A.stdout("./sdcv", "--utf8-input", "--utf8-output", - "-nj", word, "--data-dir", dict_dir) + common_options, word, "--data-dir", dict_dir) else local std_out = io.popen( - ("./sdcv --utf8-input --utf8-output -nj %q --data-dir %q"):format(word, dict_dir), + ("./sdcv --utf8-input --utf8-output %q %q --data-dir %q"):format(common_options, word, dict_dir), "r") if std_out then results_str = std_out:read("*all") @@ -198,11 +213,11 @@ function ReaderDictionary:stardictLookup(word, box) } } end - self:onLookupDone() self:showDict(word, tidyMarkup(final_results), box) end function ReaderDictionary:showDict(word, results, box) + self:dismissLookupInfo() if results and results[1] then logger.dbg("showing quick lookup window", word, results) self.dict_window = DictQuickLookup:new{ @@ -244,11 +259,30 @@ end function ReaderDictionary:onReadSettings(config) self.default_dictionary = config:readSetting("default_dictionary") + self.disable_fuzzy_search = config:readSetting("disable_fuzzy_search") + if self.disable_fuzzy_search == nil then + self.disable_fuzzy_search = G_reader_settings:isTrue("disable_fuzzy_search") + end end function ReaderDictionary:onSaveSettings() logger.dbg("save default dictionary", self.default_dictionary) self.ui.doc_settings:saveSetting("default_dictionary", self.default_dictionary) + self.ui.doc_settings:saveSetting("disable_fuzzy_search", self.disable_fuzzy_search) +end + +function ReaderDictionary:makeDisableFuzzyDefault(disable_fuzzy_search) + logger.dbg("disable fuzzy search", self.disable_fuzzy_search) + UIManager:show(ConfirmBox:new{ + text = T( + disable_fuzzy_search + and _("Disable fuzzy search by default?") + or _("Enable fuzzy search by default?") + ), + ok_callback = function() + G_reader_settings:saveSetting("disable_fuzzy_search", disable_fuzzy_search) + end, + }) end return ReaderDictionary diff --git a/frontend/apps/reader/modules/readerhighlight.lua b/frontend/apps/reader/modules/readerhighlight.lua index ea5d61fc3..4d6065ef2 100644 --- a/frontend/apps/reader/modules/readerhighlight.lua +++ b/frontend/apps/reader/modules/readerhighlight.lua @@ -118,7 +118,7 @@ function ReaderHighlight:clear() if self.hold_pos then self.hold_pos = nil self.selected_text = nil - UIManager:setDirty(self.dialog, "partial") + UIManager:setDirty(self.dialog, "ui") return true end end @@ -255,7 +255,7 @@ function ReaderHighlight:onHold(arg, ges) table.insert(boxes, self.selected_word.sbox) self.view.highlight.temp[self.hold_pos.page] = boxes end - UIManager:setDirty(self.dialog, "partial") + UIManager:setDirty(self.dialog, "ui") -- TODO: only mark word? -- Unfortunately, CREngine does not return good coordinates -- UIManager:setDirty(self.dialog, "partial", self.selected_word.sbox) diff --git a/frontend/apps/reader/modules/readermenu.lua b/frontend/apps/reader/modules/readermenu.lua index 86633925e..39d251e03 100644 --- a/frontend/apps/reader/modules/readermenu.lua +++ b/frontend/apps/reader/modules/readermenu.lua @@ -285,6 +285,7 @@ end function ReaderMenu:onTapShowMenu() self.ui:handleEvent(Event:new("ShowConfigMenu")) self.ui:handleEvent(Event:new("ShowReaderMenu")) + return true end function ReaderMenu:onTapCloseMenu() diff --git a/frontend/apps/reader/modules/readerwikipedia.lua b/frontend/apps/reader/modules/readerwikipedia.lua index d8071c223..48f2f1b3c 100644 --- a/frontend/apps/reader/modules/readerwikipedia.lua +++ b/frontend/apps/reader/modules/readerwikipedia.lua @@ -137,7 +137,7 @@ function ReaderWikipedia:onLookupWikipedia(word, box, get_fullpage, forced_lang) else self.lookup_msg = T(_("Searching Wikipedia %2 for:\n%1"), "%1", lang:upper()) end - self:onLookupStarted(word) + self:showLookupInfo(word) local results = {} local ok, pages if get_fullpage then @@ -193,7 +193,6 @@ function ReaderWikipedia:onLookupWikipedia(word, box, get_fullpage, forced_lang) } logger.dbg("dummy result table:", word, results) end - self:onLookupDone() self:showDict(word, results, box) end diff --git a/frontend/ui/elements/reader_menu_order.lua b/frontend/ui/elements/reader_menu_order.lua index d7f322949..1f7a15888 100644 --- a/frontend/ui/elements/reader_menu_order.lua +++ b/frontend/ui/elements/reader_menu_order.lua @@ -32,6 +32,7 @@ local order = { }, setting = { "read_from_right_to_left", + "disable_fuzzy_search", -- common settings -- those that don't exist will simply be skipped during menu gen "frontlight", -- if Device:hasFrontlight()