Sector/Linedef/Thing/Vertex Edit Form: the map will not be marked as changed anymore when canceling changes made in the forms, when the map wasn't marked as changed before

Copying map elements doesn't mark the map as changed anymore if the map wasn't marked as changed before copying
This commit is contained in:
biwa 2021-04-01 23:31:52 +02:00 committed by spherallic
parent 54fe5ae165
commit f59fbed358
9 changed files with 141 additions and 20 deletions

View File

@ -236,6 +236,8 @@ namespace CodeImp.DoomBuilder.Editing
// that need to be copied.
if(General.Editing.Mode.OnCopyBegin())
{
bool oldmapischanged = General.Map.IsChanged;
General.MainWindow.DisplayStatus(StatusType.Action, desc);
// Copy the marked geometry
@ -253,6 +255,12 @@ namespace CodeImp.DoomBuilder.Editing
// Set on clipboard
Clipboard.SetData(CLIPBOARD_DATA_FORMAT, memstream);
// General.Map.Map.CloneMarked will set General.Map.IsChanged to true, since it recreated the map. But since this
// creation happens in another MapSet, the currently opened map is actually not changed. Force the IsChanged property
// to false if the map wasn't changed before doing the copying
if (oldmapischanged == false)
General.Map.ForceMapIsChangedFalse();
// Done
memstream.Dispose();
General.Editing.Mode.OnCopyEnd();

View File

@ -2779,6 +2779,17 @@ namespace CodeImp.DoomBuilder
return snappedCount;
}
/// <summary>
/// This forces the "changed" variable to "false", which is normally not possible when setting the "IsChanged" property.
/// USE WITH CARE! This should only be used in very specific circumstances, where the "IsChanged" property is set to true
/// because of internal behavior
/// </summary>
internal void ForceMapIsChangedFalse()
{
changed = false;
General.MainWindow.UpdateMapChangedStatus();
}
#endregion
}
}

View File

