Undo

  • Thread starter Sergey Zamansky
  • Start date
S

Sergey Zamansky

Hi,
I use Visio 2003 ActiveX in C++ application. I created menu containing item
with caption 'Undo'.
1. I would like to add name of the last operation to the caption like 'Undo
Move'. How to do it?
2. I would like to disable 'Undo' menu when undo queue is empty. How to
evaluate that the undo queue is empty?

Thank you in advance,
Sergey.
 
C

Chris Roth [ Visio MVP ]

You can disable the undo cache at the application level:

Visio.Application.UndoEnabled = False (or C++ equivalent...)

For creating an undo block, you wrap your code in an "undo scope"

Visio.Application.BeginUndoScope
Visio.Application.EndUndoScope

Below is the VBA sample that comes in the developer reference that ships
with Visio for a sample. You can get at it through VBA (Alt+F11)

--

Hope this helps,

Chris Roth
Visio MVP


--------------------------------------------------------------------------------------


Private WithEvents vsoApplication As Visio.Application
Private lngScopeID As Long

Public Sub EndUndoScope_Example()

Dim vsoShape As Visio.Shape

'Set the module-level application variable to
'trap Application-level events.
Set vsoApplication = Visio.Application

'Begin a scope and set the module-level variable.
lngScopeID = vsoApplication.BeginUndoScope("Draw Shapes")

'Draw three shapes.
Set vsoShape = ActivePage.DrawRectangle(1, 2, 2, 1)

ActivePage.DrawOval 3, 4, 4, 3
ActivePage.DrawLine 4, 5, 5, 4

'Change a cell to trigger a CellChanged event.
vsoShape.Cells("Width").Formula = 5

'End and commit this scope.
vsoApplication.EndUndoScope lngScopeID, True

End Sub

Private Sub vsoApplication_CellChanged(ByVal Cell As IVCell)

'Check to see if this cell change is the result of something
'happening within the scope.
If vsoApplication.IsInScope(lngScopeID) Then
Debug.Print Cell.Name & " changed in scope "; lngScopeID
End If

End Sub

Private Sub vsoApplication_EnterScope(ByVal app As IVApplication, _
ByVal nScopeID As Long, _
ByVal bstrDescription As
String)

If vsoApplication.CurrentScope = lngScopeID Then
Debug.Print "Entering my scope " & nScopeID
Else
Debug.Print "Enter Scope " & bstrDescription & "(" & nScopeID & ")"
End If

End Sub

Private Sub vsoApplication_ExitScope(ByVal app As IVApplication, _
ByVal nScopeID As Long, _
ByVal bstrDescription As String, _
ByVal bErrOrCancelled As Boolean)

If vsoApplication.CurrentScope = lngScopeID Then
Debug.Print "Exiting my scope " & nScopeID
Else
Debug.Print "Exit Scope " & bstrDescription & "(" & nScopeID & ")"
End If

End Sub
 
S

Sergey Zamansky

Hi Chris,
Thank you for your answer.
However my questions were not answered.
I'll try to explain my question better.
1. My application has main menu set (not Viso menu!). The set has menu
'Edit'. I added menu items 'Undo' and 'Redo' to this menu.When user opens
menu 'Edit' I have to add name of last user action to the word 'Undo'. For
example, if user drops shape on a page and wants to undo this action then
she opens menu 'Edit' and sees menu item caption 'Undo Drop' instead of
'Undo'.
My question is how can I get name of last user action for undo when user
opens the menu?

2. I do not need to disable the undo cache. I need to disable menu item
'Undo' in my application menu (not Visio menu!). To do that I have to know
if the undo queue is empty. If the undo queue is empty then menu item 'Undo'
must be disabled. If the undo queue has entries then menu item 'Undo' must
be enabled.
My question is how can I determine that the undo queue is empty?

Thank you in advance,
Sergey
 
C

Chris Roth [ Visio MVP ]

Poke around in the help file around the stuff I mentioned earlier.

I think you can do something like GetCurrentScope, but that's just off the
top of my head, so I'm not 100% sure. My gut tells me that you can get this
info form Visio, since you can see all the Undo Scopes when you run the
Visio Event Monitor that comes with the Visio SDK.

--

Hope this helps,

Chris Roth
Visio MVP
 
M

Mike Z

I believe you may have to do this programmatically in a few steps. Setting
the "Undo" scope first may be necessary, and then you may need to catch and
handle the event when a shape is dropped... It may not be an easy task, but
should be doable.

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top