Hi.
My custom object consists of several GoShapes.
- Move the object and record the transaction.
- Move the object without transaction recording.
- After Undoing, GoStroke does not appear in the expected location.
What is the problem?
※ In my actual project, some custom objects are automatically aligned to the right as the view size changes
The automatic alignment behavior should not be recorded in transactions.
Here is the test source code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Northwoods.Go;
using System.Threading;
namespace GoStrokeTest
{
public partial class Form1 : Form
{
private GoView view;
public Form1()
{
this.InitializeComponent();
this.Init();
}
private void Init()
{
this.view = new GoView() { Dock = DockStyle.Fill };
this.Controls.Add(this.view);
this.view.Document.UndoManager = new GoUndoManager();
this.view.Document.UndoManager.ChecksTransactionLevel = true;
var button = new GoButton()
{
Text = "Test",
Location = new PointF(10, 150),
};
this.view.Document.Add(button);
var text = new GoText()
{
Text = "Ready",
Location = new PointF(50, 150),
FontSize = 14,
};
this.view.Document.Add(text);
button.Action += (s, e) =>
{
this.view.StartTransaction();
var tg = new TestGroup("Test");
this.view.Document.Add(tg);
this.view.FinishTransaction("Add");
text.Text = "Add(Record)";
Application.DoEvents();
Thread.Sleep(2000);
this.view.StartTransaction();
tg.Location = new PointF(100, 0);
this.view.FinishTransaction("Move");
text.Text = "Move(Record)";
Application.DoEvents();
Thread.Sleep(2000);
tg.Location = new PointF(200, 0);
text.Text = "Move(Not Record)";
Application.DoEvents();
Thread.Sleep(2000);
this.view.Undo();
text.Text = "Undo Move";
};
}
public class TestGroup : GoGroup
{
public TestGroup(string text)
{
this.Resizable = false;
this.PickableBackground = true;
var t = new GoText() { Selectable = false, Text = text, };
this.Add(t);
var e = new GoEllipse()
{
Selectable = false,
BrushColor = Color.Purple,
Location = new PointF(50, 0),
Size = new SizeF(50, 50),
};
this.Add(e);
var r = new GoRectangle()
{
Selectable = false,
BrushColor = Color.IndianRed,
Location = new PointF(0, 50),
Size = new SizeF(50, 50),
};
this.Add(r);
var s1 = new GoStroke() { Selectable = true };
s1.AddPoint(70, 60);
s1.AddPoint(90, 90);
this.Add(s1);
var s2 = new GoStroke() { Selectable = true };
s2.AddPoint(90, 60);
s2.AddPoint(70, 90);
this.Add(s2);
}
}
}
}