diff --git a/src/Artemis.Core/Models/ProfileConfiguration/ProfileConfigurationIcon.cs b/src/Artemis.Core/Models/ProfileConfiguration/ProfileConfigurationIcon.cs
index ff205f93d..46e5595a5 100644
--- a/src/Artemis.Core/Models/ProfileConfiguration/ProfileConfigurationIcon.cs
+++ b/src/Artemis.Core/Models/ProfileConfiguration/ProfileConfigurationIcon.cs
@@ -8,13 +8,10 @@ namespace Artemis.Core
///
/// Represents the icon of a
///
- public class ProfileConfigurationIcon : CorePropertyChanged, IStorageModel
+ public class ProfileConfigurationIcon : IStorageModel
{
private readonly ProfileConfigurationEntity _entity;
- private string? _iconName;
private Stream? _iconStream;
- private ProfileConfigurationIconType _iconType;
- private string? _originalFileName;
internal ProfileConfigurationIcon(ProfileConfigurationEntity entity)
{
@@ -24,29 +21,17 @@ namespace Artemis.Core
///
/// Gets the type of icon this profile configuration uses
///
- public ProfileConfigurationIconType IconType
- {
- get => _iconType;
- private set => SetAndNotify(ref _iconType, value);
- }
+ public ProfileConfigurationIconType IconType { get; private set; }
///
/// Gets the name of the icon if is
///
- public string? IconName
- {
- get => _iconName;
- private set => SetAndNotify(ref _iconName, value);
- }
+ public string? IconName { get; private set; }
///
/// Gets the original file name of the icon (if applicable)
///
- public string? OriginalFileName
- {
- get => _originalFileName;
- private set => SetAndNotify(ref _originalFileName, value);
- }
+ public string? OriginalFileName { get; private set; }
///
/// Updates the to the provided value and changes the is
@@ -55,11 +40,14 @@ namespace Artemis.Core
/// The name of the icon
public void SetIconByName(string iconName)
{
- IconName = iconName ?? throw new ArgumentNullException(nameof(iconName));
+ if (iconName == null) throw new ArgumentNullException(nameof(iconName));
+
+ _iconStream?.Dispose();
+ IconName = iconName;
OriginalFileName = null;
IconType = ProfileConfigurationIconType.MaterialIcon;
- _iconStream?.Dispose();
+ OnIconUpdated();
}
///
@@ -81,6 +69,7 @@ namespace Artemis.Core
IconName = null;
OriginalFileName = originalFileName;
IconType = OriginalFileName.EndsWith(".svg") ? ProfileConfigurationIconType.SvgImage : ProfileConfigurationIconType.BitmapImage;
+ OnIconUpdated();
}
///
@@ -100,14 +89,30 @@ namespace Artemis.Core
return stream;
}
+ ///
+ /// Occurs when the icon was updated
+ ///
+ public event EventHandler? IconUpdated;
+
+ ///
+ /// Invokes the event
+ ///
+ protected virtual void OnIconUpdated()
+ {
+ IconUpdated?.Invoke(this, EventArgs.Empty);
+ }
+
#region Implementation of IStorageModel
///
public void Load()
{
IconType = (ProfileConfigurationIconType) _entity.IconType;
- if (IconType == ProfileConfigurationIconType.MaterialIcon)
- IconName = _entity.MaterialIcon;
+ if (IconType != ProfileConfigurationIconType.MaterialIcon)
+ return;
+
+ IconName = _entity.MaterialIcon;
+ OnIconUpdated();
}
///
diff --git a/src/Avalonia/Artemis.UI.Shared/Controls/ProfileConfigurationIcon.axaml.cs b/src/Avalonia/Artemis.UI.Shared/Controls/ProfileConfigurationIcon.axaml.cs
index 6cbd39a0a..3037af3a8 100644
--- a/src/Avalonia/Artemis.UI.Shared/Controls/ProfileConfigurationIcon.axaml.cs
+++ b/src/Avalonia/Artemis.UI.Shared/Controls/ProfileConfigurationIcon.axaml.cs
@@ -1,5 +1,4 @@
using System;
-using System.ComponentModel;
using System.IO;
using Artemis.Core;
using Avalonia;
@@ -15,25 +14,6 @@ namespace Artemis.UI.Shared.Controls
{
public class ProfileConfigurationIcon : UserControl
{
- #region Properties
-
- ///
- /// Gets or sets the to display
- ///
- public static readonly StyledProperty ConfigurationIconProperty =
- AvaloniaProperty.Register(nameof(ConfigurationIcon));
-
- ///
- /// Gets or sets the to display
- ///
- public Core.ProfileConfigurationIcon? ConfigurationIcon
- {
- get => GetValue(ConfigurationIconProperty);
- set => SetValue(ConfigurationIconProperty, value);
- }
-
- #endregion
-
public ProfileConfigurationIcon()
{
InitializeComponent();
@@ -71,9 +51,13 @@ namespace Artemis.UI.Shared.Controls
Content = new Image {Source = new SvgImage {Source = source}};
}
else if (ConfigurationIcon.IconType == ProfileConfigurationIconType.BitmapImage)
+ {
Content = new Image {Source = new Bitmap(ConfigurationIcon.GetIconStream())};
+ }
else
+ {
Content = new MaterialIcon {Kind = MaterialIconKind.QuestionMark};
+ }
}
catch
{
@@ -86,34 +70,50 @@ namespace Artemis.UI.Shared.Controls
AvaloniaXamlLoader.Load(this);
}
- #region Event handlers
-
private void OnDetachedFromLogicalTree(object? sender, LogicalTreeAttachmentEventArgs e)
{
if (ConfigurationIcon != null)
- ConfigurationIcon.PropertyChanged -= IconOnPropertyChanged;
+ ConfigurationIcon.IconUpdated -= ConfigurationIconOnIconUpdated;
- if (Content is Image image && image.Source is IDisposable disposable)
+ if (Content is Image image && image.Source is IDisposable disposable)
disposable.Dispose();
}
private void OnPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
{
- if (e.Property == ConfigurationIconProperty)
- {
- if (e.OldValue is Core.ProfileConfigurationIcon oldIcon)
- oldIcon.PropertyChanged -= IconOnPropertyChanged;
- if (e.NewValue is Core.ProfileConfigurationIcon newIcon)
- newIcon.PropertyChanged += IconOnPropertyChanged;
- Update();
- }
+ if (e.Property != ConfigurationIconProperty)
+ return;
+
+ if (e.OldValue is Core.ProfileConfigurationIcon oldIcon)
+ oldIcon.IconUpdated -= ConfigurationIconOnIconUpdated;
+ if (e.NewValue is Core.ProfileConfigurationIcon newIcon)
+ newIcon.IconUpdated += ConfigurationIconOnIconUpdated;
+
+ Update();
}
- private void IconOnPropertyChanged(object? sender, PropertyChangedEventArgs e)
+ private void ConfigurationIconOnIconUpdated(object? sender, EventArgs e)
{
Update();
}
+ #region Properties
+
+ ///
+ /// Gets or sets the to display
+ ///
+ public static readonly StyledProperty ConfigurationIconProperty =
+ AvaloniaProperty.Register(nameof(ConfigurationIcon));
+
+ ///
+ /// Gets or sets the to display
+ ///
+ public Core.ProfileConfigurationIcon? ConfigurationIcon
+ {
+ get => GetValue(ConfigurationIconProperty);
+ set => SetValue(ConfigurationIconProperty, value);
+ }
+
#endregion
}
}
\ No newline at end of file
diff --git a/src/Avalonia/Artemis.UI/Ninject/Factories/IVMFactory.cs b/src/Avalonia/Artemis.UI/Ninject/Factories/IVMFactory.cs
index 7f83f4027..2248b2bdc 100644
--- a/src/Avalonia/Artemis.UI/Ninject/Factories/IVMFactory.cs
+++ b/src/Avalonia/Artemis.UI/Ninject/Factories/IVMFactory.cs
@@ -36,7 +36,7 @@ namespace Artemis.UI.Ninject.Factories
{
SidebarViewModel? SidebarViewModel(IScreen hostScreen);
SidebarCategoryViewModel SidebarCategoryViewModel(SidebarViewModel sidebarViewModel, ProfileCategory profileCategory);
- SidebarProfileConfigurationViewModel SidebarProfileConfigurationViewModel(ProfileConfiguration profileConfiguration);
+ SidebarProfileConfigurationViewModel SidebarProfileConfigurationViewModel(SidebarViewModel sidebarViewModel, ProfileConfiguration profileConfiguration);
}
public interface SurfaceVmFactory : IVmFactory
diff --git a/src/Avalonia/Artemis.UI/Screens/Root/Sidebar/Dialogs/ProfileConfigurationEditView.axaml b/src/Avalonia/Artemis.UI/Screens/Root/Sidebar/Dialogs/ProfileConfigurationEditView.axaml
index 8b36f089b..88bb927b5 100644
--- a/src/Avalonia/Artemis.UI/Screens/Root/Sidebar/Dialogs/ProfileConfigurationEditView.axaml
+++ b/src/Avalonia/Artemis.UI/Screens/Root/Sidebar/Dialogs/ProfileConfigurationEditView.axaml
@@ -72,10 +72,10 @@
-
+