// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using System.Collections.Generic;
using CUE.NET.Devices.Keyboard.Enums;
namespace CUE.NET.Devices.Keyboard.Keys
{
///
/// Represents a keygroup containing arbitrary keys.
///
public class ListKeyGroup : AbstractKeyGroup
{
#region Properties & Fields
protected override IKeyGroup EffectTarget => this;
///
/// Gets the list containing the keys of this keygroup.
///
protected IList GroupKeys { get; } = new List();
#endregion
#region Constructors
///
/// Initializes a new instance of the class.
///
/// The keyboard this keygroup belongs to.
/// Specifies whether this keygroup should be automatically attached or not.
public ListKeyGroup(CorsairKeyboard keyboard, bool autoAttach = true)
: base(keyboard, autoAttach)
{ }
///
/// Initializes a new instance of the class.
///
/// The keyboard this keygroup belongs to.
/// The initial keys of this keygroup.
public ListKeyGroup(CorsairKeyboard keyboard, params CorsairKey[] keys)
: this(keyboard, true, keys)
{ }
///
/// Initializes a new instance of the class.
///
/// The keyboard this keygroup belongs to.
/// The initial keys of this keygroup.
public ListKeyGroup(CorsairKeyboard keyboard, IEnumerable keys)
: this(keyboard, true, keys)
{ }
///
/// Initializes a new instance of the class.
///
/// The keyboard this keygroup belongs to.
/// Specifies whether this keygroup should be automatically attached or not.
/// The initial keys of this keygroup.
public ListKeyGroup(CorsairKeyboard keyboard, bool autoAttach, IEnumerable keys)
: base(keyboard, autoAttach)
{
AddKeys(keys);
}
///
/// Initializes a new instance of the class.
///
/// The keyboard this keygroup belongs to.
/// Specifies whether this keygroup should be automatically attached or not.
/// The initial keys of this keygroup.
public ListKeyGroup(CorsairKeyboard keyboard, bool autoAttach, params CorsairKey[] keys)
: base(keyboard, autoAttach)
{
AddKeys(keys);
}
///
/// Initializes a new instance of the class.
///
/// The keyboard this keygroup belongs to.
/// The IDs of the initial keys of this keygroup.
public ListKeyGroup(CorsairKeyboard keyboard, params CorsairKeyboardKeyId[] keys)
: this(keyboard, true, keys)
{ }
///
/// Initializes a new instance of the class.
///
/// The keyboard this keygroup belongs to.
/// The IDs of the initial keys of this keygroup.
public ListKeyGroup(CorsairKeyboard keyboard, IEnumerable keys)
: this(keyboard, true, keys)
{ }
///
/// Initializes a new instance of the class.
///
/// The keyboard this keygroup belongs to.
/// Specifies whether this keygroup should be automatically attached or not.
/// The IDs of the initial keys of this keygroup.
public ListKeyGroup(CorsairKeyboard keyboard, bool autoAttach, params CorsairKeyboardKeyId[] keys)
: base(keyboard, autoAttach)
{
AddKeys(keys);
}
///
/// Initializes a new instance of the class.
///
/// The keyboard this keygroup belongs to.
/// Specifies whether this keygroup should be automatically attached or not.
/// The IDs of the initial keys of this keygroup.
public ListKeyGroup(CorsairKeyboard keyboard, bool autoAttach, IEnumerable keys)
: base(keyboard, autoAttach)
{
AddKeys(keys);
}
#endregion
#region Methods
///
/// Adds the given key(s) to the keygroup.
///
/// The key(s) to add.
public void AddKey(params CorsairKey[] keys)
{
AddKeys(keys);
}
///
/// Adds the given key(s) to the keygroup.
///
/// The ID(s) of the key(s) to add.
public void AddKey(params CorsairKeyboardKeyId[] keyIds)
{
AddKeys(keyIds);
}
///
/// Adds the given keys to the keygroup.
///
/// The keys to add.
public void AddKeys(IEnumerable keys)
{
if (keys != null)
foreach (CorsairKey key in keys)
if (key != null && !ContainsKey(key))
GroupKeys.Add(key);
}
///
/// Adds the given keys to the keygroup.
///
/// The IDs of the keys to add.
public void AddKeys(IEnumerable keyIds)
{
if (keyIds != null)
foreach (CorsairKeyboardKeyId keyId in keyIds)
AddKey(Keyboard[keyId]);
}
///
/// Removes the given key(s) from the keygroup.
///
/// The key(s) to remove.
public void RemoveKey(params CorsairKey[] keys)
{
RemoveKeys(keys);
}
///
/// Removes the given key(s) from the keygroup.
///
/// The ID(s) of the key(s) to remove.
public void RemoveKey(params CorsairKeyboardKeyId[] keyIds)
{
RemoveKeys(keyIds);
}
///
/// Removes the given keys from the keygroup.
///
/// The keys to remove.
public void RemoveKeys(IEnumerable keys)
{
if (keys != null)
foreach (CorsairKey key in keys)
if (key != null)
GroupKeys.Remove(key);
}
///
/// Removes the given keys from the keygroup.
///
/// The IDs of the keys to remove.
public void RemoveKeys(IEnumerable keyIds)
{
if (keyIds != null)
foreach (CorsairKeyboardKeyId keyId in keyIds)
RemoveKey(Keyboard[keyId]);
}
///
/// Checks if a given key is contained by this keygroup.
///
/// The key which should be checked.
/// true if the key is contained by this keygroup; otherwise, false.
public bool ContainsKey(CorsairKey key)
{
return key != null && GroupKeys.Contains(key);
}
///
/// Checks if a given key is contained by this keygroup.
///
/// The ID of the key which should be checked.
/// true if the key is contained by this keygroup; otherwise, false.
public bool ContainsKey(CorsairKeyboardKeyId keyId)
{
return ContainsKey(Keyboard[keyId]);
}
///
/// Merges the keys from the given keygroup in this keygroup.
///
/// The keygroup to merge.
public void MergeKeys(IKeyGroup groupToMerge)
{
foreach (CorsairKey key in groupToMerge.Keys)
if (!GroupKeys.Contains(key))
GroupKeys.Add(key);
}
///
/// Gets a list containing the keys from this group.
///
/// The list containing the keys.
protected override IList GetGroupKeys()
{
return GroupKeys;
}
#endregion
}
}