DictQuickLooup: Fix a few bad interactions with ReaderHighlight's dialog (#7432)

* Disable the Search button when docless and highlight-less.
* Make sure launching a Search closes ReaderHighlight's dialog in all cases. Fix #7430
pull/7437/head
NiLuJe 3 years ago committed by GitHub
parent 861214ce2a
commit 2944d53e7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -83,7 +83,6 @@ function ReaderHighlight:init()
text = _("Search"),
callback = function()
_self:onHighlightSearch()
UIManager:close(self.highlight_dialog)
-- We don't call _self:onClose(), crengine will highlight
-- search matches on the current page, and self:clear()
-- would redraw and remove crengine native highlights
@ -100,7 +99,7 @@ function ReaderHighlight:init()
_self:lookupWikipedia()
-- We don't call _self:onClose(), we need the highlight
-- to still be there, as we may Highlight it from the
-- dict lookup widget
-- dict lookup widget.
end)
end,
}
@ -562,6 +561,7 @@ function ReaderHighlight:onShowHighlightDialog(page, index)
self:deleteHighlight(page, index)
-- other part outside of the dialog may be dirty
UIManager:close(self.edit_highlight_dialog, "ui")
self.edit_highlight_dialog = nil
end,
},
{
@ -569,6 +569,7 @@ function ReaderHighlight:onShowHighlightDialog(page, index)
callback = function()
self:editHighlight(page, index)
UIManager:close(self.edit_highlight_dialog)
self.edit_highlight_dialog = nil
end,
},
{
@ -577,6 +578,7 @@ function ReaderHighlight:onShowHighlightDialog(page, index)
self.selected_text = self.view.highlight.saved[page][index]
self:onShowHighlightMenu()
UIManager:close(self.edit_highlight_dialog)
self.edit_highlight_dialog = nil
end,
},
}
@ -1383,6 +1385,7 @@ function ReaderHighlight:addNote()
local page, index = self:saveHighlight()
self:editHighlight(page, index)
UIManager:close(self.edit_highlight_dialog)
self.edit_highlight_dialog = nil
self.ui:handleEvent(Event:new("AddNote"))
end
@ -1394,6 +1397,11 @@ end
function ReaderHighlight:onHighlightSearch()
logger.dbg("search highlight")
-- First, if our dialog is still shown, close it.
if self.highlight_dialog then
UIManager:close(self.highlight_dialog)
self.highlight_dialog = nil
end
self:highlightFromHoldPos()
if self.selected_text then
local text = util.stripPunctuation(cleanupSelectedText(self.selected_text.text))
@ -1482,6 +1490,7 @@ end
function ReaderHighlight:onClose()
UIManager:close(self.highlight_dialog)
self.highlight_dialog = nil
-- clear highlighted text
self:clear()
end

@ -61,6 +61,26 @@ local highlight_strings = {
unhighlight = _("Unhighlight"),
}
function DictQuickLookup:canSearch()
if self:isDocless() then
return false
end
if self.is_wiki then
-- In the Wiki variant of this widget, the Search button is coopted to cycle between enabled languages.
if #self.wiki_languages > 1 then
return true
end
else
-- This is to prevent an ineffective button when we're launched from the Reader's menu.
if self.ui.highlight.selected_text then
return true
end
end
return false
end
function DictQuickLookup:init()
self.dict_font_size = G_reader_settings:readSetting("dict_font_size") or 20
self.content_face = Font:getFace("cfont", self.dict_font_size)
@ -370,16 +390,14 @@ function DictQuickLookup:init()
self:onHoldClose(true)
-- close current ReaderUI in 1 sec, and create a new one
UIManager:scheduleIn(1.0, function()
local ReaderUI = require("apps/reader/readerui")
local reader = ReaderUI:_getRunningInstance()
if reader then
if self.ui then
-- close Highlight menu if any still shown
if reader.highlight then
reader.highlight:onClose()
if self.ui.highlight and self.ui.highlight.highlight_dialog then
self.ui.highlight:onClose()
end
reader:onClose()
self.ui:onClose()
end
ReaderUI:showReader(epub_path)
self.ui:showReader(epub_path)
end)
end,
})
@ -426,7 +444,7 @@ function DictQuickLookup:init()
{
id = "highlight",
text = self:getHighlightText(),
enabled = self.highlight ~= nil,
enabled = not self:isDocless() and self.highlight ~= nil,
callback = function()
if self:getHighlightText() == highlight_strings.highlight then
self.ui:handleEvent(Event:new("Highlight"))
@ -482,7 +500,7 @@ function DictQuickLookup:init()
and ( #self.wiki_languages > 1 and BD.wrap(self.wiki_languages[1]).." > "..BD.wrap(self.wiki_languages[2])
or self.wiki_languages[1] ) -- (this " > " will be auro-mirrored by bidi)
or _("Search"),
enabled = not self.is_wiki and true or #self.wiki_languages > 1,
enabled = self:canSearch(),
callback = function()
if self.is_wiki then
self:resyncWikiLanguages(true) -- rotate & resync them
@ -881,6 +899,7 @@ function DictQuickLookup:onCloseWidget()
end
end
end
-- NOTE: Drop region to make it a full-screen flash
UIManager:setDirty(nil, function()
return "flashui", nil

Loading…
Cancel
Save