Show dialogue only when there are unsaved changes

This commit is contained in:
Abdurrahmaan Iqbal
2019-10-17 10:24:45 +01:00
committed by abcdefg30
parent 780982dbe2
commit d2819dca77
2 changed files with 29 additions and 7 deletions

View File

@@ -29,6 +29,8 @@ namespace OpenRA.Mods.Common.Traits
int nextId;
public bool Modified;
public void WorldLoaded(World w, WorldRenderer wr)
{
Add(new OpenMapAction());
@@ -36,6 +38,7 @@ namespace OpenRA.Mods.Common.Traits
public void Add(IEditorAction editorAction)
{
Modified = true;
editorAction.Execute();
if (undoStack.Count > 0)
@@ -55,6 +58,8 @@ namespace OpenRA.Mods.Common.Traits
if (!HasUndos())
return;
Modified = true;
var editorAction = undoStack.Pop();
undoStack.Peek().Status = EditorActionStatus.Active;
editorAction.Action.Undo();
@@ -81,6 +86,8 @@ namespace OpenRA.Mods.Common.Traits
if (!HasRedos())
return;
Modified = true;
var editorAction = redoStack.Pop();
editorAction.Status = EditorActionStatus.Active;
@@ -114,6 +121,12 @@ namespace OpenRA.Mods.Common.Traits
while (undoStack.Peek().Id != id)
Redo();
}
public bool HasUnsavedItems()
{
// Modified and last action isn't the OpenMapAction (+ no redos)
return Modified && !(undoStack.Peek().Action is OpenMapAction && !HasRedos());
}
}
public enum EditorActionStatus