mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
hold on config panel option to set default option
This commit is contained in:
@@ -33,7 +33,9 @@ function Configurable:loadDefaults(config_options)
|
||||
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
|
||||
local settings_key = config_options.prefix.."_"..key
|
||||
local default = G_reader_settings:readSetting(settings_key)
|
||||
self[key] = default or config_options[i].options[j].default_value
|
||||
if not self[key] then
|
||||
self[key] = config_options[i].options[j].default_arg
|
||||
end
|
||||
|
||||
@@ -9,6 +9,7 @@ local TextWidget = require("ui/widget/textwidget")
|
||||
local FixedTextWidget = require("ui/widget/fixedtextwidget")
|
||||
local ProgressWidget = require("ui/widget/progresswidget")
|
||||
local ToggleSwitch = require("ui/widget/toggleswitch")
|
||||
local ConfirmBox = require("ui/widget/confirmbox")
|
||||
local Font = require("ui/font")
|
||||
local Device = require("ui/device")
|
||||
local GestureRange = require("ui/gesturerange")
|
||||
@@ -79,6 +80,13 @@ function OptionTextItem:init()
|
||||
},
|
||||
doc = "Select Option Item",
|
||||
},
|
||||
HoldSelect = {
|
||||
GestureRange:new{
|
||||
ges = "hold",
|
||||
range = self.dimen,
|
||||
},
|
||||
doc = "Hold Option Item",
|
||||
},
|
||||
}
|
||||
else
|
||||
self.active_key_events = {
|
||||
@@ -92,11 +100,21 @@ function OptionTextItem:onTapSelect()
|
||||
item[1].color = 0
|
||||
end
|
||||
self[1].color = 15
|
||||
self.config:onConfigChoose(self.values, self.name, self.event, self.args, self.events, self.current_item)
|
||||
self.config:onConfigChoose(self.values, self.name,
|
||||
self.event, self.args,
|
||||
self.events, self.current_item)
|
||||
UIManager:setDirty(self.config, "partial")
|
||||
return true
|
||||
end
|
||||
|
||||
function OptionTextItem:onHoldSelect()
|
||||
self.config:onMakeDefault(self.name, self.name_text,
|
||||
self.values or self.args,
|
||||
self.values or self.item_text,
|
||||
self.current_item)
|
||||
return true
|
||||
end
|
||||
|
||||
local OptionIconItem = InputContainer:new{}
|
||||
function OptionIconItem:init()
|
||||
self.dimen = self.icon:getSize()
|
||||
@@ -115,6 +133,14 @@ function OptionIconItem:init()
|
||||
},
|
||||
doc = "Select Option Item",
|
||||
},
|
||||
HoldSelect = {
|
||||
GestureRange:new{
|
||||
ges = "hold",
|
||||
range = self.dimen,
|
||||
},
|
||||
doc = "Hold Option Item",
|
||||
},
|
||||
|
||||
}
|
||||
end
|
||||
end
|
||||
@@ -126,11 +152,19 @@ function OptionIconItem:onTapSelect()
|
||||
end
|
||||
--self[1][1].invert = true
|
||||
self[1].color = 15
|
||||
self.config:onConfigChoose(self.values, self.name, self.event, self.args, self.events, self.current_item)
|
||||
self.config:onConfigChoose(self.values, self.name,
|
||||
self.event, self.args,
|
||||
self.events, self.current_item)
|
||||
UIManager:setDirty(self.config, "partial")
|
||||
return true
|
||||
end
|
||||
|
||||
function OptionIconItem:onHoldSelect()
|
||||
self.config:onMakeDefault(self.name, self.name_text,
|
||||
self.values, self.values, self.current_item)
|
||||
return true
|
||||
end
|
||||
|
||||
local ConfigOption = CenterContainer:new{}
|
||||
function ConfigOption:init()
|
||||
local default_name_font_size = 20
|
||||
@@ -287,6 +321,8 @@ function ConfigOption:init()
|
||||
option_items[d] = option_item
|
||||
option_item.items = option_items
|
||||
option_item.name = self.options[c].name
|
||||
option_item.name_text = self.options[c].name_text
|
||||
option_item.item_text = self.options[c].item_text
|
||||
option_item.values = self.options[c].values
|
||||
option_item.args = self.options[c].args
|
||||
option_item.event = self.options[c].event
|
||||
@@ -322,6 +358,7 @@ function ConfigOption:init()
|
||||
option_items[d] = option_item
|
||||
option_item.items = option_items
|
||||
option_item.name = self.options[c].name
|
||||
option_item.name_text = self.options[c].name_text
|
||||
option_item.values = self.options[c].values
|
||||
option_item.args = self.options[c].args
|
||||
option_item.event = self.options[c].event
|
||||
@@ -340,6 +377,7 @@ function ConfigOption:init()
|
||||
local switch = ToggleSwitch:new{
|
||||
width = math.min(max_toggle_width, toggle_width),
|
||||
name = self.options[c].name,
|
||||
name_text = self.options[c].name_text,
|
||||
toggle = self.options[c].toggle,
|
||||
alternate = self.options[c].alternate,
|
||||
values = self.options[c].values,
|
||||
@@ -537,6 +575,16 @@ function ConfigDialog:onConfigChoose(values, name, event, args, events, position
|
||||
end)
|
||||
end
|
||||
|
||||
function ConfigDialog:onMakeDefault(name, name_text, values, labels, position)
|
||||
UIManager:show(ConfirmBox:new{
|
||||
text = _("Set default ")..(name_text or "").." to "..labels[position].."?",
|
||||
ok_callback = function()
|
||||
local name = self.config_options.prefix.."_"..name
|
||||
G_reader_settings:saveSetting(name, values[position])
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
function ConfigDialog:closeDialog()
|
||||
UIManager:close(self)
|
||||
if self.close_callback then
|
||||
|
||||
@@ -74,6 +74,13 @@ function ToggleSwitch:init()
|
||||
},
|
||||
doc = "Toggle switch",
|
||||
},
|
||||
HoldSelect = {
|
||||
GestureRange:new{
|
||||
ges = "hold",
|
||||
range = self.dimen,
|
||||
},
|
||||
doc = "Hold switch",
|
||||
},
|
||||
}
|
||||
end
|
||||
end
|
||||
@@ -131,9 +138,19 @@ function ToggleSwitch:onTapSelect(arg, gev)
|
||||
self.config:onConfigEvents(self.events, self.position)
|
||||
end
|
||||
--]]
|
||||
self.config:onConfigChoose(self.values, self.name, self.event, self.args, self.events, self.position)
|
||||
self.config:onConfigChoose(self.values, self.name,
|
||||
self.event, self.args, self.events, self.position)
|
||||
UIManager:setDirty(self.config, "partial")
|
||||
return true
|
||||
end
|
||||
|
||||
function ToggleSwitch:onHoldSelect(arg, gev)
|
||||
local position = math.ceil(
|
||||
(gev.pos.x - self.dimen.x) / self.dimen.w * self.n_pos
|
||||
)
|
||||
self.config:onMakeDefault(self.name, self.name_text,
|
||||
self.values or self.args, self.toggle, position)
|
||||
return true
|
||||
end
|
||||
|
||||
return ToggleSwitch
|
||||
|
||||
Reference in New Issue
Block a user