Attempt to get rid of tweak_buttons_func completely

reviewable/pr11777/r1
nairyo 4 weeks ago
parent cdea878db4
commit 7111161fdf

@ -424,7 +424,7 @@ function ReaderDictionary:addToMainMenu(menu_items)
end
end
function ReaderDictionary:onLookupWord(word, is_sane, boxes, highlight, link, tweak_buttons_func)
function ReaderDictionary:onLookupWord(word, is_sane, boxes, highlight, link)
logger.dbg("dict lookup word:", word, boxes)
-- escape quotes and other funny characters in word
word = self:cleanSelection(word, is_sane)
@ -440,7 +440,7 @@ function ReaderDictionary:onLookupWord(word, is_sane, boxes, highlight, link, tw
-- Wrapped through Trapper, as we may be using Trapper:dismissablePopen() in it
Trapper:wrap(function()
self:stardictLookup(word, self.enabled_dict_names, not disable_fuzzy_search, boxes, link, tweak_buttons_func)
self:stardictLookup(word, self.enabled_dict_names, not disable_fuzzy_search, boxes, link)
end)
return true
end
@ -932,7 +932,7 @@ function ReaderDictionary:startSdcv(word, dict_names, fuzzy_search)
return results
end
function ReaderDictionary:stardictLookup(word, dict_names, fuzzy_search, boxes, link, tweak_buttons_func)
function ReaderDictionary:stardictLookup(word, dict_names, fuzzy_search, boxes, link)
if word == "" then
return
end
@ -992,16 +992,15 @@ function ReaderDictionary:stardictLookup(word, dict_names, fuzzy_search, boxes,
return
end
self:showDict(word, tidyMarkup(results), boxes, link, tweak_buttons_func)
self:showDict(word, tidyMarkup(results), boxes, link)
end
function ReaderDictionary:showDict(word, results, boxes, link, tweak_buttons_func)
function ReaderDictionary:showDict(word, results, boxes, link)
if results and results[1] then
logger.dbg("showing quick lookup window", #DictQuickLookup.window_list+1, ":", word, results)
self.dict_window = DictQuickLookup:new{
ui = self.ui,
highlight = self.highlight,
tweak_buttons_func = tweak_buttons_func,
dialog = self.dialog,
-- original lookup word
word = word,

@ -526,9 +526,7 @@ function DictQuickLookup:init()
})
end
end
if self.tweak_buttons_func then
self:tweak_buttons_func(buttons)
elseif self.ui then
if self.ui then
self.ui:handleEvent(Event:new("DictButtonsReady", self, buttons))
end
-- Bottom buttons get a bit less padding so their line separators

@ -472,7 +472,6 @@ end
function MenuDialog:onChangeEnableStatus(args, position)
settings.enabled = position == 2
saveSettings()
resetButtonOnLookupWindow()
end
function MenuDialog:onConfigChoose(values, name, event, args, position)
@ -1219,6 +1218,7 @@ end
Container widget. Same as sortwidget
--]]--
local VocabularyBuilderWidget = FocusManager:extend{
id = "vocab_builder_widget",
title = "",
width = nil,
height = nil,
@ -1919,15 +1919,55 @@ function VocabBuilder:addToMainMenu(menu_items)
}
end
function VocabularyBuilderWidget:onDictButtonsReady(_, buttons)
if self.due_time > os.time() then
return nil
end
local tweaked_button_count = 0
local early_break
for j = 1, #buttons do
for k = 1, #buttons[j] do
if buttons[j][k].id == "highlight" and not buttons[j][k].enabled then
buttons[j][k] = {
id = "got_it",
text = _("Got it"),
callback = function()
self.widget:gotItFromDict(self.word)
UIManager:sendEvent(Event:new("Close"))
end
}
if tweaked_button_count == 1 then
early_break = true
break
end
tweaked_button_count = tweaked_button_count + 1
elseif buttons[j][k].id == "search" and not buttons[j][k].enabled then
buttons[j][k] = {
id = "forgot",
text = _("Forgot"),
callback = function()
self.widget:forgotFromDict(self.word)
UIManager:sendEvent(Event:new("Close"))
end
}
if tweaked_button_count == 1 then
early_break = true
break
end
tweaked_button_count = tweaked_button_count + 1
end
end
if early_break then break end
end
return true -- we consume the event here!
end
function VocabBuilder:onDictButtonsReady(obj, buttons)
if obj.is_wiki_fullpage then
if settings.enabled then
-- words are added automatically, no need to add the button
return
elseif obj.is_wiki then
-- make wiki window have the same button_tweak as its presenting dictionary window
local widget = UIManager:getNthTopWidget(2)
if widget and widget.tweak_buttons_func then
widget:tweak_buttons_func(buttons)
end
end
if obj.is_wiki_fullpage then
return
end
table.insert(buttons, 1, {{
@ -1957,54 +1997,11 @@ function VocabBuilder:setupWidget()
local reload_items = function(widget)
widget.reload_time = os.time()
local vocab_items = {}
for i = 1, DB:selectCount(widget) do
for _ = 1, DB:selectCount(widget) do
table.insert(vocab_items, {
callback = function(item)
-- custom button table
local tweak_buttons_func = function() end
if item.due_time <= os.time() then
tweak_buttons_func = function(obj, buttons)
local tweaked_button_count = 0
local early_break
for j = 1, #buttons do
for k = 1, #buttons[j] do
if buttons[j][k].id == "highlight" and not buttons[j][k].enabled then
buttons[j][k] = {
id = "got_it",
text = _("Got it"),
callback = function()
self.widget:gotItFromDict(item.word)
UIManager:sendEvent(Event:new("Close"))
end
}
if tweaked_button_count == 1 then
early_break = true
break
end
tweaked_button_count = tweaked_button_count + 1
elseif buttons[j][k].id == "search" and not buttons[j][k].enabled then
buttons[j][k] = {
id = "forgot",
text = _("Forgot"),
callback = function()
self.widget:forgotFromDict(item.word)
UIManager:sendEvent(Event:new("Close"))
end
}
if tweaked_button_count == 1 then
early_break = true
break
end
tweaked_button_count = tweaked_button_count + 1
end
end
if early_break then break end
end
end
end
widget.current_lookup_word = item.word
self.ui:handleEvent(Event:new("LookupWord", item.word, true, nil, nil, nil, tweak_buttons_func))
self.ui:handleEvent(Event:new("LookupWord", item.word, true, nil, nil, nil))
end
})
end

Loading…
Cancel
Save