Dispatcher Gestures Profiles: only flush settings when changed (#6471)

reviewable/pr6477/r1
yparitcher 4 years ago committed by GitHub
parent 49a5aa179b
commit 7583571707
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -318,7 +318,7 @@ function Dispatcher:getNameFromItem(item, location, settings)
return T(settingsList[item].title, amount) return T(settingsList[item].title, amount)
end end
function Dispatcher:addItem(menu, location, settings, section) function Dispatcher:addItem(caller, menu, location, settings, section)
for _, k in ipairs(dispatcher_menu_order) do for _, k in ipairs(dispatcher_menu_order) do
if settingsList[k][section] == true and if settingsList[k][section] == true and
(settingsList[k].condition == nil or settingsList[k].condition) (settingsList[k].condition == nil or settingsList[k].condition)
@ -338,6 +338,7 @@ function Dispatcher:addItem(menu, location, settings, section)
else else
location[settings][k] = true location[settings][k] = true
end end
caller.updated = true
if touchmenu_instance then touchmenu_instance:updateItems() end if touchmenu_instance then touchmenu_instance:updateItems() end
end, end,
separator = settingsList[k].separator, separator = settingsList[k].separator,
@ -366,6 +367,7 @@ function Dispatcher:addItem(menu, location, settings, section)
location[settings] = {} location[settings] = {}
end end
location[settings][k] = spin.value location[settings][k] = spin.value
caller.updated = true
if touchmenu_instance then if touchmenu_instance then
touchmenu_instance:updateItems() touchmenu_instance:updateItems()
end end
@ -376,6 +378,7 @@ function Dispatcher:addItem(menu, location, settings, section)
hold_callback = function(touchmenu_instance) hold_callback = function(touchmenu_instance)
if location[settings] ~= nil and location[settings][k] ~= nil then if location[settings] ~= nil and location[settings][k] ~= nil then
location[settings][k] = nil location[settings][k] = nil
caller.updated = true
end end
if touchmenu_instance then touchmenu_instance:updateItems() end if touchmenu_instance then touchmenu_instance:updateItems() end
end, end,
@ -407,6 +410,7 @@ function Dispatcher:addItem(menu, location, settings, section)
location[settings] = {} location[settings] = {}
end end
location[settings][k] = spin.value location[settings][k] = spin.value
caller.updated = true
if touchmenu_instance then if touchmenu_instance then
touchmenu_instance:updateItems() touchmenu_instance:updateItems()
end end
@ -417,6 +421,7 @@ function Dispatcher:addItem(menu, location, settings, section)
hold_callback = function(touchmenu_instance) hold_callback = function(touchmenu_instance)
if location[settings] ~= nil and location[settings][k] ~= nil then if location[settings] ~= nil and location[settings][k] ~= nil then
location[settings][k] = nil location[settings][k] = nil
caller.updated = true
end end
if touchmenu_instance then if touchmenu_instance then
touchmenu_instance:updateItems() touchmenu_instance:updateItems()
@ -439,6 +444,7 @@ function Dispatcher:addItem(menu, location, settings, section)
location[settings] = {} location[settings] = {}
end end
location[settings][k] = settingsList[k].args[i] location[settings][k] = settingsList[k].args[i]
caller.updated = true
end, end,
}) })
end end
@ -454,6 +460,7 @@ function Dispatcher:addItem(menu, location, settings, section)
hold_callback = function(touchmenu_instance) hold_callback = function(touchmenu_instance)
if location[settings] ~= nil and location[settings][k] ~= nil then if location[settings] ~= nil and location[settings][k] ~= nil then
location[settings][k] = nil location[settings][k] = nil
caller.updated = true
end end
if touchmenu_instance then if touchmenu_instance then
touchmenu_instance:updateItems() touchmenu_instance:updateItems()
@ -469,13 +476,14 @@ end
--[[-- --[[--
Add a submenu to edit which items are dispatched Add a submenu to edit which items are dispatched
arguments are: arguments are:
1) the table representing the submenu (can be empty) 1) the caller so dispatcher can set the updated flag
2) the object (table) in which the settings table is found 2) the table representing the submenu (can be empty)
3) the name of the settings table 3) the object (table) in which the settings table is found
4) the name of the settings table
example usage: 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 if not Dispatcher.initialized then Dispatcher:init() end
table.insert(menu, { table.insert(menu, {
text = _("Nothing"), text = _("Nothing"),
@ -485,6 +493,7 @@ function Dispatcher:addSubMenu(menu, location, settings)
end, end,
callback = function(touchmenu_instance) callback = function(touchmenu_instance)
location[settings] = {} location[settings] = {}
caller.updated = true
if touchmenu_instance then touchmenu_instance:updateItems() end if touchmenu_instance then touchmenu_instance:updateItems() end
end, end,
}) })
@ -496,8 +505,7 @@ function Dispatcher:addSubMenu(menu, location, settings)
} }
for _, section in ipairs(section_list) do for _, section in ipairs(section_list) do
local submenu = {} local submenu = {}
-- pass caller's context Dispatcher:addItem(caller, submenu, location, settings, section[1])
Dispatcher:addItem(submenu, location, settings, section[1])
table.insert(menu, { table.insert(menu, {
text = section[2], text = section[2],
checked_func = function() checked_func = function()
@ -514,6 +522,7 @@ function Dispatcher:addSubMenu(menu, location, settings)
for k, _ in pairs(location[settings]) do for k, _ in pairs(location[settings]) do
if settingsList[k][section[1]] == true then if settingsList[k][section[1]] == true then
location[settings][k] = nil location[settings][k] = nil
caller.updated = true
end end
end end
if touchmenu_instance then touchmenu_instance:updateItems() end if touchmenu_instance then touchmenu_instance:updateItems() end

@ -27,6 +27,7 @@ local Gestures = InputContainer:new{
gestures = nil, gestures = nil,
defaults = nil, defaults = nil,
custom_multiswipes = nil, custom_multiswipes = nil,
updated = false,
} }
local gestures_path = FFIUtil.joinPath(DataStorage:getSettingsDir(), "gestures.lua") local gestures_path = FFIUtil.joinPath(DataStorage:getSettingsDir(), "gestures.lua")
@ -166,6 +167,7 @@ function Gestures:init()
end end
end end
if reset then if reset then
self.updated = true
logger.info("UI language direction changed: resetting some gestures to direction default") logger.info("UI language direction changed: resetting some gestures to direction default")
end end
G_reader_settings:flipNilOrFalse(ges_dir_setting) G_reader_settings:flipNilOrFalse(ges_dir_setting)
@ -206,6 +208,7 @@ function Gestures:genMenu(ges)
end, end,
callback = function() callback = function()
self.gestures[ges] = util.tableDeepCopy(self.defaults[ges]) self.gestures[ges] = util.tableDeepCopy(self.defaults[ges])
self.updated = true
end, end,
}) })
end end
@ -218,9 +221,10 @@ function Gestures:genMenu(ges)
end, end,
callback = function() callback = function()
self.gestures[ges] = nil self.gestures[ges] = nil
self.updated = true
end, end,
}) })
Dispatcher:addSubMenu(sub_items, self.gestures, ges) Dispatcher:addSubMenu(self, sub_items, self.gestures, ges)
return sub_items return sub_items
end end
@ -342,6 +346,7 @@ function Gestures:multiswipeRecorder(touchmenu_instance)
end end
self.custom_multiswipes[recorded_multiswipe] = true self.custom_multiswipes[recorded_multiswipe] = true
self.updated = true
--touchmenu_instance.item_table = self:genMultiswipeMenu() --touchmenu_instance.item_table = self:genMultiswipeMenu()
-- We need to update touchmenu_instance.item_table in-place for the upper -- We need to update touchmenu_instance.item_table in-place for the upper
-- menu to have it updated too -- menu to have it updated too
@ -403,6 +408,7 @@ function Gestures:genCustomMultiswipeSubmenu()
-- remove any settings for the muliswipe -- remove any settings for the muliswipe
self.settings_data.data["gesture_fm"][item] = nil self.settings_data.data["gesture_fm"][item] = nil
self.settings_data.data["gesture_reader"][item] = nil self.settings_data.data["gesture_reader"][item] = nil
self.updated = true
--touchmenu_instance.item_table = self:genMultiswipeMenu() --touchmenu_instance.item_table = self:genMultiswipeMenu()
-- We need to update touchmenu_instance.item_table in-place for the upper -- We need to update touchmenu_instance.item_table in-place for the upper
@ -1028,8 +1034,9 @@ function Gestures:onIgnoreHoldCorners(ignore_hold_corners)
end end
function Gestures:onFlushSettings() function Gestures:onFlushSettings()
if self.settings_data then if self.settings_data and self.updated then
self.settings_data:flush() self.settings_data:flush()
self.updated = false
end end
end end

