NOTE: This exercise assumes you have completed the previous exercise.
As part of our original design, we took note that it was important to address quality of life features. In this exercise you'll learn to implement Scenome application commands that form an integral part of the user experience. The first command allows you to toggle the debug state of the <WorkItemNode> so you can test and debug workloads, and the second command allows you to disable the <WorkItemNode> so that it won't be processed at all. The new commands are simple, but they make it much easier to get work done.
///////////////////////////////////////////////////////////////////////////////
//
// $author Scenomics LLC
// $description Implements algorithms for WorkItemNode.
//
// Copyright 2004-2023 Scenomics LLC. All Rights Reserved.
//
///////////////////////////////////////////////////////////////////////////////
library LibWorkItemNodeAlgorithms;
import library "type_service_enumeration_util.ssl";
import library "app_service_console_util.ssl";
import library "app_service_message_box_util.ssl";
import library "type_work_item_node_util.ssl";
///////////////////////////////////////////////////////////////////////////////
// function
///////////////////////////////////////////////////////////////////////////////
function bool ToggleDebug( NodeBuffer p_apNodes )
{
for( int i = 0; i < p_apNodes.GetCount(); ++i )
{
WorkItemNode a_oNode = (WorkItemNode)p_apNodes.Get( i );
a_oNode.Debug = !a_oNode.Debug;
}
return true;
}
This algorithm is simple and easy to understand. It iterates over a collection of <WorkItemNodes> and toggles the Debug flag. If the flag is true, it becomes false and vice versa. Generally, in Scenome Scripting Language libraries, we like to keep simple loops out of macro code. This isn't a hard and fast rule, but it helps keep the macro code readable. The <WorkItemNode> macro library will just have a single call to this library, and won't need to contain the loop iteration code.
///////////////////////////////////////////////////////////////////////////////
//
// $author Scenomics LLC
// $description Implements commands for WorkItemNode.
//
// Copyright 2004-2023 Scenomics LLC. All Rights Reserved.
//
///////////////////////////////////////////////////////////////////////////////
[Package="Scenome-Package-Project"]
import library "app_service_assert_util.ssl";
import library "app_service_console_util.ssl";
import library "app_service_message_box_util.ssl";
import library "type_work_item_node_algorithms.ssl";
///////////////////////////////////////////////////////////////////////////////
// macro
///////////////////////////////////////////////////////////////////////////////
function void WorkItemNodeCommand_OnUpdate( CommandPresentationModuleInfo commandInfo )
{
ValidateNodeCommandContext.TestSelection( commandInfo, WorkItemNode, 1, true,
"This command..." );
}
macro WorkItemNodeCommand()
[Category="WorkItemNode Commands", Package="Scenome-Package-Project", Guid="{AB4A7F29-3197-481A-9B4B-10455AE45AE9}", Image=".\\icons\\generic_script_icon.bmp"]
{
// Do something here...
}
///////////////////////////////////////////////////////////////////////////////
// macro
///////////////////////////////////////////////////////////////////////////////
function void WorkItemNodeToggleDebug_OnUpdate( CommandPresentationModuleInfo commandInfo )
{
ValidateNodeCommandContext.TestSelection( commandInfo, WorkItemNode, -1, true,
"Toggles the <WorkItemNode> debug flag" );
}
macro WorkItemNodeToggleDebug()
[Category="WorkItemNode Commands", Package="Scenome-Package-Project", Guid="{AB4A7F29-3197-481A-9B4B-10455AE45AE9}", Image=".\\icons\\generic_script_icon.bmp"]
{
auto NodeBuffer nodes = LibSelection.EditSelected( Node );
LibWorkItemNodeAlgorithms.ToggleDebug( nodes );
}
This macro is very simple. The function WorkItemNodeToggleDebug_OnUpdate ensures that the command is only active if some number of <WorkItemNode> objects are selected. This function implements the command presentation policy, which determines whether the command is grayed out or if it can be executed.
Then, in the implementation, the line auto NodeBuffer nodes = LibSelection.EditSelected( Node ); populates a <NodeBuffer> object with all the selected nodes. It's important to know that calling LibSelection.EditSelected( Node ) means that the node objects will be in a memento state, which means that we will be unable to undo our changes.
We know all the nodes in the <NodeBuffer> named nodes will all be of type <WorkItemNode> because otherwise the command cannot be executed, per the command presentation policy specified in the function WorkItemNodeToggleDebug_OnUpdate.
Finally, we call the algorithm that toggles the debug flag.
The software presents a dialog that allows you to choose which file to open.
WorkItemNode ( Standard ) Context Menu.box
The software displays a text entry dialog that allows you to enter a Scenome command macro GUID.
{AB4A7F29-3197-481A-9B4B-10455AE45AE9}
The dialog appears again in case we wish to enter another GUID.
The software creates a new <ItemElementNode> named WorkItemNodeToggleDebug and places it at the end of the list of menu items. This is the new Scenome command macro!
The software displays a dialog box that allows you to rename the node.
&Toggle Debug
The software renames the node. Using & before T sets the accelerator key to T, which means you can hit T when this menu is visible to execute this command.
This moves the node to the top of the list of menu items.
The software displays a text entry dialog that allows you to enter a Scenome command macro GUID.
{1F91F995-F612-46D4-A453-4B81096121A9}
The dialog appears again in case we wish to enter another GUID.
The software creates a new <ItemElementNode> named ToggleVisible and places it at the end of the list of menu items.
The software displays a dialog box that allows you to rename the node.
Toggle &Visible
The software renames the node. Using & before V sets the accelerator key to V, which means you can hit V when this menu is visible to execute this command.
This moves the node to the top of the list of menu items.
The software rebuilds the Octopus app.
The Octopus splash screen appears and the application starts.
You're inside the Octopus library directory.
You can see the new commands Toggle Visible and Toggle Debug. You can try them if you want. If you do, you'll notice the icons change, and that you can undo the changes.
This exercise is complete. Please proceed to the next exercise.