From f6fb35fd988c3438a2086b462d75542ffefd9ccd Mon Sep 17 00:00:00 2001 From: hius07 <62179190+hius07@users.noreply.github.com> Date: Sun, 26 Nov 2023 07:52:43 +0200 Subject: [PATCH] QuickMenu: keep open on apply (#11135) --- frontend/dispatcher.lua | 34 +++++++++++++++++++++++++++++- plugins/gestures.koplugin/main.lua | 1 + 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/frontend/dispatcher.lua b/frontend/dispatcher.lua index a4f0efc91..a0975623c 100644 --- a/frontend/dispatcher.lua +++ b/frontend/dispatcher.lua @@ -945,6 +945,7 @@ function Dispatcher:addSubMenu(caller, menu, location, settings) {"rolling", _("Reflowable documents (epub, fb2, txt…)")}, {"paging", _("Fixed layout documents (pdf, djvu, pics…)")}, } + menu.max_per_page = 1 + #section_list -- settings in page 2 for _, section in ipairs(section_list) do local submenu = {} Dispatcher:_addItem(caller, submenu, location, settings, section[1]) @@ -1020,6 +1021,31 @@ function Dispatcher:addSubMenu(caller, menu, location, settings) end end, }) + table.insert(menu, { + text = _("Keep QuickMenu open"), + checked_func = function() + return location[settings] ~= nil + and location[settings].settings ~= nil + and location[settings].settings.keep_open_on_apply + end, + callback = function() + if location[settings] then + if location[settings].settings then + if location[settings].settings.keep_open_on_apply then + location[settings].settings.keep_open_on_apply = nil + if next(location[settings].settings) == nil then + location[settings].settings = nil + end + else + location[settings].settings.keep_open_on_apply = true + end + else + location[settings].settings = {["keep_open_on_apply"] = true} + end + caller.updated = true + end + end, + }) end function Dispatcher:isActionEnabled(action) @@ -1039,6 +1065,8 @@ function Dispatcher:isActionEnabled(action) end function Dispatcher:_showAsMenu(settings, exec_props) + local title = settings.settings.name or _("QuickMenu") + local keep_open_on_apply = settings.settings.keep_open_on_apply local display_list = Dispatcher:getDisplayList(settings) local quickmenu local buttons = {} @@ -1065,6 +1093,10 @@ function Dispatcher:_showAsMenu(settings, exec_props) callback = function() UIManager:close(quickmenu) Dispatcher:execute({[v.key] = settings[v.key]}) + if keep_open_on_apply and not util.stringStartsWith(v.key, "touch_input") then + quickmenu:setTitle(title) + UIManager:show(quickmenu) + end end, hold_callback = function() if v.key:sub(1, 13) == "profile_exec_" then @@ -1076,7 +1108,7 @@ function Dispatcher:_showAsMenu(settings, exec_props) end local ButtonDialog = require("ui/widget/buttondialog") quickmenu = ButtonDialog:new{ - title = settings.settings.name or _("QuickMenu"), + title = title, title_align = "center", shrink_unneeded_width = true, shrink_min_width = math.floor(0.6 * Screen:getWidth()), diff --git a/plugins/gestures.koplugin/main.lua b/plugins/gestures.koplugin/main.lua index ecab724b2..f8ee6e298 100644 --- a/plugins/gestures.koplugin/main.lua +++ b/plugins/gestures.koplugin/main.lua @@ -244,6 +244,7 @@ function Gestures:genMenu(ges) end, }) Dispatcher:addSubMenu(self, sub_items, self.gestures, ges) + sub_items.max_per_page = nil -- restore default, settings in page 2 table.insert(sub_items, { text = _("Anchor QuickMenu to gesture position"), checked_func = function()