Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic ActionUndo (Read 4877 times)
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
ActionUndo
Sep 30th, 2015 at 7:23pm
Print Post  
Hi,
how can I get the node or link that has been modified or added by the undo command?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ActionUndo
Reply #1 - Oct 1st, 2015 at 10:35am
Print Post  
Hi,

Handle the DiagramListener.actionUndone event and inspect UndoEvent.getCommand().getItem(), after type-casting the command to appropriate type, e.g. AddItemCmd or ModifyItemCmd.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: ActionUndo
Reply #2 - Oct 1st, 2015 at 12:14pm
Print Post  
ok, thank you very much, I'll try Smiley Is there also a way to avoid to do undo to resize the node? I mean I have a node, I put some text on it, then I resize the node according to the text with the method resizeToFitText(FitSize.KeepRatio), when I click undo firstly it deletes the text then resizes the node till when it reaches the starting dimensions and then it deletes the node, but I want to avoid these passages of resize I want to delete the text and with the next undo delete the node.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ActionUndo
Reply #3 - Oct 1st, 2015 at 3:04pm
Print Post  
Try using CompositeCmd command to enclose the ChangeItemCmd objects you create for other operations:

Code
Select All
CompositeCmd composite = diagram.getUndoManager().startComposite("change text");

// run other commands here

composite.execute(); 



Alternatively, call CommandHistory.mergeUndoRecords method to merge last few commands in history into a single composite command.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: ActionUndo
Reply #4 - Oct 1st, 2015 at 3:25pm
Print Post  
Ok, thank you very much  Smiley
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: ActionUndo
Reply #5 - Oct 5th, 2015 at 8:26am
Print Post  
Sorry I tried but it doesn't work, how can I do? Can I have an example of how command history works? Should I do it in the listener of the undo or in actionUndone?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ActionUndo
Reply #6 - Oct 5th, 2015 at 1:03pm
Print Post  
actionUndone handler is too late as it means the user has already undone one of the actions you'd want to be merged with others. Try this if setting text from code:

Code
Select All
CompositeCmd composite = undoMan.startComposite("set text");

// property changes aren't saved automatically, use ChangeItemCmd
ChangeItemCmd changeText = new ChangeItemCmd(testNode, "set text");
testNode.setText("test");
diagram.executeCommand(changeText);

testNode.resizeToFitText(FitSize.KeepRatio);

composite.execute(); 



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