@ -15,6 +15,7 @@ local Profiles = WidgetContainer:new{
profiles_file = DataStorage:getSettingsDir() .. "/profiles.lua", profiles_file = DataStorage:getSettingsDir() .. "/profiles.lua",
profiles = nil, profiles = nil,
data = nil, data = nil,
updated = false,
} }
function Profiles:init() function Profiles:init()
@ -30,8 +31,9 @@ function Profiles:loadProfiles()
end end
function Profiles:onFlushSettings() function Profiles:onFlushSettings()
if self.profiles then if self.profiles and self.updated then
self.profiles:flush() self.profiles:flush()
self.updated = false
end end
end end
@ -104,7 +106,7 @@ function Profiles:getSubMenuItems()
end, end,
} }
} }
Dispatcher:addSubMenu(sub_items, self.data, k) Dispatcher:addSubMenu(self, sub_items, self.data, k)
table.insert(sub_item_table, { table.insert(sub_item_table, {
text = k, text = k,
hold_keep_menu_open = false, hold_keep_menu_open = false,
@ -120,6 +122,7 @@ end
function Profiles:newProfile(name) function Profiles:newProfile(name)
if self.data[name] == nil then if self.data[name] == nil then
self.data[name] = {} self.data[name] = {}
self.updated = true
return true return true
else else
return false return false
@ -128,6 +131,7 @@ end
function Profiles:deleteProfile(name) function Profiles:deleteProfile(name)
self.data[name] = nil self.data[name] = nil
self.updated = true
end end
return Profiles return Profiles

Loading…
Cancel
Save