Profile configuration - Implemented hotkeys

Plugin import - Fixed folders causing errors in some ZIP formats
This commit is contained in:
Robert committed 2021-06-13 21:36:47 +02:00
1 parent 6e197d725a
commit a7c7d74e03
16 files changed
+494 -158

No files matched your search

@@ -92,6 +92,21 @@ namespace Artemis.Core
/// </summary>
public ProfileConfigurationIcon Icon { get; }
/// <summary>
/// Gets or sets the <see cref="ProfileConfigurationHotkeyMode" /> used to determine hotkey behaviour
/// </summary>
public ProfileConfigurationHotkeyMode HotkeyMode { get; set; }
/// <summary>
/// Gets or sets the hotkey used to enable or toggle the profile
/// </summary>
public ProfileConfigurationHotkey? EnableHotkey { get; set; }
/// <summary>
/// Gets or sets the hotkey used to disable the profile
/// </summary>
public ProfileConfigurationHotkey? DisableHotkey { get; set; }
/// <summary>
/// Gets the profile of this profile configuration
/// </summary>
@@ -151,6 +166,10 @@ namespace Artemis.Core
ActivationConditionMet = ActivationCondition == null || ActivationCondition.Evaluate();
}
/// <summary>
/// Determines whether the profile of this configuration should be active
/// </summary>
/// <param name="includeActivationCondition">Whether or not to take activation conditions into consideration</param>
public bool ShouldBeActive(bool includeActivationCondition)
{
if (_disposed)
@@ -201,13 +220,15 @@ namespace Artemis.Core
Name = Entity.Name;
IsSuspended = Entity.IsSuspended;
ActivationBehaviour = (ActivationBehaviour) Entity.ActivationBehaviour;
HotkeyMode = (ProfileConfigurationHotkeyMode) Entity.HotkeyMode;
Order = Entity.Order;
Icon.Load();
ActivationCondition = Entity.ActivationCondition != null
? new DataModelConditionGroup(null, Entity.ActivationCondition)
: null;
ActivationCondition = Entity.ActivationCondition != null ? new DataModelConditionGroup(null, Entity.ActivationCondition) : null;
EnableHotkey = Entity.EnableHotkey != null ? new ProfileConfigurationHotkey(Entity.EnableHotkey) : null;
DisableHotkey = Entity.DisableHotkey != null ? new ProfileConfigurationHotkey(Entity.DisableHotkey) : null;
}
/// <inheritdoc />
@@ -219,18 +240,19 @@ namespace Artemis.Core
Entity.Name = Name;
Entity.IsSuspended = IsSuspended;
Entity.ActivationBehaviour = (int) ActivationBehaviour;
Entity.HotkeyMode = (int) HotkeyMode;
Entity.ProfileCategoryId = Category.Entity.Id;
Entity.Order = Order;
Icon.Save();
if (ActivationCondition != null)
{
ActivationCondition.Save();
Entity.ActivationCondition = ActivationCondition.Entity;
}
else
Entity.ActivationCondition = null;
ActivationCondition?.Save();
Entity.ActivationCondition = ActivationCondition?.Entity;
EnableHotkey?.Save();
Entity.EnableHotkey = EnableHotkey?.Entity;
DisableHotkey?.Save();
Entity.DisableHotkey = DisableHotkey?.Entity;
if (!IsMissingModule)
Entity.ModuleId = Module?.Id;
@@ -238,4 +260,66 @@ namespace Artemis.Core
#endregion
}
/// <summary>
/// Represents a type of behaviour when this profile is activated
/// </summary>
public enum ActivationBehaviour
{
/// <summary>
/// Do nothing to other profiles
/// </summary>
None,
/// <summary>
/// Disable all other profiles
/// </summary>
DisableOthers,
/// <summary>
/// Disable all other profiles below this one
/// </summary>
DisableOthersBelow,
/// <summary>
/// Disable all other profiles above this one
/// </summary>
DisableOthersAbove,
/// <summary>
/// Disable all other profiles in the same category
/// </summary>
DisableOthersInCategory,
/// <summary>
/// Disable all other profiles below this one in the same category
/// </summary>
DisableOthersBelowInCategory,
/// <summary>
/// Disable all other profiles above this one in the same category
/// </summary>
DisableOthersAboveInCategory
}
/// <summary>
/// Represents a hotkey mode for a profile configuration
/// </summary>
public enum ProfileConfigurationHotkeyMode
{
/// <summary>
/// Use no hotkeys
/// </summary>
None,
/// <summary>
/// Toggle the profile with one hotkey
/// </summary>
Toggle,
/// <summary>
/// Enable and disable the profile with two separate hotkeys
/// </summary>
EnableDisable
}
}
@@ -0,0 +1,65 @@
using Artemis.Core.Services;
using Artemis.Storage.Entities.Profile;
namespace Artemis.Core
{
/// <summary>
/// Represents a key or combination of keys that changes the suspension status of a <see cref="ProfileConfiguration"/>
/// </summary>
public class ProfileConfigurationHotkey : CorePropertyChanged, IStorageModel
{
/// <summary>
/// Creates a new instance of <see cref="ProfileConfigurationHotkey" />
/// </summary>
public ProfileConfigurationHotkey()
{
Entity = new ProfileConfigurationHotkeyEntity();
}
internal ProfileConfigurationHotkey(ProfileConfigurationHotkeyEntity entity)
{
Entity = entity;
Load();
}
internal ProfileConfigurationHotkeyEntity Entity { get; }
/// <summary>
/// Gets or sets the <see cref="KeyboardKey" /> of the hotkey
/// </summary>
public KeyboardKey? Key { get; set; }
/// <summary>
/// Gets or sets the <see cref="KeyboardModifierKey" />s of the hotkey
/// </summary>
public KeyboardModifierKey? Modifiers { get; set; }
/// <summary>
/// Determines whether the provided <see cref="ArtemisKeyboardKeyEventArgs" /> match the hotkey
/// </summary>
/// <returns><see langword="true" /> if the event args match the hotkey; otherwise <see langword="false" /></returns>
public bool MatchesEventArgs(ArtemisKeyboardKeyEventArgs eventArgs)
{
return eventArgs.Key == Key && eventArgs.Modifiers == Modifiers;
}
#region Implementation of IStorageModel
/// <inheritdoc />
public void Load()
{
Key = (KeyboardKey?) Entity.Key;
Modifiers = (KeyboardModifierKey?) Entity.Modifiers;
}
/// <inheritdoc />
public void Save()
{
Entity.Key = (int?) Key;
Entity.Modifiers = (int?) Modifiers;
}
#endregion
}
}