@ -44,6 +44,7 @@ namespace CodeImp.DoomBuilder.Windows
private List<LinedefProperties> linedefprops; //mxd
private bool preventchanges;
private bool undocreated; //mxd
private bool oldmapischanged;
private struct LinedefProperties //mxd
{
@ -153,9 +154,12 @@ namespace CodeImp.DoomBuilder.Windows
public void Setup(ICollection<Linedef> lines)
{
preventchanges = true;
// Keep this list
this.lines = lines;
oldmapischanged = General.Map.IsChanged;
//argscontrol.Reset();
undocreated = false;
// Keep this list
this.lines = lines;
if(lines.Count > 1) this.Text = "Edit Linedefs (" + lines.Count + ")";
linedefprops = new List<LinedefProperties>();
@ -513,7 +517,16 @@ namespace CodeImp.DoomBuilder.Windows
private void cancel_Click(object sender, EventArgs e)
{
//mxd. Let's pretend nothing of this really happened...
if(undocreated) General.Map.UndoRedo.WithdrawUndo();
if (undocreated)
{
General.Map.UndoRedo.WithdrawUndo();
// Changing certain properties of the linedef, like textures will set General.Map.IsChanged to true.
// But if cancel is pressed and the changes are discarded, and the map was not changed before, we have to force
// General.Map.IsChanged back to false
if (General.Map.IsChanged && oldmapischanged == false)
General.Map.ForceMapIsChangedFalse();
}
// Be gone
this.DialogResult = DialogResult.Cancel;

View File

@ -56,6 +56,7 @@ namespace CodeImp.DoomBuilder.Windows
private readonly List<PairedFieldsControl> frontUdmfControls; //mxd
private readonly List<PairedFieldsControl> backUdmfControls; //mxd
private bool oldmapischanged;
//mxd. Window setup stuff
private static int activetab;
@ -235,10 +236,27 @@ namespace CodeImp.DoomBuilder.Windows
// This sets up the form to edit the given lines
public void Setup(ICollection<Linedef> lines)
{
preventchanges = true;
// Keep this list
this.lines = lines;
// Window setup
// ano - moved this here because we don't reinstantiate the thing every time anymore
//if (General.Settings.StoreSelectedEditTab)
//{
// int activetab = General.Settings.ReadSetting("windows." + configname + ".activetab", 0);
//
// // When front or back tab was previously selected, switch to appropriate side (selectfront/selectback are set in BaseVisualGeometrySidedef.OnEditEnd)
// if ((selectfront || selectback) && (activetab == 1 || activetab == 2))
// tabs.SelectTab(selectfront ? 1 : 2);
// else
// tabs.SelectTab(activetab);
//}
preventchanges = true;
oldmapischanged = General.Map.IsChanged;
undocreated = false;
//argscontrol.Reset();
//tagsselector.Reset();
// Keep this list
this.lines = lines;
if(lines.Count > 1) this.Text = "Edit Linedefs (" + lines.Count + ")";
linedefprops = new List<LinedefProperties>();
@ -763,7 +781,16 @@ namespace CodeImp.DoomBuilder.Windows
private void cancel_Click(object sender, EventArgs e)
{
//mxd. Let's pretend nothing of this really happened...
if(undocreated) General.Map.UndoRedo.WithdrawUndo();
if (undocreated)
{
General.Map.UndoRedo.WithdrawUndo();
// Changing certain properties of the linedef, like textures will set General.Map.IsChanged to true.
// But if cancel is pressed and the changes are discarded, and the map was not changed before, we have to force
// General.Map.IsChanged back to false
if (General.Map.IsChanged && oldmapischanged == false)
General.Map.ForceMapIsChangedFalse();
}
// Be gone
this.DialogResult = DialogResult.Cancel;

View File

@ -41,6 +41,7 @@ namespace CodeImp.DoomBuilder.Windows
private List<SectorProperties> sectorprops; //mxd
private bool preventchanges; //mxd
private bool undocreated; //mxd
private bool oldmapischanged;
private struct SectorProperties //mxd
{
@ -90,9 +91,10 @@ namespace CodeImp.DoomBuilder.Windows
public void Setup(ICollection<Sector> sectors)
{
preventchanges = true; //mxd
// Keep this list
this.sectors = sectors;
oldmapischanged = General.Map.IsChanged;
undocreated = false;
// Keep this list
this.sectors = sectors;
if(sectors.Count > 1) this.Text = "Edit Sectors (" + sectors.Count + ")";
sectorprops = new List<SectorProperties>(); //mxd
@ -349,7 +351,16 @@ namespace CodeImp.DoomBuilder.Windows
private void cancel_Click(object sender, EventArgs e)
{
//mxd. perform undo
if(undocreated) General.Map.UndoRedo.WithdrawUndo();
if (undocreated)
{
General.Map.UndoRedo.WithdrawUndo();
// Changing certain properties of the sector, like floor/ceiling textures will set General.Map.IsChanged to true.
// But if cancel is pressed and the changes are discarded, and the map was not changed before, we have to force
// General.Map.IsChanged back to false
if (General.Map.IsChanged && oldmapischanged == false)
General.Map.ForceMapIsChangedFalse();
}
// And be gone
this.DialogResult = DialogResult.Cancel;

View File

@ -54,6 +54,8 @@ namespace CodeImp.DoomBuilder.Windows
private Vector2D globalslopepivot;
private Dictionary<Sector, Vector2D> slopepivots;
private bool oldmapischanged;
#endregion
#region ================== Structs
@ -243,9 +245,10 @@ namespace CodeImp.DoomBuilder.Windows
public void Setup(ICollection<Sector> sectors)
{
preventchanges = true; //mxd
// Keep this list
this.sectors = sectors;
oldmapischanged = General.Map.IsChanged;
undocreated = false;
// Keep this list
this.sectors = sectors;
if(sectors.Count > 1) this.Text = "Edit Sectors (" + sectors.Count + ")";
sectorprops = new Dictionary<Sector, SectorProperties>(sectors.Count); //mxd
@ -775,7 +778,16 @@ namespace CodeImp.DoomBuilder.Windows
private void cancel_Click(object sender, EventArgs e)
{
//mxd. Let's pretend nothing of this really happened...
if(undocreated) General.Map.UndoRedo.WithdrawUndo();
if (undocreated)
{
General.Map.UndoRedo.WithdrawUndo();
// Changing certain properties of the sector, like floor/ceiling textures will set General.Map.IsChanged to true.
// But if cancel is pressed and the changes are discarded, and the map was not changed before, we have to force
// General.Map.IsChanged back to false
if (General.Map.IsChanged && oldmapischanged == false)
General.Map.ForceMapIsChangedFalse();
}
// Be gone
this.DialogResult = DialogResult.Cancel;

View File

@ -51,6 +51,8 @@ namespace CodeImp.DoomBuilder.Windows
private List<ThingProperties> thingprops; //mxd
private bool flagsvalue_ignore = false;
private bool flags_ignore = false;
//private Dictionary<string, string> flagsrename; //mxd
private bool oldmapischanged;
private struct ThingProperties //mxd
{
@ -165,6 +167,9 @@ namespace CodeImp.DoomBuilder.Windows
public void Setup(ICollection<Thing> things)
{
preventchanges = true;
oldmapischanged = General.Map.IsChanged;
undocreated = false;
//argscontrol.Reset();
// Keep this list
this.things = things;
@ -458,7 +463,16 @@ namespace CodeImp.DoomBuilder.Windows
private void cancel_Click(object sender, EventArgs e)
{
//mxd. Perform undo?
if(undocreated) General.Map.UndoRedo.WithdrawUndo();
if (undocreated)
{
General.Map.UndoRedo.WithdrawUndo();
// Changing certain properties of the thing, like its type, will set General.Map.IsChanged to true.
// But if cancel is pressed and the changes are discarded, and the map was not changed before, we have to force
// General.Map.IsChanged back to false
if (General.Map.IsChanged && oldmapischanged == false)
General.Map.ForceMapIsChangedFalse();
}
// Be gone
this.DialogResult = DialogResult.Cancel;

View File

@ -50,6 +50,8 @@ namespace CodeImp.DoomBuilder.Windows
private static bool useabsoluteheight; //mxd
private List<ThingProperties> thingprops; //mxd
private readonly string[] renderstyles; //mxd
//private Dictionary<string, string> flagsrename; //mxd
private bool oldmapischanged;
//mxd. Window setup stuff
private static int activetab;
@ -159,6 +161,9 @@ namespace CodeImp.DoomBuilder.Windows
public void Setup(ICollection<Thing> things)
{
preventchanges = true;
oldmapischanged = General.Map.IsChanged;
undocreated = false;
//argscontrol.Reset();
// Keep this list
this.things = things;
@ -532,7 +537,16 @@ namespace CodeImp.DoomBuilder.Windows
private void cancel_Click(object sender, EventArgs e)
{
//mxd. Perform undo?
if(undocreated) General.Map.UndoRedo.WithdrawUndo();
if (undocreated)
{
General.Map.UndoRedo.WithdrawUndo();
// Changing certain properties of the sector, like its type, will set General.Map.IsChanged to true.
// But if cancel is pressed and the changes are discarded, and the map was not changed before, we have to force
// General.Map.IsChanged back to false
if (General.Map.IsChanged && oldmapischanged == false)
General.Map.ForceMapIsChangedFalse();
}
// Be gone
this.DialogResult = DialogResult.Cancel;

View File

@ -47,6 +47,7 @@ namespace CodeImp.DoomBuilder.Windows
private bool preventchanges; //mxd
private bool undocreated; //mxd
private List<VertexProperties> vertexprops; //mxd
private bool oldmapischanged;
//mxd. Window setup stuff
private static Point location = Point.Empty;
@ -123,6 +124,7 @@ namespace CodeImp.DoomBuilder.Windows
public void Setup(ICollection<Vertex> vertices, bool allowPositionChange)
{
preventchanges = true; //mxd
oldmapischanged = General.Map.IsChanged;
// Keep this list
this.vertices = vertices;
@ -361,7 +363,16 @@ namespace CodeImp.DoomBuilder.Windows
private void cancel_Click(object sender, EventArgs e)
{
//mxd. Perform undo if required
if(undocreated) General.Map.UndoRedo.WithdrawUndo();
if (undocreated)
{
General.Map.UndoRedo.WithdrawUndo();
// Changing certain properties of the vertex, like the position, will set General.Map.IsChanged to true.
// But if cancel is pressed and the changes are discarded, and the map was not changed before, we have to force
// General.Map.IsChanged back to false
if (General.Map.IsChanged && oldmapischanged == false)
General.Map.ForceMapIsChangedFalse();
}
// And close
this.DialogResult = DialogResult.Cancel;