2019-12-06 21:55:39 +00:00
|
|
|
local BD = require("ui/bidi")
|
2013-10-18 20:38:07 +00:00
|
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
2018-07-07 11:03:33 +00:00
|
|
|
local ConfirmBox = require("ui/widget/confirmbox")
|
2014-10-30 18:42:18 +00:00
|
|
|
local Device = require("device")
|
2013-10-18 20:38:07 +00:00
|
|
|
local Event = require("ui/event")
|
2017-03-28 22:10:36 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
|
|
|
local Screensaver = require("ui/screensaver")
|
|
|
|
local UIManager = require("ui/uimanager")
|
2017-04-21 09:19:14 +00:00
|
|
|
local logger = require("logger")
|
|
|
|
local dbg = require("dbg")
|
2018-07-07 11:03:33 +00:00
|
|
|
local util = require("util")
|
2017-04-21 09:19:14 +00:00
|
|
|
local Screen = Device.screen
|
2017-04-24 06:27:29 +00:00
|
|
|
local _ = require("gettext")
|
2018-07-07 11:03:33 +00:00
|
|
|
local T = require("ffi/util").template
|
2013-10-18 20:38:07 +00:00
|
|
|
|
|
|
|
local ReaderMenu = InputContainer:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
tab_item_table = nil,
|
2017-02-28 21:46:32 +00:00
|
|
|
menu_items = {},
|
2014-03-13 13:52:43 +00:00
|
|
|
registered_widgets = {},
|
2012-12-15 01:20:12 +00:00
|
|
|
}
|
2012-11-11 07:24:11 +00:00
|
|
|
|
|
|
|
function ReaderMenu:init()
|
2017-03-03 06:41:10 +00:00
|
|
|
self.menu_items = {
|
|
|
|
["KOMenu:menu_buttons"] = {
|
|
|
|
-- top menu
|
|
|
|
},
|
|
|
|
-- items in top menu
|
|
|
|
navi = {
|
2020-12-19 11:18:30 +00:00
|
|
|
icon = "appbar.navigation",
|
2017-03-03 06:41:10 +00:00
|
|
|
},
|
|
|
|
typeset = {
|
2020-12-19 11:18:30 +00:00
|
|
|
icon = "appbar.typeset",
|
2017-03-03 06:41:10 +00:00
|
|
|
},
|
|
|
|
setting = {
|
2020-12-19 11:18:30 +00:00
|
|
|
icon = "appbar.settings",
|
2017-03-03 06:41:10 +00:00
|
|
|
},
|
|
|
|
tools = {
|
2020-12-19 11:18:30 +00:00
|
|
|
icon = "appbar.tools",
|
2017-03-03 06:41:10 +00:00
|
|
|
},
|
|
|
|
search = {
|
2020-12-19 11:18:30 +00:00
|
|
|
icon = "appbar.search",
|
2017-03-03 06:41:10 +00:00
|
|
|
},
|
|
|
|
filemanager = {
|
2020-12-19 11:18:30 +00:00
|
|
|
icon = "appbar.filebrowser",
|
2017-03-03 06:41:10 +00:00
|
|
|
remember = false,
|
|
|
|
callback = function()
|
|
|
|
self:onTapCloseMenu()
|
|
|
|
self.ui:onClose()
|
2017-06-17 03:44:29 +00:00
|
|
|
self.ui:showFileManager()
|
2017-03-03 06:41:10 +00:00
|
|
|
end,
|
|
|
|
},
|
|
|
|
main = {
|
2020-12-19 11:18:30 +00:00
|
|
|
icon = "appbar.menu",
|
2017-03-03 06:41:10 +00:00
|
|
|
}
|
2017-02-28 21:46:32 +00:00
|
|
|
}
|
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
self.registered_widgets = {}
|
|
|
|
|
2014-06-10 07:57:10 +00:00
|
|
|
if Device:hasKeys() then
|
2016-12-27 07:06:47 +00:00
|
|
|
if Device:isTouchDevice() then
|
|
|
|
self.key_events.TapShowMenu = { { "Menu" }, doc = "show menu", }
|
2020-06-04 11:26:18 +00:00
|
|
|
if Device:hasFewKeys() then
|
|
|
|
self.key_events.TapShowMenu = { { { "Menu", "Right" } }, doc = "show menu", }
|
|
|
|
end
|
2016-12-27 07:06:47 +00:00
|
|
|
else
|
|
|
|
-- map menu key to only top menu because bottom menu is only
|
|
|
|
-- designed for touch devices
|
2020-07-12 18:47:49 +00:00
|
|
|
self.key_events.ShowMenu = { { "Menu" }, doc = "show menu", }
|
2020-06-04 11:26:18 +00:00
|
|
|
if Device:hasFewKeys() then
|
2020-07-12 18:47:49 +00:00
|
|
|
self.key_events.ShowMenu = { { { "Menu", "Right" } }, doc = "show menu", }
|
2020-06-04 11:26:18 +00:00
|
|
|
end
|
2016-12-27 07:06:47 +00:00
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2021-03-06 21:44:18 +00:00
|
|
|
if G_reader_settings:has("activate_menu") then
|
|
|
|
self.activation_menu = G_reader_settings:readSetting("activate_menu")
|
|
|
|
else
|
2017-08-08 16:20:46 +00:00
|
|
|
self.activation_menu = "swipe_tap"
|
|
|
|
end
|
2012-11-11 07:24:11 +00:00
|
|
|
end
|
2012-06-10 18:14:29 +00:00
|
|
|
|
2019-02-22 15:29:19 +00:00
|
|
|
function ReaderMenu:getPreviousFile()
|
2020-05-06 19:11:34 +00:00
|
|
|
return require("readhistory"):getPreviousFile(self.ui.document.file)
|
2019-02-22 15:29:19 +00:00
|
|
|
end
|
|
|
|
|
2016-12-19 04:27:56 +00:00
|
|
|
function ReaderMenu:onReaderReady()
|
|
|
|
-- deligate gesture listener to readerui
|
|
|
|
self.ges_events = {}
|
|
|
|
self.onGesture = nil
|
|
|
|
if not Device:isTouchDevice() then return end
|
|
|
|
|
|
|
|
self.ui:registerTouchZones({
|
2017-06-01 16:32:06 +00:00
|
|
|
{
|
|
|
|
id = "readermenu_tap",
|
|
|
|
ges = "tap",
|
|
|
|
screen_zone = {
|
|
|
|
ratio_x = DTAP_ZONE_MENU.x, ratio_y = DTAP_ZONE_MENU.y,
|
|
|
|
ratio_w = DTAP_ZONE_MENU.w, ratio_h = DTAP_ZONE_MENU.h,
|
|
|
|
},
|
2019-03-30 20:05:44 +00:00
|
|
|
overrides = {
|
|
|
|
"tap_forward",
|
|
|
|
"tap_backward",
|
|
|
|
},
|
2017-06-01 16:32:06 +00:00
|
|
|
handler = function(ges) return self:onTapShowMenu(ges) end,
|
|
|
|
},
|
2020-12-03 16:33:54 +00:00
|
|
|
{
|
|
|
|
id = "readermenu_ext_tap",
|
|
|
|
ges = "tap",
|
|
|
|
screen_zone = {
|
|
|
|
ratio_x = DTAP_ZONE_MENU_EXT.x, ratio_y = DTAP_ZONE_MENU_EXT.y,
|
|
|
|
ratio_w = DTAP_ZONE_MENU_EXT.w, ratio_h = DTAP_ZONE_MENU_EXT.h,
|
|
|
|
},
|
|
|
|
overrides = {
|
|
|
|
"readermenu_tap",
|
|
|
|
},
|
|
|
|
handler = function(ges) return self:onTapShowMenu(ges) end,
|
|
|
|
},
|
2016-12-19 04:27:56 +00:00
|
|
|
{
|
2017-04-15 12:45:56 +00:00
|
|
|
id = "readermenu_swipe",
|
|
|
|
ges = "swipe",
|
2016-12-19 04:27:56 +00:00
|
|
|
screen_zone = {
|
|
|
|
ratio_x = DTAP_ZONE_MENU.x, ratio_y = DTAP_ZONE_MENU.y,
|
|
|
|
ratio_w = DTAP_ZONE_MENU.w, ratio_h = DTAP_ZONE_MENU.h,
|
|
|
|
},
|
2019-03-30 20:05:44 +00:00
|
|
|
overrides = {
|
|
|
|
"rolling_swipe",
|
|
|
|
"paging_swipe",
|
|
|
|
},
|
2017-04-15 12:45:56 +00:00
|
|
|
handler = function(ges) return self:onSwipeShowMenu(ges) end,
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
2020-12-03 16:33:54 +00:00
|
|
|
{
|
|
|
|
id = "readermenu_ext_swipe",
|
|
|
|
ges = "swipe",
|
|
|
|
screen_zone = {
|
|
|
|
ratio_x = DTAP_ZONE_MENU_EXT.x, ratio_y = DTAP_ZONE_MENU_EXT.y,
|
|
|
|
ratio_w = DTAP_ZONE_MENU_EXT.w, ratio_h = DTAP_ZONE_MENU_EXT.h,
|
|
|
|
},
|
|
|
|
overrides = {
|
|
|
|
"readermenu_swipe",
|
|
|
|
},
|
|
|
|
handler = function(ges) return self:onSwipeShowMenu(ges) end,
|
|
|
|
},
|
2017-04-24 06:33:12 +00:00
|
|
|
{
|
|
|
|
id = "readermenu_pan",
|
|
|
|
ges = "pan",
|
|
|
|
screen_zone = {
|
|
|
|
ratio_x = DTAP_ZONE_MENU.x, ratio_y = DTAP_ZONE_MENU.y,
|
|
|
|
ratio_w = DTAP_ZONE_MENU.w, ratio_h = DTAP_ZONE_MENU.h,
|
|
|
|
},
|
2019-03-30 20:05:44 +00:00
|
|
|
overrides = {
|
|
|
|
"rolling_pan",
|
|
|
|
"paging_pan",
|
|
|
|
},
|
2017-04-24 06:33:12 +00:00
|
|
|
handler = function(ges) return self:onSwipeShowMenu(ges) end,
|
|
|
|
},
|
2020-12-03 16:33:54 +00:00
|
|
|
{
|
|
|
|
id = "readermenu_ext_pan",
|
|
|
|
ges = "pan",
|
|
|
|
screen_zone = {
|
|
|
|
ratio_x = DTAP_ZONE_MENU_EXT.x, ratio_y = DTAP_ZONE_MENU_EXT.y,
|
|
|
|
ratio_w = DTAP_ZONE_MENU_EXT.w, ratio_h = DTAP_ZONE_MENU_EXT.h,
|
|
|
|
},
|
|
|
|
overrides = {
|
|
|
|
"readermenu_pan",
|
|
|
|
},
|
|
|
|
handler = function(ges) return self:onSwipeShowMenu(ges) end,
|
|
|
|
},
|
2016-12-19 04:27:56 +00:00
|
|
|
})
|
2013-02-02 06:36:29 +00:00
|
|
|
end
|
|
|
|
|
2012-12-15 01:20:12 +00:00
|
|
|
function ReaderMenu:setUpdateItemTable()
|
2014-03-13 13:52:43 +00:00
|
|
|
for _, widget in pairs(self.registered_widgets) do
|
2017-04-21 09:19:14 +00:00
|
|
|
local ok, err = pcall(widget.addToMainMenu, widget, self.menu_items)
|
|
|
|
if not ok then
|
|
|
|
logger.err("failed to register widget", widget.name, err)
|
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
|
|
|
|
2014-11-21 14:41:14 +00:00
|
|
|
-- settings tab
|
|
|
|
-- insert common settings
|
2019-03-02 20:45:12 +00:00
|
|
|
for id, common_setting in pairs(dofile("frontend/ui/elements/common_settings_menu_table.lua")) do
|
2017-02-28 21:46:32 +00:00
|
|
|
self.menu_items[id] = common_setting
|
2014-11-21 14:41:14 +00:00
|
|
|
end
|
|
|
|
-- insert DjVu render mode submenu just before the last entry (show advanced)
|
|
|
|
-- this is a bit of a hack
|
2014-10-15 12:31:24 +00:00
|
|
|
if self.ui.document.is_djvu then
|
2017-03-03 06:41:10 +00:00
|
|
|
self.menu_items.djvu_render_mode = self.view:getRenderModeMenuTable()
|
2014-10-15 12:31:24 +00:00
|
|
|
end
|
2014-07-27 13:41:38 +00:00
|
|
|
|
2017-11-10 10:31:00 +00:00
|
|
|
if Device:supportsScreensaver() then
|
2017-12-17 17:27:24 +00:00
|
|
|
local ss_book_settings = {
|
2018-01-21 18:44:12 +00:00
|
|
|
text = _("Exclude this book's cover from screensaver"),
|
2017-12-17 17:27:24 +00:00
|
|
|
enabled_func = function()
|
|
|
|
return not (self.ui == nil or self.ui.document == nil)
|
2021-03-06 21:44:18 +00:00
|
|
|
and G_reader_settings:readSetting("screensaver_type") == "cover"
|
2017-12-17 17:27:24 +00:00
|
|
|
end,
|
2018-01-21 18:44:12 +00:00
|
|
|
checked_func = function()
|
2021-03-06 21:44:18 +00:00
|
|
|
return self.ui and self.ui.doc_settings and self.ui.doc_settings:isTrue("exclude_screensaver")
|
2018-01-21 18:44:12 +00:00
|
|
|
end,
|
|
|
|
callback = function()
|
2021-03-06 21:44:18 +00:00
|
|
|
if Screensaver:isExcluded() then
|
|
|
|
self.ui.doc_settings:makeFalse("exclude_screensaver")
|
2018-01-21 18:44:12 +00:00
|
|
|
else
|
2021-03-06 21:44:18 +00:00
|
|
|
self.ui.doc_settings:makeTrue("exclude_screensaver")
|
2018-01-21 18:44:12 +00:00
|
|
|
end
|
|
|
|
self.ui:saveSettings()
|
2019-10-17 13:03:40 +00:00
|
|
|
end,
|
|
|
|
added_by_readermenu_flag = true,
|
2017-02-28 21:46:32 +00:00
|
|
|
}
|
2019-10-17 13:03:40 +00:00
|
|
|
local screensaver_sub_item_table = require("ui/elements/screensaver_menu")
|
|
|
|
-- Before inserting this new item, remove any previously added one
|
|
|
|
for i = #screensaver_sub_item_table, 1, -1 do
|
|
|
|
if screensaver_sub_item_table[i].added_by_readermenu_flag then
|
|
|
|
table.remove(screensaver_sub_item_table, i)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
table.insert(screensaver_sub_item_table, ss_book_settings)
|
2017-12-17 17:27:24 +00:00
|
|
|
self.menu_items.screensaver = {
|
|
|
|
text = _("Screensaver"),
|
2019-10-17 13:03:40 +00:00
|
|
|
sub_item_table = screensaver_sub_item_table,
|
2017-12-17 17:27:24 +00:00
|
|
|
}
|
2014-09-17 10:25:13 +00:00
|
|
|
end
|
2018-08-17 18:54:11 +00:00
|
|
|
|
|
|
|
local PluginLoader = require("pluginloader")
|
|
|
|
self.menu_items.plugin_management = {
|
|
|
|
text = _("Plugin management"),
|
|
|
|
sub_item_table = PluginLoader:genPluginManagerSubItem()
|
|
|
|
}
|
2017-02-25 10:58:39 +00:00
|
|
|
-- main menu tab
|
|
|
|
-- insert common info
|
2019-03-02 20:45:12 +00:00
|
|
|
for id, common_setting in pairs(dofile("frontend/ui/elements/common_info_menu_table.lua")) do
|
2017-02-28 21:46:32 +00:00
|
|
|
self.menu_items[id] = common_setting
|
2017-02-25 10:58:39 +00:00
|
|
|
end
|
|
|
|
|
2017-09-03 13:40:50 +00:00
|
|
|
self.menu_items.exit_menu = {
|
|
|
|
text = _("Exit"),
|
|
|
|
hold_callback = function()
|
|
|
|
self:exitOrRestart()
|
|
|
|
end,
|
|
|
|
}
|
2017-03-03 06:41:10 +00:00
|
|
|
self.menu_items.exit = {
|
2017-02-25 10:58:39 +00:00
|
|
|
text = _("Exit"),
|
|
|
|
callback = function()
|
2017-05-16 09:11:11 +00:00
|
|
|
self:exitOrRestart()
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
self.menu_items.restart_koreader = {
|
|
|
|
text = _("Restart KOReader"),
|
|
|
|
callback = function()
|
|
|
|
self:exitOrRestart(function() UIManager:restartKOReader() end)
|
2017-02-25 10:58:39 +00:00
|
|
|
end,
|
2017-02-28 21:46:32 +00:00
|
|
|
}
|
2019-08-15 12:49:15 +00:00
|
|
|
if not Device:canRestart() then
|
2019-01-21 21:44:13 +00:00
|
|
|
self.menu_items.exit_menu = self.menu_items.exit
|
|
|
|
self.menu_items.exit = nil
|
|
|
|
self.menu_items.restart_koreader = nil
|
|
|
|
end
|
2017-02-25 10:58:39 +00:00
|
|
|
|
2018-07-07 11:03:33 +00:00
|
|
|
self.menu_items.open_previous_document = {
|
|
|
|
text_func = function()
|
2019-02-22 15:29:19 +00:00
|
|
|
local previous_file = self:getPreviousFile()
|
2018-07-07 11:03:33 +00:00
|
|
|
if not G_reader_settings:isTrue("open_last_menu_show_filename") or not previous_file then
|
|
|
|
return _("Open previous document")
|
|
|
|
end
|
2018-11-28 20:14:07 +00:00
|
|
|
local path, file_name = util.splitFilePathName(previous_file) -- luacheck: no unused
|
2020-01-04 00:18:51 +00:00
|
|
|
return T(_("Previous: %1"), BD.filename(file_name))
|
2018-07-07 11:03:33 +00:00
|
|
|
end,
|
|
|
|
enabled_func = function()
|
2019-02-22 15:29:19 +00:00
|
|
|
return self:getPreviousFile() ~= nil
|
2018-07-07 11:03:33 +00:00
|
|
|
end,
|
|
|
|
callback = function()
|
2020-07-12 18:47:49 +00:00
|
|
|
self.ui:onOpenLastDoc()
|
2018-07-07 11:03:33 +00:00
|
|
|
end,
|
|
|
|
hold_callback = function()
|
2019-02-22 15:29:19 +00:00
|
|
|
local previous_file = self:getPreviousFile()
|
2018-07-07 11:03:33 +00:00
|
|
|
UIManager:show(ConfirmBox:new{
|
2020-01-04 00:18:51 +00:00
|
|
|
text = T(_("Would you like to open the previous document: %1?"), BD.filepath(previous_file)),
|
2018-07-07 11:03:33 +00:00
|
|
|
ok_text = _("OK"),
|
|
|
|
ok_callback = function()
|
|
|
|
self.ui:switchDocument(previous_file)
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
2017-04-14 18:12:21 +00:00
|
|
|
local order = require("ui/elements/reader_menu_order")
|
2017-02-28 21:46:32 +00:00
|
|
|
|
2017-04-14 18:12:21 +00:00
|
|
|
local MenuSorter = require("ui/menusorter")
|
2017-03-24 20:15:35 +00:00
|
|
|
self.tab_item_table = MenuSorter:mergeAndSort("reader", self.menu_items, order)
|
2012-12-15 01:20:12 +00:00
|
|
|
end
|
2017-04-21 09:19:14 +00:00
|
|
|
dbg:guard(ReaderMenu, 'setUpdateItemTable',
|
|
|
|
function(self)
|
|
|
|
local mock_menu_items = {}
|
|
|
|
for _, widget in pairs(self.registered_widgets) do
|
|
|
|
-- make sure addToMainMenu works in debug mode
|
|
|
|
widget:addToMainMenu(mock_menu_items)
|
|
|
|
end
|
|
|
|
end)
|
2012-12-15 01:20:12 +00:00
|
|
|
|
2020-11-28 21:48:09 +00:00
|
|
|
function ReaderMenu:exitOrRestart(callback, force)
|
2017-09-11 19:37:00 +00:00
|
|
|
if self.menu_container then self:onTapCloseMenu() end
|
2020-11-28 21:48:09 +00:00
|
|
|
|
|
|
|
-- Only restart sets a callback, which suits us just fine for this check ;)
|
|
|
|
if callback and not force and not Device:isStartupScriptUpToDate() then
|
|
|
|
UIManager:show(ConfirmBox:new{
|
|
|
|
text = _("KOReader's startup script has been updated. You'll need to completely exit KOReader to finalize the update."),
|
|
|
|
ok_text = _("Restart anyway"),
|
|
|
|
ok_callback = function()
|
|
|
|
self:exitOrRestart(callback, true)
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2017-05-16 09:11:11 +00:00
|
|
|
UIManager:nextTick(function()
|
|
|
|
self.ui:onClose()
|
|
|
|
if callback ~= nil then
|
2017-09-11 19:37:00 +00:00
|
|
|
-- show an empty widget so that the callback always happens
|
|
|
|
local Widget = require("ui/widget/widget")
|
|
|
|
local widget = Widget:new{
|
|
|
|
width = Screen:getWidth(),
|
|
|
|
height = Screen:getHeight(),
|
|
|
|
}
|
|
|
|
UIManager:show(widget)
|
|
|
|
local waiting = function(waiting)
|
|
|
|
-- if we don't do this you can get a situation where either the
|
|
|
|
-- program won't exit due to remaining widgets until they're
|
|
|
|
-- dismissed or if the callback forces all widgets to close,
|
|
|
|
-- that the save document ConfirmBox is also closed
|
|
|
|
if self.ui and self.ui.document and self.ui.document:isEdited() then
|
|
|
|
logger.dbg("waiting for save settings")
|
|
|
|
UIManager:scheduleIn(1, function() waiting(waiting) end)
|
|
|
|
else
|
|
|
|
callback()
|
|
|
|
UIManager:close(widget)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
UIManager:scheduleIn(1, function() waiting(waiting) end)
|
2017-05-16 09:11:11 +00:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
local FileManager = require("apps/filemanager/filemanager")
|
|
|
|
if FileManager.instance then
|
|
|
|
FileManager.instance:onClose()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-12 18:47:49 +00:00
|
|
|
function ReaderMenu:onShowMenu(tab_index)
|
2017-03-05 11:46:27 +00:00
|
|
|
if self.tab_item_table == nil then
|
2014-03-13 13:52:43 +00:00
|
|
|
self:setUpdateItemTable()
|
|
|
|
end
|
|
|
|
|
2018-01-13 22:11:09 +00:00
|
|
|
if not tab_index then
|
|
|
|
tab_index = self.last_tab_index
|
|
|
|
end
|
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
local menu_container = CenterContainer:new{
|
|
|
|
ignore = "height",
|
|
|
|
dimen = Screen:getSize(),
|
|
|
|
}
|
|
|
|
|
2015-04-27 00:49:27 +00:00
|
|
|
local main_menu
|
2018-03-14 21:16:38 +00:00
|
|
|
if Device:isTouchDevice() or Device:hasDPad() then
|
2014-10-25 08:02:42 +00:00
|
|
|
local TouchMenu = require("ui/widget/touchmenu")
|
2014-03-13 13:52:43 +00:00
|
|
|
main_menu = TouchMenu:new{
|
|
|
|
width = Screen:getWidth(),
|
2018-01-13 22:11:09 +00:00
|
|
|
last_index = tab_index,
|
2017-02-28 21:46:32 +00:00
|
|
|
tab_item_table = self.tab_item_table,
|
2014-03-13 13:52:43 +00:00
|
|
|
show_parent = menu_container,
|
|
|
|
}
|
|
|
|
else
|
2014-10-25 08:02:42 +00:00
|
|
|
local Menu = require("ui/widget/menu")
|
2014-03-13 13:52:43 +00:00
|
|
|
main_menu = Menu:new{
|
|
|
|
title = _("Document menu"),
|
2014-10-25 08:02:42 +00:00
|
|
|
item_table = Menu.itemTableFromTouchMenu(self.tab_item_table),
|
2014-03-13 13:52:43 +00:00
|
|
|
width = Screen:getWidth() - 100,
|
2014-10-25 08:02:42 +00:00
|
|
|
show_parent = menu_container,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
ReaderUI: Saner FM/RD lifecycle
* Ensure that going from one to the other tears down the former and
its plugins before instantiating the latter and its plugins.
UIManager: Unify Event sending & broadcasting
* Make the two behave the same way (walk the widget stack from top to
bottom), and properly handle the window stack shrinking shrinking
*and* growing.
Previously, broadcasting happened bottom-to-top and didn't really
handle the list shrinking/growing, while sending only handled the list
shrinking by a single element, and hopefully that element being the one
the event was just sent to.
These two items combined allowed us to optimize suboptimal
refresh behavior with Menu and other Menu classes when
opening/closing a document.
e.g., the "opening document" Notification is now properly regional,
and the "open last doc" option no longer flashes like a crazy person
anymore.
Plugins: Allow optimizing Menu refresh with custom menus, too.
Requires moving Menu's close_callback *after* onMenuSelect, which, eh,
probably makes sense, and is probably harmless in the grand scheme of
things.
2021-05-01 16:53:04 +00:00
|
|
|
main_menu.close_callback = function()
|
2014-11-05 04:15:07 +00:00
|
|
|
self.ui:handleEvent(Event:new("CloseReaderMenu"))
|
|
|
|
end
|
|
|
|
|
|
|
|
main_menu.touch_menu_callback = function ()
|
|
|
|
self.ui:handleEvent(Event:new("CloseConfigMenu"))
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
menu_container[1] = main_menu
|
|
|
|
-- maintain a reference to menu_container
|
|
|
|
self.menu_container = menu_container
|
|
|
|
UIManager:show(menu_container)
|
|
|
|
return true
|
2012-06-10 18:14:29 +00:00
|
|
|
end
|
2012-11-11 07:24:11 +00:00
|
|
|
|
2014-09-05 13:02:13 +00:00
|
|
|
function ReaderMenu:onCloseReaderMenu()
|
2018-05-20 23:19:36 +00:00
|
|
|
if self.menu_container then
|
|
|
|
self.last_tab_index = self.menu_container[1].last_index
|
|
|
|
self:onSaveSettings()
|
|
|
|
UIManager:close(self.menu_container)
|
|
|
|
end
|
2014-09-05 13:02:13 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2018-01-21 18:44:12 +00:00
|
|
|
function ReaderMenu:onCloseDocument()
|
|
|
|
if Device:supportsScreensaver() then
|
2019-10-07 15:46:09 +00:00
|
|
|
-- Remove the item we added (which cleans up references to document
|
2018-01-21 18:44:12 +00:00
|
|
|
-- and doc_settings embedded in functions)
|
|
|
|
local screensaver_sub_item_table = require("ui/elements/screensaver_menu")
|
2019-10-17 13:03:40 +00:00
|
|
|
for i = #screensaver_sub_item_table, 1, -1 do
|
|
|
|
if screensaver_sub_item_table[i].added_by_readermenu_flag then
|
|
|
|
table.remove(screensaver_sub_item_table, i)
|
|
|
|
end
|
|
|
|
end
|
2018-01-21 18:44:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-13 22:11:09 +00:00
|
|
|
function ReaderMenu:_getTabIndexFromLocation(ges)
|
|
|
|
if self.tab_item_table == nil then
|
|
|
|
self:setUpdateItemTable()
|
|
|
|
end
|
2018-03-14 21:16:38 +00:00
|
|
|
if not ges then
|
|
|
|
return self.last_tab_index
|
2018-01-13 22:11:09 +00:00
|
|
|
-- if the start position is far right
|
2018-03-14 21:16:38 +00:00
|
|
|
elseif ges.pos.x > 2 * Screen:getWidth() / 3 then
|
2019-12-06 21:55:39 +00:00
|
|
|
return BD.mirroredUILayout() and 1 or #self.tab_item_table
|
2018-01-13 22:11:09 +00:00
|
|
|
-- if the start position is far left
|
|
|
|
elseif ges.pos.x < Screen:getWidth() / 3 then
|
2019-12-06 21:55:39 +00:00
|
|
|
return BD.mirroredUILayout() and #self.tab_item_table or 1
|
2018-01-13 22:11:09 +00:00
|
|
|
-- if center return the last index
|
|
|
|
else
|
|
|
|
return self.last_tab_index
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-15 12:45:56 +00:00
|
|
|
function ReaderMenu:onSwipeShowMenu(ges)
|
2017-08-08 16:20:46 +00:00
|
|
|
if self.activation_menu ~= "tap" and ges.direction == "south" then
|
2017-10-08 10:27:53 +00:00
|
|
|
if G_reader_settings:nilOrTrue("show_bottom_menu") then
|
|
|
|
self.ui:handleEvent(Event:new("ShowConfigMenu"))
|
|
|
|
end
|
2020-07-12 18:47:49 +00:00
|
|
|
self.ui:handleEvent(Event:new("ShowMenu", self:_getTabIndexFromLocation(ges)))
|
2017-04-15 12:45:56 +00:00
|
|
|
return true
|
|
|
|
end
|
2012-11-11 07:24:11 +00:00
|
|
|
end
|
|
|
|
|
2018-01-13 22:11:09 +00:00
|
|
|
function ReaderMenu:onTapShowMenu(ges)
|
2017-08-08 16:20:46 +00:00
|
|
|
if self.activation_menu ~= "swipe" then
|
2017-10-08 10:27:53 +00:00
|
|
|
if G_reader_settings:nilOrTrue("show_bottom_menu") then
|
|
|
|
self.ui:handleEvent(Event:new("ShowConfigMenu"))
|
|
|
|
end
|
2020-07-12 18:47:49 +00:00
|
|
|
self.ui:handleEvent(Event:new("ShowMenu", self:_getTabIndexFromLocation(ges)))
|
2017-08-08 16:20:46 +00:00
|
|
|
return true
|
|
|
|
end
|
2017-06-01 16:32:06 +00:00
|
|
|
end
|
|
|
|
|
2014-10-10 10:14:16 +00:00
|
|
|
function ReaderMenu:onTapCloseMenu()
|
|
|
|
self.ui:handleEvent(Event:new("CloseReaderMenu"))
|
|
|
|
self.ui:handleEvent(Event:new("CloseConfigMenu"))
|
|
|
|
end
|
|
|
|
|
2014-11-11 02:06:17 +00:00
|
|
|
function ReaderMenu:onReadSettings(config)
|
2014-12-01 07:32:12 +00:00
|
|
|
self.last_tab_index = config:readSetting("readermenu_tab_index") or 1
|
2014-11-11 02:06:17 +00:00
|
|
|
end
|
|
|
|
|
2013-12-27 15:18:16 +00:00
|
|
|
function ReaderMenu:onSaveSettings()
|
2014-12-03 16:14:30 +00:00
|
|
|
self.ui.doc_settings:saveSetting("readermenu_tab_index", self.last_tab_index)
|
2012-12-15 01:20:12 +00:00
|
|
|
end
|
|
|
|
|
2012-12-15 01:30:48 +00:00
|
|
|
function ReaderMenu:registerToMainMenu(widget)
|
2014-03-13 13:52:43 +00:00
|
|
|
table.insert(self.registered_widgets, widget)
|
2012-12-08 17:25:32 +00:00
|
|
|
end
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
return ReaderMenu
|