mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
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:
parent
631d8de2c3
commit
4034f438ed
@ -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
src/Artemis.Core/Utilities/MaxStack.cs
Normal file
118
src/Artemis.Core/Utilities/MaxStack.cs
Normal 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
|
||||
|
||||
}
|
||||
}
|
||||
@ -122,7 +122,7 @@ namespace Artemis.UI.Shared.Services
|
||||
public void ShowExceptionDialog(string message, Exception exception)
|
||||
{
|
||||
if (exception == null) throw new ArgumentNullException(nameof(exception));
|
||||
_windowManager.ShowDialog(new ExceptionViewModel(message, exception));
|
||||
Execute.OnUIThread(() => _windowManager.ShowDialog(new ExceptionViewModel(message, exception)));
|
||||
}
|
||||
|
||||
private IKernel GetBestKernel()
|
||||
|
||||
@ -26,7 +26,14 @@
|
||||
<DockPanel>
|
||||
<controls:AppBar Type="Dense" Title="{Binding ActiveItem.Plugin.Info.Name}" DockPanel.Dock="Top" Margin="-18 0 0 0" ShowShadow="False">
|
||||
<controls:AppBar.AppIcon>
|
||||
<shared:ArtemisIcon Icon="{Binding Icon}"></shared:ArtemisIcon>
|
||||
<shared:ArtemisIcon Icon="{Binding Plugin.Info.ResolvedIcon}"
|
||||
Margin="0 5 0 0"
|
||||
Width="20"
|
||||
Height="20"
|
||||
Grid.Row="0"
|
||||
Grid.RowSpan="3"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Top" />
|
||||
</controls:AppBar.AppIcon>
|
||||
</controls:AppBar>
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Shared;
|
||||
using Stylet;
|
||||
|
||||
@ -11,10 +12,10 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
public PluginSettingsWindowViewModel(PluginConfigurationViewModel configurationViewModel)
|
||||
{
|
||||
_configurationViewModel = configurationViewModel ?? throw new ArgumentNullException(nameof(configurationViewModel));
|
||||
Icon = configurationViewModel.Plugin.Info.Icon;
|
||||
Plugin = configurationViewModel.Plugin;
|
||||
}
|
||||
|
||||
public object Icon { get; }
|
||||
public Plugin Plugin { get; }
|
||||
|
||||
protected override void OnInitialActivate()
|
||||
{
|
||||
|
||||
@ -8,6 +8,7 @@ using Artemis.UI.Screens.Settings.Device;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using RGB.NET.Core;
|
||||
using Stylet;
|
||||
using KeyboardLayoutType = Artemis.Core.KeyboardLayoutType;
|
||||
|
||||
namespace Artemis.UI.Services
|
||||
@ -62,8 +63,11 @@ namespace Artemis.UI.Services
|
||||
private async void WindowServiceOnMainWindowOpened(object sender, EventArgs e)
|
||||
{
|
||||
List<ArtemisDevice> devices = _rgbService.Devices.Where(device => DeviceNeedsLayout(device) && !_ignoredDevices.Contains(device)).ToList();
|
||||
foreach (ArtemisDevice artemisDevice in devices)
|
||||
await RequestLayoutInput(artemisDevice);
|
||||
await Execute.OnUIThreadAsync(async () =>
|
||||
{
|
||||
foreach (ArtemisDevice artemisDevice in devices)
|
||||
await RequestLayoutInput(artemisDevice);
|
||||
});
|
||||
}
|
||||
|
||||
private async void RgbServiceOnDeviceAdded(object sender, DeviceEventArgs e)
|
||||
@ -77,7 +81,7 @@ namespace Artemis.UI.Services
|
||||
return;
|
||||
}
|
||||
|
||||
await RequestLayoutInput(e.Device);
|
||||
await Execute.OnUIThreadAsync(async () => await RequestLayoutInput(e.Device));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user