Improved Dialog Boxes for Macros

March 20, 2023

Many macros in Onetastic will display a dialog box to get user input. For instance, Insert Monthly Calendar macro will ask the user for the year and month to insert a calendar for among other options like the format, first day of week and header row color. Once a dialog box is prepared with a set of controls and displayed, it can't be changed. This leaves macros without the ability to further customize the experience as the macro cannot react to user input until the dialog box is closed by clicking on the OK button.

With a new update to Onetastic, there are several improvements to dialog boxes which can allow such customized experiences and the ability to react to changes in the dialog while it is being displayed.

Custom Buttons

First update to the dialog boxes are custom buttons. Until now, all dialog boxes came with a single "OK" button, but now you can add custom buttons using DialogBox_AddButton function. If no custom buttons are added to a dialog box, it will still have the "OK" button when it is displayed. Up to 4 buttons can be added to a dialog box. When the user clicks on a button, the dialog box closes and DialogBox_Show function will return the name of the button that was clicked. Here is a simple example:

$dialog = DialogBox_Create("Do you want to delete this page?")
DialogBox_AddButton($dialog, "&Yes", "yes") DialogBox_AddButton($dialog, "&No", "no")
ExpandIf ("yes" == DialogBox_Show($dialog)) RemoveObject($page)

This will display the following dialog box: Dialog box with custom button After user clicks on one of the "Yes" and "No" buttons, DialogBox_Show function returns either "yes" or "no", the name of the button user clicked.

DialogBox Event Handler

You can now set an event handler for dialog boxes. The event handler is a user defined function that gets called when the dialog is first created and then each time when value of one of the controls in the dialog box changes (e.g. user types into a text box, checks a check box, or chooses an option from a dropdown box etc.) or user clicks a custom button. Event handlers are not required to be set for a dialog box but can be used for more control on what controls are visible or enabled under specific conditions.

Event handlers can be set by the DialogBox_SetEventHandler function. See its documentation for more information and examples.

Hiding or Disabling Controls

Dialog box event handlers can be used to react to user action and hide or disable certain controls. These can be done via DialogBox_SetControlVisible and DialogBox_SetControlEnabled functions. Here is an example of event handler and these functions in action:

DialogBox Event Handler in action

Dialog boxes will automatically grow or shrink to fit the visible controls.

Radio Buttons

Another improvement this update brings is radio buttons. You can now use the DialogBox_AddRadioGroup function to add a set of radio buttons to a dialog box:

$dialog = DialogBox_Create("")
DialogBox_AddRadioGroup($dialog, "Choose an option", "option", "First option", Array("First option", "Second option", "Third option"))
DialogBox_Show($dialog)

This will display the following dialog box: Dialog box with radio group

Message Boxes and Task Dialogs

Two new options for displaying messages are also available. If you want to simply display a text message to the user, you can use the new ShowMessage function:

ShowMessage("No instances of the search term is found.")

This will display the following message box: Message box

For cases where you want user to pick one of a set of options but don't need any other input, you can display a task dialog using the new ShowTaskDialog function:

$message = "You can save the currently selected text as a snippet to be used for later, or you can insert one of the previously saved snippets to the current page."
$buttons = Array("Insert previously saved text snippet", "Save selected text as a snippet", "Manage text snippets")
$selected = ShowTaskDialog("Choose an option", $message, $buttons)
ExpandSwitch ($selected) ExpandCase 0: // User selected first option Break 1 ExpandCase 1: // User selected second option Break 1 ExpandCase 2: // User selected third option Break 1

Task Dialog

If you are a macro developer, start taking advantage of these improvements in your macros. If you are a macro user, expect more interactive and customized macros making their way to Macroland.

Comments

Name
Comment
gtms - 2023-09-21
Anyone notice that ShowTaskDialog rekeys the given array?
example:  
$groupchoice = ShowTaskDialog("Group for Review", "Choose group:", $groupoptions)

$groupoptions is keyed 1, 2, 3 as result of Array_Slice
$groupchoice returns 0, 1, or 2

The workaround is ($groupchoice + 1) of course, but... it would be slicker if ShowTaskDialog preserved keys that were preserved on purpose.  Thanks
Luna - 2023-04-14
Does anyone have the problem that if they try to rotate a pdf the program just freezes and you have to fully close OneNote to make it stop? Weirdly I only have this problem with two pdfs, with all the others it works fine. I've also just updated onetastic so that can't be it. Any ideas?
Tyra - 2023-04-12
these days something wrong with the OneCalendar
it can't show the full pages about each day, missing a lot of
pages I visted
I don't know why and what happened, may someone can answer me?

Other Posts

Show all posts