2
0
mirror of https://github.com/koreader/koreader synced 2024-11-16 06:12:56 +00:00

[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
This commit is contained in:
Huang Xin 2017-06-19 00:08:57 +08:00 committed by GitHub
parent b680a3f940
commit 8938786472
6 changed files with 48 additions and 13 deletions

2
base

@ -1 +1 @@
Subproject commit 48a2ff599799cc65bc7c815a5c9ee646c89a6770 Subproject commit 4cecbeffc5089972fb7410d952bd8035c1b6007d

View File

@ -1,8 +1,9 @@
local ConfirmBox = require("ui/widget/confirmbox")
local DataStorage = require("datastorage") local DataStorage = require("datastorage")
local Device = require("device") local Device = require("device")
local DictQuickLookup = require("ui/widget/dictquicklookup") local DictQuickLookup = require("ui/widget/dictquicklookup")
local InputContainer = require("ui/widget/container/inputcontainer")
local InfoMessage = require("ui/widget/infomessage") local InfoMessage = require("ui/widget/infomessage")
local InputContainer = require("ui/widget/container/inputcontainer")
local JSON = require("json") local JSON = require("json")
local UIManager = require("ui/uimanager") local UIManager = require("ui/uimanager")
local logger = require("logger") local logger = require("logger")
@ -35,6 +36,18 @@ function ReaderDictionary:addToMainMenu(menu_items)
end, 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 end
function ReaderDictionary:onLookupWord(word, box, highlight) function ReaderDictionary:onLookupWord(word, box, highlight)
@ -107,14 +120,14 @@ function ReaderDictionary:cleanSelection(text)
return text return text
end end
function ReaderDictionary:onLookupStarted(word) function ReaderDictionary:showLookupInfo(word)
local text = T(self.lookup_msg, word) local text = T(self.lookup_msg, word)
self.lookup_progress_msg = InfoMessage:new{text=text} self.lookup_progress_msg = InfoMessage:new{text=text}
UIManager:show(self.lookup_progress_msg) UIManager:show(self.lookup_progress_msg)
UIManager:forceRePaint() UIManager:forceRePaint()
end end
function ReaderDictionary:onLookupDone() function ReaderDictionary:dismissLookupInfo()
if self.lookup_progress_msg then if self.lookup_progress_msg then
UIManager:close(self.lookup_progress_msg) UIManager:close(self.lookup_progress_msg)
UIManager:forceRePaint() UIManager:forceRePaint()
@ -130,7 +143,9 @@ function ReaderDictionary:stardictLookup(word, box)
if word == "" then if word == "" then
return return
end end
self:onLookupStarted(word) if not self.disable_fuzzy_search then
self:showLookupInfo(word)
end
local final_results = {} local final_results = {}
local seen_results = {} local seen_results = {}
-- Allow for two sdcv calls : one in the classic data/dict, and -- 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.]]), 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) self:showDict(word, final_results, box)
return return
end end
for _, dict_dir in ipairs(dict_dirs) do for _, dict_dir in ipairs(dict_dirs) do
local results_str = nil local results_str = nil
local common_options = self.disable_fuzzy_search and "-njf" or "-nj"
if Device:isAndroid() then if Device:isAndroid() then
local A = require("android") local A = require("android")
results_str = A.stdout("./sdcv", "--utf8-input", "--utf8-output", results_str = A.stdout("./sdcv", "--utf8-input", "--utf8-output",
"-nj", word, "--data-dir", dict_dir) common_options, word, "--data-dir", dict_dir)
else else
local std_out = io.popen( 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") "r")
if std_out then if std_out then
results_str = std_out:read("*all") results_str = std_out:read("*all")
@ -198,11 +213,11 @@ function ReaderDictionary:stardictLookup(word, box)
} }
} }
end end
self:onLookupDone()
self:showDict(word, tidyMarkup(final_results), box) self:showDict(word, tidyMarkup(final_results), box)
end end
function ReaderDictionary:showDict(word, results, box) function ReaderDictionary:showDict(word, results, box)
self:dismissLookupInfo()
if results and results[1] then if results and results[1] then
logger.dbg("showing quick lookup window", word, results) logger.dbg("showing quick lookup window", word, results)
self.dict_window = DictQuickLookup:new{ self.dict_window = DictQuickLookup:new{
@ -244,11 +259,30 @@ end
function ReaderDictionary:onReadSettings(config) function ReaderDictionary:onReadSettings(config)
self.default_dictionary = config:readSetting("default_dictionary") 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 end
function ReaderDictionary:onSaveSettings() function ReaderDictionary:onSaveSettings()
logger.dbg("save default dictionary", self.default_dictionary) logger.dbg("save default dictionary", self.default_dictionary)
self.ui.doc_settings:saveSetting("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 end
return ReaderDictionary return ReaderDictionary

View File

@ -118,7 +118,7 @@ function ReaderHighlight:clear()
if self.hold_pos then if self.hold_pos then
self.hold_pos = nil self.hold_pos = nil
self.selected_text = nil self.selected_text = nil
UIManager:setDirty(self.dialog, "partial") UIManager:setDirty(self.dialog, "ui")
return true return true
end end
end end
@ -255,7 +255,7 @@ function ReaderHighlight:onHold(arg, ges)
table.insert(boxes, self.selected_word.sbox) table.insert(boxes, self.selected_word.sbox)
self.view.highlight.temp[self.hold_pos.page] = boxes self.view.highlight.temp[self.hold_pos.page] = boxes
end end
UIManager:setDirty(self.dialog, "partial") UIManager:setDirty(self.dialog, "ui")
-- TODO: only mark word? -- TODO: only mark word?
-- Unfortunately, CREngine does not return good coordinates -- Unfortunately, CREngine does not return good coordinates
-- UIManager:setDirty(self.dialog, "partial", self.selected_word.sbox) -- UIManager:setDirty(self.dialog, "partial", self.selected_word.sbox)

View File

@ -285,6 +285,7 @@ end
function ReaderMenu:onTapShowMenu() function ReaderMenu:onTapShowMenu()
self.ui:handleEvent(Event:new("ShowConfigMenu")) self.ui:handleEvent(Event:new("ShowConfigMenu"))
self.ui:handleEvent(Event:new("ShowReaderMenu")) self.ui:handleEvent(Event:new("ShowReaderMenu"))
return true
end end
function ReaderMenu:onTapCloseMenu() function ReaderMenu:onTapCloseMenu()

View File

@ -137,7 +137,7 @@ function ReaderWikipedia:onLookupWikipedia(word, box, get_fullpage, forced_lang)
else else
self.lookup_msg = T(_("Searching Wikipedia %2 for:\n%1"), "%1", lang:upper()) self.lookup_msg = T(_("Searching Wikipedia %2 for:\n%1"), "%1", lang:upper())
end end
self:onLookupStarted(word) self:showLookupInfo(word)
local results = {} local results = {}
local ok, pages local ok, pages
if get_fullpage then if get_fullpage then
@ -193,7 +193,6 @@ function ReaderWikipedia:onLookupWikipedia(word, box, get_fullpage, forced_lang)
} }
logger.dbg("dummy result table:", word, results) logger.dbg("dummy result table:", word, results)
end end
self:onLookupDone()
self:showDict(word, results, box) self:showDict(word, results, box)
end end

View File

@ -32,6 +32,7 @@ local order = {
}, },
setting = { setting = {
"read_from_right_to_left", "read_from_right_to_left",
"disable_fuzzy_search",
-- common settings -- common settings
-- those that don't exist will simply be skipped during menu gen -- those that don't exist will simply be skipped during menu gen
"frontlight", -- if Device:hasFrontlight() "frontlight", -- if Device:hasFrontlight()