|
@@ -15,21 +15,20 @@ public class MouseBindings
|
|
|
public MouseBindings () { }
|
|
|
|
|
|
/// <summary>Adds a <see cref="MouseBinding"/> to the collection.</summary>
|
|
|
- /// <param name="mouseEvent"></param>
|
|
|
+ /// <param name="mouseEventArgs"></param>
|
|
|
/// <param name="binding"></param>
|
|
|
- public void Add (MouseEventArgs mouseEvent, MouseBinding binding)
|
|
|
+ public void Add (MouseEventArgs mouseEventArgs, MouseBinding binding)
|
|
|
{
|
|
|
- if (TryGet (mouseEvent, out MouseBinding _))
|
|
|
+ if (TryGet (mouseEventArgs, out MouseBinding _))
|
|
|
{
|
|
|
- throw new InvalidOperationException (@$"A binding for {mouseEvent} exists ({binding}).");
|
|
|
+ throw new InvalidOperationException (@$"A binding for {mouseEventArgs} exists ({binding}).");
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- // IMPORTANT: Add a COPY of the key. This is needed because ConfigurationManager.Apply uses DeepMemberWiseCopy
|
|
|
+ // IMPORTANT: Add a COPY of the mouseEventArgs. This is needed because ConfigurationManager.Apply uses DeepMemberWiseCopy
|
|
|
// IMPORTANT: update the memory referenced by the key, and Dictionary uses caching for performance, and thus
|
|
|
- // IMPORTANT: Apply will update the Dictionary with the new key, but the old key will still be in the dictionary.
|
|
|
+ // IMPORTANT: Apply will update the Dictionary with the new mouseEventArgs, but the old mouseEventArgs will still be in the dictionary.
|
|
|
// IMPORTANT: See the ConfigurationManager.Illustrate_DeepMemberWiseCopy_Breaks_Dictionary test for details.
|
|
|
- Bindings.Add (mouseEvent, binding);
|
|
|
+ Bindings.Add (mouseEventArgs, binding);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -43,15 +42,16 @@ public class MouseBindings
|
|
|
/// Commands are only ever applied to the current <see cref="View"/> (i.e. this feature cannot be used to switch
|
|
|
/// focus to another view and perform multiple commands there).
|
|
|
/// </remarks>
|
|
|
- /// <param name="mouseEvents">The mouse flags to check.</param>
|
|
|
+ /// <param name="mouseEventArgs">The mouse flags to check.</param>
|
|
|
/// <param name="commands">
|
|
|
- /// The command to invoked on the <see cref="View"/> when <paramref name="mouseEvents"/> is received. When
|
|
|
- /// multiple commands are provided,they will be applied in sequence. The bound <paramref name="mouseEvents"/> event will be
|
|
|
+ /// The command to invoked on the <see cref="View"/> when <paramref name="mouseEventArgs"/> is received. When
|
|
|
+ /// multiple commands are provided,they will be applied in sequence. The bound <paramref name="mouseEventArgs"/> event
|
|
|
+ /// will be
|
|
|
/// consumed if any took effect.
|
|
|
/// </param>
|
|
|
- public void Add (MouseEventArgs mouseEvents, params Command [] commands)
|
|
|
+ public void Add (MouseEventArgs mouseEventArgs, params Command [] commands)
|
|
|
{
|
|
|
- if (mouseEvents.Flags == MouseFlags.None)
|
|
|
+ if (mouseEventArgs.Flags == MouseFlags.None)
|
|
|
{
|
|
|
throw new ArgumentException (@"Invalid MouseFlag", nameof (commands));
|
|
|
}
|
|
@@ -61,12 +61,12 @@ public class MouseBindings
|
|
|
throw new ArgumentException (@"At least one command must be specified", nameof (commands));
|
|
|
}
|
|
|
|
|
|
- if (TryGet (mouseEvents, out MouseBinding binding))
|
|
|
+ if (TryGet (mouseEventArgs, out MouseBinding binding))
|
|
|
{
|
|
|
- throw new InvalidOperationException (@$"A binding for {mouseEvents} exists ({binding}).");
|
|
|
+ throw new InvalidOperationException (@$"A binding for {mouseEventArgs} exists ({binding}).");
|
|
|
}
|
|
|
|
|
|
- Add (mouseEvents, new MouseBinding (commands));
|
|
|
+ Add (mouseEventArgs, new MouseBinding (commands, mouseEventArgs));
|
|
|
}
|
|
|
|
|
|
// TODO: Add a dictionary comparer that ignores Scope
|
|
@@ -74,15 +74,6 @@ public class MouseBindings
|
|
|
/// <summary>The collection of <see cref="MouseBinding"/> objects.</summary>
|
|
|
public Dictionary<MouseEventArgs, MouseBinding> Bindings { get; } = new ();
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// Gets the <see cref="MouseEventArgs"/> that are bound.
|
|
|
- /// </summary>
|
|
|
- /// <returns></returns>
|
|
|
- public IEnumerable<MouseEventArgs> GetBoundMouseEventArgs ()
|
|
|
- {
|
|
|
- return Bindings.Keys;
|
|
|
- }
|
|
|
-
|
|
|
/// <summary>Removes all <see cref="MouseBinding"/> objects from the collection.</summary>
|
|
|
public void Clear () { Bindings.Clear (); }
|
|
|
|
|
@@ -94,8 +85,8 @@ public class MouseBindings
|
|
|
public void Clear (params Command [] command)
|
|
|
{
|
|
|
KeyValuePair<MouseEventArgs, MouseBinding> [] kvps = Bindings
|
|
|
- .Where (kvp => kvp.Value.Commands.SequenceEqual (command))
|
|
|
- .ToArray ();
|
|
|
+ .Where (kvp => kvp.Value.Commands.SequenceEqual (command))
|
|
|
+ .ToArray ();
|
|
|
|
|
|
foreach (KeyValuePair<MouseEventArgs, MouseBinding> kvp in kvps)
|
|
|
{
|
|
@@ -104,27 +95,48 @@ public class MouseBindings
|
|
|
}
|
|
|
|
|
|
/// <summary>Gets the <see cref="MouseBinding"/> for the specified combination of <see cref="MouseEventArgs"/>.</summary>
|
|
|
- /// <param name="mouseEvents"></param>
|
|
|
+ /// <param name="mouseEventArgs"></param>
|
|
|
/// <returns></returns>
|
|
|
- public MouseBinding Get (MouseEventArgs mouseEvents)
|
|
|
+ public MouseBinding Get (MouseEventArgs mouseEventArgs)
|
|
|
{
|
|
|
- if (TryGet (mouseEvents, out MouseBinding binding))
|
|
|
+ if (TryGet (mouseEventArgs, out MouseBinding binding))
|
|
|
{
|
|
|
return binding;
|
|
|
}
|
|
|
|
|
|
- throw new InvalidOperationException ($"{mouseEvents} is not bound.");
|
|
|
+ throw new InvalidOperationException ($"{mouseEventArgs} is not bound.");
|
|
|
}
|
|
|
|
|
|
- /// <summary>Gets the array of <see cref="Command"/>s bound to <paramref name="mouseEvents"/> if it exists.</summary>
|
|
|
- /// <param name="mouseEvents">The key to check.</param>
|
|
|
+ /// <summary>
|
|
|
+ /// Gets combination of <see cref="MouseEventArgs"/> bound to the set of commands specified by
|
|
|
+ /// <paramref name="commands"/>.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="commands">The set of commands to search.</param>
|
|
|
/// <returns>
|
|
|
- /// The array of <see cref="Command"/>s if <paramref name="mouseEvents"/> is bound. An empty <see cref="Command"/> array
|
|
|
+ /// The combination of <see cref="MouseEventArgs"/> bound to the set of commands specified by
|
|
|
+ /// <paramref name="commands"/>. An empty list if the set of caommands was not found.
|
|
|
+ /// </returns>
|
|
|
+ public IEnumerable<MouseEventArgs> GetAllMouseEventArgsFromCommands (params Command [] commands)
|
|
|
+ {
|
|
|
+ return Bindings.Where (a => a.Value.Commands.SequenceEqual (commands)).Select (a => a.Key);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Gets the <see cref="MouseEventArgs"/> that are bound.
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ public IEnumerable<MouseEventArgs> GetBoundMouseEventArgs () { return Bindings.Keys; }
|
|
|
+
|
|
|
+ /// <summary>Gets the array of <see cref="Command"/>s bound to <paramref name="mouseEventArgs"/> if it exists.</summary>
|
|
|
+ /// <param name="mouseEventArgs">The key to check.</param>
|
|
|
+ /// <returns>
|
|
|
+ /// The array of <see cref="Command"/>s if <paramref name="mouseEventArgs"/> is bound. An empty <see cref="Command"/>
|
|
|
+ /// array
|
|
|
/// if not.
|
|
|
/// </returns>
|
|
|
- public Command [] GetCommands (MouseEventArgs mouseEvents)
|
|
|
+ public Command [] GetCommands (MouseEventArgs mouseEventArgs)
|
|
|
{
|
|
|
- if (TryGet (mouseEvents, out MouseBinding bindings))
|
|
|
+ if (TryGet (mouseEventArgs, out MouseBinding bindings))
|
|
|
{
|
|
|
return bindings.Commands;
|
|
|
}
|
|
@@ -132,32 +144,30 @@ public class MouseBindings
|
|
|
return [];
|
|
|
}
|
|
|
|
|
|
- /// <summary>Gets the first combination of <see cref="MouseEventArgs"/> bound to the set of commands specified by <paramref name="commands"/>.</summary>
|
|
|
+ /// <summary>
|
|
|
+ /// Gets the first combination of <see cref="MouseEventArgs"/> bound to the set of commands specified by
|
|
|
+ /// <paramref name="commands"/>.
|
|
|
+ /// </summary>
|
|
|
/// <param name="commands">The set of commands to search.</param>
|
|
|
- /// <returns>The first combination of <see cref="MouseEventArgs"/> bound to the set of commands specified by <paramref name="commands"/>. <see langword="null"/> if the set of caommands was not found.</returns>
|
|
|
+ /// <returns>
|
|
|
+ /// The first combination of <see cref="MouseEventArgs"/> bound to the set of commands specified by
|
|
|
+ /// <paramref name="commands"/>. <see langword="null"/> if the set of caommands was not found.
|
|
|
+ /// </returns>
|
|
|
public MouseEventArgs? GetMouseEventArgsFromCommands (params Command [] commands)
|
|
|
{
|
|
|
return Bindings.FirstOrDefault (a => a.Value.Commands.SequenceEqual (commands)).Key;
|
|
|
}
|
|
|
|
|
|
- /// <summary>Gets combination of <see cref="MouseEventArgs"/> bound to the set of commands specified by <paramref name="commands"/>.</summary>
|
|
|
- /// <param name="commands">The set of commands to search.</param>
|
|
|
- /// <returns>The combination of <see cref="MouseEventArgs"/> bound to the set of commands specified by <paramref name="commands"/>. An empty list if the set of caommands was not found.</returns>
|
|
|
- public IEnumerable<MouseEventArgs> GetAllMouseEventArgsFromCommands (params Command [] commands)
|
|
|
- {
|
|
|
- return Bindings.Where (a => a.Value.Commands.SequenceEqual (commands)).Select (a => a.Key);
|
|
|
- }
|
|
|
-
|
|
|
/// <summary>Removes a <see cref="MouseBinding"/> from the collection.</summary>
|
|
|
- /// <param name="mouseEvents"></param>
|
|
|
- public void Remove (MouseEventArgs mouseEvents)
|
|
|
+ /// <param name="mouseEventArgs"></param>
|
|
|
+ public void Remove (MouseEventArgs mouseEventArgs)
|
|
|
{
|
|
|
- if (!TryGet (mouseEvents, out MouseBinding _))
|
|
|
+ if (!TryGet (mouseEventArgs, out MouseBinding _))
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- Bindings.Remove (mouseEvents);
|
|
|
+ Bindings.Remove (mouseEventArgs);
|
|
|
}
|
|
|
|
|
|
/// <summary>Replaces the commands already bound to a combination of <see cref="MouseEventArgs"/>.</summary>
|
|
@@ -166,24 +176,27 @@ public class MouseBindings
|
|
|
/// If the combination of <see cref="MouseEventArgs"/> is not already bound, it will be added.
|
|
|
/// </para>
|
|
|
/// </remarks>
|
|
|
- /// <param name="mouseEvents">The combination of <see cref="MouseEventArgs"/> bound to the command to be replaced.</param>
|
|
|
+ /// <param name="mouseEventArgs">The combination of <see cref="MouseEventArgs"/> bound to the command to be replaced.</param>
|
|
|
/// <param name="commands">The set of commands to replace the old ones with.</param>
|
|
|
- public void ReplaceCommands (MouseEventArgs mouseEvents, params Command [] commands)
|
|
|
+ public void ReplaceCommands (MouseEventArgs mouseEventArgs, params Command [] commands)
|
|
|
{
|
|
|
- if (TryGet (mouseEvents, out MouseBinding binding))
|
|
|
+ if (TryGet (mouseEventArgs, out MouseBinding binding))
|
|
|
{
|
|
|
binding.Commands = commands;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- Add (mouseEvents, commands);
|
|
|
+ Add (mouseEventArgs, commands);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>Replaces a <see cref="MouseEventArgs"/> combination already bound to a set of <see cref="Command"/>s.</summary>
|
|
|
/// <remarks></remarks>
|
|
|
/// <param name="oldMouseEventArgs">The <see cref="MouseEventArgs"/> to be replaced.</param>
|
|
|
- /// <param name="newMouseEventArgs">The new <see cref="MouseEventArgs"/> to be used. If <see cref="Key.Empty"/> no action will be taken.</param>
|
|
|
+ /// <param name="newMouseEventArgs">
|
|
|
+ /// The new <see cref="MouseEventArgs"/> to be used. If <see cref="Key.Empty"/> no action
|
|
|
+ /// will be taken.
|
|
|
+ /// </param>
|
|
|
public void ReplaceKey (MouseEventArgs oldMouseEventArgs, MouseEventArgs newMouseEventArgs)
|
|
|
{
|
|
|
if (!TryGet (oldMouseEventArgs, out MouseBinding _))
|
|
@@ -198,17 +211,16 @@ public class MouseBindings
|
|
|
|
|
|
/// <summary>Gets the commands bound with the specified <see cref="MouseEventArgs"/>.</summary>
|
|
|
/// <remarks></remarks>
|
|
|
- /// <param name="mouseEvents">The key to check.</param>
|
|
|
+ /// <param name="mouseEventArgs">The key to check.</param>
|
|
|
/// <param name="binding">
|
|
|
/// When this method returns, contains the commands bound with the specified mouse flags, if the mouse flags are
|
|
|
/// found; otherwise, null. This parameter is passed uninitialized.
|
|
|
/// </param>
|
|
|
/// <returns><see langword="true"/> if the mouse flags are bound; otherwise <see langword="false"/>.</returns>
|
|
|
- public bool TryGet (MouseEventArgs mouseEvents, out MouseBinding binding)
|
|
|
+ public bool TryGet (MouseEventArgs mouseEventArgs, out MouseBinding binding)
|
|
|
{
|
|
|
+ binding = new ([], mouseEventArgs);
|
|
|
|
|
|
- binding = new ([]);
|
|
|
-
|
|
|
- return Bindings.TryGetValue (mouseEvents, out binding);
|
|
|
+ return Bindings.TryGetValue (mouseEventArgs, out binding);
|
|
|
}
|
|
|
}
|