Creating Undo Units

3 4

If your solution maintains any type of parallel model that contains data associated with the shapes in your drawing, it is important that the model correctly represents the state of the drawing.

To ensure that your drawings and models remain synchronized, you can add undo units to the Microsoft Visio Undo manager. An undo unit is a Component Object Model (COM) object that supports the Visio IVBUndoUnit interface (or the IOleUndoUnit interface on an in-process COM object). It contains the actions needed to undo or redo changes to an external data source that reflect changes in the drawing.

The Visio IVBUndoUnit interface is designed to allow programmers using Microsoft Visual Basic for Applications (VBA) and Microsoft Visual Basic to create their own undo units for the Visio Undo manager. To create an undo unit, you must implement this interface, along with all of its public procedures, in a class module that you insert into your project. This section describes creating an undo unit by implementing the IVBUndoUnit interface in a VBA project.

For details about implementing interfaces in VBA or Visual Basic, search for the Implements keyword in your Visual Basic documentation. For details about IVBUndoUnit, see the Visio type library.

Creating an Undo Unit

You can take two approaches to creating an undo unit:

  • You can create a single object that maintains its undone state.
  • You can create two objects—one that encapsulates actions required to undo a change, and one that encapsulates the actions required to redo a change.

This topic and the next, Creating an Undo Unit that Maintains Non-Visio Data: an Example, describe a single undo unit that maintains its undo/redo state.

To create an undo unit

  1. Insert a class module into your VBA project that implements the IVBUndoUnit class. This is your undo unit. To do this, use the Implements keyword:
  2.  Implements Visio.IVBUndoUnit 

    Inside this class module you must implement all of the public procedures of IVBUndoUnit. After you code the Implements statement, IVBUndoUnit will appear in the Object box in the code window.

  3. Select IVBUndoUnit from the Object box.
  4. Skeleton procedures become available in the Procedure box for each of the procedures you must implement, as described in the following table.

IVBUndoUnit procedures

Procedure name

Description

Description

This property returns a string describing the undo unit. This string appears in the Undo list on the Standard toolbar.

Do

This method provides the actions that are required to undo and redo your action.

If you are creating a single object for undoing and redoing, this procedure maintains your undo/redo state and adds an undo unit to the opposite stack.

If the Do method is called with a Nothing pointer, the unit should carry out the undo action but should not place anything on the undo or redo stack.

OnNextAdd

This method gets called when the next undo unit in the same scope gets added to the undo stack. When an undo unit receives an OnNextAdd notification, it communicates back to the creating object that it can longer insert data into this undo unit.

UnitSize

This property returns the approximate memory size (in bytes) of the undo unit plus resources it has allocated. The Visio engine may use this memory size when deciding whether to purge the undo queue. This value is optional and can be zero (0).

UnitTypeCLSID

This property returns a string value that can contain a CLSID to identify your undo units. You can use the same CLSID for multiple undo units and use different values in the UnitTypeLong procedure. This value is optional and can be a Null or empty string.

UnitTypeLong

This property returns a Long, which you can use to identify your objects. This value is optional and can be 0.

Adding an Undo Unit in the Visio Undo Manager

At any location in your program where you perform an action in your parallel model, you should add an instance of your undo unit that can undo or redo your action. In this way, it will get called along with everything else in the undo stack if your add-on's changes get undone.

To add an undo unit in the Visio Undo manager

  • Invoke the AddUndoUnit method of the Application object and pass it an instance of your undo unit class using the New keyword.
  • For example, if the class module that you inserted into the project was named MyUndoUnit :

     Application.AddUndoUnit New MyUndoUnit 

For details about the New keyword, see your Visual Basic documentation.



Developing Microsoft Visio Solutions 2001
Developing Microsoft Visio Solutions (Pro-Documentation)
ISBN: 0735613532
EAN: 2147483647
Year: 2004
Pages: 180

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net