|
Onetastic Macro Documentation >
>
Macro menus
Each macro adds a button to the ribbon to run the macro. Macros also will display a menu in the ribbon for more options. The top portion of ribbon button will invoke the default action for the macro and the bottom portion will display the menu. For example, Insert Monthly Calendar macro displays the following menu:

Macro menus can be static or dynamically generated based on user's usage patterns. For instance a macro like Search and Replace may display the recently used search and replace terms in the menu.
Setup function
Macro menus are created by the Setup function. Setup function is a user defined function in a macro which will get called whenever Onetastic needs to get a macro's menu to be displayed in the ribbon. Below is a sample Setup function:
Copied!
function Setup(byref $menu)
MacroMenu_AddItem($menu, "arg1", "Menu Item 1", "Description for Menu Item 1")
MacroMenu_AddItem($menu, "arg2", "Menu Item 2", "Description for Menu Item 2")
MacroMenu_AddItem($menu, "arg3", "Menu Item 3", "Description for Menu Item 3")
Setup function always has a single parameter byref $menu. This parameter is an object of type MacroMenu. You can then use the MacroMenu_AddItem function to add menu items. A macro with this Setup function will have the following menu:

The menu items added by MacroMenu_AddItem is displayed under the Presets section and each macro gets a Manage section to display common actions like Rename or Change Icon. Each menu item added in the Setup function is associated with an argument that will be passed to Main function when user clicks on that menu item. In this case if user clicks the first menu item, Main function for this macro will be called with the argument arg1.
Menu sections
By default, menu items are added to the Presets section. You can place items in different sections by passing an optional fifth argument to MacroMenu_AddItem. The available sections are "Recent", "Presets", and "Settings". Sections are displayed in the menu in this order, followed by the fixed "Manage" section.
Copied!
function Setup(byref $menu)
MacroMenu_AddItem($menu, "search1", "Recent Search 1", \
"Last used search term", "Recent")
MacroMenu_AddItem($menu, "search2", "Recent Search 2", \
"Second most recent term", "Recent")
MacroMenu_AddItem($menu, "preset1", "Preset 1", "A preset option")
MacroMenu_AddItem($menu, "colors", "Change Colors", \
"Customize display colors", "Settings")

If a section has no items, its separator is automatically hidden. This means you only need to add items to the sections your macro actually uses.
Performance Considerations
Setup function will get called every time Onetastic needs to refresh the menu for each macro. This can be after a macro execution, after a macro is edited, or after a new macro is downloaded. To avoid performance problems, Setup function should do minimal work and should not be running for a long time. Setup function for a macro will get aborted if it runs long and the menu for that macro will not be visible. Setup function also cannot access OneNote content or show dialog boxes.
Creating and Editing Setup Function
Macro editor makes it easy to create a setup function quickly via the following menu:

This will create a sample Setup function which you can use to quickly edit. If a Setup function already exists, this will switch to it.
Debugging Menu Items
As macro menu items pass arguments to the main function, you may want to debug the execution of your macro with such arguments. The debug button in the Macro Editor toolbar has a split menu that makes it easy to pick the menu items and debug their execution:

This menu will display each menu item and clicking on one of them will start the debugger with the associated argument passed to the Main function.
|