@@ -801,6 +801,7 @@ function Dispatcher._removeFromOrder(location, settings, item)
801801 end
802802 end
803803 util .tableRemoveValue (actions , " settings" , " quickmenu_separators" , item )
804+ util .tableRemoveValue (actions , " settings" , " quickmenu_action_names" , item )
804805end
805806
806807-- Get a textual representation of the enabled actions to display in a menu item.
@@ -1103,7 +1104,7 @@ function Dispatcher:addSubMenu(caller, menu, location, settings)
11031104 caller .updated = true
11041105 end
11051106 end
1106- if touchmenu_instance then touchmenu_instance :updateItems () end
1107+ touchmenu_instance :updateItems ()
11071108 end
11081109 end ,
11091110 sub_item_table = submenu ,
@@ -1118,7 +1119,7 @@ function Dispatcher:addSubMenu(caller, menu, location, settings)
11181119 enabled_func = function ()
11191120 return location [settings ] and Dispatcher :_itemsCount (location [settings ]) > 1 or false
11201121 end ,
1121- callback = function (touchmenu_instance )
1122+ callback = function ()
11221123 Dispatcher ._sortActions (caller , location [settings ])
11231124 end ,
11241125 keep_menu_open = true ,
@@ -1204,6 +1205,82 @@ function Dispatcher:addSubMenu(caller, menu, location, settings)
12041205 end
12051206 end ,
12061207 })
1208+ table.insert (menu , {
1209+ text = _ (" Rename QuickMenu actions" ),
1210+ enabled_func = function ()
1211+ return util .tableGetValue (location [settings ], " settings" , " show_as_quickmenu" ) or false
1212+ end ,
1213+ checked_func = function ()
1214+ return util .tableGetValue (location [settings ], " settings" , " quickmenu_action_names" )
1215+ end ,
1216+ check_callback_updates_menu = true ,
1217+ callback = function (touchmenu_instance )
1218+ local function rename_update_func ()
1219+ caller .updated = true
1220+ touchmenu_instance :updateItems ()
1221+ end
1222+ Dispatcher .renameQuickMenuActions (location [settings ], rename_update_func )
1223+ end ,
1224+ hold_callback = function (touchmenu_instance ) -- reset all custom names
1225+ util .tableRemoveValue (location [settings ], " settings" , " quickmenu_action_names" )
1226+ caller .updated = true
1227+ touchmenu_instance :updateItems ()
1228+ end ,
1229+ })
1230+ end
1231+
1232+ function Dispatcher .renameQuickMenuActions (actions , rename_update_func )
1233+ local rename_callback , rename_hold_callback
1234+ rename_callback = function (action , quickmenu )
1235+ local InputDialog = require (" ui/widget/inputdialog" )
1236+ local name_input
1237+ name_input = InputDialog :new {
1238+ title = _ (" Enter action name" ),
1239+ description = T (_ (" Action: %1" ), action .text ),
1240+ input = util .tableGetValue (actions , " settings" , " quickmenu_action_names" , action .key ) or action .text ,
1241+ buttons = {{
1242+ {
1243+ text = _ (" Cancel" ),
1244+ id = " close" ,
1245+ callback = function ()
1246+ UIManager :close (name_input )
1247+ end ,
1248+ },
1249+ {
1250+ text = _ (" Default" ),
1251+ callback = function ()
1252+ name_input :setInputText (action .text , nil , false )
1253+ end ,
1254+ },
1255+ {
1256+ text = _ (" Save" ),
1257+ callback = function ()
1258+ local new_name = name_input :getInputText ()
1259+ if new_name == " " or new_name == action .text then -- reset custom name
1260+ util .tableRemoveValue (actions , " settings" , " quickmenu_action_names" , action .key )
1261+ else
1262+ util .tableSetValue (actions , new_name , " settings" , " quickmenu_action_names" , action .key )
1263+ end
1264+ UIManager :close (name_input )
1265+ UIManager :close (quickmenu )
1266+ rename_update_func ()
1267+ Dispatcher ._showAsMenu (actions , nil , rename_callback , rename_hold_callback )
1268+ end ,
1269+ },
1270+ }},
1271+ }
1272+ UIManager :show (name_input )
1273+ name_input :onShowKeyboard ()
1274+ end
1275+ rename_hold_callback = function (action , quickmenu ) -- reset custom name
1276+ if util .tableGetValue (actions , " settings" , " quickmenu_action_names" , action .key ) then
1277+ util .tableRemoveValue (actions , " settings" , " quickmenu_action_names" , action .key )
1278+ UIManager :close (quickmenu )
1279+ rename_update_func ()
1280+ Dispatcher ._showAsMenu (actions , nil , rename_callback , rename_hold_callback )
1281+ end
1282+ end
1283+ Dispatcher ._showAsMenu (actions , nil , rename_callback , rename_hold_callback )
12071284end
12081285
12091286function Dispatcher :isActionEnabled (action )
@@ -1222,7 +1299,7 @@ function Dispatcher:isActionEnabled(action)
12221299 return not disabled
12231300end
12241301
1225- function Dispatcher ._showAsMenu (settings , exec_props )
1302+ function Dispatcher ._showAsMenu (settings , exec_props , rename_callback , rename_hold_callback )
12261303 local title = settings .settings .name
12271304 local keep_open_on_apply = settings .settings .keep_open_on_apply
12281305 local display_list = Dispatcher .getDisplayList (settings )
@@ -1241,22 +1318,34 @@ function Dispatcher._showAsMenu(settings, exec_props)
12411318 }})
12421319 end
12431320 for _ , v in ipairs (display_list ) do
1321+ local text = util .tableGetValue (settings , " settings" , " quickmenu_action_names" , v .key ) -- custom name
1322+ if text and rename_callback then -- rename mode
1323+ text = " \u{F040} " .. text -- "pen" symbol
1324+ end
12441325 table.insert (buttons , {{
1245- text = v .text ,
1246- enabled = Dispatcher :isActionEnabled (settingsList [v .key ]),
1326+ text = text or v .text ,
1327+ enabled = rename_callback ~= nil or Dispatcher :isActionEnabled (settingsList [v .key ]),
12471328 menu_style = true ,
12481329 callback = function ()
1249- UIManager :close (quickmenu )
1250- Dispatcher :execute ({[v .key ] = settings [v .key ]})
1251- if keep_open_on_apply and not util .stringStartsWith (v .key , " touch_input" ) then
1252- quickmenu :setTitle (title )
1253- UIManager :show (quickmenu )
1330+ if rename_callback then
1331+ rename_callback (v , quickmenu )
1332+ else
1333+ UIManager :close (quickmenu )
1334+ Dispatcher :execute ({[v .key ] = settings [v .key ]})
1335+ if keep_open_on_apply and not util .stringStartsWith (v .key , " touch_input" ) then
1336+ quickmenu :setTitle (title )
1337+ UIManager :show (quickmenu )
1338+ end
12541339 end
12551340 end ,
12561341 hold_callback = function ()
1257- if v .key :sub (1 , 13 ) == " profile_exec_" then
1258- UIManager :close (quickmenu )
1259- UIManager :sendEvent (Event :new (settingsList [v .key ].event , settingsList [v .key ].arg , { qm_show = true }))
1342+ if rename_hold_callback then
1343+ rename_hold_callback (v , quickmenu )
1344+ else
1345+ if v .key :sub (1 , 13 ) == " profile_exec_" then
1346+ UIManager :close (quickmenu )
1347+ UIManager :sendEvent (Event :new (settingsList [v .key ].event , settingsList [v .key ].arg , { qm_show = true }))
1348+ end
12601349 end
12611350 end ,
12621351 }})
0 commit comments