2013-10-18 20:38:07 +00:00
|
|
|
local ConfigDialog = require("ui/widget/configdialog")
|
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-08-05 19:49:00 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
2013-10-18 20:38:07 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
2018-10-26 15:27:43 +00:00
|
|
|
local CreOptions = require("ui/data/creoptions")
|
|
|
|
local KoptOptions = require("ui/data/koptoptions")
|
2013-10-18 20:38:07 +00:00
|
|
|
local _ = require("gettext")
|
|
|
|
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 00:14:48 +00:00
|
|
|
local ReaderConfig = InputContainer:extend{
|
2014-03-13 13:52:43 +00:00
|
|
|
last_panel_index = 1,
|
2013-07-14 10:48:06 +00:00
|
|
|
}
|
2012-12-14 10:20:04 +00:00
|
|
|
|
|
|
|
function ReaderConfig:init()
|
2018-10-26 15:27:43 +00:00
|
|
|
if self.document.koptinterface ~= nil then
|
|
|
|
self.options = KoptOptions
|
|
|
|
else
|
|
|
|
self.options = CreOptions
|
|
|
|
end
|
|
|
|
self.configurable:loadDefaults(self.options)
|
|
|
|
|
2018-04-19 18:44:13 +00:00
|
|
|
if Device:hasKeys() then
|
2022-10-27 00:01:51 +00:00
|
|
|
self.key_events.ShowConfigMenu = { { { "Press", "AA" } } }
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2022-01-25 00:32:46 +00:00
|
|
|
self:initGesListener()
|
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
|
2022-10-30 22:05:04 +00:00
|
|
|
|
|
|
|
-- delegate gesture listener to ReaderUI, NOP our own
|
|
|
|
self.ges_events = nil
|
2013-02-02 06:36:29 +00:00
|
|
|
end
|
|
|
|
|
2022-10-30 22:05:04 +00:00
|
|
|
function ReaderConfig:onGesture() end
|
|
|
|
|
2013-02-02 06:36:29 +00:00
|
|
|
function ReaderConfig:initGesListener()
|
2022-09-27 23:10:50 +00:00
|
|
|
if not Device:isTouchDevice() then return end
|
|
|
|
|
|
|
|
local DTAP_ZONE_CONFIG = G_defaults:readSetting("DTAP_ZONE_CONFIG")
|
|
|
|
local DTAP_ZONE_CONFIG_EXT = G_defaults:readSetting("DTAP_ZONE_CONFIG_EXT")
|
2017-08-05 19:49:00 +00:00
|
|
|
self.ui:registerTouchZones({
|
|
|
|
{
|
|
|
|
id = "readerconfigmenu_tap",
|
|
|
|
ges = "tap",
|
|
|
|
screen_zone = {
|
|
|
|
ratio_x = DTAP_ZONE_CONFIG.x, ratio_y = DTAP_ZONE_CONFIG.y,
|
|
|
|
ratio_w = DTAP_ZONE_CONFIG.w, ratio_h = DTAP_ZONE_CONFIG.h,
|
|
|
|
},
|
2019-03-30 20:05:44 +00:00
|
|
|
overrides = {
|
|
|
|
"tap_forward",
|
|
|
|
"tap_backward",
|
|
|
|
},
|
2017-08-05 19:49:00 +00:00
|
|
|
handler = function() return self:onTapShowConfigMenu() end,
|
|
|
|
},
|
2020-12-03 16:33:54 +00:00
|
|
|
{
|
|
|
|
id = "readerconfigmenu_ext_tap",
|
|
|
|
ges = "tap",
|
|
|
|
screen_zone = {
|
|
|
|
ratio_x = DTAP_ZONE_CONFIG_EXT.x, ratio_y = DTAP_ZONE_CONFIG_EXT.y,
|
|
|
|
ratio_w = DTAP_ZONE_CONFIG_EXT.w, ratio_h = DTAP_ZONE_CONFIG_EXT.h,
|
|
|
|
},
|
|
|
|
overrides = {
|
|
|
|
"readerconfigmenu_tap",
|
|
|
|
},
|
|
|
|
handler = function() return self:onTapShowConfigMenu() end,
|
|
|
|
},
|
2017-08-05 19:49:00 +00:00
|
|
|
{
|
|
|
|
id = "readerconfigmenu_swipe",
|
|
|
|
ges = "swipe",
|
|
|
|
screen_zone = {
|
|
|
|
ratio_x = DTAP_ZONE_CONFIG.x, ratio_y = DTAP_ZONE_CONFIG.y,
|
|
|
|
ratio_w = DTAP_ZONE_CONFIG.w, ratio_h = DTAP_ZONE_CONFIG.h,
|
|
|
|
},
|
2019-03-30 20:05:44 +00:00
|
|
|
overrides = {
|
|
|
|
"rolling_swipe",
|
|
|
|
"paging_swipe",
|
|
|
|
},
|
2017-08-05 19:49:00 +00:00
|
|
|
handler = function(ges) return self:onSwipeShowConfigMenu(ges) end,
|
2017-08-13 18:41:10 +00:00
|
|
|
},
|
2020-12-03 16:33:54 +00:00
|
|
|
{
|
|
|
|
id = "readerconfigmenu_ext_swipe",
|
|
|
|
ges = "swipe",
|
|
|
|
screen_zone = {
|
|
|
|
ratio_x = DTAP_ZONE_CONFIG_EXT.x, ratio_y = DTAP_ZONE_CONFIG_EXT.y,
|
|
|
|
ratio_w = DTAP_ZONE_CONFIG_EXT.w, ratio_h = DTAP_ZONE_CONFIG_EXT.h,
|
|
|
|
},
|
|
|
|
overrides = {
|
|
|
|
"readerconfigmenu_swipe",
|
|
|
|
},
|
|
|
|
handler = function(ges) return self:onSwipeShowConfigMenu(ges) end,
|
|
|
|
},
|
2017-08-13 18:41:10 +00:00
|
|
|
{
|
|
|
|
id = "readerconfigmenu_pan",
|
|
|
|
ges = "pan",
|
|
|
|
screen_zone = {
|
|
|
|
ratio_x = DTAP_ZONE_CONFIG.x, ratio_y = DTAP_ZONE_CONFIG.y,
|
|
|
|
ratio_w = DTAP_ZONE_CONFIG.w, ratio_h = DTAP_ZONE_CONFIG.h,
|
|
|
|
},
|
2019-03-30 20:05:44 +00:00
|
|
|
overrides = {
|
|
|
|
"rolling_pan",
|
|
|
|
"paging_pan",
|
|
|
|
},
|
2017-08-13 18:41:10 +00:00
|
|
|
handler = function(ges) return self:onSwipeShowConfigMenu(ges) end,
|
2017-08-05 19:49:00 +00:00
|
|
|
},
|
2020-12-03 16:33:54 +00:00
|
|
|
{
|
|
|
|
id = "readerconfigmenu_ext_pan",
|
|
|
|
ges = "pan",
|
|
|
|
screen_zone = {
|
|
|
|
ratio_x = DTAP_ZONE_CONFIG_EXT.x, ratio_y = DTAP_ZONE_CONFIG_EXT.y,
|
|
|
|
ratio_w = DTAP_ZONE_CONFIG_EXT.w, ratio_h = DTAP_ZONE_CONFIG_EXT.h,
|
|
|
|
},
|
|
|
|
overrides = {
|
|
|
|
"readerconfigmenu_pan",
|
|
|
|
},
|
|
|
|
handler = function(ges) return self:onSwipeShowConfigMenu(ges) end,
|
|
|
|
},
|
2017-08-05 19:49:00 +00:00
|
|
|
})
|
2012-12-14 10:20:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderConfig:onShowConfigMenu()
|
2014-03-13 13:52:43 +00:00
|
|
|
self.config_dialog = ConfigDialog:new{
|
2019-08-30 11:47:51 +00:00
|
|
|
document = self.document,
|
2014-03-13 13:52:43 +00:00
|
|
|
ui = self.ui,
|
|
|
|
configurable = self.configurable,
|
|
|
|
config_options = self.options,
|
|
|
|
is_always_active = true,
|
|
|
|
close_callback = function() self:onCloseCallback() end,
|
|
|
|
}
|
|
|
|
self.ui:handleEvent(Event:new("DisableHinting"))
|
|
|
|
-- show last used panel when opening config dialog
|
|
|
|
self.config_dialog:onShowConfigPanel(self.last_panel_index)
|
|
|
|
UIManager:show(self.config_dialog)
|
2021-05-19 20:57:54 +00:00
|
|
|
self.ui:handleEvent(Event:new("HandledAsSwipe")) -- cancel any pan scroll made
|
2012-12-14 10:20:04 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
return true
|
2012-12-14 10:20:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderConfig:onTapShowConfigMenu()
|
2017-08-08 16:20:46 +00:00
|
|
|
if self.activation_menu ~= "swipe" then
|
|
|
|
self:onShowConfigMenu()
|
|
|
|
return true
|
|
|
|
end
|
2012-12-14 10:20:04 +00:00
|
|
|
end
|
|
|
|
|
2017-08-05 19:49:00 +00:00
|
|
|
function ReaderConfig:onSwipeShowConfigMenu(ges)
|
2017-08-08 16:20:46 +00:00
|
|
|
if self.activation_menu ~= "tap" and ges.direction == "north" then
|
2017-08-05 19:49:00 +00:00
|
|
|
self:onShowConfigMenu()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-14 10:20:04 +00:00
|
|
|
function ReaderConfig:onSetDimensions(dimen)
|
2014-03-13 13:52:43 +00:00
|
|
|
-- since we cannot redraw config_dialog with new size, we close
|
|
|
|
-- the old one on screen size change
|
|
|
|
if self.config_dialog then
|
|
|
|
self.config_dialog:closeDialog()
|
|
|
|
end
|
2012-12-14 10:20:04 +00:00
|
|
|
end
|
2012-12-24 09:36:52 +00:00
|
|
|
|
2013-07-14 10:48:06 +00:00
|
|
|
function ReaderConfig:onCloseCallback()
|
2014-03-13 13:52:43 +00:00
|
|
|
self.last_panel_index = self.config_dialog.panel_index
|
2017-10-07 13:23:39 +00:00
|
|
|
self.config_dialog = nil
|
2014-03-13 13:52:43 +00:00
|
|
|
self.ui:handleEvent(Event:new("RestoreHinting"))
|
2013-07-14 10:48:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- event handler for readercropping
|
2014-10-10 10:14:16 +00:00
|
|
|
function ReaderConfig:onCloseConfigMenu()
|
2014-10-25 10:01:37 +00:00
|
|
|
if self.config_dialog then
|
|
|
|
self.config_dialog:closeDialog()
|
|
|
|
end
|
2013-02-02 20:42:59 +00:00
|
|
|
end
|
|
|
|
|
2012-12-24 09:36:52 +00:00
|
|
|
function ReaderConfig:onReadSettings(config)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.configurable:loadSettings(config, self.options.prefix.."_")
|
2018-03-15 14:39:44 +00:00
|
|
|
local config_panel_index = config:readSetting("config_panel_index")
|
|
|
|
if config_panel_index then
|
|
|
|
config_panel_index = math.min(config_panel_index, #self.options)
|
|
|
|
end
|
|
|
|
self.last_panel_index = config_panel_index or 1
|
2012-12-24 09:36:52 +00:00
|
|
|
end
|
|
|
|
|
2013-12-27 15:18:16 +00:00
|
|
|
function ReaderConfig:onSaveSettings()
|
2014-03-13 13:52:43 +00:00
|
|
|
self.configurable:saveSettings(self.ui.doc_settings, self.options.prefix.."_")
|
|
|
|
self.ui.doc_settings:saveSetting("config_panel_index", self.last_panel_index)
|
2012-12-24 09:36:52 +00:00
|
|
|
end
|
2013-10-18 20:38:07 +00:00
|
|
|
|
|
|
|
return ReaderConfig
|