mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Refactored to use strictly locals
This commit is contained in:
@@ -1,54 +1,14 @@
|
||||
require "ui/widget/config"
|
||||
local ConfigDialog = require("ui/widget/configdialog")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local Device = require("ui/device")
|
||||
local GestureRange = require("ui/gesturerange")
|
||||
local Geom = require("ui/geometry")
|
||||
local Screen = require("ui/screen")
|
||||
local Event = require("ui/event")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local _ = require("gettext")
|
||||
|
||||
Configurable = {}
|
||||
|
||||
function Configurable:hash(sep)
|
||||
local hash = ""
|
||||
local excluded = {multi_threads = true,}
|
||||
for key,value in pairs(self) do
|
||||
if type(value) == "number" or type(value) == "string"
|
||||
and not excluded[key] then
|
||||
hash = hash..sep..value
|
||||
end
|
||||
end
|
||||
return hash
|
||||
end
|
||||
|
||||
function Configurable:loadDefaults(config_options)
|
||||
for i=1,#config_options do
|
||||
local options = config_options[i].options
|
||||
for j=1,#config_options[i].options do
|
||||
local key = config_options[i].options[j].name
|
||||
self[key] = config_options[i].options[j].default_value
|
||||
if not self[key] then
|
||||
self[key] = config_options[i].options[j].default_arg
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Configurable:loadSettings(settings, prefix)
|
||||
for key,value in pairs(self) do
|
||||
if type(value) == "number" or type(value) == "string"
|
||||
or type(value) == "table" then
|
||||
local saved_value = settings:readSetting(prefix..key)
|
||||
self[key] = (saved_value == nil) and self[key] or saved_value
|
||||
--Debug("Configurable:loadSettings", "key", key, "saved value", saved_value,"Configurable.key", self[key])
|
||||
end
|
||||
end
|
||||
--Debug("loaded config:", dump(Configurable))
|
||||
end
|
||||
|
||||
function Configurable:saveSettings(settings, prefix)
|
||||
for key,value in pairs(self) do
|
||||
if type(value) == "number" or type(value) == "string"
|
||||
or type(value) == "table" then
|
||||
settings:saveSetting(prefix..key, value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
ReaderConfig = InputContainer:new{
|
||||
local ReaderConfig = InputContainer:new{
|
||||
last_panel_index = 1,
|
||||
}
|
||||
|
||||
@@ -130,3 +90,5 @@ function ReaderConfig:onCloseDocument()
|
||||
self.configurable:saveSettings(self.ui.doc_settings, self.options.prefix.."_")
|
||||
self.ui.doc_settings:saveSetting("config_panel_index", self.last_panel_index)
|
||||
end
|
||||
|
||||
return ReaderConfig
|
||||
|
||||
Reference in New Issue
Block a user