mirror of
https://github.com/koreader/koreader.git
synced 2025-12-13 20:36:53 +01:00
Touchmenu: fix menu refreshing on check (#13996)
This commit is contained in:
@@ -99,6 +99,7 @@ function ReaderBookmark:addToMainMenu(menu_items)
|
||||
checked_func = function()
|
||||
return self.ui.paging.bookmark_flipping_mode
|
||||
end,
|
||||
check_callback_closes_menu = true,
|
||||
callback = function(touchmenu_instance)
|
||||
self.ui.paging:onToggleBookmarkFlipping()
|
||||
touchmenu_instance:closeMenu()
|
||||
|
||||
@@ -1122,6 +1122,7 @@ See Style tweaks → Miscellaneous → Alternative ToC hints.]])
|
||||
checked_func = function()
|
||||
return self.ui.document:isTocAlternativeToc()
|
||||
end,
|
||||
check_callback_closes_menu = true,
|
||||
callback = function(touchmenu_instance)
|
||||
if self.ui.document:isTocAlternativeToc() then
|
||||
UIManager:show(ConfirmBox:new{
|
||||
|
||||
@@ -995,11 +995,10 @@ function Dispatcher:addSubMenu(caller, menu, location, settings)
|
||||
menu.ignored_by_menu_search = true -- all those would be duplicated
|
||||
table.insert(menu, {
|
||||
text = _("Nothing"),
|
||||
keep_menu_open = true,
|
||||
no_refresh_on_check = true,
|
||||
checked_func = function()
|
||||
return location[settings] ~= nil and Dispatcher:_itemsCount(location[settings]) == 0
|
||||
end,
|
||||
check_callback_updates_menu = true,
|
||||
callback = function(touchmenu_instance)
|
||||
local function do_remove()
|
||||
local actions = location[settings]
|
||||
|
||||
@@ -14,6 +14,7 @@ local function genMenuItem(text, mode)
|
||||
return Screen:getRotationMode() == mode
|
||||
end,
|
||||
radio = true,
|
||||
check_callback_closes_menu = true,
|
||||
callback = function(touchmenu_instance)
|
||||
UIManager:broadcastEvent(Event:new("SetRotationMode", mode))
|
||||
touchmenu_instance:closeMenu()
|
||||
|
||||
@@ -50,6 +50,8 @@ local TouchMenuItem = InputContainer:extend{
|
||||
dimen = nil,
|
||||
face = Font:getFace("smallinfofont"),
|
||||
show_parent = nil,
|
||||
check_callback_updates_menu = nil, -- set to true for item with checkmark if its callback updates menu
|
||||
check_callback_closes_menu = nil, -- set to true for item with checkmark if its callback closes menu
|
||||
}
|
||||
|
||||
function TouchMenuItem:init()
|
||||
@@ -206,8 +208,7 @@ function TouchMenuItem:onTapSelect(arg, ges)
|
||||
-- Unhighlight
|
||||
--
|
||||
self.item_frame.invert = false
|
||||
-- NOTE: If the menu is going to be closed, we can safely drop that.
|
||||
if self.item.keep_menu_open then
|
||||
if self.item.keep_menu_open or self.item.check_callback_updates_menu then
|
||||
UIManager:widgetInvert(self.item_frame, highlight_dimen.x, highlight_dimen.y, highlight_dimen.w)
|
||||
UIManager:setDirty(nil, "ui", highlight_dimen)
|
||||
end
|
||||
@@ -924,7 +925,7 @@ function TouchMenu:onMenuSelect(item, tap_on_checkmark)
|
||||
-- must set keep_menu_open=true if that is wished)
|
||||
callback(self)
|
||||
if refresh then
|
||||
if not item.no_refresh_on_check then
|
||||
if not (item.check_callback_updates_menu or item.check_callback_closes_menu) then
|
||||
self:updateItems()
|
||||
end
|
||||
elseif not item.keep_menu_open then
|
||||
|
||||
@@ -170,8 +170,8 @@ function SSH:addToMainMenu(menu_items)
|
||||
sub_item_table = {
|
||||
{
|
||||
text = _("SSH server"),
|
||||
keep_menu_open = true,
|
||||
checked_func = function() return self:isRunning() end,
|
||||
check_callback_updates_menu = true,
|
||||
callback = function(touchmenu_instance)
|
||||
self:onToggleSSHServer()
|
||||
-- sleeping might not be needed, but it gives the feeling
|
||||
|
||||
@@ -131,6 +131,7 @@ function AutoTurn:addToMainMenu(menu_items)
|
||||
return self:_enabled() and T(_("Autoturn: %1"), time_string) or _("Autoturn")
|
||||
end,
|
||||
checked_func = function() return self:_enabled() end,
|
||||
check_callback_updates_menu = true,
|
||||
callback = function(menu)
|
||||
local DateTimeWidget = require("ui/widget/datetimewidget")
|
||||
local autoturn_seconds = G_reader_settings:readSetting("autoturn_timeout_seconds", 30)
|
||||
|
||||
@@ -608,6 +608,7 @@ function AutoWarmth:getSubMenuItems()
|
||||
return not self.easy_mode
|
||||
end,
|
||||
help_text = _("In the expert mode, different types of twilight can be used in addition to civil twilight."),
|
||||
check_callback_updates_menu = true,
|
||||
callback = function(touchmenu_instance)
|
||||
self.easy_mode = not self.easy_mode
|
||||
G_reader_settings:saveSetting("autowarmth_easy_mode", self.easy_mode)
|
||||
@@ -662,6 +663,7 @@ function AutoWarmth:getFlOffDuringDayMenu()
|
||||
return _("Frontlight off during day")
|
||||
end
|
||||
end,
|
||||
check_callback_updates_menu = true,
|
||||
callback = function(touchmenu_instance)
|
||||
if self.easy_mode then
|
||||
self.fl_off_during_day = not self.fl_off_during_day
|
||||
@@ -889,6 +891,7 @@ function AutoWarmth:getScheduleMenu()
|
||||
checked_func = function()
|
||||
return self.scheduler_times[num] ~= nil
|
||||
end,
|
||||
check_callback_updates_menu = true,
|
||||
callback = function(touchmenu_instance)
|
||||
local hh = 12
|
||||
local mm = 0
|
||||
@@ -1112,6 +1115,7 @@ function AutoWarmth:getWarmthMenu()
|
||||
})
|
||||
end
|
||||
end,
|
||||
check_callback_updates_menu = true,
|
||||
callback = function(touchmenu_instance)
|
||||
if Device:hasNaturalLight() then
|
||||
if self.control_warmth and self.control_nightmode then
|
||||
|
||||
@@ -303,6 +303,7 @@ function Calibre:getWirelessMenuTable()
|
||||
checked_func = function()
|
||||
return G_reader_settings:has("calibre_wireless_url")
|
||||
end,
|
||||
check_callback_updates_menu = true,
|
||||
callback = function(touchmenu_instance)
|
||||
local MultiInputDialog = require("ui/widget/multiinputdialog")
|
||||
local url_dialog
|
||||
|
||||
@@ -502,6 +502,7 @@ function CoverImage:menuEntryCache()
|
||||
checked_func = function()
|
||||
return self.cover_image_cache_maxfiles >= 0
|
||||
end,
|
||||
check_callback_updates_menu = true,
|
||||
callback = function(touchmenu_instance)
|
||||
self:sizeSpinner(touchmenu_instance, "cover_image_cache_maxfiles", _("Number of covers"), -1, 100, 36, self.cleanCache)
|
||||
end,
|
||||
@@ -522,6 +523,7 @@ function CoverImage:menuEntryCache()
|
||||
checked_func = function()
|
||||
return self.cover_image_cache_maxsize >= 0
|
||||
end,
|
||||
check_callback_updates_menu = true,
|
||||
callback = function(touchmenu_instance)
|
||||
self:sizeSpinner(touchmenu_instance, "cover_image_cache_maxsize", _("Cache size"), -1, 100, 5, self.cleanCache, C_("Data storage size", "MB"))
|
||||
end,
|
||||
@@ -574,6 +576,7 @@ function CoverImage:menuEntrySetPath(key, title, help, info, default, folder_onl
|
||||
checked_func = function()
|
||||
return isFileOk(self[key]) or (isPathAllowed(self[key]) and folder_only)
|
||||
end,
|
||||
check_callback_updates_menu = true,
|
||||
callback = function(touchmenu_instance)
|
||||
UIManager:show(ConfirmBox:new{
|
||||
text = info,
|
||||
|
||||
@@ -295,11 +295,10 @@ function Gestures:genMenu(ges)
|
||||
if gestures_list[ges] ~= nil then
|
||||
table.insert(sub_items, {
|
||||
text = T(_("%1 (default)"), Dispatcher:menuTextFunc(self.defaults[ges])),
|
||||
keep_menu_open = true,
|
||||
no_refresh_on_check = true,
|
||||
checked_func = function()
|
||||
return util.tableEquals(self.gestures[ges], self.defaults[ges])
|
||||
end,
|
||||
check_callback_updates_menu = true,
|
||||
callback = function(touchmenu_instance)
|
||||
local function do_remove()
|
||||
self.gestures[ges] = util.tableDeepCopy(self.defaults[ges])
|
||||
@@ -313,11 +312,10 @@ function Gestures:genMenu(ges)
|
||||
end
|
||||
table.insert(sub_items, {
|
||||
text = _("Pass through"),
|
||||
keep_menu_open = true,
|
||||
no_refresh_on_check = true,
|
||||
checked_func = function()
|
||||
return self.gestures[ges] == nil
|
||||
end,
|
||||
check_callback_updates_menu = true,
|
||||
callback = function(touchmenu_instance)
|
||||
local function do_remove()
|
||||
self.gestures[ges] = nil
|
||||
|
||||
@@ -192,11 +192,10 @@ function HotKeys:genMenu(hotkey)
|
||||
local default_text = default_action and Dispatcher:menuTextFunc(default_action) or _("No action")
|
||||
table.insert(sub_items, {
|
||||
text = T(_("%1 (default)"), default_text),
|
||||
keep_menu_open = true,
|
||||
no_refresh_on_check = true,
|
||||
checked_func = function()
|
||||
return util.tableEquals(self.hotkeys[hotkey], self.defaults[hotkey])
|
||||
end,
|
||||
check_callback_updates_menu = true,
|
||||
callback = function(touchmenu_instance)
|
||||
local function do_remove()
|
||||
self.hotkeys[hotkey] = util.tableDeepCopy(self.defaults[hotkey])
|
||||
@@ -209,12 +208,10 @@ function HotKeys:genMenu(hotkey)
|
||||
end
|
||||
table.insert(sub_items, {
|
||||
text = _("No action"),
|
||||
keep_menu_open = true,
|
||||
no_refresh_on_check = true,
|
||||
separator = true,
|
||||
checked_func = function()
|
||||
return self.hotkeys[hotkey] == nil or next(self.hotkeys[hotkey]) == nil
|
||||
end,
|
||||
check_callback_updates_menu = true,
|
||||
callback = function(touchmenu_instance)
|
||||
local function do_remove()
|
||||
self.hotkeys[hotkey] = nil
|
||||
@@ -223,6 +220,7 @@ function HotKeys:genMenu(hotkey)
|
||||
end
|
||||
Dispatcher.removeActions(self.hotkeys[hotkey], do_remove)
|
||||
end,
|
||||
separator = true,
|
||||
})
|
||||
Dispatcher:addSubMenu(self, sub_items, self.hotkeys, hotkey)
|
||||
-- Since we are already handling potential conflicts via overrideConflictingKeyEvents(), both "No action" and "Nothing",
|
||||
|
||||
@@ -629,10 +629,10 @@ function Profiles:genAutoExecPathChangedMenuItem(text, event, profile_name, sepa
|
||||
local value = util.tableGetValue(self.autoexec, event, profile_name, condition)
|
||||
return value and txt .. ": " .. value or txt
|
||||
end,
|
||||
no_refresh_on_check = true,
|
||||
checked_func = function()
|
||||
return util.tableGetValue(self.autoexec, event, profile_name, condition)
|
||||
end,
|
||||
check_callback_updates_menu = true,
|
||||
callback = function(touchmenu_instance)
|
||||
local dialog
|
||||
local buttons = {{
|
||||
@@ -760,10 +760,10 @@ function Profiles:genAutoExecDocConditionalMenuItem(text, event, profile_name, s
|
||||
local txt = util.tableGetValue(self.autoexec, event, profile_name, condition, prop)
|
||||
return txt and title .. " " .. txt or title:sub(1, -2)
|
||||
end,
|
||||
no_refresh_on_check = true,
|
||||
checked_func = function()
|
||||
return util.tableGetValue(self.autoexec, event, profile_name, condition, prop) and true
|
||||
end,
|
||||
check_callback_updates_menu = true,
|
||||
callback = function(touchmenu_instance)
|
||||
local dialog
|
||||
local buttons = self.document == nil and {} or {{
|
||||
@@ -830,10 +830,10 @@ function Profiles:genAutoExecDocConditionalMenuItem(text, event, profile_name, s
|
||||
enabled_func = function()
|
||||
return not util.tableGetValue(self.autoexec, event_always, profile_name)
|
||||
end,
|
||||
no_refresh_on_check = true,
|
||||
checked_func = function()
|
||||
return util.tableGetValue(self.autoexec, event, profile_name, conditions[3][2]) and true
|
||||
end,
|
||||
check_callback_updates_menu = true,
|
||||
callback = function(touchmenu_instance)
|
||||
local condition = conditions[3][2]
|
||||
local dialog
|
||||
@@ -895,10 +895,10 @@ function Profiles:genAutoExecDocConditionalMenuItem(text, event, profile_name, s
|
||||
enabled_func = function()
|
||||
return not util.tableGetValue(self.autoexec, event_always, profile_name)
|
||||
end,
|
||||
no_refresh_on_check = true,
|
||||
checked_func = function()
|
||||
return util.tableGetValue(self.autoexec, event, profile_name, conditions[4][2]) and true
|
||||
end,
|
||||
check_callback_updates_menu = true,
|
||||
callback = function(touchmenu_instance)
|
||||
local condition = conditions[4][2]
|
||||
local collections = util.tableGetValue(self.autoexec, event, profile_name, condition)
|
||||
|
||||
Reference in New Issue
Block a user