Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic LinkCreated undo/redo (Read 4185 times)
hhko
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 20
Joined: Feb 9th, 2010
LinkCreated undo/redo
Feb 22nd, 2010 at 9:57am
Print Post  
Hi.  Grin

when LinkCreated, I changed origin shape of brush.
and I called UndoManager.Undo();
but. undo only created link.
why? Does not restore the shape of brush?

Code
Select All
private void DiagramLinkCreatedEvent(object sender, MindFusion.Diagramming.LinkEventArgs e)
{
     // I changed Origin of Brush
     // so, I want to undo created Link and origin of Brush.
     e.Link.Origin.Brush = new MindFusion.Drawing.LinearGradientBrush(Color.FromArgb(100, Color.White), Color.FromArgb(212, 212, 90), 270);
}
 


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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: LinkCreated undo/redo
Reply #1 - Feb 22nd, 2010 at 10:44am
Print Post  
  
Back to top
 
IP Logged
 
hhko
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 20
Joined: Feb 9th, 2010
Re: LinkCreated undo/redo
Reply #2 - Feb 22nd, 2010 at 11:14am
Print Post  
Hi. thank you.

I want to composite ChangeItemCmd(change brush) and AddItemCmd(Link).

but. currently, divided two commands.
how to implement one command ?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: LinkCreated undo/redo
Reply #3 - Feb 22nd, 2010 at 11:58am
Print Post  
I think the brush will be saved as part of the add command if you change it in response to the InitializeLink event. Or otherwise you could use the MergeUndoRecords method to combine the last two commands.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
hhko
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 20
Joined: Feb 9th, 2010
Re: LinkCreated undo/redo
Reply #4 - Feb 22nd, 2010 at 3:57pm
Print Post  
LinkCreated event is succeed.

Code
Select All
private void DiagramLinkCreatedEvent(object sender, MindFusion.Diagramming.LinkEventArgs e)
{
    MindFusion.Diagramming.Commands.ChangeItemCmd cmd = new MindFusion.Diagramming.Commands.ChangeItemCmd(e.Link.Origin, "Change");
    ChangeFactorColor(e.Link.Origin);
    cmd.Execute();
    diagramView.Diagram.UndoManager.History.MergeUndoRecords(2, "ChangeFactorColor");
} 



but. When a shape is deleted, LinkDeletedEvent is failed(MergeUndoRecords function is an exception).
Code
Select All
private void DiagramLinkDeletedEvent(object sender, LinkEventArgs e)
{
    try
    {
	  MindFusion.Diagramming.Commands.ChangeItemCmd cmd = new MindFusion.Diagramming.Commands.ChangeItemCmd(e.Link.Origin, "Change");
	  ChangeFactorColor(e.Link.Origin);
	  cmd.Execute();
	  diagramView.Diagram.UndoManager.History.MergeUndoRecords(2, "ChangeFactorColor");
    }
    catch (System.Exception ex)
    {

    }
} 



How to improve code?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: LinkCreated undo/redo
Reply #5 - Feb 23rd, 2010 at 9:20am
Print Post  
What does the ChangeFactorColor method do? I've tried setting a property in its place, but there wasn't any exception thrown.

Stoyan
  
Back to top
 
IP Logged
 
hhko
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 20
Joined: Feb 9th, 2010
Re: LinkCreated undo/redo
Reply #6 - Feb 23rd, 2010 at 10:07am
Print Post  
Code
Select All
void ChangeFactorColor(DiagramItem item)
{
    item.Brush = new MindFusion.Drawing.LinearGradientBrush(Color.FromArgb(100, Color.White), Color.FromArgb(212, 212, 90), 270);
} 



MergeUndoRecords function is exception.
diagramView.Diagram.UndoManager.History.MergeUndoRecords(2, "ChangeFactorColor");

exception is System.NullReferenceException.
  
Back to top
 
IP Logged
 
hhko
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 20
Joined: Feb 9th, 2010
Re: LinkCreated undo/redo
Reply #7 - Feb 23rd, 2010 at 10:13am
Print Post  
LinkCreated event is called from execute function of AddItemCmd is completed.
so. this code can succeed.
Code
Select All
MindFusion.Diagramming.Commands.ChangeItemCmd cmd = new MindFusion.Diagramming.Commands.ChangeItemCmd(startShape, "Change");
startShape.Brush = ...;
cmd.Execute();

diagramView.Diagram.UndoManager.History.MergeUndoRecords(2, "ChangeFactorColor"); 



but. I think that LinkDeleted event is not called from execute function of RemoveItemCmd is completed.


MergeUndoRecords function is exception.
MergeUndoRecords(2 <-- i think this is bug?
Code
Select All
diagramView.Diagram.UndoManager.History.MergeUndoRecords(2, "ChangeFactorColor");
 



how to improve ?
  
Back to top
 
IP Logged
 
hhko
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 20
Joined: Feb 9th, 2010
Re: LinkCreated undo/redo
Reply #8 - Feb 23rd, 2010 at 11:26am
Print Post  
I sended example source code and avi movie to your e-mail.
please check.  Wink
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: LinkCreated undo/redo
Reply #9 - Feb 23rd, 2010 at 3:47pm
Print Post  
It seems MergeUndo cannot be executed in the context of an active composite command, and the control is recording one when deleting items. It works fine if you leave only this code:

Code
Select All
ChangeItemCmd cmd = new ChangeItemCmd(e.Link.Origin, "Change");
e.Link.Origin.Brush = new MindFusion.Drawing.LinearGradientBrush(Color.FromArgb(100, Color.White), Color.Blue, 270);
cmd.Execute(); 



and there's no need to merge records because the ChangeItem command becomes a part of the composite command anyway.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint