QuickMenu: add long-press on profile (#10671)

reviewable/pr10758/r1
hius07 10 months ago committed by GitHub
parent 500eadf895
commit b36ccc7249
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -992,10 +992,22 @@ function Dispatcher:isActionEnabled(action)
return not disabled return not disabled
end end
function Dispatcher:_showAsMenu(settings, gesture) function Dispatcher:_showAsMenu(settings, exec_props)
local display_list = Dispatcher:getDisplayList(settings) local display_list = Dispatcher:getDisplayList(settings)
local quickmenu local quickmenu
local buttons = {} local buttons = {}
if exec_props and exec_props.qm_show then
table.insert(buttons, {{
text = _("Execute all"),
align = "left",
font_face = "smallinfofont",
font_size = 22,
callback = function()
UIManager:close(quickmenu)
Dispatcher:execute(settings, { qm_show = false })
end,
}})
end
for _, v in ipairs(display_list) do for _, v in ipairs(display_list) do
table.insert(buttons, {{ table.insert(buttons, {{
text = v.text, text = v.text,
@ -1008,6 +1020,12 @@ function Dispatcher:_showAsMenu(settings, gesture)
UIManager:close(quickmenu) UIManager:close(quickmenu)
Dispatcher:execute({[v.key] = settings[v.key]}) Dispatcher:execute({[v.key] = settings[v.key]})
end, end,
hold_callback = function()
if v.key:sub(1, 13) == "profile_exec_" then
UIManager:close(quickmenu)
UIManager:sendEvent(Event:new(settingsList[v.key].event, settingsList[v.key].arg, { qm_show = true }))
end
end,
}}) }})
end end
local ButtonDialog = require("ui/widget/buttondialog") local ButtonDialog = require("ui/widget/buttondialog")
@ -1018,7 +1036,7 @@ function Dispatcher:_showAsMenu(settings, gesture)
shrink_min_width = math.floor(0.6 * Screen:getWidth()), shrink_min_width = math.floor(0.6 * Screen:getWidth()),
use_info_style = false, use_info_style = false,
buttons = buttons, buttons = buttons,
anchor = (gesture and gesture.anchor_quickmenu) and (gesture.end_pos or gesture.pos), anchor = exec_props and exec_props.qm_anchor,
} }
UIManager:show(quickmenu) UIManager:show(quickmenu)
end end
@ -1027,16 +1045,20 @@ end
Calls the events in a settings list Calls the events in a settings list
arguments are: arguments are:
1) the settings table 1) the settings table
2) optionally a `gestures` object 2) execution management table: { qm_show = true|false} - forcibly show QM / run
{ qm_anchor = ges.pos } - anchor position
{ gesture = ges } - a `gestures` object
--]]-- --]]--
function Dispatcher:execute(settings, gesture) function Dispatcher:execute(settings, exec_props)
if settings.settings ~= nil and settings.settings.show_as_quickmenu == true then if ((exec_props == nil or exec_props.qm_show == nil) and settings.settings and settings.settings.show_as_quickmenu)
return Dispatcher:_showAsMenu(settings, gesture) or (exec_props and exec_props.qm_show) then
return Dispatcher:_showAsMenu(settings, exec_props)
end end
local has_many = Dispatcher:_itemsCount(settings) > 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
local gesture = exec_props and exec_props.gesture
for k, v in iter_func(settings) do for k, v in iter_func(settings) do
if type(k) == "number" then if type(k) == "number" then
k = v k = v
@ -1053,27 +1075,25 @@ function Dispatcher:execute(settings, gesture)
end end
UIManager:sendEvent(Event:new("ConfigChange", settingsList[k].configurable.name, value)) UIManager:sendEvent(Event:new("ConfigChange", settingsList[k].configurable.name, value))
end end
if settingsList[k].category == "none" then
local category = settingsList[k].category
local event = settingsList[k].event
if category == "none" then
if settingsList[k].arg ~= nil then if settingsList[k].arg ~= nil then
UIManager:sendEvent(Event:new(settingsList[k].event, settingsList[k].arg, gesture)) UIManager:sendEvent(Event:new(event, settingsList[k].arg, exec_props))
else else
UIManager:sendEvent(Event:new(settingsList[k].event)) UIManager:sendEvent(Event:new(event))
end end
end elseif category == "absolutenumber" or category == "string" then
if settingsList[k].category == "absolutenumber" UIManager:sendEvent(Event:new(event, v))
or settingsList[k].category == "string" elseif category == "arg" then
then -- the event can accept a gesture object or an argument
UIManager:sendEvent(Event:new(settingsList[k].event, v))
end
-- the event can accept a gesture object or an argument
if settingsList[k].category == "arg" then
local arg = gesture or settingsList[k].arg local arg = gesture or settingsList[k].arg
UIManager:sendEvent(Event:new(settingsList[k].event, arg)) UIManager:sendEvent(Event:new(event, arg))
end elseif category == "incrementalnumber" then
-- the event can accept a gesture object or a number -- the event can accept a gesture object or a number
if settingsList[k].category == "incrementalnumber" then
local arg = v ~= 0 and v or gesture or 0 local arg = v ~= 0 and v or gesture or 0
UIManager:sendEvent(Event:new(settingsList[k].event, arg)) UIManager:sendEvent(Event:new(event, arg))
end end
end end
Notification:resetNotifySource() Notification:resetNotifySource()

