How can I cancel User dropped shape?

S

Sergey Tatarenko

Please help, I'm really desperate with this one.

I have a GUI that is prompted on Selection_Added event, when user
cancels the GUI I want do cancel the drop scope.
I tried to call the EndUndoScope(1264, False) to undo the last scope,
but Visio leaves the dropped shape on the page.
Does anyone have an idea how this could be done?

Thanks in advance, any idea will be appreciated.
Sergey.
 
S

Sergey Tatarenko

I develop a GUI that uses Visio control.

When user drop a shape from stencil an event Selection Added is fired.
Upon this even I present a Dialog Box that can be canceled by the
user. If user cancels the Dialog Box I want to cancel the whole
operation including the Dropped Shape.
“Delete selection” will work but it can be “Undo”ed, therefore I tried
canceling the Visio Drop scope in which the Selectione Added occurs.
However it leave the dropped shape on the page.

I’m really desperate with this issue.

Thanks in advance,
Sergey.
 
D

David J Parker

The only events that give the opportunity to stop something happening are
those that begin QueryXXXXX
Therefore, your only option is to delete the shape in code, after it has
been dropped. You should do this when NoEventsPending fires.
 
D

David J Parker

...or call Undo if it is available

David J Parker said:
The only events that give the opportunity to stop something happening are
those that begin QueryXXXXX
Therefore, your only option is to delete the shape in code, after it has
been dropped. You should do this when NoEventsPending fires.
 
A

Andy

I develop a GUI that uses Visio control.

When user drop a shape from stencil an event Selection Added is fired.
Upon this even I present a Dialog Box that can be canceled by the
user. If user cancels the Dialog Box I want to cancel the whole
operation including the Dropped Shape.
“Delete selection” will work but it can be “Undo”ed, therefore I tried
canceling the Visio Drop scope in which the Selectione Added occurs.
However it leave the dropped shape on the page.

I’m really desperate with this issue.

Thanks in advance,
Sergey.

I do that with my dialogs, if the user cancels, then i just delete the
added shape and then purge the undo to prevent the user from undoing
the action calling visio.application.purgeundo. Note, that in my case
I'm not concerned about the user being able to undo changes.
 
S

Sergey Tatarenko

I do that with my dialogs, if the user cancels, then i just delete the
added shape and then purge the undo to prevent the user from undoing
the action calling visio.application.purgeundo. Note, that in my case
I'm not concerned about the user being able to undo changes.

In this Application it the case, before I was required to implement
the Undo/Redo functionality! :(
As I know in Visio I can clean all the Undo stack or nothing!
May be there is a way to clean just the last scope from undo , but I
don't know about.

The same problem is with calling the Undo to revert the Drop scope -
it will be possible to Redo it, but from User's point of view he din't
Undo anything therefore there should no redo!

I'm stuck with it.
 
S

Sergey Tatarenko

The only events that give the opportunity to stop something happening are
those that begin QueryXXXXX
Therefore, your only option is to delete the shape in code, after it has
been dropped.  You should do this when NoEventsPending fires.

Can't I just call the EndUndoScope for the "Drop Scope" with
CommitChanges=False?
 
A

Andy

Can't I just call the EndUndoScope for the "Drop Scope" with
CommitChanges=False?

Could you not live with the undo dropping the shape back on the
diagram and having your form reappear? You can always check in your
form code if the action is a result of an undo and behavice
differently if required. Logically, if the user dropped the shape
there is nothing wrong with the undo putting it back.

Not sure about calling endscope.

Dropping shapes is the only area that has given me issues in the past,
you don't get to know anything until the shape is dropped so to late
to wrap it in your own undo scope.
 
V

visiSteve

Could you not live with the undo dropping the shape back on the
diagram and having your form reappear? You can always check in your
form code if the action is a result of an undo and behavice
differently if required. Logically, if the user dropped the shape
there is nothing wrong with the undo putting it back.

Not sure about calling endscope.

Dropping shapes is the only area that has given me issues in the past,
you don't get to know anything until the shape is dropped so to late
to wrap it in your own undo scope.- Hide quoted text -

- Show quoted text -

I usually do something like this (example code is from VBA but concept
is the same in C# or any other language):

Private Sub Document_ShapeAdded(ByVal Shape as IVShape)

If Not Shape.Application.IsUndoingOrRedoing Then
If MsgBox("Should I delete it?", vbOKCancel) = vbOK Then
Shape.Delete
End If
End If

End Sub

Do I end up with an extra item on the undo stack if the user chooses
to delete the shape in the dialog? Sure, but oh well -- it doesn't
cause any problems. Remember that any actions you perform within the
scope of a Visio event (deleting the shape in this case) are wrapped
within the outer scope of the original event, so when the user chooses
Undo it will roll back all actions that took place within the scope of
the outer event. You don't need to do any BeginUndoScope or
EndUndoScope actions in this situation, since the scopes you create
would be underneath the original ShapeAdded scope.

Hope that helps!
 
S

Sergey Tatarenko

Hi,
Many thanks to all replyers.
I tried couple of approaches, each had it's own problems.
Eventually I've got help from Miscrosoft Visio Developers team here is
their solution witch suites my needs the best:

void Application_ShapeAdded(Shape Shape)
{
//praveenb: We might want to check the condition where the
Shape was added because of a "Redo"
if (currentApp.IsUndoingOrRedoing) return;

Debug.Print("Shape added -" + Shape.Name + "Current Scope
= " + currentApp.CurrentScope.ToString());
Shape.Text = "I added this text, do I really want it?";

if (MessageBox.Show("Do you want to cancel the drop
scope?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
//Start a new thread to cancel the Shape Added. This
is required as we are still in "Drop On Page" scope.
System.Threading.Thread t = new System.Threading.Thread
(new System.Threading.ThreadStart(undoLastShapeAdd));
t.Start();
//currentApp.EndUndoScope(currentApp.CurrentScope,
false);
}
}

void undoLastShapeAdd()
{
//Undo the last action (Shape Add)
currentApp.Undo();

//Overrite the last Redo stack...So that user is not able
to REDO our above UNDO.
int scopeId = currentApp.BeginUndoScope("Do Nothing");
//Some harmless API call...
currentApp.ActivePage.Name = currentApp.ActivePage.Name;
currentApp.EndUndoScope(scopeId, true);
}

The trick is to call Undo from ANOTHER THREAD!!!, then override
previously undone operation by smoll "do nothing" undo-scope.

Hope it may help to somebody maintaining clear Undo in their Visio
based applications.

Best regards,
Sergey Tatarenko
 

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