Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Undo/Redo Composite commands (Read 5331 times)
Rich Cassell
Junior Member
**
Offline


I Love MindFusion!

Posts: 63
Joined: Sep 19th, 2012
Undo/Redo Composite commands
Feb 21st, 2013 at 2:36pm
Print Post  
Hey,

I'm wanting to build in undo and redo functionality into my MindFusion project but i'm having a few issues that i need some guidance with.

In my software, the user doesn't just create a single node like with most MF examples but one operation may create a few nodes all linked together so in order to do undo/redo i've found that i must use composite commands.

Undoing a single command works absolutely fine; the nextUndo parameter of the UndoManager is populated with the compositeCommand and pressing my undo button does exactly what you'd expect. My first issue is that subsequent presses of the button don't seem to do anything, as though it's run out of history... Does the Capacity field refer to how many composite commands it holds? Or how many individual commands (I.e if ONE composite command has TWENTY individual commands, how many places in history capacity does this take up).

My second problem is that Redo doesn't seem to work at all, no matter what happens the nextRedo method of the UndoManager always remains at Nothing. Am i missing something?

Any help will be great!

Thanks,
Cass
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Undo/Redo Composite commands
Reply #1 - Feb 21st, 2013 at 5:07pm
Print Post  
Hi,

If you aren't getting any other commands in the undo history, it sounds as if the current composite is still active and new commands are added to it instead to the history stack. What does your code that creates the composite command look like?

Stoyan
  
Back to top
 
IP Logged
 
Rich Cassell
Junior Member
**
Offline


I Love MindFusion!

Posts: 63
Joined: Sep 19th, 2012
Re: Undo/Redo Composite commands
Reply #2 - Feb 22nd, 2013 at 7:54am
Print Post  
Hi Stoyan,

Cheers for the reply.

I'm enabling undo in the UndoManager and then using the following code to create a command

Code
Select All
        Dim composite As CompositeCmd = doc.UndoManager.StartComposite("Create")
       'Do things here
        composite.Execute() 

  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Undo/Redo Composite commands
Reply #3 - Feb 22nd, 2013 at 8:08am
Print Post  
Hi,

At what point are you calling this code, and if you check the composite.Title value, is it equal to "Create"? StartComposite will return the current composite command if there's already one used by the control for some reason, and it might lead to problems if you execute it and the control tries to add to it later.

Stoyan
  
Back to top
 
IP Logged
 
Rich Cassell
Junior Member
**
Offline


I Love MindFusion!

Posts: 63
Joined: Sep 19th, 2012
Re: Undo/Redo Composite commands
Reply #4 - Feb 22nd, 2013 at 8:15am
Print Post  
Hi,

The idea of my program is very similar to the Workflow Designer MF example where you drag a control onto any link on the diagram. The difference being, some controls might be a single node whereas others could be any number of nodes and links... The code i sent is done in the dragDrop method... So the "StartComposite" line is at the beginning of the sub, and then the actual creation is done, and the Execute method is at the end.

The title does stay at "Create", and in the example i've just tried the subCommands list in composite contains 28 commands.

I have just noticed though - some of those 28 commands are actually OTHER compositeCmd records where it does something else as part of the dragDrop. Could that be a problem??

Cass
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Undo/Redo Composite commands
Reply #5 - Feb 22nd, 2013 at 8:28am
Print Post  
Hi,

Are the other composite commands yours or ones created internally by the diagram? If they are yours, try either creating them using a new CompositeCommand() constructor call instead of UndoManager.StartComposite(), or do not call their Execute method in the end if you detect they aren't actually a newly created command but the outer one from the DragDrop handler. If they are internal diagram commands, what's their Title value?

Stoyan
  
Back to top
 
IP Logged
 
Rich Cassell
Junior Member
**
Offline


I Love MindFusion!

Posts: 63
Joined: Sep 19th, 2012
Re: Undo/Redo Composite commands
Reply #6 - Feb 22nd, 2013 at 8:39am
Print Post  
Hi,

The actual CompositeCmds inside it are internally created and have a title of "Route".

The other commands in there are AddItemCmd and RemoveItemCmd records and these are coded by me using the StartComposite command in separate methods so i'll try and change these for CompositeCommands first of all!

Thanks for your help so far!

Cass
  
Back to top
 
IP Logged
 
Rich Cassell
Junior Member
**
Offline


I Love MindFusion!

Posts: 63
Joined: Sep 19th, 2012
Re: Undo/Redo Composite commands
Reply #7 - Feb 22nd, 2013 at 8:43am
Print Post  
Hi Stoyan,

Sorry, ignore that last message... In fact all 3 command types within my dragDrop compositeCommand are all created internally - none of my other create calls are made inside the dragDrop method.

As i said, the first Undo works perfectly, it just seems to be subsequent ones, as though (like you said earlier) it's not "forgetting" about it and is appending to it rather than making a new one.

Redo still doesn't do anything

Thanks!

Cass
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Undo/Redo Composite commands
Reply #8 - Feb 22nd, 2013 at 9:06am
Print Post  
Hi,

Could you trace it with a debugger to verify if execution ever reaches the composite.Execute() call? There could be some exception thrown before that, and you might never notice it because .NET catches all exceptions thrown from OLE drag-and-drop handlers.

Stoyan
  
Back to top
 
IP Logged
 
Rich Cassell
Junior Member
**
Offline


I Love MindFusion!

Posts: 63
Joined: Sep 19th, 2012
Re: Undo/Redo Composite commands
Reply #9 - Feb 22nd, 2013 at 9:14am
Print Post  
Hi Stoyan,

Yes it definitely reaches the execute call because the first Undo works, and i can drill down into composite to see it's contents at that point too.

As some extra info, I put a break point at the actual "diagram.UndoManager.Undo" call and looked at the undo it runs... The first always works, and contains a selection of different command types like i mentioned before.... If i press it again, the NextUndo setting IS set again with the next undo command i'd expect BUT all of the commands are ModifyItemCmds and has a title of "Flowchart Layout". NextRedo stays at Nothing, i'd expect it to show the content of the last NextUndo command?

Cass
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Undo/Redo Composite commands
Reply #10 - Feb 22nd, 2013 at 9:31am
Print Post  
Hi,

I have tried this both with and without FlowchartLayout but couldn't see any problems. Here is my test project, let me know what I should change to reproduce:
https://mindfusion.eu/_samples/WorkflowDesignerUndoTest.zip

Stoyan
  
Back to top
 
IP Logged
 
Rich Cassell
Junior Member
**
Offline


I Love MindFusion!

Posts: 63
Joined: Sep 19th, 2012
Re: Undo/Redo Composite commands
Reply #11 - Feb 22nd, 2013 at 9:50am
Print Post  
Hi Stoyan!

Got it working! Thanks very much for your example project, very helpful.

Believe it or not the ONLY difference was that straight after calling "diagram.undoManager.Undo", i was then immediately calling "LayoutDiagram". Not sure why that would make a difference but it was the only difference i could see. Removing that line fixed both undo and redo commands.

Thanks again! Smiley

Cass
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Undo/Redo Composite commands
Reply #12 - Feb 22nd, 2013 at 10:22am
Print Post  
Hi,

Doing anything that modifies the diagram structure or item positions will clear all redo-able commands in the queue since they would not be consistent with the new diagram state in the general case. That would explain why there's nothing to redo. If your LayoutDiagram method creates a composite command as well, perhaps it was the one left open - check if it is executed at the end.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint