UnDo Problem

Hi Walter,





I use DrawTool to draw on view.

Tell me why I can’t undo after inserted node.

Help me please.



//The DrawTool class



using System;

using System.Drawing;

using System.Windows.Forms;

using Northwoods.Go;



namespace OrgCharter

{

///



/// Summary description for WFDDrawingTool.

///


[Serializable]

public class DrawTool : GoTool

{

public DrawTool(GoView view) : base(view) {}



public override void Start()

{

StartTransaction();

}



public override void Stop()

{

this.View.Cursor = this.View.DefaultCursor;

StopTransaction();

}



public override void DoMouseDown()

{

GoTextNode oJoin = new GoTextNode();

oJoin.Location = new PointF(this.FirstInput.DocPoint.X , this.FirstInput.DocPoint.Y);



this.View.Document.Add(oJoin);

StopTool();

}



public override void DoMouseUp()

{

// don’t call the base functionality, which assumes mouse up stops the tool

}



public override void DoKeyDown()

{

if (this.LastInput.Key == Keys.Enter)

{

GoTextNode oJoin = new GoTextNode();

oJoin.Location = new PointF(this.FirstInput.DocPoint.X , this.FirstInput.DocPoint.Y);



this.View.Document.Add(oJoin);

StopTool(); }

else

{

base.DoKeyDown();

}

}



}

}

After the tool is all done, because the user has typed Enter, and thus because the transaction had been finished, I would think that Undo should work fine.
If you want to be able to undo while your tool is still running, you have two choices: either do each GoDocument.Add in a separate transaction, or you can fake the undo yourself.
You can do the latter by handling ^Z and ^Y in your tool and explicitly removing or re-adding the nodes your tool has added while it has been running. Your tool will need to keep a list of those nodes yourself, so that it will know what to remove or add next, depending on the command. Actually, the StrokeDrawingTool and PolygonDrawingTool in Demo1 do this (although just for ^Z), for the points in the shape that the user specifies by clicking.

Hi Walter,



My case is similar to topic ‘Add link to NewLinkLayer’ of Sylvana.



Thank you anyway.