Example Programs

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating a TestStand Tool Menu Item with Undo & Redo Support

Overview

This example shows how you can implement undo/redo support for a custom tool menu item in TestStand so that a user can easily revert changes made to the sequence file within the tool.  This example covers the following concepts

  • Adding a custom tool to the TestStand Tools menu.
  • Using the TestStand API to allow changes to be undone.

 

Description

When developing a custom tool in TestStand which makes changes to a target sequence file, it is beneficial to allow the user to undo the changes if necessary.  The TestStand API provides methods to allow you to specify the start and end of the edits made by the tool so that the undo operation reverts only the changes made by the tool.

 

In order to support Undo and Redo for an edit to the sequence file, follow these steps:

 

  1. Before the edit, notify the ApplicationManger control that you are intending to make an edit to a file that it is managing:

    ApplicationManager.BeginEdit()
    dsfsdfasdfsdafasf.PNG
    If the file is in a non-editable state, for example it is executing or is read only, the method returns True.

    Note: you can access the application manager for the sequence editor using the following engine method: 
    Engine.GetInternalOption(InternalOption_ApplicationManager)
    Since the ApplicationManager class is defined in the TestStand UI control API, you must use an ActiveX step to interact with it; only the core and adapter APIs are available in expressions.

  2. Create a new UndoItemCreator object, which manages one or more edits that should be undo-able.  The inputs of this method allow you to configure the type of operation, and the file it applies to. Use Runstate.InitialSelection to access the sequence file and the properties that the user selected when launching the tool

    Locals.undoItem = RunState.Engine.NewUndoItemCreator(EditKind_ChangeObject, RunState.InitialSelection.SelectedFile, "")
  3. Mark the start of the operation.  Use BeginEditEx to specify a single object to modify, or BeginBatchEdit to specify multiple objects.  You can call these methods multiple times for a single UndoItemCreator object.
    Locals.undoItem.AsUndoItemCreator.BeginBatchEdit(RunState.InitialSelection.SelectedPropertyObjects)
  4. Do the operation.  In this example, the tool modifies a numeric array property using the SetValVariant() method.
  5. Increment the change count of the sequence file being modified to indicate that it has been modified
    RunState.InitialSelection.SelectedFile.IncChangeCount()
  6. Mark the end of the edit
    Locals.undoItem.AsUndoItemCreator.EndBatchEdit()
  7. Post the undo item.  Any changes that were made since the UndoItemCreator object was created are included in a single undo-able operation.
    Locals.undoItem.AsUndoItemCreator.CreateAndPostUndoItem()
  8. Call the EndEdit method on the application manager to ensure that the application generates the EndEdit event.

Hardware and Software Requirements

TestStand Tool Menu Item with Undo Support.zip

TestStand 2014 or Compatible

LabVIEW 2013 or Compatible (for modifying waveform editor dialog)

 

Steps to Implement or Execute Code

To install the example in the TestStand tool menu:

  1. Close the sequence editor.
  2. Extract the files in the attached archive.  Copy the WaveFormEditor folder into the <TestStand Public>/Components/Tools folder.
  3. Move the WaveformEditor.ini in the folder to the <TestStand Public>/Setup/ToolMenusToInstall folder.
  4. Restart Sequence Editor.

To use the Waveform Editor Tool

  1. Create a new numeric array property, such as a local, and select it.
  2. Select the property, then navigate to Tools » Waveform Editor. Note that the tool will be greyed if a numeric array property is not selected.

    2018-04-04_113626.png

  3. Edit the array in the dialog, or use the Generate Waveform to create a set of waveform data.

    2018-04-04_115337.png

  4. Click OK, and observe that the array object in TestStand has been updated.
  5. Undo the operation using Edit » Undo. Observe that the array reverts to the original state.

 

Additional Information or References

Al B.
Staff Software Engineer - TestStand
CTA/CLD
Contributors