@ -1153,8 +1153,11 @@ function Gestures:gestureAction(action, ges)
return return
else else
self.ui:handleEvent(Event:new("HandledAsSwipe")) self.ui:handleEvent(Event:new("HandledAsSwipe"))
ges.anchor_quickmenu = action_list.settings and action_list.settings.anchor_quickmenu local exec_props = { gesture = ges }
Dispatcher:execute(action_list, ges) if action_list.settings and action_list.settings.anchor_quickmenu then
exec_props.qm_anchor = ges.end_pos or ges.pos
end
Dispatcher:execute(action_list, exec_props)
end end
return true return true
end end

@ -124,20 +124,14 @@ function Profiles:getSubMenuItems()
text = _("Execute"), text = _("Execute"),
callback = function(touchmenu_instance) callback = function(touchmenu_instance)
touchmenu_instance:onClose() touchmenu_instance:onClose()
local show_as_quickmenu = v.settings.show_as_quickmenu self:onProfileExecute(k, { qm_show = false })
self.data[k].settings.show_as_quickmenu = nil
self:onProfileExecute(k)
self.data[k].settings.show_as_quickmenu = show_as_quickmenu
end, end,
}, },
{ {
text = _("Show as QuickMenu"), text = _("Show as QuickMenu"),
callback = function(touchmenu_instance) callback = function(touchmenu_instance)
touchmenu_instance:onClose() touchmenu_instance:onClose()
local show_as_quickmenu = v.settings.show_as_quickmenu self:onProfileExecute(k, { qm_show = true })
self.data[k].settings.show_as_quickmenu = true
self:onProfileExecute(k)
self.data[k].settings.show_as_quickmenu = show_as_quickmenu
end, end,
}, },
{ {
@ -259,8 +253,8 @@ function Profiles:getSubMenuItems()
return sub_item_table return sub_item_table
end end
function Profiles:onProfileExecute(name, gesture) function Profiles:onProfileExecute(name, exec_props)
Dispatcher:execute(self.data[name], gesture) Dispatcher:execute(self.data[name], exec_props)
end end
function Profiles:editProfileName(editCallback, old_name) function Profiles:editProfileName(editCallback, old_name)
@ -388,7 +382,7 @@ function Profiles:updateGestures(action_old_name, action_new_name)
table.remove(gesture_loaded.settings.order, i) table.remove(gesture_loaded.settings.order, i)
if #gesture.settings.order == 0 then if #gesture.settings.order == 0 then
gesture.settings.order = nil gesture.settings.order = nil
if #gesture.settings == 0 then if next(gesture.settings) == nil then
gesture.settings = nil gesture.settings = nil
end end
end end
@ -403,7 +397,7 @@ function Profiles:updateGestures(action_old_name, action_new_name)
gesture[action_new_name] = true gesture[action_new_name] = true
gesture_loaded[action_new_name] = true gesture_loaded[action_new_name] = true
else else
if #gesture == 0 then if next(gesture) == nil then
all_gestures.data[section][gesture_name] = nil all_gestures.data[section][gesture_name] = nil
end end
end end

Loading…
Cancel
Save