Dispatcher: preserve profile name, show actions count (#9682)

(1) Preserve profile name when selecting the "Nothing" action.
(2) Show number of actions instead of "Many".
reviewable/pr9696/r1
hius07 2 years ago committed by GitHub
parent 07be320722
commit d37803a8e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -38,6 +38,7 @@ local UIManager = require("ui/uimanager")
local util = require("util")
local _ = require("gettext")
local C_ = _.pgettext
local N_ = _.ngettext
local T = require("ffi/util").template
local Dispatcher = {
@ -488,6 +489,17 @@ local function iter_func(settings)
end
end
-- Returns the number of items present in the settings table
function Dispatcher:_itemsCount(settings)
if settings then
local count = util.tableSize(settings)
if count > 0 and settings.settings ~= nil then
count = count - 1
end
return count
end
end
-- Returns a display name for the item.
function Dispatcher:getNameFromItem(item, settings)
if settingsList[item] == nil then
@ -551,17 +563,14 @@ end
function Dispatcher:menuTextFunc(settings)
local action_name = _("Pass through")
if settings then
local count = util.tableSize(settings)
local count = Dispatcher:_itemsCount(settings)
if count == 0 then return _("Nothing") end
if count > 1 and settings.settings ~= nil then
count = count - 1
end
if count == 1 then
local item = next(settings)
if item == "settings" then item = next(settings, item) end
action_name = Dispatcher:getNameFromItem(item, settings)
else
action_name = _("Many")
action_name = T(N_("", "%1 actions", count), count)
end
end
return action_name
@ -798,10 +807,14 @@ function Dispatcher:addSubMenu(caller, menu, location, settings)
text = _("Nothing"),
separator = true,
checked_func = function()
return location[settings] ~= nil and next(location[settings]) == nil
return location[settings] ~= nil and Dispatcher:_itemsCount(location[settings]) == 0
end,
callback = function(touchmenu_instance)
local name = location[settings] and location[settings].settings and location[settings].settings.name
location[settings] = {}
if name then
location[settings].settings = { name = name }
end
caller.updated = true
if touchmenu_instance then touchmenu_instance:updateItems() end
end,
@ -931,7 +944,7 @@ function Dispatcher:execute(settings, gesture)
if settings.settings ~= nil and settings.settings.show_as_quickmenu == true then
return Dispatcher:_showAsMenu(settings)
end
local has_many = util.tableSize(settings) > (settings.settings ~= nil and 2 or 1)
local has_many = Dispatcher:_itemsCount(settings) > 1
if has_many then
UIManager:broadcastEvent(Event:new("BatchedUpdate"))
end

Loading…
Cancel
Save