mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Dispatcher Gestures Profiles: only flush settings when changed (#6471)
This commit is contained in:
@@ -318,7 +318,7 @@ function Dispatcher:getNameFromItem(item, location, settings)
|
||||
return T(settingsList[item].title, amount)
|
||||
end
|
||||
|
||||
function Dispatcher:addItem(menu, location, settings, section)
|
||||
function Dispatcher:addItem(caller, menu, location, settings, section)
|
||||
for _, k in ipairs(dispatcher_menu_order) do
|
||||
if settingsList[k][section] == true and
|
||||
(settingsList[k].condition == nil or settingsList[k].condition)
|
||||
@@ -338,6 +338,7 @@ function Dispatcher:addItem(menu, location, settings, section)
|
||||
else
|
||||
location[settings][k] = true
|
||||
end
|
||||
caller.updated = true
|
||||
if touchmenu_instance then touchmenu_instance:updateItems() end
|
||||
end,
|
||||
separator = settingsList[k].separator,
|
||||
@@ -366,6 +367,7 @@ function Dispatcher:addItem(menu, location, settings, section)
|
||||
location[settings] = {}
|
||||
end
|
||||
location[settings][k] = spin.value
|
||||
caller.updated = true
|
||||
if touchmenu_instance then
|
||||
touchmenu_instance:updateItems()
|
||||
end
|
||||
@@ -376,6 +378,7 @@ function Dispatcher:addItem(menu, location, settings, section)
|
||||
hold_callback = function(touchmenu_instance)
|
||||
if location[settings] ~= nil and location[settings][k] ~= nil then
|
||||
location[settings][k] = nil
|
||||
caller.updated = true
|
||||
end
|
||||
if touchmenu_instance then touchmenu_instance:updateItems() end
|
||||
end,
|
||||
@@ -407,6 +410,7 @@ function Dispatcher:addItem(menu, location, settings, section)
|
||||
location[settings] = {}
|
||||
end
|
||||
location[settings][k] = spin.value
|
||||
caller.updated = true
|
||||
if touchmenu_instance then
|
||||
touchmenu_instance:updateItems()
|
||||
end
|
||||
@@ -417,6 +421,7 @@ function Dispatcher:addItem(menu, location, settings, section)
|
||||
hold_callback = function(touchmenu_instance)
|
||||
if location[settings] ~= nil and location[settings][k] ~= nil then
|
||||
location[settings][k] = nil
|
||||
caller.updated = true
|
||||
end
|
||||
if touchmenu_instance then
|
||||
touchmenu_instance:updateItems()
|
||||
@@ -439,6 +444,7 @@ function Dispatcher:addItem(menu, location, settings, section)
|
||||
location[settings] = {}
|
||||
end
|
||||
location[settings][k] = settingsList[k].args[i]
|
||||
caller.updated = true
|
||||
end,
|
||||
})
|
||||
end
|
||||
@@ -454,6 +460,7 @@ function Dispatcher:addItem(menu, location, settings, section)
|
||||
hold_callback = function(touchmenu_instance)
|
||||
if location[settings] ~= nil and location[settings][k] ~= nil then
|
||||
location[settings][k] = nil
|
||||
caller.updated = true
|
||||
end
|
||||
if touchmenu_instance then
|
||||
touchmenu_instance:updateItems()
|
||||
@@ -469,13 +476,14 @@ end
|
||||
--[[--
|
||||
Add a submenu to edit which items are dispatched
|
||||
arguments are:
|
||||
1) the table representing the submenu (can be empty)
|
||||
2) the object (table) in which the settings table is found
|
||||
3) the name of the settings table
|
||||
1) the caller so dispatcher can set the updated flag
|
||||
2) the table representing the submenu (can be empty)
|
||||
3) the object (table) in which the settings table is found
|
||||
4) the name of the settings table
|
||||
example usage:
|
||||
Dispatcher.addSubMenu(sub_items, self.data, "profile1")
|
||||
Dispatcher.addSubMenu(self, sub_items, self.data, "profile1")
|
||||
--]]--
|
||||
function Dispatcher:addSubMenu(menu, location, settings)
|
||||
function Dispatcher:addSubMenu(caller, menu, location, settings)
|
||||
if not Dispatcher.initialized then Dispatcher:init() end
|
||||
table.insert(menu, {
|
||||
text = _("Nothing"),
|
||||
@@ -485,6 +493,7 @@ function Dispatcher:addSubMenu(menu, location, settings)
|
||||
end,
|
||||
callback = function(touchmenu_instance)
|
||||
location[settings] = {}
|
||||
caller.updated = true
|
||||
if touchmenu_instance then touchmenu_instance:updateItems() end
|
||||
end,
|
||||
})
|
||||
@@ -496,8 +505,7 @@ function Dispatcher:addSubMenu(menu, location, settings)
|
||||
}
|
||||
for _, section in ipairs(section_list) do
|
||||
local submenu = {}
|
||||
-- pass caller's context
|
||||
Dispatcher:addItem(submenu, location, settings, section[1])
|
||||
Dispatcher:addItem(caller, submenu, location, settings, section[1])
|
||||
table.insert(menu, {
|
||||
text = section[2],
|
||||
checked_func = function()
|
||||
@@ -514,6 +522,7 @@ function Dispatcher:addSubMenu(menu, location, settings)
|
||||
for k, _ in pairs(location[settings]) do
|
||||
if settingsList[k][section[1]] == true then
|
||||
location[settings][k] = nil
|
||||
caller.updated = true
|
||||
end
|
||||
end
|
||||
if touchmenu_instance then touchmenu_instance:updateItems() end
|
||||
|
||||
@@ -27,6 +27,7 @@ local Gestures = InputContainer:new{
|
||||
gestures = nil,
|
||||
defaults = nil,
|
||||
custom_multiswipes = nil,
|
||||
updated = false,
|
||||
}
|
||||
local gestures_path = FFIUtil.joinPath(DataStorage:getSettingsDir(), "gestures.lua")
|
||||
|
||||
@@ -166,6 +167,7 @@ function Gestures:init()
|
||||
end
|
||||
end
|
||||
if reset then
|
||||
self.updated = true
|
||||
logger.info("UI language direction changed: resetting some gestures to direction default")
|
||||
end
|
||||
G_reader_settings:flipNilOrFalse(ges_dir_setting)
|
||||
@@ -206,6 +208,7 @@ function Gestures:genMenu(ges)
|
||||
end,
|
||||
callback = function()
|
||||
self.gestures[ges] = util.tableDeepCopy(self.defaults[ges])
|
||||
self.updated = true
|
||||
end,
|
||||
})
|
||||
end
|
||||
@@ -218,9 +221,10 @@ function Gestures:genMenu(ges)
|
||||
end,
|
||||
callback = function()
|
||||
self.gestures[ges] = nil
|
||||
self.updated = true
|
||||
end,
|
||||
})
|
||||
Dispatcher:addSubMenu(sub_items, self.gestures, ges)
|
||||
Dispatcher:addSubMenu(self, sub_items, self.gestures, ges)
|
||||
return sub_items
|
||||
end
|
||||
|
||||
@@ -342,6 +346,7 @@ function Gestures:multiswipeRecorder(touchmenu_instance)
|
||||
end
|
||||
|
||||
self.custom_multiswipes[recorded_multiswipe] = true
|
||||
self.updated = true
|
||||
--touchmenu_instance.item_table = self:genMultiswipeMenu()
|
||||
-- We need to update touchmenu_instance.item_table in-place for the upper
|
||||
-- menu to have it updated too
|
||||
@@ -403,6 +408,7 @@ function Gestures:genCustomMultiswipeSubmenu()
|
||||
-- remove any settings for the muliswipe
|
||||
self.settings_data.data["gesture_fm"][item] = nil
|
||||
self.settings_data.data["gesture_reader"][item] = nil
|
||||
self.updated = true
|
||||
|
||||
--touchmenu_instance.item_table = self:genMultiswipeMenu()
|
||||
-- We need to update touchmenu_instance.item_table in-place for the upper
|
||||
@@ -1028,8 +1034,9 @@ function Gestures:onIgnoreHoldCorners(ignore_hold_corners)
|
||||
end
|
||||
|
||||
function Gestures:onFlushSettings()
|
||||
if self.settings_data then
|
||||
if self.settings_data and self.updated then
|
||||
self.settings_data:flush()
|
||||
self.updated = false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ local Profiles = WidgetContainer:new{
|
||||
profiles_file = DataStorage:getSettingsDir() .. "/profiles.lua",
|
||||
profiles = nil,
|
||||
data = nil,
|
||||
updated = false,
|
||||
}
|
||||
|
||||
function Profiles:init()
|
||||
@@ -30,8 +31,9 @@ function Profiles:loadProfiles()
|
||||
end
|
||||
|
||||
function Profiles:onFlushSettings()
|
||||
if self.profiles then
|
||||
if self.profiles and self.updated then
|
||||
self.profiles:flush()
|
||||
self.updated = false
|
||||
end
|
||||
end
|
||||
|
||||
@@ -104,7 +106,7 @@ function Profiles:getSubMenuItems()
|
||||
end,
|
||||
}
|
||||
}
|
||||
Dispatcher:addSubMenu(sub_items, self.data, k)
|
||||
Dispatcher:addSubMenu(self, sub_items, self.data, k)
|
||||
table.insert(sub_item_table, {
|
||||
text = k,
|
||||
hold_keep_menu_open = false,
|
||||
@@ -120,6 +122,7 @@ end
|
||||
function Profiles:newProfile(name)
|
||||
if self.data[name] == nil then
|
||||
self.data[name] = {}
|
||||
self.updated = true
|
||||
return true
|
||||
else
|
||||
return false
|
||||
@@ -128,6 +131,7 @@ end
|
||||
|
||||
function Profiles:deleteProfile(name)
|
||||
self.data[name] = nil
|
||||
self.updated = true
|
||||
end
|
||||
|
||||
return Profiles
|
||||
|
||||
Reference in New Issue
Block a user