mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Sidebar - Fixed removed categories not dissapearing
Sidebar - Fixed exception when creating a category with an already in use name
This commit is contained in:
1 parent
6a12286783
commit
d4bd44b504
10 files changed
+193
-144
No files matched your search
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
|
||||
namespace Artemis.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Provides data for profile configuration events.
|
||||
/// </summary>
|
||||
public class ProfileCategoryEventArgs : EventArgs
|
||||
{
|
||||
internal ProfileCategoryEventArgs(ProfileCategory profileCategory)
|
||||
{
|
||||
ProfileCategory = profileCategory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the profile category this event is related to
|
||||
/// </summary>
|
||||
public ProfileCategory ProfileCategory { get; }
|
||||
}
|
||||
@@ -20,9 +20,11 @@ public class ProfileCategory : CorePropertyChanged, IStorageModel
|
||||
/// Creates a new instance of the <see cref="ProfileCategory" /> class
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the category</param>
|
||||
internal ProfileCategory(string name)
|
||||
/// <param name="order">The order of the category</param>
|
||||
internal ProfileCategory(string name, int order)
|
||||
{
|
||||
_name = name;
|
||||
_order = order;
|
||||
Entity = new ProfileCategoryEntity();
|
||||
ProfileConfigurations = new ReadOnlyCollection<ProfileConfiguration>(_profileConfigurations);
|
||||
}
|
||||
|
||||
@@ -6,135 +6,135 @@ using SkiaSharp;
|
||||
namespace Artemis.Core.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Provides access to profile storage and is responsible for activating default profiles
|
||||
/// Provides access to profile storage and is responsible for activating default profiles.
|
||||
/// </summary>
|
||||
public interface IProfileService : IArtemisService
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the JSON serializer settings used to import/export profiles
|
||||
/// Gets the JSON serializer settings used to import/export profiles.
|
||||
/// </summary>
|
||||
public static JsonSerializerSettings ExportSettings { get; } = new() {TypeNameHandling = TypeNameHandling.All, Formatting = Formatting.Indented};
|
||||
|
||||
/// <summary>
|
||||
/// Gets a read only collection containing all the profile categories
|
||||
/// Gets a read only collection containing all the profile categories.
|
||||
/// </summary>
|
||||
ReadOnlyCollection<ProfileCategory> ProfileCategories { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a read only collection containing all the profile configurations
|
||||
/// Gets a read only collection containing all the profile configurations.
|
||||
/// </summary>
|
||||
ReadOnlyCollection<ProfileConfiguration> ProfileConfigurations { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a boolean indicating whether hotkeys are enabled
|
||||
/// Gets or sets a boolean indicating whether hotkeys are enabled.
|
||||
/// </summary>
|
||||
bool HotkeysEnabled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a boolean indicating whether rendering should only be done for profiles being edited
|
||||
/// Gets or sets a boolean indicating whether rendering should only be done for profiles being edited.
|
||||
/// </summary>
|
||||
bool RenderForEditor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the profile element to focus on while rendering for the editor
|
||||
/// Gets or sets the profile element to focus on while rendering for the editor.
|
||||
/// </summary>
|
||||
ProfileElement? EditorFocus { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Activates the profile of the given <see cref="ProfileConfiguration" /> with the currently active surface
|
||||
/// Activates the profile of the given <see cref="ProfileConfiguration" /> with the currently active surface.
|
||||
/// </summary>
|
||||
/// <param name="profileConfiguration">The profile configuration of the profile to activate</param>
|
||||
/// <param name="profileConfiguration">The profile configuration of the profile to activate.</param>
|
||||
Profile ActivateProfile(ProfileConfiguration profileConfiguration);
|
||||
|
||||
/// <summary>
|
||||
/// Deactivates the profile of the given <see cref="ProfileConfiguration" /> with the currently active surface
|
||||
/// Deactivates the profile of the given <see cref="ProfileConfiguration" /> with the currently active surface.
|
||||
/// </summary>
|
||||
/// <param name="profileConfiguration">The profile configuration of the profile to activate</param>
|
||||
/// <param name="profileConfiguration">The profile configuration of the profile to activate.</param>
|
||||
void DeactivateProfile(ProfileConfiguration profileConfiguration);
|
||||
|
||||
/// <summary>
|
||||
/// Permanently deletes the profile of the given <see cref="ProfileConfiguration" />
|
||||
/// Permanently deletes the profile of the given <see cref="ProfileConfiguration" />.
|
||||
/// </summary>
|
||||
/// <param name="profileConfiguration">The profile configuration of the profile to delete</param>
|
||||
/// <param name="profileConfiguration">The profile configuration of the profile to delete.</param>
|
||||
void DeleteProfile(ProfileConfiguration profileConfiguration);
|
||||
|
||||
/// <summary>
|
||||
/// Saves the provided <see cref="ProfileCategory" /> and it's <see cref="ProfileConfiguration" />s but not the
|
||||
/// <see cref="Profile" />s themselves
|
||||
/// <see cref="Profile" />s themselves.
|
||||
/// </summary>
|
||||
/// <param name="profileCategory">The profile category to update</param>
|
||||
/// <param name="profileCategory">The profile category to update.</param>
|
||||
void SaveProfileCategory(ProfileCategory profileCategory);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new profile category and saves it to persistent storage
|
||||
/// Creates a new profile category and saves it to persistent storage.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the new profile category, must be unique</param>
|
||||
/// <returns>The newly created profile category</returns>
|
||||
/// <param name="name">The name of the new profile category, must be unique.</param>
|
||||
/// <returns>The newly created profile category.</returns>
|
||||
ProfileCategory CreateProfileCategory(string name);
|
||||
|
||||
/// <summary>
|
||||
/// Permanently deletes the provided profile category
|
||||
/// Permanently deletes the provided profile category.
|
||||
/// </summary>
|
||||
void DeleteProfileCategory(ProfileCategory profileCategory);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new profile configuration and adds it to the provided <see cref="ProfileCategory" />
|
||||
/// Creates a new profile configuration and adds it to the provided <see cref="ProfileCategory" />.
|
||||
/// </summary>
|
||||
/// <param name="category">The profile category to add the profile to</param>
|
||||
/// <param name="name">The name of the new profile configuration</param>
|
||||
/// <param name="icon">The icon of the new profile configuration</param>
|
||||
/// <returns>The newly created profile configuration</returns>
|
||||
/// <param name="category">The profile category to add the profile to.</param>
|
||||
/// <param name="name">The name of the new profile configuration.</param>
|
||||
/// <param name="icon">The icon of the new profile configuration.</param>
|
||||
/// <returns>The newly created profile configuration.</returns>
|
||||
ProfileConfiguration CreateProfileConfiguration(ProfileCategory category, string name, string icon);
|
||||
|
||||
/// <summary>
|
||||
/// Removes the provided profile configuration from the <see cref="ProfileCategory" />
|
||||
/// Removes the provided profile configuration from the <see cref="ProfileCategory" />.
|
||||
/// </summary>
|
||||
/// <param name="profileConfiguration"></param>
|
||||
void RemoveProfileConfiguration(ProfileConfiguration profileConfiguration);
|
||||
|
||||
/// <summary>
|
||||
/// Loads the icon of this profile configuration if needed and puts it into <c>ProfileConfiguration.Icon.FileIcon</c>
|
||||
/// Loads the icon of this profile configuration if needed and puts it into <c>ProfileConfiguration.Icon.FileIcon</c>.
|
||||
/// </summary>
|
||||
void LoadProfileConfigurationIcon(ProfileConfiguration profileConfiguration);
|
||||
|
||||
/// <summary>
|
||||
/// Saves the current icon of this profile
|
||||
/// Saves the current icon of this profile.
|
||||
/// </summary>
|
||||
void SaveProfileConfigurationIcon(ProfileConfiguration profileConfiguration);
|
||||
|
||||
/// <summary>
|
||||
/// Writes the profile to persistent storage
|
||||
/// Writes the profile to persistent storage.
|
||||
/// </summary>
|
||||
/// <param name="profile"></param>
|
||||
/// <param name="includeChildren"></param>
|
||||
void SaveProfile(Profile profile, bool includeChildren);
|
||||
|
||||
/// <summary>
|
||||
/// Exports the profile described in the given <see cref="ProfileConfiguration" /> into an export model
|
||||
/// Exports the profile described in the given <see cref="ProfileConfiguration" /> into an export model.
|
||||
/// </summary>
|
||||
/// <param name="profileConfiguration">The profile configuration of the profile to export</param>
|
||||
/// <returns>The resulting export model</returns>
|
||||
/// <param name="profileConfiguration">The profile configuration of the profile to export.</param>
|
||||
/// <returns>The resulting export model.</returns>
|
||||
ProfileConfigurationExportModel ExportProfile(ProfileConfiguration profileConfiguration);
|
||||
|
||||
/// <summary>
|
||||
/// Imports the provided base64 encoded GZIPed JSON as a profile configuration
|
||||
/// Imports the provided base64 encoded GZIPed JSON as a profile configuration.
|
||||
/// </summary>
|
||||
/// <param name="category">The <see cref="ProfileCategory" /> in which to import the profile</param>
|
||||
/// <param name="exportModel">The model containing the profile to import</param>
|
||||
/// <param name="makeUnique">Whether or not to give the profile a new GUID, making it unique</param>
|
||||
/// <param name="category">The <see cref="ProfileCategory" /> in which to import the profile.</param>
|
||||
/// <param name="exportModel">The model containing the profile to import.</param>
|
||||
/// <param name="makeUnique">Whether or not to give the profile a new GUID, making it unique.</param>
|
||||
/// <param name="markAsFreshImport">
|
||||
/// Whether or not to mark the profile as a fresh import, causing it to be adapted until
|
||||
/// any changes are made to it
|
||||
/// any changes are made to it.
|
||||
/// </param>
|
||||
/// <param name="nameAffix">Text to add after the name of the profile (separated by a dash)</param>
|
||||
/// <returns>The resulting profile configuration</returns>
|
||||
/// <param name="nameAffix">Text to add after the name of the profile (separated by a dash).</param>
|
||||
/// <returns>The resulting profile configuration.</returns>
|
||||
ProfileConfiguration ImportProfile(ProfileCategory category, ProfileConfigurationExportModel exportModel, bool makeUnique = true, bool markAsFreshImport = true,
|
||||
string? nameAffix = "imported");
|
||||
|
||||
/// <summary>
|
||||
/// Adapts a given profile to the currently active devices
|
||||
/// Adapts a given profile to the currently active devices.
|
||||
/// </summary>
|
||||
/// <param name="profile">The profile to adapt</param>
|
||||
/// <param name="profile">The profile to adapt.</param>
|
||||
void AdaptProfile(Profile profile);
|
||||
|
||||
/// <summary>
|
||||
@@ -143,18 +143,28 @@ public interface IProfileService : IArtemisService
|
||||
void UpdateProfiles(double deltaTime);
|
||||
|
||||
/// <summary>
|
||||
/// Renders all currently active profiles
|
||||
/// Renders all currently active profiles.
|
||||
/// </summary>
|
||||
/// <param name="canvas"></param>
|
||||
void RenderProfiles(SKCanvas canvas);
|
||||
|
||||
/// <summary>
|
||||
/// Occurs whenever a profile has been activated
|
||||
/// Occurs whenever a profile has been activated.
|
||||
/// </summary>
|
||||
public event EventHandler<ProfileConfigurationEventArgs>? ProfileActivated;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs whenever a profile has been deactivated
|
||||
/// Occurs whenever a profile has been deactivated.
|
||||
/// </summary>
|
||||
public event EventHandler<ProfileConfigurationEventArgs>? ProfileDeactivated;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs whenever a profile category is added.
|
||||
/// </summary>
|
||||
public event EventHandler<ProfileCategoryEventArgs>? ProfileCategoryAdded;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs whenever a profile category is removed.
|
||||
/// </summary>
|
||||
public event EventHandler<ProfileCategoryEventArgs>? ProfileCategoryRemoved;
|
||||
}
|
||||
@@ -53,16 +53,6 @@ internal class ProfileService : IProfileService
|
||||
UpdateModules();
|
||||
}
|
||||
|
||||
protected virtual void OnProfileActivated(ProfileConfigurationEventArgs e)
|
||||
{
|
||||
ProfileActivated?.Invoke(this, e);
|
||||
}
|
||||
|
||||
protected virtual void OnProfileDeactivated(ProfileConfigurationEventArgs e)
|
||||
{
|
||||
ProfileDeactivated?.Invoke(this, e);
|
||||
}
|
||||
|
||||
private void InputServiceOnKeyboardKeyUp(object? sender, ArtemisKeyboardKeyEventArgs e)
|
||||
{
|
||||
if (!HotkeysEnabled)
|
||||
@@ -386,13 +376,16 @@ internal class ProfileService : IProfileService
|
||||
|
||||
public ProfileCategory CreateProfileCategory(string name)
|
||||
{
|
||||
ProfileCategory profileCategory;
|
||||
lock (_profileRepository)
|
||||
{
|
||||
ProfileCategory profileCategory = new(name);
|
||||
profileCategory = new ProfileCategory(name, _profileCategories.Count + 1);
|
||||
_profileCategories.Add(profileCategory);
|
||||
SaveProfileCategory(profileCategory);
|
||||
return profileCategory;
|
||||
}
|
||||
|
||||
OnProfileCategoryAdded(new ProfileCategoryEventArgs(profileCategory));
|
||||
return profileCategory;
|
||||
}
|
||||
|
||||
public void DeleteProfileCategory(ProfileCategory profileCategory)
|
||||
@@ -406,6 +399,8 @@ internal class ProfileService : IProfileService
|
||||
_profileCategories.Remove(profileCategory);
|
||||
_profileCategoryRepository.Remove(profileCategory.Entity);
|
||||
}
|
||||
|
||||
OnProfileCategoryRemoved(new ProfileCategoryEventArgs(profileCategory));
|
||||
}
|
||||
|
||||
public ProfileConfiguration CreateProfileConfiguration(ProfileCategory category, string name, string icon)
|
||||
@@ -543,6 +538,32 @@ internal class ProfileService : IProfileService
|
||||
_profileRepository.Save(profile.ProfileEntity);
|
||||
}
|
||||
|
||||
#region Events
|
||||
|
||||
public event EventHandler<ProfileConfigurationEventArgs>? ProfileActivated;
|
||||
public event EventHandler<ProfileConfigurationEventArgs>? ProfileDeactivated;
|
||||
public event EventHandler<ProfileCategoryEventArgs>? ProfileCategoryAdded;
|
||||
public event EventHandler<ProfileCategoryEventArgs>? ProfileCategoryRemoved;
|
||||
|
||||
protected virtual void OnProfileActivated(ProfileConfigurationEventArgs e)
|
||||
{
|
||||
ProfileActivated?.Invoke(this, e);
|
||||
}
|
||||
|
||||
protected virtual void OnProfileDeactivated(ProfileConfigurationEventArgs e)
|
||||
{
|
||||
ProfileDeactivated?.Invoke(this, e);
|
||||
}
|
||||
|
||||
protected virtual void OnProfileCategoryAdded(ProfileCategoryEventArgs e)
|
||||
{
|
||||
ProfileCategoryAdded?.Invoke(this, e);
|
||||
}
|
||||
|
||||
protected virtual void OnProfileCategoryRemoved(ProfileCategoryEventArgs e)
|
||||
{
|
||||
ProfileCategoryRemoved?.Invoke(this, e);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in new issue
Block a user