UI - Fix possible exception when showing dialogs

Profile editor - Limit undo/redo to 20 actions for now
Plugins - Fix custom icons not displaying in settings windows
This commit is contained in:
Robert committed 2021-07-06 23:45:34 +02:00
1 parent 631d8de2c3
commit 4034f438ed
7 files changed
+143 -13

No files matched your search

+4 -4
View File
@@ -25,8 +25,8 @@ namespace Artemis.Core
Scripts = new List<ProfileScript>();
ScriptConfigurations = new List<ScriptConfiguration>();
UndoStack = new Stack<string>();
RedoStack = new Stack<string>();
UndoStack = new MaxStack<string>(20);
RedoStack = new MaxStack<string>(20);
Load();
}
@@ -75,8 +75,8 @@ namespace Artemis.Core
/// </summary>
public ProfileEntity ProfileEntity { get; internal set; }
internal Stack<string> UndoStack { get; set; }
internal Stack<string> RedoStack { get; set; }
internal MaxStack<string> UndoStack { get; set; }
internal MaxStack<string> RedoStack { get; set; }
/// <inheritdoc />
public override void Update(double deltaTime)
@@ -470,7 +470,7 @@ namespace Artemis.Core.Services
// Keep the profile from being rendered by locking it
lock (profile)
{
if (!profile.UndoStack.Any())
if (profile.UndoStack.Count == 0)
{
_logger.Debug("Undo profile update - Failed, undo stack empty");
return false;
@@ -496,7 +496,7 @@ namespace Artemis.Core.Services
// Keep the profile from being rendered by locking it
lock (profile)
{
if (!profile.RedoStack.Any())
if (profile.RedoStack.Count == 0)
{
_logger.Debug("Redo profile update - Failed, redo empty");
return false;
+118
View File
@@ -0,0 +1,118 @@
// Source: https://ntsblog.homedev.com.au/index.php/2010/05/06/c-stack-with-maximum-limit/
using System;
using System.Collections;
using System.Collections.Generic;
namespace Artemis.Core
{
/// <summary>
/// Generic stack implementation with a maximum limit
/// When something is pushed on the last item is removed from the list
/// </summary>
[Serializable]
internal class MaxStack<T>
{
#region Fields
private int _limit;
private LinkedList<T> _list;
#endregion
#region Constructors
public MaxStack(int maxSize)
{
_limit = maxSize;
_list = new LinkedList<T>();
}
#endregion
#region Public Stack Implementation
public void Push(T value)
{
if (_list.Count == _limit)
{
_list.RemoveLast();
}
_list.AddFirst(value);
}
public T Pop()
{
if (_list.Count > 0)
{
T value = _list.First.Value;
_list.RemoveFirst();
return value;
}
else
{
throw new InvalidOperationException("The Stack is empty");
}
}
public T Peek()
{
if (_list.Count > 0)
{
T value = _list.First.Value;
return value;
}
else
{
throw new InvalidOperationException("The Stack is empty");
}
}
public void Clear()
{
_list.Clear();
}
public int Count
{
get { return _list.Count; }
}
/// <summary>
/// Checks if the top object on the stack matches the value passed in
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public bool IsTop(T value)
{
bool result = false;
if (this.Count > 0)
{
result = Peek().Equals(value);
}
return result;
}
public bool Contains(T value)
{
bool result = false;
if (this.Count > 0)
{
result = _list.Contains(value);
}
return result;
}
public IEnumerator GetEnumerator()
{
return _list.GetEnumerator();
}
#endregion
}
}