Skip to content

Commit d1b4888

Browse files
committed
allow macros to be registered with a custom submenu name
1 parent bd8190b commit d1b4888

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -490,23 +490,23 @@ The purpose of this construct is to allow circular references between modules. L
490490
491491
Call this method as replacement for returning your module.
492492
493-
__:registerMacro(*str* [name=@name], *str* [description=@description], *func* processing_function, *func* [validation_function], *func* is_active_function, *bool* [useSubmenu=false])__
493+
__:registerMacro(*str* [name=@name], *str* [description=@description], *func* processing_function, *func* [validation_function], *func* is_active_function, *bool|string* [submenu=false])__
494494
495495
Alternative Signature:
496496
497-
__:registerMacro(*func* processing_function, *func* [validation_function], *func* is_active_function, *bool* [useSubmenu=false])__
497+
__:registerMacro(*func* processing_function, *func* [validation_function], *func* is_active_function, *bool|string* [submenu=false])__
498498
499499
Registers a single macro using script name and description by default.
500-
If __useSubmenu__ is set to true, the macro will be placed in a submenu using the script name.
500+
Use __submenu__ to specify a submenu name to use for this macro or set it to `true` to use the automation script name.
501501
502502
If the script entry in the DependencyControl configuration file contains a __customMenu__ property, the macro will be placed in the specified menu. Do note that that this setting is for *user customization* and not to be changed without the user's consent.
503503
504504
For the other arguments, please refer to the [aegisub.register_macro](http://docs.aegisub.org/latest/Automation/Lua/Registration/#aegisub.register_macro) API documentation.
505505
506-
__:registerMacros(*tbl* macros, *bool* [useSubmenuDefault=true])__
506+
__:registerMacros(*tbl* macros, *bool|string* [submenuDefault=true])__
507507
508508
Registers multiple macros, where __macros__ is a list of tables containing the arguments to a __:registerMacro()__ call for each automation menu entry. a single macro using script name and description by default.
509-
If __useSubmenuDefault__ is set to true, the macros will be placed in a submenu using the script name unless overriden by per-macro settings.
509+
Use __submenuDefault__ to specify a submenu all macros will be placed in unless overriden on a per-macro basis. Defaults to `true` which causes the automation script name to be used as the submenu name.
510510
511511
__:registerTests(unitTestArgs...)__
512512

modules/DependencyControl.moon

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -462,15 +462,17 @@ class DependencyControl
462462
@registerTests selfRef, ...
463463
return selfRef
464464

465-
registerMacro: (name=@name, description=@description, process, validate, isActive, useSubmenu) =>
466-
-- alternative signature
465+
registerMacro: (name=@name, description=@description, process, validate, isActive, submenu) =>
466+
-- alternative signature takes name and description from script
467467
if type(name)=="function"
468-
process, validate, isActive, useSubmenu = name, description, process, validate
468+
process, validate, isActive, submenu = name, description, process, validate
469469
name, description = @name, @description
470470

471-
menuName = {}
472-
menuName[1] = @config.c.customMenu if @config.c.customMenu
473-
menuName[#menuName+1] = @name if useSubmenu
471+
-- use automation script name for submenu by default
472+
submenu = @name if submenu == true
473+
474+
menuName = { @config.c.customMenu }
475+
menuName[#menuName+1] = submenu if submenu
474476
menuName[#menuName+1] = name
475477

476478
-- check for updates before running a macro
@@ -481,10 +483,11 @@ class DependencyControl
481483

482484
aegisub.register_macro table.concat(menuName, "/"), description, processHooked, validate, isActive
483485

484-
registerMacros: (macros = {}, useSubmenuDefault = true) =>
486+
registerMacros: (macros = {}, submenuDefault = true) =>
485487
for macro in *macros
486-
useSubmenu = type(macro[1])=="function" and 4 or 6
487-
macro[useSubmenu] = useSubmenuDefault if macro[useSubmenu]==nil
488+
-- allow macro table to omit name and description
489+
submenuIdx = type(macro[1])=="function" and 4 or 6
490+
macro[submenuIdx] = submenuDefault if macro[submenuIdx] == nil
488491
@registerMacro unpack(macro, 1, 6)
489492

490493
setVersion: (version) =>

0 commit comments

Comments
 (0)