the entire undo/redo system in Universal Editor needs a MAJOR overhaul

This commit is contained in:
Michael Becker 2019-12-16 07:58:20 -05:00
parent 4a8cc6f516
commit c3a1516811
No known key found for this signature in database
GPG Key ID: 389DFF5D73781A12
2 changed files with 36 additions and 4 deletions

View File

@ -399,6 +399,7 @@ namespace UniversalEditor.UserInterface
mvarUpdating--;
}
public bool InEdit { get { return mvarEditing > 0; } }
public void BeginEdit()
{
if (mvarUpdating > 0) return;
@ -424,6 +425,15 @@ namespace UniversalEditor.UserInterface
// clear out all the redos
redo.Clear();
}
public void ContinueEdit()
{
if (undo.Count > 0)
{
EDITINFO edit = undo.Pop();
edit.oldValue = mvarObjectModel.Clone() as ObjectModel;
undo.Push(edit);
}
}
public void BeginEdit(string PropertyName, object Value = null, object ParentObject = null, Control editingControl = null)
{
if (mvarEditing > 0)

View File

@ -26,6 +26,7 @@ using UniversalEditor.UserInterface;
using MBS.Framework.UserInterface;
using MBS.Framework.UserInterface.Controls;
using MBS.Framework.UserInterface.Layouts;
using System.ComponentModel;
namespace UniversalEditor.Editors.Text.Plain
{
@ -62,18 +63,35 @@ namespace UniversalEditor.Editors.Text.Plain
return _er;
}
bool working = false;
private void txt_Changed(object sender, EventArgs e)
{
PlainTextObjectModel om = (this.ObjectModel as PlainTextObjectModel);
BeginEdit();
om.Text = txt.Text;
EndEdit();
if (!working)
{
if (!InEdit)
{
BeginEdit();
}
om.Text = txt.Text;
txt.ResetChangedByUser();
}
}
protected override void OnObjectModelSaving(CancelEventArgs e)
{
base.OnObjectModelSaving(e);
if (InEdit)
EndEdit();
}
public PlainTextEditor ()
{
txt = new TextBox();
txt = new TextBox();
txt.Changed += txt_Changed;
txt.Multiline = true;
@ -85,12 +103,16 @@ namespace UniversalEditor.Editors.Text.Plain
{
base.OnObjectModelChanged(e);
working = true;
txt.Text = String.Empty;
working = false;
PlainTextObjectModel om = (this.ObjectModel as PlainTextObjectModel);
if (om == null) return;
working = true;
txt.Text = om.Text;
working = false;
}
}
}