From 1f8574cf7e2c17e4c8782d7c5dbdb9d12f9d9658 Mon Sep 17 00:00:00 2001 From: yparitcher Date: Fri, 10 Sep 2021 16:14:07 -0400 Subject: [PATCH] Dispatcher:removeAction() Gestures: use sub_item_table_func to allow the menu to refresh on change --- frontend/dispatcher.lua | 17 ++++++++++++++++- plugins/gestures.koplugin/main.lua | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/frontend/dispatcher.lua b/frontend/dispatcher.lua index 0dfeccf5e..ac485a5fa 100644 --- a/frontend/dispatcher.lua +++ b/frontend/dispatcher.lua @@ -36,6 +36,7 @@ local Notification = require("ui/widget/notification") local ReaderZooming = require("apps/reader/modules/readerzooming") local Screen = require("device").screen local UIManager = require("ui/uimanager") +local util = require("util") local _ = require("gettext") local C_ = _.pgettext local T = require("ffi/util").template @@ -440,6 +441,20 @@ function Dispatcher:registerAction(name, value) return true end +--[[-- +Removes settings at runtime. + +@param name the key to use in the table +--]]-- +function Dispatcher:removeAction(name) + local k = util.arrayContains(dispatcher_menu_order, name) + if k then + table.remove(dispatcher_menu_order, k) + settingsList[name] = nil + end + return true +end + -- Returns a display name for the item. function Dispatcher:getNameFromItem(item, location, settings) if settingsList[item] == nil then @@ -631,7 +646,7 @@ arguments are: 3) the object (table) in which the settings table is found 4) the name of the settings table example usage: - Dispatcher.addSubMenu(self, sub_items, self.data, "profile1") + Dispatcher:addSubMenu(self, sub_items, self.data, "profile1") --]]-- function Dispatcher:addSubMenu(caller, menu, location, settings) Dispatcher:init() diff --git a/plugins/gestures.koplugin/main.lua b/plugins/gestures.koplugin/main.lua index 153e047ad..e091f9a28 100644 --- a/plugins/gestures.koplugin/main.lua +++ b/plugins/gestures.koplugin/main.lua @@ -240,7 +240,7 @@ function Gestures:genSubItem(ges, separator, hold_callback) return { text_func = function() return self:gestureTitleFunc(ges) end, enabled_func = enabled_func, - sub_item_table = self:genMenu(ges), + sub_item_table_func = function() return self:genMenu(ges) end, separator = separator, hold_callback = hold_callback, }