Adding Group and Child -- 2 Transactions

I have noticed another behaviour which I’m not sure is a bug or by design. It appears that when adding a group and a child node within the same transaction, two undo operations are required to undo this transaction.

Consider the following method which builds the diagram:

private void BuildDiagram()

            var diagram = ctlDiagram;              
            var group = new GraphLinksModelNodeData<string>();
            group.IsSubGraph = true;
            group.Key = "TheGroup";
            group.Text = "Grouper";

            var n1 = new GraphLinksModelNodeData<string> { Key = "32", Location = new Point(250, 80), Text = "Accounts Payable", SubGraphKey = "TheGroup" };
            var n2 = new GraphLinksModelNodeData<string> { Key = "10", Location = new Point(160, 210), Text = "Administration Expenses", SubGraphKey = "TheGroup" };
            var n3 = new GraphLinksModelNodeData<string> { Key = "22", Location = new Point(330, 210), Text = "Cash", SubGraphKey = "TheGroup" };
            var n4 = new GraphLinksModelNodeData<string> { Key = "16", Location = new Point(183, 329), Text = "Deprecitation", SubGraphKey = "TheGroup" };

            diagram.Model.AddLink(n1, null, n2, "T");
            diagram.Model.AddLink(n1, null, n3, "T");
            diagram.Model.AddLink(n2, null, n4, "T");             

If I want to undo this action, I have to call diagram.CommandHandler.UndoCommand(null); twice. However, If remove the line that adds the group to the model: diagram.Model.AddNode(group); then I only have to call diagram.CommandHandler.UndoCommand(null); once.

When one drops or pastes code into a Visual Studio editor, undoing also requires two steps: one to undo the formatting of the text according to the current language options, and a second to actually remove the pasted text. So this is reasonable behavior.

However, it is inconsistent, as you have seen, with other circumstances – namely when a Group is not involved.

I think we will try making it more consistent and then see if that causes any problems.

Thanks Walter