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

Loading…
Cancel
Save